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);
} else if (entity instanceof EntityProp) {
it.remove();
player.getScene().removeEntity(entity);
}
}
@@ -112,7 +113,10 @@ public class BattleService extends BaseGameService {
// Delete enemies if the player won
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

View File

@@ -176,11 +176,18 @@ public class Scene {
this.entities.put(entity.getEntityId(), entity);
}
public synchronized void removeEntity(GameEntity entity) {
removeEntity(entity.getEntityId());
}
public synchronized void removeEntity(int entityId) {
GameEntity entity = this.entities.remove(entityId);
// TODO send packet
}
if (entity != null) {
player.sendPacket(new PacketSceneGroupRefreshScNotify(null, entity));
}
}
public SceneInfo toProto() {
// Proto
var proto = SceneInfo.newInstance()

View File

@@ -14,13 +14,13 @@ public class PacketSceneGroupRefreshScNotify extends BasePacket {
public PacketSceneGroupRefreshScNotify(GameEntity toAdd, GameEntity toRemove) {
super(CmdId.SceneGroupRefreshScNotify);
var group = SceneGroupRefreshInfo.newInstance().setGroupId(toAdd.getGroupId());
var group = SceneGroupRefreshInfo.newInstance();
if (toAdd != null) {
group.setGroupId(toAdd.getGroupId());
group.addRefreshEntity(SceneEntityRefreshInfo.newInstance().setAddEntity(toAdd.toSceneEntityProto()));
}
if (toRemove != null) {
} else if (toRemove != null) {
group.setGroupId(toRemove.getGroupId());
group.addRefreshEntity(SceneEntityRefreshInfo.newInstance().setDelEntity(toRemove.getEntityId()));
}