slayer plugin: use npchiglight for task highlights

This commit is contained in:
Adam
2021-08-07 15:18:45 -04:00
parent a3350a61c8
commit c7b444d892
10 changed files with 193 additions and 246 deletions

View File

@@ -27,6 +27,7 @@ package net.runelite.client.plugins.npchighlight;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.inject.Binder;
import com.google.inject.Provides; import com.google.inject.Provides;
import java.awt.Color; import java.awt.Color;
import java.time.Instant; import java.time.Instant;
@@ -38,6 +39,7 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.function.Predicate;
import javax.inject.Inject; import javax.inject.Inject;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.Getter; import lombok.Getter;
@@ -77,7 +79,7 @@ import net.runelite.client.util.WildcardMatcher;
tags = {"highlight", "minimap", "npcs", "overlay", "respawn", "tags"} tags = {"highlight", "minimap", "npcs", "overlay", "respawn", "tags"}
) )
@Slf4j @Slf4j
public class NpcIndicatorsPlugin extends Plugin public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService
{ {
private static final int MAX_ACTOR_VIEW_RANGE = 15; private static final int MAX_ACTOR_VIEW_RANGE = 15;
@@ -173,12 +175,20 @@ public class NpcIndicatorsPlugin extends Plugin
*/ */
private boolean skipNextSpawnCheck = false; private boolean skipNextSpawnCheck = false;
private final List<Predicate<NPC>> higlightPredicates = new ArrayList<>();
@Provides @Provides
NpcIndicatorsConfig provideConfig(ConfigManager configManager) NpcIndicatorsConfig provideConfig(ConfigManager configManager)
{ {
return configManager.getConfig(NpcIndicatorsConfig.class); return configManager.getConfig(NpcIndicatorsConfig.class);
} }
@Override
public void configure(Binder binder)
{
binder.bind(NpcIndicatorsService.class).toInstance(this);
}
@Override @Override
protected void startUp() throws Exception protected void startUp() throws Exception
{ {
@@ -187,7 +197,7 @@ public class NpcIndicatorsPlugin extends Plugin
clientThread.invoke(() -> clientThread.invoke(() ->
{ {
skipNextSpawnCheck = true; skipNextSpawnCheck = true;
rebuildAllNpcs(); rebuild();
}); });
} }
@@ -230,7 +240,7 @@ public class NpcIndicatorsPlugin extends Plugin
return; return;
} }
clientThread.invoke(this::rebuildAllNpcs); clientThread.invoke(this::rebuild);
} }
@Subscribe @Subscribe
@@ -394,7 +404,23 @@ public class NpcIndicatorsPlugin extends Plugin
memorizeNpc(npc); memorizeNpc(npc);
spawnedNpcsThisTick.add(npc); spawnedNpcsThisTick.add(npc);
} }
return;
} }
for (Predicate<NPC> predicate : higlightPredicates)
{
if (predicate.test(npc))
{
highlightedNpcs.add(npc);
if (!client.isInInstancedRegion())
{
memorizeNpc(npc);
spawnedNpcsThisTick.add(npc);
}
return;
}
}
} }
@Subscribe @Subscribe
@@ -534,8 +560,8 @@ public class NpcIndicatorsPlugin extends Plugin
return Text.fromCSV(configNpcs); return Text.fromCSV(configNpcs);
} }
@VisibleForTesting @Override
void rebuildAllNpcs() public void rebuild()
{ {
highlights = getHighlights(); highlights = getHighlights();
highlightedNpcs.clear(); highlightedNpcs.clear();
@@ -548,6 +574,7 @@ public class NpcIndicatorsPlugin extends Plugin
return; return;
} }
outer:
for (NPC npc : client.getNpcs()) for (NPC npc : client.getNpcs())
{ {
final String npcName = npc.getName(); final String npcName = npc.getName();
@@ -573,6 +600,19 @@ public class NpcIndicatorsPlugin extends Plugin
continue; continue;
} }
for (Predicate<NPC> predicate : higlightPredicates)
{
if (predicate.test(npc))
{
if (!client.isInInstancedRegion())
{
memorizeNpc(npc);
}
highlightedNpcs.add(npc);
continue outer;
}
}
// NPC is not highlighted // NPC is not highlighted
memorizedNpcs.remove(npc.getIndex()); memorizedNpcs.remove(npc.getIndex());
} }
@@ -680,4 +720,16 @@ public class NpcIndicatorsPlugin extends Plugin
despawnedNpcsThisTick.clear(); despawnedNpcsThisTick.clear();
teleportGraphicsObjectSpawnedThisTick.clear(); teleportGraphicsObjectSpawnedThisTick.clear();
} }
@Override
public void registerHighlighter(Predicate<NPC> p)
{
higlightPredicates.add(p);
}
@Override
public void unregisterHighlighter(Predicate<NPC> p)
{
higlightPredicates.remove(p);
}
} }

