Merge remote-tracking branch 'runelite/master'

This commit is contained in:
Owain van Brakel
2021-08-25 06:18:52 +02:00
15 changed files with 1353 additions and 1237 deletions

View File

@@ -69,7 +69,7 @@ import net.runelite.api.events.WidgetLoaded;
import net.runelite.api.vars.AccountType; import net.runelite.api.vars.AccountType;
import net.runelite.api.widgets.Widget; import net.runelite.api.widgets.Widget;
import static net.runelite.api.widgets.WidgetID.ADVENTURE_LOG_ID; import static net.runelite.api.widgets.WidgetID.ADVENTURE_LOG_ID;
import static net.runelite.api.widgets.WidgetID.GENERIC_SCROLL_GROUP_ID; import static net.runelite.api.widgets.WidgetID.DIARY_QUEST_GROUP_ID;
import static net.runelite.api.widgets.WidgetID.KILL_LOGS_GROUP_ID; import static net.runelite.api.widgets.WidgetID.KILL_LOGS_GROUP_ID;
import net.runelite.api.widgets.WidgetInfo; import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.callback.ClientThread; import net.runelite.client.callback.ClientThread;
@@ -109,9 +109,9 @@ import org.apache.commons.text.WordUtils;
public class ChatCommandsPlugin extends Plugin public class ChatCommandsPlugin extends Plugin
{ {
private static final Pattern KILLCOUNT_PATTERN = Pattern.compile("Your (?:completion count for |subdued |completed )?(.+?) (?:(?:kill|harvest|lap|completion) )?(?:count )?is: <col=ff0000>(\\d+)</col>"); private static final Pattern KILLCOUNT_PATTERN = Pattern.compile("Your (?:completion count for |subdued |completed )?(.+?) (?:(?:kill|harvest|lap|completion) )?(?:count )?is: <col=ff0000>(\\d+)</col>");
private static final String COX_TEAM_SIZES = "(?:\\d+(?:\\+|-\\d+)? players|Solo)"; private static final String TEAM_SIZES = "(?:\\d+(?:\\+|-\\d+)? players|Solo)";
private static final Pattern RAIDS_PB_PATTERN = Pattern.compile("<col=ef20ff>Congratulations - your raid is complete!</col><br>Team size: <col=ff0000>" + COX_TEAM_SIZES + "</col> Duration:</col> <col=ff0000>(?<pb>[0-9:]+(?:\\.[0-9]+)?)</col> \\(new personal best\\)</col>"); private static final Pattern RAIDS_PB_PATTERN = Pattern.compile("<col=ef20ff>Congratulations - your raid is complete!</col><br>Team size: <col=ff0000>" + TEAM_SIZES + "</col> Duration:</col> <col=ff0000>(?<pb>[0-9:]+(?:\\.[0-9]+)?)</col> \\(new personal best\\)</col>");
private static final Pattern RAIDS_DURATION_PATTERN = Pattern.compile("<col=ef20ff>Congratulations - your raid is complete!</col><br>Team size: <col=ff0000>" + COX_TEAM_SIZES + "</col> Duration:</col> <col=ff0000>[0-9:.]+</col> Personal best: </col><col=ff0000>(?<pb>[0-9:]+(?:\\.[0-9]+)?)</col>"); private static final Pattern RAIDS_DURATION_PATTERN = Pattern.compile("<col=ef20ff>Congratulations - your raid is complete!</col><br>Team size: <col=ff0000>" + TEAM_SIZES + "</col> Duration:</col> <col=ff0000>[0-9:.]+</col> Personal best: </col><col=ff0000>(?<pb>[0-9:]+(?:\\.[0-9]+)?)</col>");
private static final Pattern TOB_WAVE_PB_PATTERN = Pattern.compile("Theatre of Blood wave completion time: <col=ff0000>(?<pb>[0-9:]+(?:\\.[0-9]+)?)</col> \\(new personal best\\)"); private static final Pattern TOB_WAVE_PB_PATTERN = Pattern.compile("Theatre of Blood wave completion time: <col=ff0000>(?<pb>[0-9:]+(?:\\.[0-9]+)?)</col> \\(new personal best\\)");
private static final Pattern TOB_WAVE_DURATION_PATTERN = Pattern.compile("Theatre of Blood wave completion time: <col=ff0000>[0-9:.]+</col>\\. Personal best: (?<pb>[0-9:]+(?:\\.[0-9]+)?)"); private static final Pattern TOB_WAVE_DURATION_PATTERN = Pattern.compile("Theatre of Blood wave completion time: <col=ff0000>[0-9:.]+</col>\\. Personal best: (?<pb>[0-9:]+(?:\\.[0-9]+)?)");
private static final Pattern KILL_DURATION_PATTERN = Pattern.compile("(?i)(?:(?:Fight |Lap |Challenge |Corrupted challenge )?duration:|Subdued in) <col=[0-9a-f]{6}>[0-9:.]+</col>\\. Personal best: (?:<col=ff0000>)?(?<pb>[0-9:]+(?:\\.[0-9]+)?)"); private static final Pattern KILL_DURATION_PATTERN = Pattern.compile("(?i)(?:(?:Fight |Lap |Challenge |Corrupted challenge )?duration:|Subdued in) <col=[0-9a-f]{6}>[0-9:.]+</col>\\. Personal best: (?:<col=ff0000>)?(?<pb>[0-9:]+(?:\\.[0-9]+)?)");
@@ -119,9 +119,7 @@ public class ChatCommandsPlugin extends Plugin
private static final Pattern DUEL_ARENA_WINS_PATTERN = Pattern.compile("You (were defeated|won)! You have(?: now)? won (\\d+) duels?"); private static final Pattern DUEL_ARENA_WINS_PATTERN = Pattern.compile("You (were defeated|won)! You have(?: now)? won (\\d+) duels?");
private static final Pattern DUEL_ARENA_LOSSES_PATTERN = Pattern.compile("You have(?: now)? lost (\\d+) duels?"); private static final Pattern DUEL_ARENA_LOSSES_PATTERN = Pattern.compile("You have(?: now)? lost (\\d+) duels?");
private static final Pattern ADVENTURE_LOG_TITLE_PATTERN = Pattern.compile("The Exploits of (.+)"); private static final Pattern ADVENTURE_LOG_TITLE_PATTERN = Pattern.compile("The Exploits of (.+)");
private static final Pattern ADVENTURE_LOG_COX_PB_PATTERN = Pattern.compile("Fastest (?:kill|run)(?: - \\(Team size: " + COX_TEAM_SIZES + "\\))?: ([0-9:]+(?:\\.[0-9]+)?)"); private static final Pattern ADVENTURE_LOG_PB_PATTERN = Pattern.compile("Fastest (?:kill|run)(?: - \\(Team size: " + TEAM_SIZES + "\\))?: ([0-9:]+(?:\\.[0-9]+)?)");
private static final Pattern ADVENTURE_LOG_BOSS_PB_PATTERN = Pattern.compile("[a-zA-Z]+(?: [a-zA-Z]+)*");
private static final Pattern ADVENTURE_LOG_PB_PATTERN = Pattern.compile("(" + ADVENTURE_LOG_BOSS_PB_PATTERN + "(?: - " + ADVENTURE_LOG_BOSS_PB_PATTERN + ")*) (?:" + ADVENTURE_LOG_COX_PB_PATTERN + "( )*)+");
private static final Pattern HS_PB_PATTERN = Pattern.compile("Floor (?<floor>\\d) time: <col=ff0000>(?<floortime>[0-9:]+(?:\\.[0-9]+)?)</col>(?: \\(new personal best\\)|. Personal best: (?<floorpb>[0-9:]+(?:\\.[0-9]+)?))" + private static final Pattern HS_PB_PATTERN = Pattern.compile("Floor (?<floor>\\d) time: <col=ff0000>(?<floortime>[0-9:]+(?:\\.[0-9]+)?)</col>(?: \\(new personal best\\)|. Personal best: (?<floorpb>[0-9:]+(?:\\.[0-9]+)?))" +
"(?:<br>Overall time: <col=ff0000>(?<otime>[0-9:]+(?:\\.[0-9]+)?)</col>(?: \\(new personal best\\)|. Personal best: (?<opb>[0-9:]+(?:\\.[0-9]+)?)))?"); "(?:<br>Overall time: <col=ff0000>(?<otime>[0-9:]+(?:\\.[0-9]+)?)</col>(?: \\(new personal best\\)|. Personal best: (?<opb>[0-9:]+(?:\\.[0-9]+)?)))?");
private static final Pattern HS_KC_FLOOR_PATTERN = Pattern.compile("You have completed Floor (\\d) of the Hallowed Sepulchre! Total completions: <col=ff0000>([0-9,]+)</col>\\."); private static final Pattern HS_KC_FLOOR_PATTERN = Pattern.compile("You have completed Floor (\\d) of the Hallowed Sepulchre! Total completions: <col=ff0000>([0-9,]+)</col>\\.");
@@ -392,6 +390,9 @@ public class ChatCommandsPlugin extends Plugin
unsetPb(boss); unsetPb(boss);
unsetKc(boss.replace(":", ".")); unsetKc(boss.replace(":", "."));
unsetPb(boss.replace(":", ".")); unsetPb(boss.replace(":", "."));
// Unset old story mode
unsetKc("Theatre of Blood Story Mode");
unsetPb("Theatre of Blood Story Mode");
} }
setKc(renamedBoss, kc); setKc(renamedBoss, kc);
@@ -630,37 +631,47 @@ public class ChatCommandsPlugin extends Plugin
} }
} }
// Adventure log - Counters
if (scrollInterfaceLoaded) if (scrollInterfaceLoaded)
{ {
scrollInterfaceLoaded = false; scrollInterfaceLoaded = false;
if (client.getLocalPlayer().getName().equals(pohOwner)) if (client.getLocalPlayer().getName().equals(pohOwner))
{ {
String counterText = Text.sanitizeMultilineText(client.getWidget(WidgetInfo.GENERIC_SCROLL_TEXT).getText()); Widget parent = client.getWidget(WidgetInfo.DIARY_QUEST_WIDGET_TEXT);
Matcher mCounterText = ADVENTURE_LOG_PB_PATTERN.matcher(counterText); // Each line is a separate static child
while (mCounterText.find()) Widget[] children = parent.getStaticChildren();
String[] text = Arrays.stream(children)
.map(Widget::getText)
.map(Text::removeTags)
.toArray(String[]::new);
for (int i = 0; i < text.length; ++i)
{ {
String bossName = longBossName(mCounterText.group(1)); String boss = longBossName(text[i]);
if (bossName.equalsIgnoreCase("chambers of xeric") || double pb = Double.MAX_VALUE;
bossName.equalsIgnoreCase("chambers of xeric challenge mode"))
for (i = i + 1; i < text.length; ++i)
{ {
Matcher mCoxRuns = ADVENTURE_LOG_COX_PB_PATTERN.matcher(mCounterText.group()); String line = text[i];
double bestPbTime = Double.MAX_VALUE; if (line.isEmpty())
while (mCoxRuns.find())
{ {
bestPbTime = Math.min(timeStringToSeconds(mCoxRuns.group(1)), bestPbTime); break;
} }
// So we don't reset people's already saved PB's if they had one before the update
double currentPb = getPb(bossName); // Some bosses have multiple pbs for each team size, just use the lowest
if (currentPb == 0 || currentPb > bestPbTime) Matcher matcher = ADVENTURE_LOG_PB_PATTERN.matcher(line);
if (matcher.find())
{ {
setPb(bossName, bestPbTime); double s = timeStringToSeconds(matcher.group(1));
pb = Math.min(pb, s);
} }
} }
else
if (pb < Double.MAX_VALUE)
{ {
String pbTime = mCounterText.group(2); log.debug("Found adventure log PB for {}: {}", boss, pb);
setPb(bossName, timeStringToSeconds(pbTime)); setPb(boss, pb);
} }
} }
} }
@@ -719,7 +730,7 @@ public class ChatCommandsPlugin extends Plugin
case KILL_LOGS_GROUP_ID: case KILL_LOGS_GROUP_ID:
bossLogLoaded = true; bossLogLoaded = true;
break; break;
case GENERIC_SCROLL_GROUP_ID: case DIARY_QUEST_GROUP_ID:
scrollInterfaceLoaded = true; scrollInterfaceLoaded = true;
break; break;
} }
@@ -1965,13 +1976,17 @@ public class ChatCommandsPlugin extends Plugin
case "raids 2": case "raids 2":
return "Theatre of Blood"; return "Theatre of Blood";
case "Theatre of Blood: Story Mode": case "theatre of blood: story mode":
case "tob sm": case "tob sm":
case "tob story mode": case "tob story mode":
case "tob story": case "tob story":
return "Theatre of Blood Story Mode"; case "Theatre of Blood: Entry Mode":
case "tob em":
case "tob entry mode":
case "tob entry":
return "Theatre of Blood Entry Mode";
case "Theatre of Blood: Hard Mode": case "theatre of blood: hard mode":
case "tob cm": case "tob cm":
case "tob hm": case "tob hm":
case "tob hard mode": case "tob hard mode":

