runelite-api: add ability to get npc index

This commit is contained in:
Adam
2018-03-10 09:54:47 -05:00
parent c3920e5814
commit 7320a4f61a
4 changed files with 42 additions and 0 deletions

View File

@@ -34,4 +34,5 @@ public interface NPC extends Actor
@Override
int getCombatLevel();
int getIndex();
}

View File

@@ -65,6 +65,7 @@ import net.runelite.rs.api.RSDeque;
import net.runelite.rs.api.RSHashTable;
import net.runelite.rs.api.RSIndexedSprite;
import net.runelite.rs.api.RSItemContainer;
import net.runelite.rs.api.RSNPC;
import net.runelite.rs.api.RSName;
import net.runelite.rs.api.RSWidget;
@@ -494,6 +495,24 @@ public abstract class RSClientMixin implements RSClient
eventBus.post(gameStateChange);
}
@FieldHook("cachedNPCs")
@Inject
public static void cachedNPCsChanged(int idx)
{
RSNPC[] cachedNPCs = client.getCachedNPCs();
if (idx < 0 || idx >= cachedNPCs.length)
{
return;
}
RSNPC npc = cachedNPCs[idx];
if (npc != null)
{
npc.setIndex(idx);
}
}
@Inject
@FieldHook("grandExchangeOffers")
public static void onGrandExchangeOffersChanged(int idx)

View File

@@ -32,6 +32,9 @@ import net.runelite.rs.api.RSNPCComposition;
@Mixin(RSNPC.class)
public abstract class RSNPCMixin implements RSNPC
{
@Inject
private int npcIndex;
@Inject
@Override
public int getId()
@@ -55,4 +58,18 @@ public abstract class RSNPCMixin implements RSNPC
RSNPCComposition composition = getComposition();
return composition == null ? -1 : composition.getCombatLevel();
}
@Inject
@Override
public int getIndex()
{
return npcIndex;
}
@Inject
@Override
public void setIndex(int id)
{
npcIndex = id;
}
}

View File

@@ -31,4 +31,9 @@ public interface RSNPC extends RSActor, NPC
{
@Import("composition")
RSNPCComposition getComposition();
@Override
int getIndex();
void setIndex(int id);
}