View File

@@ -0,0 +1,35 @@
/*
* Copyright (c) 2021, 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.plugins.npchighlight;
import java.util.function.Predicate;
import net.runelite.api.NPC;
public interface NpcIndicatorsService
{
void registerHighlighter(Predicate<NPC> p);
void unregisterHighlighter(Predicate<NPC> p);
void rebuild();
}

View File

@@ -25,8 +25,6 @@
*/ */
package net.runelite.client.plugins.slayer; package net.runelite.client.plugins.slayer;
import java.awt.Color;
import net.runelite.client.config.Alpha;
import net.runelite.client.config.Config; import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigGroup; import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem; import net.runelite.client.config.ConfigItem;
@@ -101,18 +99,6 @@ public interface SlayerConfig extends Config
return false; return false;
} }
@Alpha
@ConfigItem(
position = 6,
keyName = "targetColor",
name = "Target Color",
description = "Color of the highlighted targets"
)
default Color getTargetColor()
{
return Color.RED;
}
@ConfigItem( @ConfigItem(
position = 7, position = 7,
keyName = "weaknessPrompt", keyName = "weaknessPrompt",

View File

@@ -39,9 +39,11 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.function.Predicate;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named;
import joptsimple.internal.Strings; import joptsimple.internal.Strings;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.Getter; import lombok.Getter;
@@ -60,6 +62,7 @@ import static net.runelite.api.Skill.SLAYER;
import net.runelite.api.coords.WorldPoint; import net.runelite.api.coords.WorldPoint;
import net.runelite.api.events.ActorDeath; import net.runelite.api.events.ActorDeath;
import net.runelite.api.events.ChatMessage; import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.CommandExecuted;
import net.runelite.api.events.GameStateChanged; import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.GameTick; import net.runelite.api.events.GameTick;
import net.runelite.api.events.HitsplatApplied; import net.runelite.api.events.HitsplatApplied;
@@ -81,18 +84,23 @@ import net.runelite.client.events.ChatInput;
import net.runelite.client.events.ConfigChanged; import net.runelite.client.events.ConfigChanged;
import net.runelite.client.game.ItemManager; import net.runelite.client.game.ItemManager;
import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDependency;
import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.plugins.npchighlight.NpcIndicatorsPlugin;
import net.runelite.client.plugins.npchighlight.NpcIndicatorsService;
import net.runelite.client.ui.overlay.OverlayManager; import net.runelite.client.ui.overlay.OverlayManager;
import net.runelite.client.ui.overlay.infobox.InfoBoxManager; import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
import net.runelite.client.util.ColorUtil; import net.runelite.client.util.ColorUtil;
import net.runelite.client.util.Text; import net.runelite.client.util.Text;
import net.runelite.http.api.chat.ChatClient; import net.runelite.http.api.chat.ChatClient;
import org.apache.commons.lang3.ArrayUtils;
@PluginDescriptor( @PluginDescriptor(
name = "Slayer", name = "Slayer",
description = "Show additional slayer task related information", description = "Show additional slayer task related information",
tags = {"combat", "notifications", "overlay", "tasks"} tags = {"combat", "notifications", "overlay", "tasks"}
) )
@PluginDependency(NpcIndicatorsPlugin.class)
@Slf4j @Slf4j
public class SlayerPlugin extends Plugin public class SlayerPlugin extends Plugin
{ {
@@ -151,15 +159,9 @@ public class SlayerPlugin extends Plugin
@Inject @Inject
private ClientThread clientThread; private ClientThread clientThread;
@Inject
private TargetClickboxOverlay targetClickboxOverlay;
@Inject @Inject
private TargetWeaknessOverlay targetWeaknessOverlay; private TargetWeaknessOverlay targetWeaknessOverlay;
@Inject
private TargetMinimapOverlay targetMinimapOverlay;
@Inject @Inject
private ChatMessageManager chatMessageManager; private ChatMessageManager chatMessageManager;
@@ -172,8 +174,15 @@ public class SlayerPlugin extends Plugin
@Inject @Inject
private ChatClient chatClient; private ChatClient chatClient;
@Inject
private NpcIndicatorsService npcIndicatorsService;
@Getter(AccessLevel.PACKAGE) @Getter(AccessLevel.PACKAGE)
private List<NPC> highlightedTargets = new ArrayList<>(); private final List<NPC> targets = new ArrayList<>();
@Inject
@Named("developerMode")
boolean developerMode;
private final Set<NPC> taggedNpcs = new HashSet<>(); private final Set<NPC> taggedNpcs = new HashSet<>();
private int taggedNpcsDiedPrevTick; private int taggedNpcsDiedPrevTick;
@@ -201,13 +210,16 @@ public class SlayerPlugin extends Plugin
private boolean loginFlag; private boolean loginFlag;
private final List<String> targetNames = new ArrayList<>(); private final List<String> targetNames = new ArrayList<>();
public final Predicate<NPC> isTarget = (n) -> config.highlightTargets() && targets.contains(n);
@Override @Override
protected void startUp() throws Exception protected void startUp() throws Exception
{ {
chatCommandManager.registerCommandAsync(TASK_COMMAND_STRING, this::taskLookup, this::taskSubmit);
npcIndicatorsService.registerHighlighter(isTarget);
overlayManager.add(overlay); overlayManager.add(overlay);
overlayManager.add(targetClickboxOverlay);
overlayManager.add(targetWeaknessOverlay); overlayManager.add(targetWeaknessOverlay);
overlayManager.add(targetMinimapOverlay);
if (client.getGameState() == GameState.LOGGED_IN) if (client.getGameState() == GameState.LOGGED_IN)
{ {
@@ -224,23 +236,21 @@ public class SlayerPlugin extends Plugin
getStringProfileConfig(SlayerConfig.TASK_LOC_KEY), false)); getStringProfileConfig(SlayerConfig.TASK_LOC_KEY), false));
} }
} }
chatCommandManager.registerCommandAsync(TASK_COMMAND_STRING, this::taskLookup, this::taskSubmit);
} }
@Override @Override
protected void shutDown() throws Exception protected void shutDown() throws Exception
{ {
chatCommandManager.unregisterCommand(TASK_COMMAND_STRING);
npcIndicatorsService.unregisterHighlighter(isTarget);
npcIndicatorsService.rebuild();
overlayManager.remove(overlay); overlayManager.remove(overlay);
overlayManager.remove(targetClickboxOverlay);
overlayManager.remove(targetWeaknessOverlay); overlayManager.remove(targetWeaknessOverlay);
overlayManager.remove(targetMinimapOverlay);
removeCounter(); removeCounter();
highlightedTargets.clear(); targets.clear();
taggedNpcs.clear(); taggedNpcs.clear();
cachedXp = -1; cachedXp = -1;
chatCommandManager.unregisterCommand(TASK_COMMAND_STRING);
} }
@Provides @Provides
@@ -260,7 +270,7 @@ public class SlayerPlugin extends Plugin
taskName = ""; taskName = "";
amount = 0; amount = 0;
loginFlag = true; loginFlag = true;
highlightedTargets.clear(); targets.clear();
taggedNpcs.clear(); taggedNpcs.clear();
break; break;
case LOGGED_IN: case LOGGED_IN:
@@ -279,6 +289,16 @@ public class SlayerPlugin extends Plugin
} }
} }
@Subscribe
public void onCommandExecuted(CommandExecuted commandExecuted)
{
if (developerMode && commandExecuted.getCommand().equals("task"))
{
setTask(commandExecuted.getArguments()[0], 42, 42);
log.debug("Set task to {}", commandExecuted.getArguments()[0]);
}
}
@VisibleForTesting @VisibleForTesting
int getIntProfileConfig(String key) int getIntProfileConfig(String key)
{ {
@@ -313,13 +333,16 @@ public class SlayerPlugin extends Plugin
setProfileConfig(SlayerConfig.TASK_LOC_KEY, taskLocation); setProfileConfig(SlayerConfig.TASK_LOC_KEY, taskLocation);
} }
@Subscribe @Subscribe(
// Run prior to npc indicators plugin so targets is populated before the isTarget predicate is checked
priority = 1
)
public void onNpcSpawned(NpcSpawned npcSpawned) public void onNpcSpawned(NpcSpawned npcSpawned)
{ {
NPC npc = npcSpawned.getNpc(); NPC npc = npcSpawned.getNpc();
if (isTarget(npc)) if (isTarget(npc))
{ {
highlightedTargets.add(npc); targets.add(npc);
} }
} }
@@ -328,7 +351,7 @@ public class SlayerPlugin extends Plugin
{ {
NPC npc = npcDespawned.getNpc(); NPC npc = npcDespawned.getNpc();
taggedNpcs.remove(npc); taggedNpcs.remove(npc);
highlightedTargets.remove(npc); targets.remove(npc);
} }
@Subscribe @Subscribe
@@ -541,7 +564,7 @@ public class SlayerPlugin extends Plugin
{ {
Actor actor = hitsplatApplied.getActor(); Actor actor = hitsplatApplied.getActor();
Hitsplat hitsplat = hitsplatApplied.getHitsplat(); Hitsplat hitsplat = hitsplatApplied.getHitsplat();
if (hitsplat.getHitsplatType() == Hitsplat.HitsplatType.DAMAGE_ME && highlightedTargets.contains(actor)) if (hitsplat.getHitsplatType() == Hitsplat.HitsplatType.DAMAGE_ME && targets.contains(actor))
{ {
// If the actor is in highlightedTargets it must be an NPC and also a task assignment // If the actor is in highlightedTargets it must be an NPC and also a task assignment
taggedNpcs.add((NPC) actor); taggedNpcs.add((NPC) actor);
@@ -562,18 +585,25 @@ public class SlayerPlugin extends Plugin
@Subscribe @Subscribe
private void onConfigChanged(ConfigChanged event) private void onConfigChanged(ConfigChanged event)
{ {
if (!event.getGroup().equals(SlayerConfig.GROUP_NAME) || !event.getKey().equals("infobox")) if (!event.getGroup().equals(SlayerConfig.GROUP_NAME))
{ {
return; return;
} }
if (config.showInfobox()) if (event.getKey().equals("infobox"))
{ {
clientThread.invoke(this::addCounter); if (config.showInfobox())
{
clientThread.invoke(this::addCounter);
}
else
{
removeCounter();
}
} }
else else
{ {
removeCounter(); npcIndicatorsService.rebuild();
} }
} }
@@ -619,27 +649,25 @@ public class SlayerPlugin extends Plugin
return false; return false;
} }
String name = npc.getName(); final NPCComposition composition = npc.getTransformedComposition();
if (name == null) if (composition == null)
{ {
return false; return false;
} }
name = name.toLowerCase(); final String name = composition.getName()
.replace('\u00A0', ' ')
.toLowerCase();
for (String target : targetNames) for (String target : targetNames)
{ {
if (name.contains(target)) if (name.contains(target))
{ {
NPCComposition composition = npc.getTransformedComposition(); if (ArrayUtils.contains(composition.getActions(), "Attack")
// Pick action is for zygomite-fungi
if (composition != null) || ArrayUtils.contains(composition.getActions(), "Pick"))
{ {
List<String> actions = Arrays.asList(composition.getActions()); return true;
if (actions.contains("Attack") || actions.contains("Pick")) //Pick action is for zygomite-fungi
{
return true;
}
} }
} }
} }
@@ -662,13 +690,13 @@ public class SlayerPlugin extends Plugin
private void rebuildTargetList() private void rebuildTargetList()
{ {
highlightedTargets.clear(); targets.clear();
for (NPC npc : client.getNpcs()) for (NPC npc : client.getNpcs())
{ {
if (isTarget(npc)) if (isTarget(npc))
{ {
highlightedTargets.add(npc); targets.add(npc);
} }
} }
} }
@@ -701,6 +729,7 @@ public class SlayerPlugin extends Plugin
Task task = Task.getTask(name); Task task = Task.getTask(name);
rebuildTargetNames(task); rebuildTargetNames(task);
rebuildTargetList(); rebuildTargetList();
npcIndicatorsService.rebuild();
} }
private void addCounter() private void addCounter()

