Fixed an issue that was leading to unreliable respawn mechanics on multi-behavior NPCs

This commit is contained in:
Ceikry
2023-05-16 12:42:22 +00:00
committed by Ryan
parent c04ee0f821
commit f7b707c3da
2 changed files with 13 additions and 4 deletions
@@ -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
@@ -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);