View File

@@ -479,14 +479,14 @@ public class GrandExchangePlugin extends Plugin
private WorldType getGeWorldType() private WorldType getGeWorldType()
{ {
EnumSet<net.runelite.api.WorldType> worldTypes = client.getWorldType(); EnumSet<net.runelite.api.WorldType> worldTypes = client.getWorldType();
if (worldTypes.contains(net.runelite.api.WorldType.DEADMAN)) if (worldTypes.contains(net.runelite.api.WorldType.DEADMAN_TOURNAMENT))
{
return WorldType.DEADMAN;
}
else if (worldTypes.contains(net.runelite.api.WorldType.DEADMAN_TOURNAMENT))
{ {
return WorldType.DEADMAN_TOURNAMENT; return WorldType.DEADMAN_TOURNAMENT;
} }
else if (worldTypes.contains(net.runelite.api.WorldType.DEADMAN))
{
return WorldType.DEADMAN;
}
else else
{ {
return null; return null;

View File

@@ -1,82 +0,0 @@
/*
* Copyright (c) 2018, Seth <http://github.com/sethtroll>
* 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.implings;
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 ImplingMinimapOverlay extends Overlay
{
private final ImplingsPlugin plugin;
private final ImplingsConfig config;
@Inject
private ImplingMinimapOverlay(ImplingsPlugin plugin, ImplingsConfig config)
{
setPosition(OverlayPosition.DYNAMIC);
setLayer(OverlayLayer.ABOVE_WIDGETS);
this.plugin = plugin;
this.config = config;
}
@Override
public Dimension render(Graphics2D graphics)
{
List<NPC> imps = plugin.getImplings();
if (imps.isEmpty())
{
return null;
}
for (NPC imp : imps)
{
Point impLocation = imp.getMinimapLocation();
Color color = plugin.npcToColor(imp);
if (!plugin.showNpc(imp) || impLocation == null || color == null)
{
continue;
}
OverlayUtil.renderMinimapLocation(graphics, impLocation, color);
if (config.showName())
{
Point textLocation = new Point(impLocation.getX() + 1, impLocation.getY());
OverlayUtil.renderTextLocation(graphics, textLocation, imp.getName(), color);
}
}
return null;
}
}

View File

@@ -31,13 +31,11 @@ import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem; import net.runelite.client.config.ConfigItem;
import net.runelite.client.config.ConfigSection; import net.runelite.client.config.ConfigSection;
/** @ConfigGroup(ImplingsConfig.GROUP)
*
* @author robin
*/
@ConfigGroup("implings")
public interface ImplingsConfig extends Config public interface ImplingsConfig extends Config
{ {
String GROUP = "implings";
enum ImplingMode enum ImplingMode
{ {
NONE, NONE,

View File

@@ -28,13 +28,10 @@ import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Polygon; import java.awt.Polygon;
import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import net.runelite.api.Actor;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.api.NPC;
import net.runelite.api.Point;
import net.runelite.api.Perspective; import net.runelite.api.Perspective;
import net.runelite.api.Point;
import net.runelite.api.coords.LocalPoint; import net.runelite.api.coords.LocalPoint;
import net.runelite.api.coords.WorldPoint; import net.runelite.api.coords.WorldPoint;
import net.runelite.client.ui.overlay.Overlay; import net.runelite.client.ui.overlay.Overlay;
@@ -42,10 +39,7 @@ import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPosition; import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayUtil; import net.runelite.client.ui.overlay.OverlayUtil;
/** class ImplingsOverlay extends Overlay
* @author robin
*/
public class ImplingsOverlay extends Overlay
{ {
private final Client client; private final Client client;
private final ImplingsConfig config; private final ImplingsConfig config;
@@ -64,25 +58,6 @@ public class ImplingsOverlay extends Overlay
@Override @Override
public Dimension render(Graphics2D graphics) public Dimension render(Graphics2D graphics)
{ {
List<NPC> implings = plugin.getImplings();
if (implings.isEmpty())
{
return null;
}
for (NPC imp : implings)
{
Color color = plugin.npcToColor(imp);
if (!plugin.showNpc(imp) || color == null)
{
continue;
}
drawImp(graphics, imp, imp.getName(), color);
}
//Draw static spawns
if (config.showSpawn()) if (config.showSpawn())
{ {
for (ImplingSpawn spawn : ImplingSpawn.values()) for (ImplingSpawn spawn : ImplingSpawn.values())
@@ -126,20 +101,4 @@ public class ImplingsOverlay extends Overlay
OverlayUtil.renderTextLocation(graphics, textPoint, text, color); OverlayUtil.renderTextLocation(graphics, textPoint, text, color);
} }
} }
private void drawImp(Graphics2D graphics, Actor actor, String text, Color color)
{
Polygon poly = actor.getCanvasTilePoly();
if (poly != null)
{
OverlayUtil.renderPolygon(graphics, poly, color);
}
Point textLocation = actor.getCanvasTextLocation(graphics, text, actor.getLogicalHeight());
if (textLocation != null)
{
OverlayUtil.renderTextLocation(graphics, textLocation, text, color);
}
}
} }

View File

@@ -26,22 +26,22 @@ package net.runelite.client.plugins.implings;
import com.google.inject.Provides; import com.google.inject.Provides;
import java.awt.Color; import java.awt.Color;
import java.util.ArrayList; import java.util.function.Function;
import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import lombok.AccessLevel;
import lombok.Getter;
import net.runelite.api.GameState;
import net.runelite.api.NPC; import net.runelite.api.NPC;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.NpcChanged; import net.runelite.api.events.NpcChanged;
import net.runelite.api.events.NpcDespawned;
import net.runelite.api.events.NpcSpawned; import net.runelite.api.events.NpcSpawned;
import net.runelite.client.Notifier; import net.runelite.client.Notifier;
import net.runelite.client.callback.ClientThread;
import net.runelite.client.config.ConfigManager; import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe; import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.events.ConfigChanged;
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.HighlightedNpc;
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;
@PluginDescriptor( @PluginDescriptor(
@@ -49,26 +49,45 @@ import net.runelite.client.ui.overlay.OverlayManager;
description = "Highlight nearby implings on the minimap and on-screen", description = "Highlight nearby implings on the minimap and on-screen",
tags = {"hunter", "minimap", "overlay", "imp"} tags = {"hunter", "minimap", "overlay", "imp"}
) )
@PluginDependency(NpcIndicatorsPlugin.class)
public class ImplingsPlugin extends Plugin public class ImplingsPlugin extends Plugin
{ {
@Getter(AccessLevel.PACKAGE)
private final List<NPC> implings = new ArrayList<>();
@Inject @Inject
private OverlayManager overlayManager; private OverlayManager overlayManager;
@Inject @Inject
private ImplingsOverlay overlay; private ImplingsOverlay overlay;
@Inject
private ImplingMinimapOverlay minimapOverlay;
@Inject @Inject
private ImplingsConfig config; private ImplingsConfig config;
@Inject @Inject
private Notifier notifier; private Notifier notifier;
@Inject
private NpcIndicatorsService npcIndicatorsService;
@Inject
private ClientThread clientThread;
public final Function<NPC, HighlightedNpc> isTarget = (npc) ->
{
Impling impling = Impling.findImpling(npc.getId());
if (impling != null && showImpling(impling))
{
Color color = implingColor(impling);
return HighlightedNpc.builder()
.npc(npc)
.highlightColor(color)
.fillColor(new Color(0, 0, 0, 50))
.tile(true)
.name(true)
.nameOnMinimap(config.showName())
.build();
}
return null;
};
@Provides @Provides
ImplingsConfig getConfig(ConfigManager configManager) ImplingsConfig getConfig(ConfigManager configManager)
{ {
@@ -79,15 +98,25 @@ public class ImplingsPlugin extends Plugin
protected void startUp() protected void startUp()
{ {
overlayManager.add(overlay); overlayManager.add(overlay);
overlayManager.add(minimapOverlay); npcIndicatorsService.registerHighlighter(isTarget);
} }
@Override @Override
protected void shutDown() protected void shutDown()
{ {
implings.clear(); npcIndicatorsService.unregisterHighlighter(isTarget);
overlayManager.remove(overlay); overlayManager.remove(overlay);
overlayManager.remove(minimapOverlay); }
@Subscribe
private void onConfigChanged(ConfigChanged event)
{
if (!event.getGroup().equals(ImplingsConfig.GROUP))
{
return;
}
clientThread.invoke(npcIndicatorsService::rebuild);
} }
@Subscribe @Subscribe
@@ -102,8 +131,6 @@ public class ImplingsPlugin extends Plugin
{ {
notifier.notify(impling.getImplingType().getName() + " impling is in the area"); notifier.notify(impling.getImplingType().getName() + " impling is in the area");
} }
implings.add(npc);
} }
} }
@@ -119,43 +146,11 @@ public class ImplingsPlugin extends Plugin
{ {
notifier.notify(impling.getImplingType().getName() + " impling is in the area"); notifier.notify(impling.getImplingType().getName() + " impling is in the area");
} }
if (!implings.contains(npc))
{
implings.add(npc);
}
} }
} }
@Subscribe private boolean showImpling(Impling impling)
public void onGameStateChanged(GameStateChanged event)
{ {
if (event.getGameState() == GameState.LOGIN_SCREEN || event.getGameState() == GameState.HOPPING)
{
implings.clear();
}
}
@Subscribe
public void onNpcDespawned(NpcDespawned npcDespawned)
{
if (implings.isEmpty())
{
return;
}
NPC npc = npcDespawned.getNpc();
implings.remove(npc);
}
boolean showNpc(NPC npc)
{
Impling impling = Impling.findImpling(npc.getId());
if (impling == null)
{
return false;
}
ImplingsConfig.ImplingMode impMode = showImplingType(impling.getImplingType()); ImplingsConfig.ImplingMode impMode = showImplingType(impling.getImplingType());
return impMode == ImplingsConfig.ImplingMode.HIGHLIGHT || impMode == ImplingsConfig.ImplingMode.NOTIFY; return impMode == ImplingsConfig.ImplingMode.HIGHLIGHT || impMode == ImplingsConfig.ImplingMode.NOTIFY;
} }
@@ -193,17 +188,10 @@ public class ImplingsPlugin extends Plugin
} }
} }
Color npcToColor(NPC npc) private Color implingColor(Impling impling)
{ {
Impling impling = Impling.findImpling(npc.getId());
if (impling == null)
{
return null;
}
switch (impling.getImplingType()) switch (impling.getImplingType())
{ {
case BABY: case BABY:
return config.getBabyColor(); return config.getBabyColor();
case YOUNG: case YOUNG:
@@ -229,7 +217,7 @@ public class ImplingsPlugin extends Plugin
case LUCKY: case LUCKY:
return config.getLuckyColor(); return config.getLuckyColor();
default: default:
return null; throw new IllegalArgumentException();
} }
} }
} }

