Flag npc as dead when their health ratio hits 0
Sometimes npcs despawn without their HP var visible after death
This commit is contained in:
@@ -65,4 +65,11 @@ public interface NPC extends Actor
|
|||||||
* @return the transformed NPC
|
* @return the transformed NPC
|
||||||
*/
|
*/
|
||||||
NPCComposition getTransformedComposition();
|
NPCComposition getTransformedComposition();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if this NPC has died
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
boolean isDead();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ import net.runelite.rs.api.RSCombatInfo2;
|
|||||||
import net.runelite.rs.api.RSCombatInfoList;
|
import net.runelite.rs.api.RSCombatInfoList;
|
||||||
import net.runelite.rs.api.RSCombatInfoListHolder;
|
import net.runelite.rs.api.RSCombatInfoListHolder;
|
||||||
import net.runelite.rs.api.RSModel;
|
import net.runelite.rs.api.RSModel;
|
||||||
|
import net.runelite.rs.api.RSNPC;
|
||||||
import net.runelite.rs.api.RSNode;
|
import net.runelite.rs.api.RSNode;
|
||||||
|
|
||||||
@Mixin(RSActor.class)
|
@Mixin(RSActor.class)
|
||||||
@@ -235,12 +236,19 @@ public abstract class RSActorMixin implements RSActor
|
|||||||
@MethodHook("setCombatInfo")
|
@MethodHook("setCombatInfo")
|
||||||
public void setCombatInfo(int combatInfoId, int gameCycle, int var3, int var4, int healthRatio, int health)
|
public void setCombatInfo(int combatInfoId, int gameCycle, int var3, int var4, int healthRatio, int health)
|
||||||
{
|
{
|
||||||
if (healthRatio == 0 && this == client.getLocalPlayer())
|
if (healthRatio == 0)
|
||||||
{
|
{
|
||||||
log.debug("You died!");
|
if (this == client.getLocalPlayer())
|
||||||
|
{
|
||||||
|
log.debug("You died!");
|
||||||
|
|
||||||
LocalPlayerDeath event = new LocalPlayerDeath();
|
LocalPlayerDeath event = new LocalPlayerDeath();
|
||||||
eventBus.post(event);
|
eventBus.post(event);
|
||||||
|
}
|
||||||
|
else if (this instanceof RSNPC)
|
||||||
|
{
|
||||||
|
((RSNPC) this).setDead(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,9 @@ public abstract class RSNPCMixin implements RSNPC
|
|||||||
@Inject
|
@Inject
|
||||||
private int npcIndex;
|
private int npcIndex;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private boolean dead;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Override
|
@Override
|
||||||
public int getId()
|
public int getId()
|
||||||
@@ -149,4 +152,18 @@ public abstract class RSNPCMixin implements RSNPC
|
|||||||
}
|
}
|
||||||
return composition;
|
return composition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
@Override
|
||||||
|
public boolean isDead()
|
||||||
|
{
|
||||||
|
return dead;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
@Override
|
||||||
|
public void setDead(boolean dead)
|
||||||
|
{
|
||||||
|
this.dead = dead;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,4 +37,6 @@ public interface RSNPC extends RSActor, NPC
|
|||||||
int getIndex();
|
int getIndex();
|
||||||
|
|
||||||
void setIndex(int id);
|
void setIndex(int id);
|
||||||
|
|
||||||
|
void setDead(boolean dead);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user