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);
|
||||
} 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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user