View File

@@ -0,0 +1,45 @@
/*
* 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.awt.Color;
import lombok.Builder;
import lombok.Value;
import net.runelite.api.NPC;
@Value
@Builder
public class HighlightedNpc
{
NPC npc;
Color highlightColor;
Color fillColor;
boolean hull;
boolean tile;
boolean swTile;
boolean outline;
boolean name;
boolean nameOnMinimap;
}

View File

@@ -39,7 +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 java.util.function.Function;
import javax.inject.Inject; import javax.inject.Inject;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.Getter; import lombok.Getter;
@@ -116,7 +116,7 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService
* NPCs to highlight * NPCs to highlight
*/ */
@Getter(AccessLevel.PACKAGE) @Getter(AccessLevel.PACKAGE)
private final Set<NPC> highlightedNpcs = new HashSet<>(); private final Map<NPC, HighlightedNpc> highlightedNpcs = new HashMap<>();
/** /**
* Dead NPCs that should be displayed with a respawn indicator if the config is on. * Dead NPCs that should be displayed with a respawn indicator if the config is on.
@@ -175,7 +175,7 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService
*/ */
private boolean skipNextSpawnCheck = false; private boolean skipNextSpawnCheck = false;
private final List<Predicate<NPC>> higlightPredicates = new ArrayList<>(); private final List<Function<NPC, HighlightedNpc>> higlightPredicates = new ArrayList<>();
@Provides @Provides
NpcIndicatorsConfig provideConfig(ConfigManager configManager) NpcIndicatorsConfig provideConfig(ConfigManager configManager)
@@ -265,7 +265,7 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService
color = config.deadNpcMenuColor(); color = config.deadNpcMenuColor();
} }
if (color == null && highlightedNpcs.contains(npc) && config.highlightMenuNames() && (!npc.isDead() || !config.ignoreDeadNpcs())) if (color == null && highlightedNpcs.containsKey(npc) && config.highlightMenuNames() && (!npc.isDead() || !config.ignoreDeadNpcs()))
{ {
color = config.highlightColor(); color = config.highlightColor();
} }
@@ -365,7 +365,7 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService
memorizeNpc(npc); memorizeNpc(npc);
npcTags.add(id); npcTags.add(id);
} }
highlightedNpcs.add(npc); highlightedNpcs.put(npc, highlightedNpc(npc));
} }
} }
else else
@@ -391,14 +391,14 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService
if (npcTags.contains(npc.getIndex())) if (npcTags.contains(npc.getIndex()))
{ {
memorizeNpc(npc); memorizeNpc(npc);
highlightedNpcs.add(npc); highlightedNpcs.put(npc, highlightedNpc(npc));
spawnedNpcsThisTick.add(npc); spawnedNpcsThisTick.add(npc);
return; return;
} }
if (highlightMatchesNPCName(npcName)) if (highlightMatchesNPCName(npcName))
{ {
highlightedNpcs.add(npc); highlightedNpcs.put(npc, highlightedNpc(npc));
if (!client.isInInstancedRegion()) if (!client.isInInstancedRegion())
{ {
memorizeNpc(npc); memorizeNpc(npc);
@@ -407,11 +407,12 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService
return; return;
} }
for (Predicate<NPC> predicate : higlightPredicates) for (Function<NPC, HighlightedNpc> predicate : higlightPredicates)
{ {
if (predicate.test(npc)) HighlightedNpc highlightedNpc = predicate.apply(npc);
if (highlightedNpc != null)
{ {
highlightedNpcs.add(npc); highlightedNpcs.put(npc, highlightedNpc);
if (!client.isInInstancedRegion()) if (!client.isInInstancedRegion())
{ {
memorizeNpc(npc); memorizeNpc(npc);
@@ -452,7 +453,18 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService
if (npcTags.contains(npc.getIndex()) if (npcTags.contains(npc.getIndex())
|| highlightMatchesNPCName(npcName)) || highlightMatchesNPCName(npcName))
{ {
highlightedNpcs.add(npc); highlightedNpcs.put(npc, highlightedNpc(npc));
return;
}
for (Function<NPC, HighlightedNpc> predicate : higlightPredicates)
{
HighlightedNpc highlightedNpc = predicate.apply(npc);
if (highlightedNpc != null)
{
highlightedNpcs.put(npc, highlightedNpc);
return;
}
} }
} }
@@ -586,7 +598,7 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService
if (npcTags.contains(npc.getIndex())) if (npcTags.contains(npc.getIndex()))
{ {
highlightedNpcs.add(npc); highlightedNpcs.put(npc, highlightedNpc(npc));
continue; continue;
} }
@@ -596,19 +608,20 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService
{ {
memorizeNpc(npc); memorizeNpc(npc);
} }
highlightedNpcs.add(npc); highlightedNpcs.put(npc, highlightedNpc(npc));
continue; continue;
} }
for (Predicate<NPC> predicate : higlightPredicates) for (Function<NPC, HighlightedNpc> predicate : higlightPredicates)
{ {
if (predicate.test(npc)) HighlightedNpc highlightedNpc = predicate.apply(npc);
if (highlightedNpc != null)
{ {
if (!client.isInInstancedRegion()) if (!client.isInInstancedRegion())
{ {
memorizeNpc(npc); memorizeNpc(npc);
} }
highlightedNpcs.add(npc); highlightedNpcs.put(npc, highlightedNpc);
continue outer; continue outer;
} }
} }
@@ -721,14 +734,29 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService
teleportGraphicsObjectSpawnedThisTick.clear(); teleportGraphicsObjectSpawnedThisTick.clear();
} }
private HighlightedNpc highlightedNpc(NPC npc)
{
return HighlightedNpc.builder()
.npc(npc)
.highlightColor(config.highlightColor())
.fillColor(config.fillColor())
.hull(config.highlightHull())
.tile(config.highlightTile())
.swTile(config.highlightSouthWestTile())
.outline(config.highlightOutline())
.name(config.drawNames())
.nameOnMinimap(config.drawMinimapNames())
.build();
}
@Override @Override
public void registerHighlighter(Predicate<NPC> p) public void registerHighlighter(Function<NPC, HighlightedNpc> p)
{ {
higlightPredicates.add(p); higlightPredicates.add(p);
} }
@Override @Override
public void unregisterHighlighter(Predicate<NPC> p) public void unregisterHighlighter(Function<NPC, HighlightedNpc> p)
{ {
higlightPredicates.remove(p); higlightPredicates.remove(p);
} }

View File

@@ -24,12 +24,12 @@
*/ */
package net.runelite.client.plugins.npchighlight; package net.runelite.client.plugins.npchighlight;
import java.util.function.Predicate; import java.util.function.Function;
import net.runelite.api.NPC; import net.runelite.api.NPC;
public interface NpcIndicatorsService public interface NpcIndicatorsService
{ {
void registerHighlighter(Predicate<NPC> p); void registerHighlighter(Function<NPC, HighlightedNpc> p);
void unregisterHighlighter(Predicate<NPC> p); void unregisterHighlighter(Function<NPC, HighlightedNpc> p);
void rebuild(); void rebuild();
} }

View File

@@ -55,16 +55,18 @@ public class NpcMinimapOverlay extends Overlay
@Override @Override
public Dimension render(Graphics2D graphics) public Dimension render(Graphics2D graphics)
{ {
for (NPC npc : plugin.getHighlightedNpcs()) for (HighlightedNpc highlightedNpc : plugin.getHighlightedNpcs().values())
{ {
renderNpcOverlay(graphics, npc, Text.removeTags(npc.getName()), config.highlightColor()); renderNpcOverlay(graphics, highlightedNpc);
} }
return null; return null;
} }
private void renderNpcOverlay(Graphics2D graphics, NPC actor, String name, Color color) private void renderNpcOverlay(Graphics2D graphics, HighlightedNpc highlightedNpc)
{ {
NPC actor = highlightedNpc.getNpc();
String name = Text.removeTags(actor.getName());
NPCComposition npcComposition = actor.getTransformedComposition(); NPCComposition npcComposition = actor.getTransformedComposition();
if (npcComposition == null || !npcComposition.isInteractible() if (npcComposition == null || !npcComposition.isInteractible()
|| (actor.isDead() && config.ignoreDeadNpcs())) || (actor.isDead() && config.ignoreDeadNpcs()))
@@ -75,9 +77,10 @@ public class NpcMinimapOverlay extends Overlay
Point minimapLocation = actor.getMinimapLocation(); Point minimapLocation = actor.getMinimapLocation();
if (minimapLocation != null) if (minimapLocation != null)
{ {
Color color = highlightedNpc.getHighlightColor();
OverlayUtil.renderMinimapLocation(graphics, minimapLocation, color.darker()); OverlayUtil.renderMinimapLocation(graphics, minimapLocation, color.darker());
if (config.drawMinimapNames()) if (highlightedNpc.isNameOnMinimap())
{ {
OverlayUtil.renderTextLocation(graphics, minimapLocation, name, color); OverlayUtil.renderTextLocation(graphics, minimapLocation, name, color);
} }

View File

@@ -89,9 +89,9 @@ public class NpcSceneOverlay extends Overlay
plugin.getDeadNpcsToDisplay().forEach((id, npc) -> renderNpcRespawn(npc, graphics)); plugin.getDeadNpcsToDisplay().forEach((id, npc) -> renderNpcRespawn(npc, graphics));
} }
for (NPC npc : plugin.getHighlightedNpcs()) for (HighlightedNpc highlightedNpc : plugin.getHighlightedNpcs().values())
{ {
renderNpcOverlay(graphics, npc); renderNpcOverlay(graphics, highlightedNpc);
} }
return null; return null;
@@ -141,8 +141,9 @@ public class NpcSceneOverlay extends Overlay
} }
} }
private void renderNpcOverlay(Graphics2D graphics, NPC actor) private void renderNpcOverlay(Graphics2D graphics, HighlightedNpc highlightedNpc)
{ {
NPC actor = highlightedNpc.getNpc();
NPCComposition npcComposition = actor.getTransformedComposition(); NPCComposition npcComposition = actor.getTransformedComposition();
if (npcComposition == null || !npcComposition.isInteractible() if (npcComposition == null || !npcComposition.isInteractible()
|| (actor.isDead() && config.ignoreDeadNpcs())) || (actor.isDead() && config.ignoreDeadNpcs()))
@@ -150,16 +151,16 @@ public class NpcSceneOverlay extends Overlay
return; return;
} }
final Color borderColor = config.highlightColor(); final Color borderColor = highlightedNpc.getHighlightColor();
final Color fillColor = config.fillColor(); final Color fillColor = highlightedNpc.getFillColor();
if (config.highlightHull()) if (highlightedNpc.isHull())
{ {
Shape objectClickbox = actor.getConvexHull(); Shape objectClickbox = actor.getConvexHull();
renderPoly(graphics, borderColor, fillColor, objectClickbox); renderPoly(graphics, borderColor, fillColor, objectClickbox);
} }
if (config.highlightTile()) if (highlightedNpc.isTile())
{ {
int size = npcComposition.getSize(); int size = npcComposition.getSize();
LocalPoint lp = actor.getLocalLocation(); LocalPoint lp = actor.getLocalLocation();
@@ -168,7 +169,7 @@ public class NpcSceneOverlay extends Overlay
renderPoly(graphics, borderColor, fillColor, tilePoly); renderPoly(graphics, borderColor, fillColor, tilePoly);
} }
if (config.highlightSouthWestTile()) if (highlightedNpc.isSwTile())
{ {
int size = npcComposition.getSize(); int size = npcComposition.getSize();
LocalPoint lp = actor.getLocalLocation(); LocalPoint lp = actor.getLocalLocation();
@@ -181,12 +182,12 @@ public class NpcSceneOverlay extends Overlay
renderPoly(graphics, borderColor, fillColor, southWestTilePoly); renderPoly(graphics, borderColor, fillColor, southWestTilePoly);
} }
if (config.highlightOutline()) if (highlightedNpc.isOutline())
{ {
modelOutlineRenderer.drawOutline(actor, (int)config.borderWidth(), borderColor, config.outlineFeather()); modelOutlineRenderer.drawOutline(actor, (int)config.borderWidth(), borderColor, config.outlineFeather());
} }
if (config.drawNames() && actor.getName() != null) if (highlightedNpc.isName() && actor.getName() != null)
{ {
String npcName = Text.removeTags(actor.getName()); String npcName = Text.removeTags(actor.getName());
Point textLocation = actor.getCanvasTextLocation(graphics, npcName, actor.getLogicalHeight() + 40); Point textLocation = actor.getCanvasTextLocation(graphics, npcName, actor.getLogicalHeight() + 40);

View File

@@ -25,6 +25,8 @@
*/ */
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;
@@ -90,17 +92,51 @@ public interface SlayerConfig extends Config
@ConfigItem( @ConfigItem(
position = 5, position = 5,
keyName = "highlightTargets", keyName = "highlightHull",
name = "Highlight Targets", name = "Highlight hull",
description = "Highlight monsters you can kill for your current slayer assignment" description = "Configures whether the NPC hull should be highlighted"
) )
default boolean highlightTargets() default boolean highlightHull()
{
return false;
}
@ConfigItem(
position = 6,
keyName = "highlightTile",
name = "Highlight tile",
description = "Configures whether the NPC tile should be highlighted"
)
default boolean highlightTile()
{ {
return false; return false;
} }
@ConfigItem( @ConfigItem(
position = 7, position = 7,
keyName = "highlightOutline",
name = "Highlight outline",
description = "Configures whether or not the NPC outline should be highlighted"
)
default boolean highlightOutline()
{
return false;
}
@Alpha
@ConfigItem(
position = 8,
keyName = "targetColor",
name = "Target color",
description = "Color of the highlighted targets"
)
default Color getTargetColor()
{
return Color.RED;
}
@ConfigItem(
position = 9,
keyName = "weaknessPrompt", keyName = "weaknessPrompt",
name = "Show Monster Weakness", name = "Show Monster Weakness",
description = "Show an overlay on a monster when it is weak enough to finish off (Only Lizards, Gargoyles & Rockslugs)" description = "Show an overlay on a monster when it is weak enough to finish off (Only Lizards, Gargoyles & Rockslugs)"
@@ -111,7 +147,7 @@ public interface SlayerConfig extends Config
} }
@ConfigItem( @ConfigItem(
position = 8, position = 10,
keyName = "taskCommand", keyName = "taskCommand",
name = "Task Command", name = "Task Command",
description = "Configures whether the slayer task command is enabled<br> !task" description = "Configures whether the slayer task command is enabled<br> !task"

View File

@@ -39,7 +39,7 @@ 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.function.Function;
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;
@@ -86,6 +86,7 @@ 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.PluginDependency;
import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.plugins.npchighlight.HighlightedNpc;
import net.runelite.client.plugins.npchighlight.NpcIndicatorsPlugin; import net.runelite.client.plugins.npchighlight.NpcIndicatorsPlugin;
import net.runelite.client.plugins.npchighlight.NpcIndicatorsService; import net.runelite.client.plugins.npchighlight.NpcIndicatorsService;
import net.runelite.client.ui.overlay.OverlayManager; import net.runelite.client.ui.overlay.OverlayManager;
@@ -210,7 +211,23 @@ 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); public final Function<NPC, HighlightedNpc> isTarget = (n) ->
{
if ((config.highlightHull() || config.highlightTile() || config.highlightOutline()) && targets.contains(n))
{
Color color = config.getTargetColor();
return HighlightedNpc.builder()
.npc(n)
.highlightColor(color)
.fillColor(ColorUtil.colorWithAlpha(color, color.getAlpha() / 12))
.hull(config.highlightHull())
.tile(config.highlightTile())
.outline(config.highlightOutline())
.build();
}
return null;
};
@Override @Override
protected void startUp() throws Exception protected void startUp() throws Exception
@@ -603,7 +620,7 @@ public class SlayerPlugin extends Plugin
} }
else else
{ {
npcIndicatorsService.rebuild(); clientThread.invoke(npcIndicatorsService::rebuild);
} }
} }

