Merge pull request #917 from Toocanzs/opponent-info
Continue to update opponent info while on screen
This commit is contained in:
@@ -39,6 +39,8 @@ public interface Client extends GameEngine
|
|||||||
|
|
||||||
List<NPC> getNpcs();
|
List<NPC> getNpcs();
|
||||||
|
|
||||||
|
NPC[] getCachedNPCs();
|
||||||
|
|
||||||
int getBoostedSkillLevel(Skill skill);
|
int getBoostedSkillLevel(Skill skill);
|
||||||
|
|
||||||
int getRealSkillLevel(Skill skill);
|
int getRealSkillLevel(Skill skill);
|
||||||
|
|||||||
@@ -34,4 +34,5 @@ public interface NPC extends Actor
|
|||||||
@Override
|
@Override
|
||||||
int getCombatLevel();
|
int getCombatLevel();
|
||||||
|
|
||||||
|
int getIndex();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import java.util.Map;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import net.runelite.api.Actor;
|
import net.runelite.api.Actor;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
|
import net.runelite.api.NPC;
|
||||||
import net.runelite.api.Player;
|
import net.runelite.api.Player;
|
||||||
import net.runelite.api.Varbits;
|
import net.runelite.api.Varbits;
|
||||||
import net.runelite.client.ui.overlay.Overlay;
|
import net.runelite.client.ui.overlay.Overlay;
|
||||||
@@ -60,6 +61,8 @@ class OpponentInfoOverlay extends Overlay
|
|||||||
private static final Duration WAIT = Duration.ofSeconds(3);
|
private static final Duration WAIT = Duration.ofSeconds(3);
|
||||||
|
|
||||||
private final Client client;
|
private final Client client;
|
||||||
|
private final NPC[] clientNpcs;
|
||||||
|
|
||||||
private Integer lastMaxHealth;
|
private Integer lastMaxHealth;
|
||||||
private DecimalFormat df = new DecimalFormat("0.0");
|
private DecimalFormat df = new DecimalFormat("0.0");
|
||||||
private float lastRatio = 0;
|
private float lastRatio = 0;
|
||||||
@@ -67,6 +70,7 @@ class OpponentInfoOverlay extends Overlay
|
|||||||
private String opponentName;
|
private String opponentName;
|
||||||
private String opponentsOpponentName;
|
private String opponentsOpponentName;
|
||||||
private Map<String, Integer> oppInfoHealth = OpponentInfoPlugin.loadNpcHealth();
|
private Map<String, Integer> oppInfoHealth = OpponentInfoPlugin.loadNpcHealth();
|
||||||
|
private NPC lastOpponent;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
OpponentInfoOverlay(Client client)
|
OpponentInfoOverlay(Client client)
|
||||||
@@ -74,6 +78,7 @@ class OpponentInfoOverlay extends Overlay
|
|||||||
setPosition(OverlayPosition.TOP_LEFT);
|
setPosition(OverlayPosition.TOP_LEFT);
|
||||||
setPriority(OverlayPriority.HIGH);
|
setPriority(OverlayPriority.HIGH);
|
||||||
this.client = client;
|
this.client = client;
|
||||||
|
this.clientNpcs = client.getCachedNPCs();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Actor getOpponent()
|
private Actor getOpponent()
|
||||||
@@ -92,6 +97,25 @@ class OpponentInfoOverlay extends Overlay
|
|||||||
{
|
{
|
||||||
Actor opponent = getOpponent();
|
Actor opponent = getOpponent();
|
||||||
|
|
||||||
|
// If opponent is null, try to use last opponent
|
||||||
|
if (opponent == null)
|
||||||
|
{
|
||||||
|
if (lastOpponent != null && clientNpcs[lastOpponent.getIndex()] != lastOpponent)
|
||||||
|
{
|
||||||
|
// lastOpponent is no longer valid
|
||||||
|
lastOpponent = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
opponent = lastOpponent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Update last opponent
|
||||||
|
lastOpponent = opponent instanceof NPC ? (NPC) opponent : null;
|
||||||
|
}
|
||||||
|
|
||||||
if (opponent != null && opponent.getHealth() > 0)
|
if (opponent != null && opponent.getHealth() > 0)
|
||||||
{
|
{
|
||||||
lastTime = Instant.now();
|
lastTime = Instant.now();
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ import net.runelite.rs.api.RSDeque;
|
|||||||
import net.runelite.rs.api.RSHashTable;
|
import net.runelite.rs.api.RSHashTable;
|
||||||
import net.runelite.rs.api.RSIndexedSprite;
|
import net.runelite.rs.api.RSIndexedSprite;
|
||||||
import net.runelite.rs.api.RSItemContainer;
|
import net.runelite.rs.api.RSItemContainer;
|
||||||
|
import net.runelite.rs.api.RSNPC;
|
||||||
import net.runelite.rs.api.RSName;
|
import net.runelite.rs.api.RSName;
|
||||||
import net.runelite.rs.api.RSWidget;
|
import net.runelite.rs.api.RSWidget;
|
||||||
|
|
||||||
@@ -494,6 +495,24 @@ public abstract class RSClientMixin implements RSClient
|
|||||||
eventBus.post(gameStateChange);
|
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
|
@Inject
|
||||||
@FieldHook("grandExchangeOffers")
|
@FieldHook("grandExchangeOffers")
|
||||||
public static void onGrandExchangeOffersChanged(int idx)
|
public static void onGrandExchangeOffersChanged(int idx)
|
||||||
|
|||||||
@@ -32,6 +32,9 @@ import net.runelite.rs.api.RSNPCComposition;
|
|||||||
@Mixin(RSNPC.class)
|
@Mixin(RSNPC.class)
|
||||||
public abstract class RSNPCMixin implements RSNPC
|
public abstract class RSNPCMixin implements RSNPC
|
||||||
{
|
{
|
||||||
|
@Inject
|
||||||
|
private int npcIndex;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Override
|
@Override
|
||||||
public int getId()
|
public int getId()
|
||||||
@@ -55,4 +58,18 @@ public abstract class RSNPCMixin implements RSNPC
|
|||||||
RSNPCComposition composition = getComposition();
|
RSNPCComposition composition = getComposition();
|
||||||
return composition == null ? -1 : composition.getCombatLevel();
|
return composition == null ? -1 : composition.getCombatLevel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
@Override
|
||||||
|
public int getIndex()
|
||||||
|
{
|
||||||
|
return npcIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
@Override
|
||||||
|
public void setIndex(int id)
|
||||||
|
{
|
||||||
|
npcIndex = id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,6 +129,7 @@ public interface RSClient extends RSGameEngine, Client
|
|||||||
int[] getNpcIndices();
|
int[] getNpcIndices();
|
||||||
|
|
||||||
@Import("cachedNPCs")
|
@Import("cachedNPCs")
|
||||||
|
@Override
|
||||||
RSNPC[] getCachedNPCs();
|
RSNPC[] getCachedNPCs();
|
||||||
|
|
||||||
@Import("collisionMaps")
|
@Import("collisionMaps")
|
||||||
|
|||||||
@@ -31,4 +31,9 @@ public interface RSNPC extends RSActor, NPC
|
|||||||
{
|
{
|
||||||
@Import("composition")
|
@Import("composition")
|
||||||
RSNPCComposition getComposition();
|
RSNPCComposition getComposition();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
int getIndex();
|
||||||
|
|
||||||
|
void setIndex(int id);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user