View File

@@ -1,85 +0,0 @@
/*
* Copyright (c) 2018, James Swindle <wilingua@gmail.com>
* Copyright (c) 2018, Adam <Adam@sigterm.info>
* Copyright (c) 2018, Shaun Dreclin <shaundreclin@gmail.com>
* 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.plugins.slayer;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.util.List;
import javax.inject.Inject;
import net.runelite.api.NPC;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.util.ColorUtil;
public class TargetClickboxOverlay extends Overlay
{
private final SlayerConfig config;
private final SlayerPlugin plugin;
@Inject
TargetClickboxOverlay(SlayerConfig config, SlayerPlugin plugin)
{
this.config = config;
this.plugin = plugin;
setPosition(OverlayPosition.DYNAMIC);
setLayer(OverlayLayer.ABOVE_SCENE);
}
@Override
public Dimension render(Graphics2D graphics)
{
if (!config.highlightTargets())
{
return null;
}
List<NPC> targets = plugin.getHighlightedTargets();
for (NPC target : targets)
{
renderTargetOverlay(graphics, target, config.getTargetColor());
}
return null;
}
private void renderTargetOverlay(Graphics2D graphics, NPC actor, Color color)
{
Shape objectClickbox = actor.getConvexHull();
if (objectClickbox != null)
{
graphics.setColor(color);
graphics.setStroke(new BasicStroke(2));
graphics.draw(objectClickbox);
graphics.setColor(ColorUtil.colorWithAlpha(color, color.getAlpha() / 12));
graphics.fill(objectClickbox);
}
}
}

View File

@@ -1,80 +0,0 @@
/*
* Copyright (c) 2018, James Swindle <wilingua@gmail.com>
* Copyright (c) 2018, Adam <Adam@sigterm.info>
* Copyright (c) 2018, Shaun Dreclin <shaundreclin@gmail.com>
* 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.plugins.slayer;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.util.List;
import javax.inject.Inject;
import net.runelite.api.NPC;
import net.runelite.api.Point;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayUtil;
public class TargetMinimapOverlay extends Overlay
{
private final SlayerConfig config;
private final SlayerPlugin plugin;
@Inject
TargetMinimapOverlay(SlayerConfig config, SlayerPlugin plugin)
{
this.config = config;
this.plugin = plugin;
setPosition(OverlayPosition.DYNAMIC);
setLayer(OverlayLayer.ABOVE_WIDGETS);
}
@Override
public Dimension render(Graphics2D graphics)
{
if (!config.highlightTargets())
{
return null;
}
List<NPC> targets = plugin.getHighlightedTargets();
for (NPC target : targets)
{
renderTargetOverlay(graphics, target, config.getTargetColor());
}
return null;
}
private void renderTargetOverlay(Graphics2D graphics, NPC actor, Color color)
{
Point minimapLocation = actor.getMinimapLocation();
if (minimapLocation != null)
{
OverlayUtil.renderMinimapLocation(graphics, minimapLocation, color);
}
}
}

View File

@@ -64,7 +64,7 @@ class TargetWeaknessOverlay extends Overlay
@Override @Override
public Dimension render(Graphics2D graphics) public Dimension render(Graphics2D graphics)
{ {
final List<NPC> targets = plugin.getHighlightedTargets(); final List<NPC> targets = plugin.getTargets();
if (targets.isEmpty() || !config.weaknessPrompt()) if (targets.isEmpty() || !config.weaknessPrompt())
{ {

View File

@@ -28,7 +28,6 @@ import com.google.common.reflect.ClassPath;
import com.google.common.reflect.ClassPath.ClassInfo; import com.google.common.reflect.ClassPath.ClassInfo;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.inject.grapher.graphviz.GraphvizGrapher; import com.google.inject.grapher.graphviz.GraphvizGrapher;
import com.google.inject.grapher.graphviz.GraphvizModule; import com.google.inject.grapher.graphviz.GraphvizModule;
import com.google.inject.testing.fieldbinder.Bind; import com.google.inject.testing.fieldbinder.Bind;
@@ -39,10 +38,8 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import net.runelite.api.Client; import net.runelite.api.Client;
@@ -153,24 +150,28 @@ public class PluginManagerTest
@Test @Test
public void dumpGraph() throws Exception public void dumpGraph() throws Exception
{ {
List<Module> modules = new ArrayList<>();
modules.add(new GraphvizModule());
modules.add(new RuneLiteModule(mock(OkHttpClient.class), () -> null, true, false,
RuneLite.DEFAULT_SESSION_FILE,
RuneLite.DEFAULT_CONFIG_FILE));
PluginManager pluginManager = new PluginManager(true, false, null, null, null, null); PluginManager pluginManager = new PluginManager(true, false, null, null, null, null);
pluginManager.loadCorePlugins(); pluginManager.loadCorePlugins();
modules.addAll(pluginManager.getPlugins());
File file = folder.newFile(); Injector graphvizInjector = Guice.createInjector(new GraphvizModule());
try (PrintWriter out = new PrintWriter(file, "UTF-8")) GraphvizGrapher graphvizGrapher = graphvizInjector.getInstance(GraphvizGrapher.class);
File dotFolder = folder.newFolder();
try (PrintWriter out = new PrintWriter(new File(dotFolder, "runelite.dot"), "UTF-8"))
{ {
Injector injector = Guice.createInjector(modules); graphvizGrapher.setOut(out);
GraphvizGrapher grapher = injector.getInstance(GraphvizGrapher.class); graphvizGrapher.setRankdir("TB");
grapher.setOut(out); graphvizGrapher.graph(RuneLite.getInjector());
grapher.setRankdir("TB"); }
grapher.graph(injector);
for (Plugin p : pluginManager.getPlugins())
{
try (PrintWriter out = new PrintWriter(new File(dotFolder, p.getName() + ".dot"), "UTF-8"))
{
graphvizGrapher.setOut(out);
graphvizGrapher.setRankdir("TB");
graphvizGrapher.graph(p.getInjector());
}
} }
} }

View File

@@ -99,7 +99,7 @@ public class NpcIndicatorsPluginTest
when(npcIndicatorsConfig.getNpcToHighlight()).thenReturn("goblin"); when(npcIndicatorsConfig.getNpcToHighlight()).thenReturn("goblin");
when(npcIndicatorsConfig.deadNpcMenuColor()).thenReturn(Color.RED); when(npcIndicatorsConfig.deadNpcMenuColor()).thenReturn(Color.RED);
npcIndicatorsPlugin.rebuildAllNpcs(); npcIndicatorsPlugin.rebuild();
NPC npc = mock(NPC.class); NPC npc = mock(NPC.class);
when(npc.getName()).thenReturn("Goblin"); when(npc.getName()).thenReturn("Goblin");
@@ -124,7 +124,7 @@ public class NpcIndicatorsPluginTest
when(npcIndicatorsConfig.highlightMenuNames()).thenReturn(true); when(npcIndicatorsConfig.highlightMenuNames()).thenReturn(true);
when(npcIndicatorsConfig.getHighlightColor()).thenReturn(Color.BLUE); when(npcIndicatorsConfig.getHighlightColor()).thenReturn(Color.BLUE);
npcIndicatorsPlugin.rebuildAllNpcs(); npcIndicatorsPlugin.rebuild();
NPC npc = mock(NPC.class); NPC npc = mock(NPC.class);
when(npc.getName()).thenReturn("Goblin"); when(npc.getName()).thenReturn("Goblin");
@@ -146,7 +146,7 @@ public class NpcIndicatorsPluginTest
{ {
when(npcIndicatorsConfig.getNpcToHighlight()).thenReturn("Joseph"); when(npcIndicatorsConfig.getNpcToHighlight()).thenReturn("Joseph");
npcIndicatorsPlugin.rebuildAllNpcs(); npcIndicatorsPlugin.rebuild();
NPC npc = mock(NPC.class); NPC npc = mock(NPC.class);
when(npc.getName()).thenReturn("Joseph"); when(npc.getName()).thenReturn("Joseph");
@@ -165,7 +165,7 @@ public class NpcIndicatorsPluginTest
{ {
when(npcIndicatorsConfig.getNpcToHighlight()).thenReturn("Werewolf"); when(npcIndicatorsConfig.getNpcToHighlight()).thenReturn("Werewolf");
npcIndicatorsPlugin.rebuildAllNpcs(); npcIndicatorsPlugin.rebuild();
NPC npc = mock(NPC.class); NPC npc = mock(NPC.class);
when(npc.getName()).thenReturn("Joseph"); when(npc.getName()).thenReturn("Joseph");

View File

@@ -31,6 +31,7 @@ import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named;
import net.runelite.api.ChatMessageType; import net.runelite.api.ChatMessageType;
import static net.runelite.api.ChatMessageType.GAMEMESSAGE; import static net.runelite.api.ChatMessageType.GAMEMESSAGE;
import net.runelite.api.Client; import net.runelite.api.Client;
@@ -55,6 +56,7 @@ import net.runelite.client.chat.ChatCommandManager;
import net.runelite.client.chat.ChatMessageManager; import net.runelite.client.chat.ChatMessageManager;
import net.runelite.client.config.ConfigManager; import net.runelite.client.config.ConfigManager;
import net.runelite.client.game.ItemManager; import net.runelite.client.game.ItemManager;
import net.runelite.client.plugins.npchighlight.NpcIndicatorsService;
import net.runelite.client.ui.overlay.OverlayManager; import net.runelite.client.ui.overlay.OverlayManager;
import net.runelite.client.ui.overlay.infobox.InfoBoxManager; import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
import net.runelite.http.api.chat.ChatClient; import net.runelite.http.api.chat.ChatClient;
@@ -168,6 +170,14 @@ public class SlayerPluginTest
@Bind @Bind
ChatClient chatClient; ChatClient chatClient;
@Bind
@Named("developerMode")
boolean developerMode;
@Mock
@Bind
NpcIndicatorsService npcIndicatorsService;
@Inject @Inject
SlayerPlugin slayerPlugin; SlayerPlugin slayerPlugin;
@@ -871,14 +881,13 @@ public class SlayerPluginTest
slayerPlugin.onStatChanged(statChanged); slayerPlugin.onStatChanged(statChanged);
NPCComposition npcComposition = mock(NPCComposition.class); NPCComposition npcComposition = mock(NPCComposition.class);
when(npcComposition.getName()).thenReturn("Suqah");
when(npcComposition.getActions()).thenReturn(new String[]{"Attack"}); when(npcComposition.getActions()).thenReturn(new String[]{"Attack"});
NPC npc1 = mock(NPC.class); NPC npc1 = mock(NPC.class);
when(npc1.getName()).thenReturn("Suqah");
when(npc1.getTransformedComposition()).thenReturn(npcComposition); when(npc1.getTransformedComposition()).thenReturn(npcComposition);
NPC npc2 = mock(NPC.class); NPC npc2 = mock(NPC.class);
when(npc2.getName()).thenReturn("Suqah");
when(npc2.getTransformedComposition()).thenReturn(npcComposition); when(npc2.getTransformedComposition()).thenReturn(npcComposition);
when(client.getNpcs()).thenReturn(Arrays.asList(npc1, npc2)); when(client.getNpcs()).thenReturn(Arrays.asList(npc1, npc2));