View File

@@ -25,10 +25,12 @@
package net.runelite.client.plugins.chatcommands; package net.runelite.client.plugins.chatcommands;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.gson.Gson;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.testing.fieldbinder.Bind; import com.google.inject.testing.fieldbinder.Bind;
import com.google.inject.testing.fieldbinder.BoundFieldModule; import com.google.inject.testing.fieldbinder.BoundFieldModule;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import javax.inject.Inject; import javax.inject.Inject;
import net.runelite.api.ChatMessageType; import net.runelite.api.ChatMessageType;
@@ -38,18 +40,21 @@ import static net.runelite.api.ChatMessageType.TRADE;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.api.MessageNode; import net.runelite.api.MessageNode;
import net.runelite.api.Player; import net.runelite.api.Player;
import net.runelite.api.ScriptID;
import net.runelite.api.events.ChatMessage; import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.GameTick; import net.runelite.api.events.GameTick;
import net.runelite.api.events.ScriptPostFired;
import net.runelite.api.events.WidgetLoaded; import net.runelite.api.events.WidgetLoaded;
import net.runelite.api.widgets.Widget; import net.runelite.api.widgets.Widget;
import static net.runelite.api.widgets.WidgetID.ADVENTURE_LOG_ID; import static net.runelite.api.widgets.WidgetID.ADVENTURE_LOG_ID;
import static net.runelite.api.widgets.WidgetID.GENERIC_SCROLL_GROUP_ID; import static net.runelite.api.widgets.WidgetID.DIARY_QUEST_GROUP_ID;
import net.runelite.api.widgets.WidgetInfo; import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.chat.ChatCommandManager; import net.runelite.client.chat.ChatCommandManager;
import net.runelite.client.chat.ChatMessageManager; import net.runelite.client.chat.ChatMessageManager;
import net.runelite.client.config.ChatColorConfig; import net.runelite.client.config.ChatColorConfig;
import net.runelite.client.config.ConfigManager; import net.runelite.client.config.ConfigManager;
import net.runelite.client.config.RuneLiteConfig; import net.runelite.client.config.RuneLiteConfig;
import net.runelite.http.api.RuneLiteAPI;
import net.runelite.http.api.chat.ChatClient; import net.runelite.http.api.chat.ChatClient;
import net.runelite.http.api.hiscore.HiscoreClient; import net.runelite.http.api.hiscore.HiscoreClient;
import net.runelite.http.api.hiscore.HiscoreSkill; import net.runelite.http.api.hiscore.HiscoreSkill;
@@ -62,11 +67,9 @@ import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
import org.mockito.Mock; import org.mockito.Mock;
import static org.mockito.Mockito.any; import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
@@ -118,6 +121,8 @@ public class ChatCommandsPluginTest
@Inject @Inject
ChatCommandsPlugin chatCommandsPlugin; ChatCommandsPlugin chatCommandsPlugin;
final Gson gson = RuneLiteAPI.GSON;
@Before @Before
public void before() public void before()
{ {
@@ -183,17 +188,17 @@ public class ChatCommandsPluginTest
} }
@Test @Test
public void testTheatreOfBloodStoryMode() public void testTheatreOfBloodEntryMode()
{ {
ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "",
"Wave 'The Final Challenge' (Story Mode) complete!<br>Duration: <col=ff0000>2:42</col><br>Theatre of Blood wave completion time: <col=ff0000>17:00</col> (new personal best)", null, 0); "Wave 'The Final Challenge' (Entry Mode) complete!<br>Duration: <col=ff0000>2:42</col><br>Theatre of Blood wave completion time: <col=ff0000>17:00</col> (new personal best)", null, 0);
chatCommandsPlugin.onChatMessage(chatMessage); chatCommandsPlugin.onChatMessage(chatMessage);
ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", "Your completed Theatre of Blood: Story Mode count is: <col=ff0000>73</col>.", null, 0); ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", "Your completed Theatre of Blood: Entry Mode count is: <col=ff0000>73</col>.", null, 0);
chatCommandsPlugin.onChatMessage(chatMessageEvent); chatCommandsPlugin.onChatMessage(chatMessageEvent);
verify(configManager).setRSProfileConfiguration("killcount", "theatre of blood story mode", 73); verify(configManager).setRSProfileConfiguration("killcount", "theatre of blood entry mode", 73);
verify(configManager).setRSProfileConfiguration("personalbest", "theatre of blood story mode", 17 * 60.); verify(configManager).setRSProfileConfiguration("personalbest", "theatre of blood entry mode", 17 * 60.);
} }
@Test @Test
@@ -535,181 +540,6 @@ public class ChatCommandsPluginTest
verify(configManager).setRSProfileConfiguration("personalbest", "chambers of xeric", 20 * 60 + 19.2); verify(configManager).setRSProfileConfiguration("personalbest", "chambers of xeric", 20 * 60 + 19.2);
} }
@Test
public void testAdventureLogCountersPage()
{
Widget advLogWidget = mock(Widget.class);
Widget advLogExploitsTextWidget = mock(Widget.class);
when(advLogWidget.getChild(ChatCommandsPlugin.ADV_LOG_EXPLOITS_TEXT_INDEX)).thenReturn(advLogExploitsTextWidget);
when(advLogExploitsTextWidget.getText()).thenReturn("The Exploits of " + PLAYER_NAME);
when(client.getWidget(WidgetInfo.ADVENTURE_LOG)).thenReturn(advLogWidget);
when(configManager.getRSProfileConfiguration(anyString(), anyString(), any(Class.class))).thenReturn(2224.0);
WidgetLoaded advLogEvent = new WidgetLoaded();
advLogEvent.setGroupId(ADVENTURE_LOG_ID);
chatCommandsPlugin.onWidgetLoaded(advLogEvent);
chatCommandsPlugin.onGameTick(new GameTick());
String COUNTER_TEXT = "Duel Arena<br>Wins: <col=d0c0b0>4</col><br>Losses: <col=d0c0b0>2</col>" +
"<br><br>Last Man Standing<br>Rank: <col=d0c0b0>0</col>" +
"<br><br>Treasure Trails<br>Beginner: <col=d0c0b0>0</col><br>Easy: <col=d0c0b0>7</col>" +
"<br>Medium: <col=d0c0b0>28</col><br>Hard: <col=d0c0b0>108</col><br>Elite: <col=d0c0b0>15</col>" +
"<br>Master: <col=d0c0b0>27</col><br>Rank: <col=d0c0b0>Novice</col>" +
"<br><br>Chompy Hunting<br>Kills: <col=d0c0b0>1,000</col><br>Rank: <col=d0c0b0>Ogre Expert</col>" +
"<br><br>Order of the White Knights<br>Rank: <col=d0c0b0>Master</col><br>with a kill score of <col=d0c0b0>1,300</col>" +
"<br><br>TzHaar Fight Cave<br>Fastest run: <col=d0c0b0>38:10</col>" +
"<br><br>Inferno<br>Fastest run: <col=d0c0b0>-</col><br><br>Zulrah<br>" +
"Fastest kill: <col=d0c0b0>5:48</col><br><br>Vorkath<br>Fastest kill: <col=d0c0b0>1:21</col>" +
"<br><br>Galvek<br>Fastest kill: <col=d0c0b0>-</col><br><br>Grotesque Guardians<br>" +
"Fastest kill: <col=d0c0b0>2:49</col><br><br>Alchemical Hydra<br>Fastest kill: <col=d0c0b0>-</col>" +
"<br><br>Hespori<br>Fastest kill: <col=d0c0b0>0:57</col><br><br>Nightmare<br>" +
"Fastest kill: <col=d0c0b0>3:30</col><br><br>The Gauntlet<br>Fastest run: <col=d0c0b0>-</col>" +
"<br><br>The Corrupted Gauntlet<br>Fastest run: <col=d0c0b0>-</col><br><br>Fragment of Seren<br>Fastest kill: <col=d0c0b0>-</col>" +
"<br><br>Chambers of Xeric<br>Fastest run - (Team size: 24+ players): <col=d0c0b0>24:17</col>" +
"<br><br>Chambers of Xeric - Challenge mode<br>Fastest run - (Team size: Solo): <col=d0c0b0>22:15</col>" +
"<br><br>Barbarian Assault<br>High-level gambles: <col=d0c0b0>0</col><br><br>Fremennik spirits rested: <col=d0c0b0>0</col>";
Widget countersPage = mock(Widget.class);
when(countersPage.getText()).thenReturn(COUNTER_TEXT);
when(client.getWidget(WidgetInfo.GENERIC_SCROLL_TEXT)).thenReturn(countersPage);
WidgetLoaded countersLogEvent = new WidgetLoaded();
countersLogEvent.setGroupId(GENERIC_SCROLL_GROUP_ID);
chatCommandsPlugin.onWidgetLoaded(countersLogEvent);
chatCommandsPlugin.onGameTick(new GameTick());
verify(configManager).setRSProfileConfiguration("personalbest", "tztok-jad", 38 * 60 + 10.0);
verify(configManager).setRSProfileConfiguration("personalbest", "zulrah", 5 * 60 + 48.0);
verify(configManager).setRSProfileConfiguration("personalbest", "vorkath", 60 + 21.0);
verify(configManager).setRSProfileConfiguration("personalbest", "grotesque guardians", 2 * 60 + 49.0);
verify(configManager).setRSProfileConfiguration("personalbest", "hespori", 57.0);
verify(configManager).setRSProfileConfiguration("personalbest", "nightmare", 3 * 60 + 30.0);
verify(configManager).setRSProfileConfiguration("personalbest", "chambers of xeric", 24 * 60 + 17.0);
verify(configManager).setRSProfileConfiguration("personalbest", "chambers of xeric challenge mode", 22 * 60 + 15.0);
}
@Test
public void testAdventurerLogCountersPage2()
{
Widget advLogWidget = mock(Widget.class);
Widget advLogExploitsTextWidget = mock(Widget.class);
when(advLogWidget.getChild(ChatCommandsPlugin.ADV_LOG_EXPLOITS_TEXT_INDEX)).thenReturn(advLogExploitsTextWidget);
when(advLogExploitsTextWidget.getText()).thenReturn("The Exploits of " + PLAYER_NAME);
when(client.getWidget(WidgetInfo.ADVENTURE_LOG)).thenReturn(advLogWidget);
WidgetLoaded advLogEvent = new WidgetLoaded();
advLogEvent.setGroupId(ADVENTURE_LOG_ID);
chatCommandsPlugin.onWidgetLoaded(advLogEvent);
chatCommandsPlugin.onGameTick(new GameTick());
String COUNTER_TEXT = "Duel Arena<br>Wins: <col=d0c0b0>12</col><br>Losses: <col=d0c0b0>20</col>" +
"<br><br>Last Man Standing<br>Rank: <col=d0c0b0>0</col>" +
"<br><br>Treasure Trails<br>Beginner: <col=d0c0b0>1</col><br>Easy: <col=d0c0b0>4</col>" +
"<br>Medium: <col=d0c0b0>35</col><br>Hard: <col=d0c0b0>66</col><br>Elite: <col=d0c0b0>2</col>" +
"<br>Master: <col=d0c0b0>0</col><br>Rank: <col=d0c0b0>Novice</col>" +
"<br><br>Chompy Hunting<br>Kills: <col=d0c0b0>300</col><br>Rank: <col=d0c0b0>Ogre Forester</col>" +
"<br><br>Order of the White Knights<br>Rank: <col=d0c0b0>Unrated</col><br>with a kill score of <col=d0c0b0>99</col>" +
"<br><br>TzHaar Fight Cave<br>Fastest run: <col=d0c0b0>65:12</col>" +
"<br><br>Inferno<br>Fastest run: <col=d0c0b0>-</col><br><br>Zulrah<br>" +
"Fastest kill: <col=d0c0b0>2:55</col><br><br>Vorkath<br>Fastest kill: <col=d0c0b0>1:37</col>" +
"<br><br>Galvek<br>Fastest kill: <col=d0c0b0>-</col><br><br>Grotesque Guardians<br>" +
"Fastest kill: <col=d0c0b0>-</col><br><br>Alchemical Hydra<br>Fastest kill: <col=d0c0b0>-</col>" +
"<br><br>Hespori<br>Fastest kill: <col=d0c0b0>1:42</col><br><br>Nightmare<br>" +
"Fastest kill: <col=d0c0b0>-</col><br><br>The Gauntlet<br>Fastest run: <col=d0c0b0>-</col>" +
"<br><br>The Corrupted Gauntlet<br>Fastest run: <col=d0c0b0>-</col><br><br>Fragment of Seren<br>Fastest kill: <col=d0c0b0>-</col>" +
"<br><br>Chambers of Xeric<br>Fastest run - (Team size: Solo): <col=d0c0b0>21:23</col><br>Fastest run - (Team size: 3 players): <col=d0c0b0>27:16</col>" +
"<br><br>Chambers of Xeric - Challenge mode<br>Fastest run - (Team size: Solo): <col=d0c0b0>34:30</col><br>Fastest run - (Team size: 4 players): <col=d0c0b0>21:26</col>" +
"<br><br>Barbarian Assault<br>High-level gambles: <col=d0c0b0>0</col><br><br>Fremennik spirits rested: <col=d0c0b0>0</col>";
Widget countersPage = mock(Widget.class);
when(countersPage.getText()).thenReturn(COUNTER_TEXT);
when(client.getWidget(WidgetInfo.GENERIC_SCROLL_TEXT)).thenReturn(countersPage);
WidgetLoaded countersLogEvent = new WidgetLoaded();
countersLogEvent.setGroupId(GENERIC_SCROLL_GROUP_ID);
chatCommandsPlugin.onWidgetLoaded(countersLogEvent);
chatCommandsPlugin.onGameTick(new GameTick());
verify(configManager).setRSProfileConfiguration("personalbest", "tztok-jad", 65 * 60 + 12.0);
verify(configManager).setRSProfileConfiguration("personalbest", "zulrah", 2 * 60 + 55.0);
verify(configManager).setRSProfileConfiguration("personalbest", "vorkath", 60 + 37.0);
verify(configManager).setRSProfileConfiguration("personalbest", "hespori", 60 + 42.0);
verify(configManager).setRSProfileConfiguration("personalbest", "chambers of xeric", 21 * 60 + 23.0);
verify(configManager).setRSProfileConfiguration("personalbest", "chambers of xeric challenge mode", 21 * 60 + 26.0);
}
@Test
public void testAdventurerLogCountersPagePrecise()
{
Widget advLogWidget = mock(Widget.class);
Widget advLogExploitsTextWidget = mock(Widget.class);
when(advLogWidget.getChild(ChatCommandsPlugin.ADV_LOG_EXPLOITS_TEXT_INDEX)).thenReturn(advLogExploitsTextWidget);
when(advLogExploitsTextWidget.getText()).thenReturn("The Exploits of " + PLAYER_NAME);
when(client.getWidget(WidgetInfo.ADVENTURE_LOG)).thenReturn(advLogWidget);
WidgetLoaded advLogEvent = new WidgetLoaded();
advLogEvent.setGroupId(ADVENTURE_LOG_ID);
chatCommandsPlugin.onWidgetLoaded(advLogEvent);
chatCommandsPlugin.onGameTick(new GameTick());
String COUNTER_TEXT = "Duel Arena<br>Wins: <col=d0c0b0>12</col><br>Losses: <col=d0c0b0>20</col>" +
"<br><br>Last Man Standing<br>Rank: <col=d0c0b0>0</col>" +
"<br><br>Treasure Trails<br>Beginner: <col=d0c0b0>1</col><br>Easy: <col=d0c0b0>4</col>" +
"<br>Medium: <col=d0c0b0>35</col><br>Hard: <col=d0c0b0>66</col><br>Elite: <col=d0c0b0>2</col>" +
"<br>Master: <col=d0c0b0>0</col><br>Rank: <col=d0c0b0>Novice</col>" +
"<br><br>Chompy Hunting<br>Kills: <col=d0c0b0>300</col><br>Rank: <col=d0c0b0>Ogre Forester</col>" +
"<br><br>Order of the White Knights<br>Rank: <col=d0c0b0>Unrated</col><br>with a kill score of <col=d0c0b0>99</col>" +
"<br><br>TzHaar Fight Cave<br>Fastest run: <col=d0c0b0>65:12.00</col>" +
"<br><br>Inferno<br>Fastest run: <col=d0c0b0>-</col><br><br>Zulrah<br>" +
"Fastest kill: <col=d0c0b0>2:55.20</col><br><br>Vorkath<br>Fastest kill: <col=d0c0b0>1:37.20</col>" +
"<br><br>Galvek<br>Fastest kill: <col=d0c0b0>-</col><br><br>Grotesque Guardians<br>" +
"Fastest kill: <col=d0c0b0>-</col><br><br>Alchemical Hydra<br>Fastest kill: <col=d0c0b0>-</col>" +
"<br><br>Hespori<br>Fastest kill: <col=d0c0b0>1:42.40</col><br><br>Nightmare<br>" +
"Fastest kill: <col=d0c0b0>-</col><br><br>The Gauntlet<br>Fastest run: <col=d0c0b0>-</col>" +
"<br><br>The Corrupted Gauntlet<br>Fastest run: <col=d0c0b0>-</col><br><br>Fragment of Seren<br>Fastest kill: <col=d0c0b0>-</col>" +
"<br><br>Chambers of Xeric<br>Fastest run - (Team size: Solo): <col=d0c0b0>21:23.20</col><br>Fastest run - (Team size: 3 players): <col=d0c0b0>27:16.40</col>" +
"<br><br>Chambers of Xeric - Challenge mode<br>Fastest run - (Team size: Solo): <col=d0c0b0>34:30.20</col><br>Fastest run - (Team size: 4 players): <col=d0c0b0>21:26.00</col>" +
"<br><br>Barbarian Assault<br>High-level gambles: <col=d0c0b0>0</col><br><br>Fremennik spirits rested: <col=d0c0b0>0</col>";
Widget countersPage = mock(Widget.class);
when(countersPage.getText()).thenReturn(COUNTER_TEXT);
when(client.getWidget(WidgetInfo.GENERIC_SCROLL_TEXT)).thenReturn(countersPage);
WidgetLoaded countersLogEvent = new WidgetLoaded();
countersLogEvent.setGroupId(GENERIC_SCROLL_GROUP_ID);
chatCommandsPlugin.onWidgetLoaded(countersLogEvent);
chatCommandsPlugin.onGameTick(new GameTick());
verify(configManager).setRSProfileConfiguration("personalbest", "tztok-jad", 65 * 60 + 12.0);
verify(configManager).setRSProfileConfiguration("personalbest", "zulrah", 2 * 60 + 55.2);
verify(configManager).setRSProfileConfiguration("personalbest", "vorkath", 60 + 37.2);
verify(configManager).setRSProfileConfiguration("personalbest", "hespori", 60 + 42.40);
verify(configManager).setRSProfileConfiguration("personalbest", "chambers of xeric", 21 * 60 + 23.20);
verify(configManager).setRSProfileConfiguration("personalbest", "chambers of xeric challenge mode", 21 * 60 + 26.0);
}
@Test
public void testNotYourAdventureLogCountersPage()
{
Widget advLogWidget = mock(Widget.class);
Widget advLogExploitsTextWidget = mock(Widget.class);
when(advLogWidget.getChild(ChatCommandsPlugin.ADV_LOG_EXPLOITS_TEXT_INDEX)).thenReturn(advLogExploitsTextWidget);
when(advLogExploitsTextWidget.getText()).thenReturn("The Exploits of " + "not the player");
when(client.getWidget(WidgetInfo.ADVENTURE_LOG)).thenReturn(advLogWidget);
WidgetLoaded advLogEvent = new WidgetLoaded();
advLogEvent.setGroupId(ADVENTURE_LOG_ID);
chatCommandsPlugin.onWidgetLoaded(advLogEvent);
chatCommandsPlugin.onGameTick(new GameTick());
WidgetLoaded countersLogEvent = new WidgetLoaded();
countersLogEvent.setGroupId(GENERIC_SCROLL_GROUP_ID);
chatCommandsPlugin.onWidgetLoaded(countersLogEvent);
chatCommandsPlugin.onGameTick(new GameTick());
verifyNoMoreInteractions(configManager);
}
@Test @Test
public void testPlayerSkillLookup() throws IOException public void testPlayerSkillLookup() throws IOException
{ {
@@ -952,6 +782,158 @@ public class ChatCommandsPluginTest
verify(configManager).setRSProfileConfiguration("personalbest", "tempoross", 5 * 60 + 42.6); verify(configManager).setRSProfileConfiguration("personalbest", "tempoross", 5 * 60 + 42.6);
} }
@Test
public void testNightmarePb()
{
ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Nightmare kill count is: <col=ff0000>1130</col>", null, 0);
chatCommandsPlugin.onChatMessage(chatMessage);
chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Team size: <col=ff0000>5 players</col> Fight duration: <col=ff0000>3:28</col> (new personal best)", null, 0);
chatCommandsPlugin.onChatMessage(chatMessage);
verify(configManager).setRSProfileConfiguration("killcount", "nightmare", 1130);
verify(configManager).setRSProfileConfiguration("personalbest", "nightmare", 3 * 60 + 28.0);
}
@Test
public void testNightmareNoPb()
{
ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Nightmare kill count is: <col=ff0000>1130</col>", null, 0);
chatCommandsPlugin.onChatMessage(chatMessage);
chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Team size: <col=ff0000>Solo</col> Fight duration: <col=ff0000>10:47</col>. Personal best: 8:44", null, 0);
chatCommandsPlugin.onChatMessage(chatMessage);
verify(configManager).setRSProfileConfiguration("killcount", "nightmare", 1130);
verify(configManager).setRSProfileConfiguration("personalbest", "nightmare", 8 * 60 + 44.0);
}
@Test
public void testPlayerPetList()
{
Widget logEntryHeaderWidget = mock(Widget.class);
when(client.getWidget(WidgetInfo.COLLECTION_LOG_ENTRY_HEADER)).thenReturn(logEntryHeaderWidget);
Widget[] logEntryHeaderItemsWidget = new Widget[1];
when(logEntryHeaderWidget.getChildren()).thenReturn(logEntryHeaderItemsWidget);
Widget logEntryHeaderTitleWidget = mock(Widget.class);
when(logEntryHeaderWidget.getChild(ChatCommandsPlugin.COL_LOG_ENTRY_HEADER_TITLE_INDEX))
.thenReturn(logEntryHeaderTitleWidget);
when(logEntryHeaderTitleWidget.getText()).thenReturn("All Pets");
Widget logEntryItemsWidget = mock(Widget.class);
when(client.getWidget(WidgetInfo.COLLECTION_LOG_ENTRY_ITEMS)).thenReturn(logEntryItemsWidget);
Widget[] logPetEntriesWidget = new Widget[3];
for (int i = 0; i < 3; i++)
{
logPetEntriesWidget[i] = mock(Widget.class);
when(logPetEntriesWidget[i].getOpacity()).thenReturn(175);
}
when(logPetEntriesWidget[1].getName()).thenReturn("<col=ff9040>Ikkle hydra</col>");
when(logPetEntriesWidget[1].getOpacity()).thenReturn(0);
when(logEntryItemsWidget.getChildren()).thenReturn(logPetEntriesWidget);
ScriptPostFired scriptPostFired = new ScriptPostFired(ScriptID.COLLECTION_DRAW_LIST);
chatCommandsPlugin.onScriptPostFired(scriptPostFired);
chatCommandsPlugin.onGameTick(new GameTick());
Pet[] playerPetList = new Pet[1];
playerPetList[0] = Pet.IKKLE_HYDRA;
verify(configManager).setRSProfileConfiguration("chatcommands", "pets", gson.toJson(playerPetList));
}
@Test
public void testEmptyPlayerPetList()
{
Widget logEntryHeaderWidget = mock(Widget.class);
when(client.getWidget(WidgetInfo.COLLECTION_LOG_ENTRY_HEADER)).thenReturn(logEntryHeaderWidget);
Widget[] logEntryHeaderItemsWidget = new Widget[1];
when(logEntryHeaderWidget.getChildren()).thenReturn(logEntryHeaderItemsWidget);
Widget logEntryHeaderTitleWidget = mock(Widget.class);
when(logEntryHeaderWidget.getChild(ChatCommandsPlugin.COL_LOG_ENTRY_HEADER_TITLE_INDEX))
.thenReturn(logEntryHeaderTitleWidget);
when(logEntryHeaderTitleWidget.getText()).thenReturn("All Pets");
Widget logEntryItemsWidget = mock(Widget.class);
when(client.getWidget(WidgetInfo.COLLECTION_LOG_ENTRY_ITEMS)).thenReturn(logEntryItemsWidget);
Widget[] logPetEntriesWidget = new Widget[3];
for (int i = 0; i < 3; i++)
{
logPetEntriesWidget[i] = mock(Widget.class);
when(logPetEntriesWidget[i].getOpacity()).thenReturn(175);
}
when(logEntryItemsWidget.getChildren()).thenReturn(logPetEntriesWidget);
ScriptPostFired scriptPostFired = new ScriptPostFired(ScriptID.COLLECTION_DRAW_LIST);
chatCommandsPlugin.onScriptPostFired(scriptPostFired);
chatCommandsPlugin.onGameTick(new GameTick());
verify(configManager).setRSProfileConfiguration("chatcommands", "pets", gson.toJson(new Pet[0]));
}
@Test
public void testUpdatePlayerPetList()
{
Widget logEntryHeaderWidget = mock(Widget.class);
when(client.getWidget(WidgetInfo.COLLECTION_LOG_ENTRY_HEADER)).thenReturn(logEntryHeaderWidget);
Widget[] logEntryHeaderItemsWidget = new Widget[1];
when(logEntryHeaderWidget.getChildren()).thenReturn(logEntryHeaderItemsWidget);
Widget logEntryHeaderTitleWidget = mock(Widget.class);
when(logEntryHeaderWidget.getChild(ChatCommandsPlugin.COL_LOG_ENTRY_HEADER_TITLE_INDEX))
.thenReturn(logEntryHeaderTitleWidget);
when(logEntryHeaderTitleWidget.getText()).thenReturn("All Pets");
Widget logEntryItemsWidget = mock(Widget.class);
when(client.getWidget(WidgetInfo.COLLECTION_LOG_ENTRY_ITEMS)).thenReturn(logEntryItemsWidget);
Widget[] logPetEntriesWidget = new Widget[3];
for (int i = 0; i < 3; i++)
{
logPetEntriesWidget[i] = mock(Widget.class);
when(logPetEntriesWidget[i].getOpacity()).thenReturn(175);
}
when(logPetEntriesWidget[1].getName()).thenReturn("<col=ff9040>Ikkle hydra</col>");
when(logPetEntriesWidget[1].getOpacity()).thenReturn(0);
when(logEntryItemsWidget.getChildren()).thenReturn(logPetEntriesWidget);
ScriptPostFired scriptPostFired = new ScriptPostFired(ScriptID.COLLECTION_DRAW_LIST);
chatCommandsPlugin.onScriptPostFired(scriptPostFired);
chatCommandsPlugin.onGameTick(new GameTick());
Pet[] playerPetList = new Pet[1];
playerPetList[0] = Pet.IKKLE_HYDRA;
verify(configManager).setRSProfileConfiguration("chatcommands", "pets", gson.toJson(playerPetList));
ChatMessage chatMessage = new ChatMessage();
chatMessage.setMessage("New item added to your collection log: Chompy chick");
chatMessage.setType(GAMEMESSAGE);
when(configManager.getRSProfileConfiguration("chatcommands", "pets",
String.class)).thenReturn(gson.toJson(playerPetList));
chatCommandsPlugin.onChatMessage(chatMessage);
playerPetList = new Pet[2];
playerPetList[0] = Pet.IKKLE_HYDRA;
playerPetList[1] = Pet.CHOMPY_CHICK;
verify(configManager).setRSProfileConfiguration("chatcommands", "pets", gson.toJson(playerPetList));
}
@Test @Test
public void testTimeStringToSeconds() public void testTimeStringToSeconds()
{ {
@@ -964,4 +946,130 @@ public class ChatCommandsPluginTest
// h:mm:ss // h:mm:ss
assertEquals(2 * 3600 + 50 * 60 + 30.2, ChatCommandsPlugin.timeStringToSeconds("2:50:30.20"), DELTA); assertEquals(2 * 3600 + 50 * 60 + 30.2, ChatCommandsPlugin.timeStringToSeconds("2:50:30.20"), DELTA);
} }
@Test
public void testCounters()
{
final String[] log = {
"Chompy Hunting",
"Kills: <col=ffffff>1,003</col>",
"Rank: <col=ffffff>Ogre Expert</col>",
"",
"Order of the White Knights",
"Rank: <col=ffffff>Master</col>",
"with a kill score of <col=ffffff>1,300</col>",
"",
"TzHaar Fight Cave",
"Fastest run: <col=ffffff>33:53</col>",
"",
"Inferno",
"Fastest run: <col=ffffff>2:02:20</col>",
"",
"Zulrah",
"Fastest kill: <col=ffffff>0:47</col>",
"",
"Vorkath",
"Fastest kill: <col=ffffff>1:04</col>",
"",
"Galvek",
"Fastest kill: <col=ffffff>-</col>",
"",
"Grotesque Guardians",
"Fastest kill: <col=ffffff>1:20</col>",
"",
"Alchemical Hydra",
"Fastest kill: <col=ffffff>1:34</col>",
"",
"Hespori",
"Fastest kill: <col=ffffff>1:24</col>",
"",
// Nightmare is here 3x!
"Nightmare", // including one only called "Nightmare"
"Fastest kill: <col=ffffff>-</col>", // with no time
"",
"The Nightmare",
"Fastest kill - (Team size: 6+ players): <col=ffffff>3:22</col>",
"",
"The Nightmare",
"Fastest kill - (Team size: 6+ players): <col=ffffff>3:22</col>",
"",
"Phosani's Nightmare",
"Fastest kill: <col=ffffff>-</col>",
"",
"The Gauntlet",
"Fastest run: <col=ffffff>-</col>",
"",
"The Corrupted Gauntlet",
"Fastest run: <col=ffffff>-</col>",
"",
"Fragment of Seren",
"Fastest kill: <col=ffffff>-</col>",
"",
"Chambers of Xeric",
"Fastest run - (Team size: Solo): <col=ffffff>28:07</col>",
"Fastest run - (Team size: 2 players): <col=ffffff>24:40</col>",
"Fastest run - (Team size: 3 players): <col=ffffff>25:35</col>",
"Fastest run - (Team size: 4 players): <col=ffffff>22:40</col>",
"Fastest run - (Team size: 5 players): <col=ffffff>23:00</col>",
"Fastest run - (Team size: 6 players): <col=ffffff>28:11</col>",
"",
"Chambers of Xeric - Challenge mode",
"Fastest run - (Team size: 3 players): <col=ffffff>45:41</col>",
"",
"Theatre of Blood",
"Fastest Room time (former): <col=ffffff>18:45</col>",
"Fastest Wave time (former): <col=ffffff>22:01</col>",
"Fastest Room time - (Team size: (3 player): <col=ffffff>19:50</col>",
"Fastest Overall time - (Team size: 3 player): <col=ffffff>22:47</col>",
"Fastest Room time - (Team size: (4 player): <col=ffffff>17:38</col>",
"Fastest Overall time - (Team size: 4 player): <col=ffffff>20:31</col>",
"Fastest Room time - (Team size: (5 player): <col=ffffff>18:45</col>",
"Fastest Overall time - (Team size: 5 player): <col=ffffff>22:01</col>",
"",
"Tempoross",
"Fastest run: <col=ffffff>3:54</col>",
"",
"Barbarian Assault",
"High-level gambles: <col=ffffff>0</col>",
"",
"Fremennik spirits rested: <col=ffffff>0</col>",
};
// adv log
Widget advLogWidget = mock(Widget.class);
Widget advLogExploitsTextWidget = mock(Widget.class);
when(advLogWidget.getChild(ChatCommandsPlugin.ADV_LOG_EXPLOITS_TEXT_INDEX)).thenReturn(advLogExploitsTextWidget);
when(advLogExploitsTextWidget.getText()).thenReturn("The Exploits of " + PLAYER_NAME);
when(client.getWidget(WidgetInfo.ADVENTURE_LOG)).thenReturn(advLogWidget);
// counters
when(client.getWidget(WidgetInfo.DIARY_QUEST_WIDGET_TEXT)).thenAnswer(a ->
{
Widget widget = mock(Widget.class);
Widget[] children = Arrays.stream(log)
.map(s ->
{
Widget w = mock(Widget.class);
when(w.getText()).thenReturn(s);
return w;
})
.toArray(Widget[]::new);
when(widget.getStaticChildren()).thenReturn(children);
return widget;
});
WidgetLoaded advLogEvent = new WidgetLoaded();
advLogEvent.setGroupId(ADVENTURE_LOG_ID);
chatCommandsPlugin.onWidgetLoaded(advLogEvent);
chatCommandsPlugin.onGameTick(new GameTick());
WidgetLoaded countersLogEvent = new WidgetLoaded();
countersLogEvent.setGroupId(DIARY_QUEST_GROUP_ID);
chatCommandsPlugin.onWidgetLoaded(countersLogEvent);
chatCommandsPlugin.onGameTick(new GameTick());
verify(configManager).setRSProfileConfiguration("personalbest", "tztok-jad", 2033.0);
verify(configManager).setRSProfileConfiguration("personalbest", "tempoross", 234.0);
verify(configManager).setRSProfileConfiguration("personalbest", "chambers of xeric", 1360.0); // the lowest time
}
} }

