Create NPC manager that can return HP for NPC
- Create NPC manager and move logic from opponent info there for getting NPC HP based on combat level and name - Make opponent info use NPC manager instead of its own implementation Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Adam <Adam@sigterm.info>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.runelite.client.game;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
public class NPCManager
|
||||
{
|
||||
private final Map<String, Integer> healthMap;
|
||||
|
||||
@Inject
|
||||
private NPCManager()
|
||||
{
|
||||
final Gson gson = new Gson();
|
||||
final Type typeToken = new TypeToken<Map<String, Integer>>()
|
||||
{
|
||||
}.getType();
|
||||
|
||||
final InputStream healthFile = getClass().getResourceAsStream("/npc_health.json");
|
||||
healthMap = gson.fromJson(new InputStreamReader(healthFile), typeToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns health for target NPC based on it's combat level and name
|
||||
* @param name npc name
|
||||
* @param combatLevel npc combat level
|
||||
* @return health or null if HP is unknown
|
||||
*/
|
||||
@Nullable
|
||||
public Integer getHealth(final String name, final int combatLevel)
|
||||
{
|
||||
return healthMap.get(name + "_" + combatLevel);
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,7 @@ 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.game.NPCManager;
|
||||
import net.runelite.client.ui.overlay.Overlay;
|
||||
import net.runelite.client.ui.overlay.OverlayPosition;
|
||||
import net.runelite.client.ui.overlay.OverlayPriority;
|
||||
@@ -57,6 +58,7 @@ class OpponentInfoOverlay extends Overlay
|
||||
private final OpponentInfoPlugin opponentInfoPlugin;
|
||||
private final OpponentInfoConfig opponentInfoConfig;
|
||||
private final HiscoreManager hiscoreManager;
|
||||
private final NPCManager npcManager;
|
||||
|
||||
private final PanelComponent panelComponent = new PanelComponent();
|
||||
|
||||
@@ -67,13 +69,18 @@ class OpponentInfoOverlay extends Overlay
|
||||
private String opponentsOpponentName;
|
||||
|
||||
@Inject
|
||||
private OpponentInfoOverlay(Client client, OpponentInfoPlugin opponentInfoPlugin,
|
||||
OpponentInfoConfig opponentInfoConfig, HiscoreManager hiscoreManager)
|
||||
private OpponentInfoOverlay(
|
||||
Client client,
|
||||
OpponentInfoPlugin opponentInfoPlugin,
|
||||
OpponentInfoConfig opponentInfoConfig,
|
||||
HiscoreManager hiscoreManager,
|
||||
NPCManager npcManager)
|
||||
{
|
||||
this.client = client;
|
||||
this.opponentInfoPlugin = opponentInfoPlugin;
|
||||
this.opponentInfoConfig = opponentInfoConfig;
|
||||
this.hiscoreManager = hiscoreManager;
|
||||
this.npcManager = npcManager;
|
||||
|
||||
setPosition(OverlayPosition.TOP_LEFT);
|
||||
setPriority(OverlayPriority.HIGH);
|
||||
@@ -102,7 +109,7 @@ class OpponentInfoOverlay extends Overlay
|
||||
lastMaxHealth = null;
|
||||
if (opponent instanceof NPC)
|
||||
{
|
||||
lastMaxHealth = opponentInfoPlugin.getOppInfoHealth().get(opponentName + "_" + opponent.getCombatLevel());
|
||||
lastMaxHealth = npcManager.getHealth(opponentName, opponent.getCombatLevel());
|
||||
}
|
||||
else if (opponent instanceof Player)
|
||||
{
|
||||
|
||||
@@ -26,16 +26,10 @@
|
||||
package net.runelite.client.plugins.opponentinfo;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.inject.Provides;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Type;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Map;
|
||||
import javax.inject.Inject;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
@@ -84,9 +78,6 @@ public class OpponentInfoPlugin extends Plugin
|
||||
|
||||
private Instant lastTime;
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private final Map<String, Integer> oppInfoHealth = loadNpcHealth();
|
||||
|
||||
@Provides
|
||||
OpponentInfoConfig provideConfig(ConfigManager configManager)
|
||||
{
|
||||
@@ -164,15 +155,4 @@ public class OpponentInfoPlugin extends Plugin
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, Integer> loadNpcHealth()
|
||||
{
|
||||
Gson gson = new Gson();
|
||||
Type type = new TypeToken<Map<String, Integer>>()
|
||||
{
|
||||
}.getType();
|
||||
|
||||
InputStream healthFile = OpponentInfoPlugin.class.getResourceAsStream("/npc_health.json");
|
||||
return gson.fromJson(new InputStreamReader(healthFile), type);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user