mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-12 21:34:35 +01:00
Delete npc monsters when winning a battle
This commit is contained in:
@@ -66,6 +66,7 @@ public class BattleService extends BaseGameService {
|
|||||||
monsters.add(monster);
|
monsters.add(monster);
|
||||||
} else if (entity instanceof EntityProp) {
|
} else if (entity instanceof EntityProp) {
|
||||||
it.remove();
|
it.remove();
|
||||||
|
player.getScene().removeEntity(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,7 +113,10 @@ public class BattleService extends BaseGameService {
|
|||||||
|
|
||||||
// Delete enemies if the player won
|
// Delete enemies if the player won
|
||||||
if (result == BattleEndStatus.BATTLE_END_WIN) {
|
if (result == BattleEndStatus.BATTLE_END_WIN) {
|
||||||
|
// Could optimize it a little better
|
||||||
|
for (var monster : battle.getNpcMonsters()) {
|
||||||
|
player.getScene().removeEntity(monster);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Done - Clear battle object from player
|
// Done - Clear battle object from player
|
||||||
|
|||||||
@@ -176,11 +176,18 @@ public class Scene {
|
|||||||
this.entities.put(entity.getEntityId(), entity);
|
this.entities.put(entity.getEntityId(), entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public synchronized void removeEntity(GameEntity entity) {
|
||||||
|
removeEntity(entity.getEntityId());
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized void removeEntity(int entityId) {
|
public synchronized void removeEntity(int entityId) {
|
||||||
GameEntity entity = this.entities.remove(entityId);
|
GameEntity entity = this.entities.remove(entityId);
|
||||||
// TODO send packet
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (entity != null) {
|
||||||
|
player.sendPacket(new PacketSceneGroupRefreshScNotify(null, entity));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public SceneInfo toProto() {
|
public SceneInfo toProto() {
|
||||||
// Proto
|
// Proto
|
||||||
var proto = SceneInfo.newInstance()
|
var proto = SceneInfo.newInstance()
|
||||||
|
|||||||
@@ -14,13 +14,13 @@ public class PacketSceneGroupRefreshScNotify extends BasePacket {
|
|||||||
public PacketSceneGroupRefreshScNotify(GameEntity toAdd, GameEntity toRemove) {
|
public PacketSceneGroupRefreshScNotify(GameEntity toAdd, GameEntity toRemove) {
|
||||||
super(CmdId.SceneGroupRefreshScNotify);
|
super(CmdId.SceneGroupRefreshScNotify);
|
||||||
|
|
||||||
var group = SceneGroupRefreshInfo.newInstance().setGroupId(toAdd.getGroupId());
|
var group = SceneGroupRefreshInfo.newInstance();
|
||||||
|
|
||||||
if (toAdd != null) {
|
if (toAdd != null) {
|
||||||
|
group.setGroupId(toAdd.getGroupId());
|
||||||
group.addRefreshEntity(SceneEntityRefreshInfo.newInstance().setAddEntity(toAdd.toSceneEntityProto()));
|
group.addRefreshEntity(SceneEntityRefreshInfo.newInstance().setAddEntity(toAdd.toSceneEntityProto()));
|
||||||
}
|
} else if (toRemove != null) {
|
||||||
|
group.setGroupId(toRemove.getGroupId());
|
||||||
if (toRemove != null) {
|
|
||||||
group.addRefreshEntity(SceneEntityRefreshInfo.newInstance().setDelEntity(toRemove.getEntityId()));
|
group.addRefreshEntity(SceneEntityRefreshInfo.newInstance().setDelEntity(toRemove.getEntityId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user