Skip to content

Commit

Permalink
Add Overlay for Silver Jewelry to Slayer Plugin
Browse files Browse the repository at this point in the history
Add overlay to display charge counter on Expeditious Bracelet and Bracelet of Slaughter.
  • Loading branch information
Unknown authored and Adam- committed May 11, 2018
1 parent 1044781 commit 593bab8
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,40 @@ default int points()
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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -106,6 +108,9 @@ public Dimension render(Graphics2D graphics)
return null;
}

int slaughterCount = plugin.getSlaughterChargeCount();
int expeditiousCount = plugin.getExpeditiousChargeCount();

graphics.setFont(FontManager.getRunescapeSmallFont());

for (WidgetItem item : getSlayerWidgetItems())
Expand All @@ -119,7 +124,20 @@ public Dimension render(Graphics2D graphics)

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
Expand All @@ -135,7 +153,7 @@ private Collection<WidgetItem> getSlayerWidgetItems()
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
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;
Expand Down Expand Up @@ -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*) (.*)\\.");
Expand All @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -136,6 +148,8 @@ protected void startUp() throws Exception
{
setPoints(config.points());
setStreak(config.streak());
setExpeditiousChargeCount(config.expeditious());
setSlaughterChargeCount(config.slaughter());
clientThread.invokeLater(() -> setTask(config.taskName(), config.amount()));
}
}
Expand Down Expand Up @@ -171,6 +185,8 @@ public void onGameStateChange(GameStateChanged event)
{
setPoints(config.points());
setStreak(config.streak());
setExpeditiousChargeCount(config.expeditious());
setSlaughterChargeCount(config.slaughter());
setTask(config.taskName(), config.amount());
loginFlag = false;
}
Expand All @@ -184,6 +200,8 @@ private void save()
config.taskName(taskName);
config.points(points);
config.streak(streak);
config.expeditious(expeditiousChargeCount);
config.slaughter(slaughterChargeCount);
}

@Subscribe
Expand All @@ -201,12 +219,29 @@ public void onGameTick(GameTick tick)
{
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)
{
Expand Down Expand Up @@ -255,11 +290,30 @@ public void onChatMessage(ChatMessage event)
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."))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
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;
Expand All @@ -39,6 +42,7 @@
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;
Expand All @@ -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;
Expand Down Expand Up @@ -173,10 +183,31 @@ public void testBracletSlaughter()
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
Expand All @@ -185,9 +216,30 @@ public void testBraceletExpeditious()
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());
}
}

0 comments on commit 593bab8

Please sign in to comment.