View File

@@ -155,12 +155,12 @@ public class NpcIndicatorsPluginTest
when(npc.getName()).thenReturn("Joseph"); when(npc.getName()).thenReturn("Joseph");
npcIndicatorsPlugin.onNpcSpawned(new NpcSpawned(npc)); npcIndicatorsPlugin.onNpcSpawned(new NpcSpawned(npc));
assertTrue(npcIndicatorsPlugin.getHighlightedNpcs().contains(npc)); assertTrue(npcIndicatorsPlugin.getHighlightedNpcs().containsKey(npc));
when(npc.getName()).thenReturn("Werewolf"); when(npc.getName()).thenReturn("Werewolf");
npcIndicatorsPlugin.onNpcChanged(new NpcChanged(npc, null)); npcIndicatorsPlugin.onNpcChanged(new NpcChanged(npc, null));
assertFalse(npcIndicatorsPlugin.getHighlightedNpcs().contains(npc)); assertFalse(npcIndicatorsPlugin.getHighlightedNpcs().containsKey(npc));
} }
@Test @Test
@@ -174,11 +174,11 @@ public class NpcIndicatorsPluginTest
when(npc.getName()).thenReturn("Joseph"); when(npc.getName()).thenReturn("Joseph");
npcIndicatorsPlugin.onNpcSpawned(new NpcSpawned(npc)); npcIndicatorsPlugin.onNpcSpawned(new NpcSpawned(npc));
assertFalse(npcIndicatorsPlugin.getHighlightedNpcs().contains(npc)); assertFalse(npcIndicatorsPlugin.getHighlightedNpcs().containsKey(npc));
when(npc.getName()).thenReturn("Werewolf"); when(npc.getName()).thenReturn("Werewolf");
npcIndicatorsPlugin.onNpcChanged(new NpcChanged(npc, null)); npcIndicatorsPlugin.onNpcChanged(new NpcChanged(npc, null));
assertTrue(npcIndicatorsPlugin.getHighlightedNpcs().contains(npc)); assertTrue(npcIndicatorsPlugin.getHighlightedNpcs().containsKey(npc));
} }
} }