Fixed an issue that was leading to unreliable respawn mechanics on multi-behavior NPCs
This commit is contained in:
@@ -13,6 +13,7 @@ class ImplingSpawnerBehavior : NPCBehavior (*ImplingSpawner.getIds()) {
|
|||||||
val isPuro = isPuroSpawner(self)
|
val isPuro = isPuroSpawner(self)
|
||||||
val delay = if (isPuro) 120 else 180
|
val delay = if (isPuro) 120 else 180
|
||||||
setAttribute(self, "transformTime", getWorldTicks() + secondsToTicks(delay))
|
setAttribute(self, "transformTime", getWorldTicks() + secondsToTicks(delay))
|
||||||
|
self.setRespawnTicks(3)
|
||||||
self.isRespawn = isPuro
|
self.isRespawn = isPuro
|
||||||
self.walkRadius = if (isPuro) 20 else 100
|
self.walkRadius = if (isPuro) 20 else 100
|
||||||
self.isWalks = true
|
self.isWalks = true
|
||||||
|
|||||||
@@ -145,6 +145,8 @@ public class NPC extends Entity {
|
|||||||
|
|
||||||
public NPCBehavior behavior;
|
public NPCBehavior behavior;
|
||||||
|
|
||||||
|
public boolean isRespawning = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new {@code NPC} {@code Object}.
|
* Constructs a new {@code NPC} {@code Object}.
|
||||||
* @param id The NPC id.
|
* @param id The NPC id.
|
||||||
@@ -403,9 +405,10 @@ public class NPC extends Entity {
|
|||||||
teleport(getProperties().getSpawnLocation());
|
teleport(getProperties().getSpawnLocation());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (respawnTick == GameWorld.getTicks()) {
|
if (isRespawning && respawnTick <= GameWorld.getTicks()) {
|
||||||
behavior.onRespawn(this);
|
behavior.onRespawn(this);
|
||||||
onRespawn();
|
onRespawn();
|
||||||
|
isRespawning = false;
|
||||||
}
|
}
|
||||||
handleTickActions();
|
handleTickActions();
|
||||||
super.tick();
|
super.tick();
|
||||||
@@ -525,7 +528,6 @@ public class NPC extends Entity {
|
|||||||
if (getZoneMonitor().handleDeath(killer)) {
|
if (getZoneMonitor().handleDeath(killer)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setRespawnTick(GameWorld.getTicks() + definition.getConfiguration(NPCConfigParser.RESPAWN_DELAY, 17));
|
|
||||||
Player p = !(killer instanceof Player) ? null : (Player) killer;
|
Player p = !(killer instanceof Player) ? null : (Player) killer;
|
||||||
if (p != null) {
|
if (p != null) {
|
||||||
p.incrementAttribute("/save:" + STATS_BASE + ":" + STATS_ENEMIES_KILLED);
|
p.incrementAttribute("/save:" + STATS_BASE + ":" + STATS_ENEMIES_KILLED);
|
||||||
@@ -534,10 +536,16 @@ public class NPC extends Entity {
|
|||||||
handleDrops(p, killer);
|
handleDrops(p, killer);
|
||||||
if (!isRespawn())
|
if (!isRespawn())
|
||||||
clear();
|
clear();
|
||||||
killer.dispatch(new NPCKillEvent(this));
|
isRespawning = true;
|
||||||
behavior.onDeathFinished(this, killer);
|
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
|
@Override
|
||||||
public void commenceDeath(Entity killer) {
|
public void commenceDeath(Entity killer) {
|
||||||
behavior.onDeathStarted(this, killer);
|
behavior.onDeathStarted(this, killer);
|
||||||
|
|||||||
Reference in New Issue
Block a user