Delete npc monsters when winning a battle

This commit is contained in:
Melledy
2023-09-26 03:21:03 -07:00
parent 769a288e7b
commit 5a21304b3f
3 changed files with 18 additions and 7 deletions

View File

@@ -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

View File

@@ -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()

View File

@@ -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()));
} }