Add Overlay for Silver Jewelry to Slayer Plugin
Add overlay to display charge counter on Expeditious Bracelet and Bracelet of Slaughter.
This commit is contained in:
@@ -175,4 +175,40 @@ public interface SlayerConfig extends Config
|
||||
description = ""
|
||||
)
|
||||
void points(int points);
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "expeditious",
|
||||
name = "",
|
||||
description = "",
|
||||
hidden = true
|
||||
)
|
||||
default int expeditious()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "expeditious",
|
||||
name = "",
|
||||
description = ""
|
||||
)
|
||||
void expeditious(int expeditious);
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "slaughter",
|
||||
name = "",
|
||||
description = "",
|
||||
hidden = true
|
||||
)
|
||||
default int slaughter()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "slaughter",
|
||||
name = "",
|
||||
description = ""
|
||||
)
|
||||
void slaughter(int slaughter);
|
||||
}
|
||||
|
||||
@@ -79,7 +79,9 @@ class SlayerOverlay extends Overlay
|
||||
ItemID.TURQUOISE_SLAYER_HELMET_I,
|
||||
ItemID.SLAYER_RING_ETERNAL,
|
||||
ItemID.ENCHANTED_GEM,
|
||||
ItemID.ETERNAL_GEM
|
||||
ItemID.ETERNAL_GEM,
|
||||
ItemID.BRACELET_OF_SLAUGHTER,
|
||||
ItemID.EXPEDITIOUS_BRACELET
|
||||
);
|
||||
|
||||
@Inject
|
||||
@@ -106,6 +108,9 @@ class SlayerOverlay extends Overlay
|
||||
return null;
|
||||
}
|
||||
|
||||
int slaughterCount = plugin.getSlaughterChargeCount();
|
||||
int expeditiousCount = plugin.getExpeditiousChargeCount();
|
||||
|
||||
graphics.setFont(FontManager.getRunescapeSmallFont());
|
||||
|
||||
for (WidgetItem item : getSlayerWidgetItems())
|
||||
@@ -119,7 +124,20 @@ class SlayerOverlay extends Overlay
|
||||
|
||||
final Rectangle bounds = item.getCanvasBounds();
|
||||
final TextComponent textComponent = new TextComponent();
|
||||
textComponent.setText(String.valueOf(amount));
|
||||
|
||||
if (item.getId() == ItemID.EXPEDITIOUS_BRACELET)
|
||||
{
|
||||
textComponent.setText(String.valueOf(expeditiousCount));
|
||||
}
|
||||
else if (item.getId() == ItemID.BRACELET_OF_SLAUGHTER)
|
||||
{
|
||||
textComponent.setText(String.valueOf(slaughterCount));
|
||||
}
|
||||
else
|
||||
{
|
||||
textComponent.setText(String.valueOf(amount));
|
||||
}
|
||||
|
||||
// Draw the counter in the bottom left for equipment, and top left for jewelry
|
||||
textComponent.setPosition(new Point(bounds.x, bounds.y + (slayerJewelry.contains(itemId)
|
||||
? bounds.height
|
||||
@@ -135,7 +153,7 @@ class SlayerOverlay extends Overlay
|
||||
Query inventoryQuery = new InventoryWidgetItemQuery();
|
||||
WidgetItem[] inventoryWidgetItems = queryRunner.runQuery(inventoryQuery);
|
||||
|
||||
Query equipmentQuery = new EquipmentItemQuery().slotEquals(WidgetInfo.EQUIPMENT_HELMET, WidgetInfo.EQUIPMENT_RING);
|
||||
Query equipmentQuery = new EquipmentItemQuery().slotEquals(WidgetInfo.EQUIPMENT_HELMET, WidgetInfo.EQUIPMENT_RING, WidgetInfo.EQUIPMENT_GLOVES);
|
||||
WidgetItem[] equipmentWidgetItems = queryRunner.runQuery(equipmentQuery);
|
||||
|
||||
WidgetItem[] items = concat(inventoryWidgetItems, equipmentWidgetItems, WidgetItem.class);
|
||||
|
||||
@@ -41,6 +41,7 @@ import javax.inject.Inject;
|
||||
import joptsimple.internal.Strings;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.api.ChatMessageType;
|
||||
import net.runelite.api.Client;
|
||||
@@ -80,6 +81,8 @@ public class SlayerPlugin extends Plugin
|
||||
private static final String CHAT_SUPERIOR_MESSAGE = "A superior foe has appeared...";
|
||||
private static final String CHAT_BRACELET_SLAUGHTER = "Your bracelet of slaughter prevents your slayer count decreasing.";
|
||||
private static final String CHAT_BRACELET_EXPEDITIOUS = "Your expeditious bracelet helps you progress your slayer task faster.";
|
||||
private static final String CHAT_BRACELET_SLAUGHTER_CHARGE = "Your bracelet of slaughter has ";
|
||||
private static final String CHAT_BRACELET_EXPEDITIOUS_CHARGE = "Your expeditious bracelet has ";
|
||||
|
||||
//NPC messages
|
||||
private static final Pattern NPC_ASSIGN_MESSAGE = Pattern.compile(".*Your new task is to kill (\\d*) (.*)\\.");
|
||||
@@ -88,6 +91,9 @@ public class SlayerPlugin extends Plugin
|
||||
//Reward UI
|
||||
private static final Pattern REWARD_POINTS = Pattern.compile("Reward points: (\\d*)");
|
||||
|
||||
private static final int EXPEDITIOUS_CHARGE = 30;
|
||||
private static final int SLAUGHTER_CHARGE = 30;
|
||||
|
||||
@Inject
|
||||
private Client client;
|
||||
|
||||
@@ -126,6 +132,12 @@ public class SlayerPlugin extends Plugin
|
||||
private int cachedXp;
|
||||
private Instant infoTimer;
|
||||
private boolean loginFlag;
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
@Setter(AccessLevel.PACKAGE)
|
||||
private int expeditiousChargeCount;
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
@Setter(AccessLevel.PACKAGE)
|
||||
private int slaughterChargeCount;
|
||||
|
||||
@Override
|
||||
protected void startUp() throws Exception
|
||||
@@ -136,6 +148,8 @@ public class SlayerPlugin extends Plugin
|
||||
{
|
||||
setPoints(config.points());
|
||||
setStreak(config.streak());
|
||||
setExpeditiousChargeCount(config.expeditious());
|
||||
setSlaughterChargeCount(config.slaughter());
|
||||
clientThread.invokeLater(() -> setTask(config.taskName(), config.amount()));
|
||||
}
|
||||
}
|
||||
@@ -171,6 +185,8 @@ public class SlayerPlugin extends Plugin
|
||||
{
|
||||
setPoints(config.points());
|
||||
setStreak(config.streak());
|
||||
setExpeditiousChargeCount(config.expeditious());
|
||||
setSlaughterChargeCount(config.slaughter());
|
||||
setTask(config.taskName(), config.amount());
|
||||
loginFlag = false;
|
||||
}
|
||||
@@ -184,6 +200,8 @@ public class SlayerPlugin extends Plugin
|
||||
config.taskName(taskName);
|
||||
config.points(points);
|
||||
config.streak(streak);
|
||||
config.expeditious(expeditiousChargeCount);
|
||||
config.slaughter(slaughterChargeCount);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@@ -201,12 +219,29 @@ public class SlayerPlugin extends Plugin
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
String taskName = found1 ? mAssign.group(2) : mCurrent.group(1);
|
||||
int amount = Integer.parseInt(found1 ? mAssign.group(1) : mCurrent.group(2));
|
||||
|
||||
setTask(taskName, amount);
|
||||
}
|
||||
|
||||
Widget braceletBreakWidget = client.getWidget(WidgetInfo.DIALOG_SPRITE_TEXT);
|
||||
if (braceletBreakWidget != null)
|
||||
{
|
||||
String braceletText = Text.removeTags(braceletBreakWidget.getText()); //remove color and linebreaks
|
||||
if (braceletText.contains("bracelet of slaughter"))
|
||||
{
|
||||
slaughterChargeCount = SLAUGHTER_CHARGE;
|
||||
config.slaughter(slaughterChargeCount);
|
||||
}
|
||||
else if (braceletText.contains("expeditious bracelet"))
|
||||
{
|
||||
expeditiousChargeCount = EXPEDITIOUS_CHARGE;
|
||||
config.expeditious(expeditiousChargeCount);
|
||||
}
|
||||
}
|
||||
|
||||
Widget rewardsBarWidget = client.getWidget(WidgetInfo.SLAYER_REWARDS_TOPBAR);
|
||||
if (rewardsBarWidget != null)
|
||||
{
|
||||
@@ -255,11 +290,30 @@ public class SlayerPlugin extends Plugin
|
||||
if (chatMsg.startsWith(CHAT_BRACELET_SLAUGHTER))
|
||||
{
|
||||
amount++;
|
||||
slaughterChargeCount = --slaughterChargeCount <= 0 ? SLAUGHTER_CHARGE : slaughterChargeCount;
|
||||
config.slaughter(slaughterChargeCount);
|
||||
}
|
||||
|
||||
if (chatMsg.startsWith(CHAT_BRACELET_EXPEDITIOUS))
|
||||
{
|
||||
amount--;
|
||||
expeditiousChargeCount = --expeditiousChargeCount <= 0 ? EXPEDITIOUS_CHARGE : expeditiousChargeCount;
|
||||
config.expeditious(expeditiousChargeCount);
|
||||
}
|
||||
|
||||
if (chatMsg.startsWith(CHAT_BRACELET_EXPEDITIOUS_CHARGE))
|
||||
{
|
||||
expeditiousChargeCount = Integer.parseInt(chatMsg
|
||||
.replace(CHAT_BRACELET_EXPEDITIOUS_CHARGE, "")
|
||||
.replace(" charges left.", ""));
|
||||
config.expeditious(expeditiousChargeCount);
|
||||
}
|
||||
if (chatMsg.startsWith(CHAT_BRACELET_SLAUGHTER_CHARGE))
|
||||
{
|
||||
slaughterChargeCount = Integer.parseInt(chatMsg
|
||||
.replace(CHAT_BRACELET_SLAUGHTER_CHARGE, "")
|
||||
.replace(" charges left.", ""));
|
||||
config.slaughter(slaughterChargeCount);
|
||||
}
|
||||
|
||||
if (chatMsg.endsWith("; return to a Slayer master."))
|
||||
|
||||
@@ -31,6 +31,9 @@ import javax.inject.Inject;
|
||||
import static net.runelite.api.ChatMessageType.SERVER;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.events.ChatMessage;
|
||||
import net.runelite.api.events.GameTick;
|
||||
import net.runelite.api.widgets.Widget;
|
||||
import net.runelite.api.widgets.WidgetInfo;
|
||||
import net.runelite.client.Notifier;
|
||||
import net.runelite.client.game.ItemManager;
|
||||
import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
|
||||
@@ -39,6 +42,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -60,6 +64,12 @@ public class SlayerPluginTest
|
||||
private static final String BRACLET_SLAUGHTER = "Your bracelet of slaughter prevents your slayer count decreasing.";
|
||||
private static final String BRACLET_EXPEDITIOUS = "Your expeditious bracelet helps you progress your slayer task faster.";
|
||||
|
||||
private static final String CHAT_BRACELET_SLAUGHTER_CHARGE = "Your bracelet of slaughter has 12 charges left.";
|
||||
private static final String CHAT_BRACELET_EXPEDITIOUS_CHARGE = "Your expeditious bracelet has 12 charges left.";
|
||||
|
||||
private static final String BREAK_SLAUGHTER = "The bracelet shatters. Your next bracelet of slaughter<br>will start afresh from 30 charges.";
|
||||
private static final String BREAK_EXPEDITIOUS = "The bracelet shatters. Your next expeditious bracelet<br>will start afresh from 30 charges.";
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
Client client;
|
||||
@@ -173,10 +183,31 @@ public class SlayerPluginTest
|
||||
ChatMessage chatMessageEvent = new ChatMessage(SERVER, "", BRACLET_SLAUGHTER, null);
|
||||
|
||||
slayerPlugin.setAmount(42);
|
||||
slayerPlugin.setSlaughterChargeCount(10);
|
||||
|
||||
slayerPlugin.onChatMessage(chatMessageEvent);
|
||||
|
||||
assertEquals(9, slayerPlugin.getSlaughterChargeCount());
|
||||
assertEquals(43, slayerPlugin.getAmount());
|
||||
|
||||
chatMessageEvent = new ChatMessage(SERVER, "", CHAT_BRACELET_SLAUGHTER_CHARGE, null);
|
||||
slayerPlugin.onChatMessage(chatMessageEvent);
|
||||
|
||||
assertEquals(12, slayerPlugin.getSlaughterChargeCount());
|
||||
|
||||
slayerPlugin.setSlaughterChargeCount(1);
|
||||
chatMessageEvent = new ChatMessage(SERVER, "", BRACLET_SLAUGHTER, null);
|
||||
slayerPlugin.onChatMessage(chatMessageEvent);
|
||||
|
||||
assertEquals(30, slayerPlugin.getSlaughterChargeCount());
|
||||
|
||||
Widget braceletBreakWidget = mock(Widget.class);
|
||||
when(braceletBreakWidget.getText()).thenReturn(BREAK_SLAUGHTER);
|
||||
when(client.getWidget(WidgetInfo.DIALOG_SPRITE_TEXT)).thenReturn(braceletBreakWidget);
|
||||
|
||||
slayerPlugin.setSlaughterChargeCount(-1);
|
||||
slayerPlugin.onGameTick(new GameTick());
|
||||
assertEquals(30, slayerPlugin.getSlaughterChargeCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -185,9 +216,30 @@ public class SlayerPluginTest
|
||||
ChatMessage chatMessageEvent = new ChatMessage(SERVER, "", BRACLET_EXPEDITIOUS, null);
|
||||
|
||||
slayerPlugin.setAmount(42);
|
||||
slayerPlugin.setExpeditiousChargeCount(10);
|
||||
|
||||
slayerPlugin.onChatMessage(chatMessageEvent);
|
||||
|
||||
assertEquals(41, slayerPlugin.getAmount());
|
||||
assertEquals(9, slayerPlugin.getExpeditiousChargeCount());
|
||||
|
||||
chatMessageEvent = new ChatMessage(SERVER, "", CHAT_BRACELET_EXPEDITIOUS_CHARGE, null);
|
||||
slayerPlugin.onChatMessage(chatMessageEvent);
|
||||
|
||||
assertEquals(12, slayerPlugin.getExpeditiousChargeCount());
|
||||
|
||||
slayerPlugin.setExpeditiousChargeCount(1);
|
||||
chatMessageEvent = new ChatMessage(SERVER, "", BRACLET_EXPEDITIOUS, null);
|
||||
slayerPlugin.onChatMessage(chatMessageEvent);
|
||||
|
||||
assertEquals(30, slayerPlugin.getExpeditiousChargeCount());
|
||||
|
||||
Widget braceletBreakWidget = mock(Widget.class);
|
||||
when(braceletBreakWidget.getText()).thenReturn(BREAK_EXPEDITIOUS);
|
||||
when(client.getWidget(WidgetInfo.DIALOG_SPRITE_TEXT)).thenReturn(braceletBreakWidget);
|
||||
|
||||
slayerPlugin.setExpeditiousChargeCount(-1);
|
||||
slayerPlugin.onGameTick(new GameTick());
|
||||
assertEquals(30, slayerPlugin.getExpeditiousChargeCount());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user