Skip to content

Commit

Permalink
Flag npc as dead when their health ratio hits 0
Browse files Browse the repository at this point in the history
Sometimes npcs despawn without their HP var visible after death
  • Loading branch information
Adam- committed May 31, 2018
1 parent fd3a27f commit 8a6fc94
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
7 changes: 7 additions & 0 deletions runelite-api/src/main/java/net/runelite/api/NPC.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,11 @@ public interface NPC extends Actor
* @return the transformed NPC
*/
NPCComposition getTransformedComposition();

/**
* Returns true if this NPC has died
*
* @return
*/
boolean isDead();
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import net.runelite.rs.api.RSCombatInfoList;
import net.runelite.rs.api.RSCombatInfoListHolder;
import net.runelite.rs.api.RSModel;
import net.runelite.rs.api.RSNPC;
import net.runelite.rs.api.RSNode;

@Mixin(RSActor.class)
Expand Down Expand Up @@ -235,12 +236,19 @@ public WorldArea getWorldArea()
@MethodHook("setCombatInfo")
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();
eventBus.post(event);
LocalPlayerDeath event = new LocalPlayerDeath();
eventBus.post(event);
}
else if (this instanceof RSNPC)
{
((RSNPC) this).setDead(true);
}
}
}
}
17 changes: 17 additions & 0 deletions runelite-mixins/src/main/java/net/runelite/mixins/RSNPCMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public abstract class RSNPCMixin implements RSNPC
@Inject
private int npcIndex;

@Inject
private boolean dead;

@Inject
@Override
public int getId()
Expand Down Expand Up @@ -149,4 +152,18 @@ public NPCComposition getTransformedComposition()
}
return composition;
}

@Inject
@Override
public boolean isDead()
{
return dead;
}

@Inject
@Override
public void setDead(boolean dead)
{
this.dead = dead;
}
}
2 changes: 2 additions & 0 deletions runescape-api/src/main/java/net/runelite/rs/api/RSNPC.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ public interface RSNPC extends RSActor, NPC
int getIndex();

void setIndex(int id);

void setDead(boolean dead);
}

0 comments on commit 8a6fc94

Please sign in to comment.