opponent info: use player hitpoints from hiscores
This commit is contained in:
@@ -38,6 +38,7 @@ import net.runelite.api.Client;
|
||||
import net.runelite.api.NPC;
|
||||
import net.runelite.api.Player;
|
||||
import net.runelite.api.Varbits;
|
||||
import net.runelite.client.game.HiscoreManager;
|
||||
import net.runelite.client.ui.overlay.Overlay;
|
||||
import net.runelite.client.ui.overlay.OverlayPosition;
|
||||
import net.runelite.client.ui.overlay.OverlayPriority;
|
||||
@@ -45,6 +46,7 @@ import net.runelite.client.ui.overlay.components.PanelComponent;
|
||||
import net.runelite.client.ui.overlay.components.ProgressBarComponent;
|
||||
import net.runelite.client.ui.overlay.components.TitleComponent;
|
||||
import net.runelite.client.util.Text;
|
||||
import net.runelite.http.api.hiscore.HiscoreResult;
|
||||
|
||||
class OpponentInfoOverlay extends Overlay
|
||||
{
|
||||
@@ -53,6 +55,9 @@ class OpponentInfoOverlay extends Overlay
|
||||
private static final Duration WAIT = Duration.ofSeconds(3);
|
||||
|
||||
private final Client client;
|
||||
private final OpponentInfoPlugin opponentInfoPlugin;
|
||||
private final HiscoreManager hiscoreManager;
|
||||
|
||||
private final NPC[] clientNpcs;
|
||||
private final PanelComponent panelComponent = new PanelComponent();
|
||||
private final Map<String, Integer> oppInfoHealth = OpponentInfoPlugin.loadNpcHealth();
|
||||
@@ -65,9 +70,12 @@ class OpponentInfoOverlay extends Overlay
|
||||
private NPC lastOpponent;
|
||||
|
||||
@Inject
|
||||
private OpponentInfoOverlay(Client client)
|
||||
private OpponentInfoOverlay(Client client, OpponentInfoPlugin opponentInfoPlugin, HiscoreManager hiscoreManager)
|
||||
{
|
||||
this.client = client;
|
||||
this.opponentInfoPlugin = opponentInfoPlugin;
|
||||
this.hiscoreManager = hiscoreManager;
|
||||
|
||||
this.clientNpcs = client.getCachedNPCs();
|
||||
setPosition(OverlayPosition.TOP_LEFT);
|
||||
setPriority(OverlayPriority.HIGH);
|
||||
@@ -116,7 +124,24 @@ class OpponentInfoOverlay extends Overlay
|
||||
lastTime = Instant.now();
|
||||
lastRatio = (float) opponent.getHealthRatio() / (float) opponent.getHealth();
|
||||
opponentName = Text.removeTags(opponent.getName());
|
||||
lastMaxHealth = oppInfoHealth.get(opponentName + "_" + opponent.getCombatLevel());
|
||||
|
||||
lastMaxHealth = null;
|
||||
if (opponent instanceof NPC)
|
||||
{
|
||||
lastMaxHealth = oppInfoHealth.get(opponentName + "_" + opponent.getCombatLevel());
|
||||
}
|
||||
else if (opponent instanceof Player)
|
||||
{
|
||||
HiscoreResult hiscoreResult = hiscoreManager.lookupAsync(opponentName, opponentInfoPlugin.getHiscoreEndpoint());
|
||||
if (hiscoreResult != null)
|
||||
{
|
||||
int hp = hiscoreResult.getHitpoints().getLevel();
|
||||
if (hp > 0)
|
||||
{
|
||||
lastMaxHealth = hp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Actor opponentsOpponent = opponent.getInteracting();
|
||||
if (opponentsOpponent != null
|
||||
|
||||
@@ -24,31 +24,69 @@
|
||||
*/
|
||||
package net.runelite.client.plugins.opponentinfo;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.Gson;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Map;
|
||||
import javax.inject.Inject;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.GameState;
|
||||
import net.runelite.api.WorldType;
|
||||
import net.runelite.api.events.GameStateChanged;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.plugins.PluginDescriptor;
|
||||
import net.runelite.client.ui.overlay.Overlay;
|
||||
import net.runelite.http.api.hiscore.HiscoreEndpoint;
|
||||
|
||||
@PluginDescriptor(
|
||||
name = "Opponent Information"
|
||||
)
|
||||
public class OpponentInfoPlugin extends Plugin
|
||||
{
|
||||
@Inject
|
||||
private Client client;
|
||||
|
||||
@Inject
|
||||
private OpponentInfoOverlay overlay;
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private HiscoreEndpoint hiscoreEndpoint = HiscoreEndpoint.NORMAL;
|
||||
|
||||
@Override
|
||||
public Overlay getOverlay()
|
||||
{
|
||||
return overlay;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onGameStateChanged(GameStateChanged gameStateChanged)
|
||||
{
|
||||
if (gameStateChanged.getGameState() != GameState.LOGGED_IN)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
EnumSet<WorldType> worldType = client.getWorldType();
|
||||
if (worldType.contains(WorldType.DEADMAN))
|
||||
{
|
||||
hiscoreEndpoint = HiscoreEndpoint.DEADMAN;
|
||||
}
|
||||
else if (worldType.contains(WorldType.SEASONAL_DEADMAN))
|
||||
{
|
||||
hiscoreEndpoint = HiscoreEndpoint.SEASONAL_DEADMAN;
|
||||
}
|
||||
else
|
||||
{
|
||||
hiscoreEndpoint = HiscoreEndpoint.NORMAL;
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<String, Integer> loadNpcHealth()
|
||||
{
|
||||
Gson gson = new Gson();
|
||||
|
||||
Reference in New Issue
Block a user