From f7b707c3da6e63895988f923cf743ae2f635d64b Mon Sep 17 00:00:00 2001 From: Ceikry Date: Tue, 16 May 2023 12:42:22 +0000 Subject: [PATCH] Fixed an issue that was leading to unreliable respawn mechanics on multi-behavior NPCs --- .../hunter/implings/ImplingSpawnerBehavior.kt | 1 + .../src/main/core/game/node/entity/npc/NPC.java | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Server/src/main/content/global/skill/hunter/implings/ImplingSpawnerBehavior.kt b/Server/src/main/content/global/skill/hunter/implings/ImplingSpawnerBehavior.kt index d00142473..e431eac0f 100644 --- a/Server/src/main/content/global/skill/hunter/implings/ImplingSpawnerBehavior.kt +++ b/Server/src/main/content/global/skill/hunter/implings/ImplingSpawnerBehavior.kt @@ -13,6 +13,7 @@ class ImplingSpawnerBehavior : NPCBehavior (*ImplingSpawner.getIds()) { val isPuro = isPuroSpawner(self) val delay = if (isPuro) 120 else 180 setAttribute(self, "transformTime", getWorldTicks() + secondsToTicks(delay)) + self.setRespawnTicks(3) self.isRespawn = isPuro self.walkRadius = if (isPuro) 20 else 100 self.isWalks = true diff --git a/Server/src/main/core/game/node/entity/npc/NPC.java b/Server/src/main/core/game/node/entity/npc/NPC.java index bb3324f47..696f5c6dc 100644 --- a/Server/src/main/core/game/node/entity/npc/NPC.java +++ b/Server/src/main/core/game/node/entity/npc/NPC.java @@ -145,6 +145,8 @@ public class NPC extends Entity { public NPCBehavior behavior; + public boolean isRespawning = false; + /** * Constructs a new {@code NPC} {@code Object}. * @param id The NPC id. @@ -403,9 +405,10 @@ public class NPC extends Entity { teleport(getProperties().getSpawnLocation()); return; } - if (respawnTick == GameWorld.getTicks()) { - behavior.onRespawn(this); + if (isRespawning && respawnTick <= GameWorld.getTicks()) { + behavior.onRespawn(this); onRespawn(); + isRespawning = false; } handleTickActions(); super.tick(); @@ -525,7 +528,6 @@ public class NPC extends Entity { if (getZoneMonitor().handleDeath(killer)) { return; } - setRespawnTick(GameWorld.getTicks() + definition.getConfiguration(NPCConfigParser.RESPAWN_DELAY, 17)); Player p = !(killer instanceof Player) ? null : (Player) killer; if (p != null) { p.incrementAttribute("/save:" + STATS_BASE + ":" + STATS_ENEMIES_KILLED); @@ -534,10 +536,16 @@ public class NPC extends Entity { handleDrops(p, killer); if (!isRespawn()) clear(); - killer.dispatch(new NPCKillEvent(this)); + isRespawning = true; behavior.onDeathFinished(this, killer); + killer.dispatch(new NPCKillEvent(this)); + setRespawnTick(GameWorld.getTicks() + definition.getConfiguration(NPCConfigParser.RESPAWN_DELAY, 17)); } + public void setRespawnTicks (int ticks) { + definition.getHandlers().put(NPCConfigParser.RESPAWN_DELAY, ticks); + } + @Override public void commenceDeath(Entity killer) { behavior.onDeathStarted(this, killer);