From a6d122ac97eb36f5d3ec2fd321e699248fa45b61 Mon Sep 17 00:00:00 2001 From: MasonPMGit Date: Sun, 12 Jun 2022 21:45:26 -0500 Subject: [PATCH] item charges: add bracelet of clay --- .../plugins/itemcharges/ItemChargeConfig.java | 25 +++++++++++++ .../plugins/itemcharges/ItemChargePlugin.java | 36 +++++++++++++++++++ .../plugins/itemcharges/ItemChargeType.java | 3 +- .../plugins/itemcharges/ItemWithConfig.java | 3 +- .../itemcharges/ItemChargePluginTest.java | 34 ++++++++++++++++++ 5 files changed, 99 insertions(+), 2 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemChargeConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemChargeConfig.java index eb0350e0ad..db554050ef 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemChargeConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemChargeConfig.java @@ -47,6 +47,7 @@ public interface ItemChargeConfig extends Config String KEY_EXPLORERS_RING = "explorerRing"; String KEY_RING_OF_FORGING = "ringOfForging"; String KEY_BLOOD_ESSENCE = "bloodEssence"; + String KEY_BRACELET_OF_CLAY = "braceletOfClay"; @ConfigSection( name = "Charge Settings", @@ -428,4 +429,28 @@ public interface ItemChargeConfig extends Config { return true; } + + @ConfigItem( + keyName = "showBraceletOfClayCharges", + name = "Bracelet of Clay Charges", + description = "Show Bracelet of Clay item charges", + position = 31, + section = chargesSection + ) + default boolean showBraceletOfClayCharges() + { + return true; + } + + @ConfigItem( + keyName = "braceletOfClayNotification", + name = "Bracelet of Clay Notification", + description = "Send a notification when a Bracelet of Clay breaks", + position = 32, + section = notificationSection + ) + default boolean braceletOfClayNotification() + { + return true; + } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemChargePlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemChargePlugin.java index 89ec2dff05..7505d586bb 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemChargePlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemChargePlugin.java @@ -137,6 +137,11 @@ public class ItemChargePlugin extends Plugin "You manage to extract power from the Blood Essence and craft (\\d{1,3}) extra runes?\\." ); private static final String BLOOD_ESSENCE_ACTIVATE_TEXT = "You activate the blood essence."; + private static final String BRACELET_OF_CLAY_USE_TEXT = "You manage to mine some clay."; + private static final String BRACELET_OF_CLAY_BREAK_TEXT = "Your bracelet of clay crumbles to dust."; + private static final Pattern BRACELET_OF_CLAY_CHECK_PATTERN = Pattern.compile( + "You can mine (\\d{1,2}) more pieces? of soft clay before your bracelet crumbles to dust\\." + ); private static final int MAX_DODGY_CHARGES = 10; private static final int MAX_BINDING_CHARGES = 16; @@ -146,6 +151,7 @@ public class ItemChargePlugin extends Plugin private static final int MAX_AMULET_OF_BOUNTY_CHARGES = 10; private static final int MAX_SLAYER_BRACELET_CHARGES = 30; private static final int MAX_BLOOD_ESSENCE_CHARGES = 1000; + private static final int MAX_BRACELET_OF_CLAY_CHARGES = 28; private int lastExplorerRingCharge = -1; @@ -237,6 +243,7 @@ public class ItemChargePlugin extends Plugin Matcher expeditiousCheckMatcher = EXPEDITIOUS_BRACELET_CHECK_PATTERN.matcher(message); Matcher bloodEssenceCheckMatcher = BLOOD_ESSENCE_CHECK_PATTERN.matcher(message); Matcher bloodEssenceExtractMatcher = BLOOD_ESSENCE_EXTRACT_PATTERN.matcher(message); + Matcher braceletOfClayCheckMatcher = BRACELET_OF_CLAY_CHECK_PATTERN.matcher(message); if (config.recoilNotification() && message.contains(RING_OF_RECOIL_BREAK_MESSAGE)) { @@ -439,6 +446,29 @@ public class ItemChargePlugin extends Plugin { updateBloodEssenceCharges(MAX_BLOOD_ESSENCE_CHARGES); } + else if (braceletOfClayCheckMatcher.find()) + { + updateBraceletOfClayCharges(Integer.parseInt(braceletOfClayCheckMatcher.group(1))); + } + else if (message.equals(BRACELET_OF_CLAY_USE_TEXT)) + { + final ItemContainer equipment = client.getItemContainer(InventoryID.EQUIPMENT); + + // Determine if the player mined with a Bracelet of Clay equipped. + if (equipment != null && equipment.contains(ItemID.BRACELET_OF_CLAY)) + { + int charges = Ints.constrainToRange(getItemCharges(ItemChargeConfig.KEY_BRACELET_OF_CLAY) - 1, 0, MAX_BRACELET_OF_CLAY_CHARGES); + updateBraceletOfClayCharges(charges); + } + } + else if (message.equals(BRACELET_OF_CLAY_BREAK_TEXT)) + { + if (config.braceletOfClayNotification()) + { + notifier.notify("Your bracelet of clay has crumbled to dust"); + } + updateBraceletOfClayCharges(MAX_BRACELET_OF_CLAY_CHARGES); + } } } @@ -572,6 +602,12 @@ public class ItemChargePlugin extends Plugin updateInfoboxes(); } + private void updateBraceletOfClayCharges(final int value) + { + setItemCharges(ItemChargeConfig.KEY_BRACELET_OF_CLAY, value); + updateInfoboxes(); + } + private void checkDestroyWidget() { final int currentTick = client.getTickCount(); diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemChargeType.java b/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemChargeType.java index 3178fa9953..1d4548a368 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemChargeType.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemChargeType.java @@ -52,7 +52,8 @@ enum ItemChargeType RING_OF_FORGING(ItemChargeConfig::showRingOfForgingCount), POTION(ItemChargeConfig::showPotionDoseCount), GUTHIX_REST(ItemChargeConfig::showGuthixRestDoses), - BLOOD_ESSENCE(ItemChargeConfig::showBloodEssenceCharges); + BLOOD_ESSENCE(ItemChargeConfig::showBloodEssenceCharges), + BRACELET_OF_CLAY(ItemChargeConfig::showBraceletOfClayCharges); private final Predicate enabled; } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemWithConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemWithConfig.java index 581410c1f9..bdafd8e62d 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemWithConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemWithConfig.java @@ -47,7 +47,8 @@ enum ItemWithConfig BRACELET_OF_SLAUGHTER(ItemID.BRACELET_OF_SLAUGHTER, ItemChargeConfig.KEY_BRACELET_OF_SLAUGHTER, ItemChargeType.BRACELET_OF_SLAUGHTER), EXPEDITIOUS_BRACELET(ItemID.EXPEDITIOUS_BRACELET, ItemChargeConfig.KEY_EXPEDITIOUS_BRACELET, ItemChargeType.EXPEDITIOUS_BRACELET), CHRONICLE(ItemID.CHRONICLE, ItemChargeConfig.KEY_CHRONICLE, ItemChargeType.TELEPORT), - BLOOD_ESSENCE(ItemID.BLOOD_ESSENCE_ACTIVE, ItemChargeConfig.KEY_BLOOD_ESSENCE, ItemChargeType.BLOOD_ESSENCE); + BLOOD_ESSENCE(ItemID.BLOOD_ESSENCE_ACTIVE, ItemChargeConfig.KEY_BLOOD_ESSENCE, ItemChargeType.BLOOD_ESSENCE), + BRACELET_OF_CLAY(ItemID.BRACELET_OF_CLAY, ItemChargeConfig.KEY_BRACELET_OF_CLAY, ItemChargeType.BRACELET_OF_CLAY); private final int itemId; private final String configKey; diff --git a/runelite-client/src/test/java/net/runelite/client/plugins/itemcharges/ItemChargePluginTest.java b/runelite-client/src/test/java/net/runelite/client/plugins/itemcharges/ItemChargePluginTest.java index 464ec09bad..f111286e44 100644 --- a/runelite-client/src/test/java/net/runelite/client/plugins/itemcharges/ItemChargePluginTest.java +++ b/runelite-client/src/test/java/net/runelite/client/plugins/itemcharges/ItemChargePluginTest.java @@ -96,6 +96,9 @@ public class ItemChargePluginTest private static final String ACTIVATE_BLOOD_ESSENCE = "You activate the blood essence."; private static final String EXTRACT_BLOOD_ESSENCE = "You manage to extract power from the Blood Essence and craft 67 extra runes."; private static final String CHECK_BLOOD_ESSENCE = "Your blood essence has 56 charges remaining"; + private static final String CHECK_BRACELET_OF_CLAY = "You can mine 13 more pieces of soft clay before your bracelet crumbles to dust."; + private static final String USED_BRACELET_OF_CLAY = "You manage to mine some clay."; + private static final String BREAK_BRACELET_OF_CLAY = "Your bracelet of clay crumbles to dust."; @Mock @Bind @@ -450,4 +453,35 @@ public class ItemChargePluginTest itemChargePlugin.onChatMessage(chatMessage); verify(configManager).setRSProfileConfiguration(ItemChargeConfig.GROUP, ItemChargeConfig.KEY_BLOOD_ESSENCE, 56); } + + @Test + public void testBraceletOfClayCheck() + { + ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", CHECK_BRACELET_OF_CLAY, "", 0); + itemChargePlugin.onChatMessage(chatMessage); + verify(configManager).setRSProfileConfiguration(ItemChargeConfig.GROUP, ItemChargeConfig.KEY_BRACELET_OF_CLAY, 13); + } + + @Test + public void testBraceletOfClayUsed() + { + when(configManager.getRSProfileConfiguration(ItemChargeConfig.GROUP, ItemChargeConfig.KEY_BRACELET_OF_CLAY, Integer.class)).thenReturn(25); + // Create equipment inventory with bracelet of clay + ItemContainer equipmentItemContainer = mock(ItemContainer.class); + when(client.getItemContainer(InventoryID.EQUIPMENT)).thenReturn(equipmentItemContainer); + when(equipmentItemContainer.contains(ItemID.BRACELET_OF_CLAY)).thenReturn(true); + when(equipmentItemContainer.getItems()).thenReturn(new Item[0]); + // Run message + ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", USED_BRACELET_OF_CLAY, "", 0); + itemChargePlugin.onChatMessage(chatMessage); + verify(configManager).setRSProfileConfiguration(ItemChargeConfig.GROUP, ItemChargeConfig.KEY_BRACELET_OF_CLAY, 24); + } + + @Test + public void testBraceletOfClayBreak() + { + ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", BREAK_BRACELET_OF_CLAY, "", 0); + itemChargePlugin.onChatMessage(chatMessage); + verify(configManager).setRSProfileConfiguration(ItemChargeConfig.GROUP, ItemChargeConfig.KEY_BRACELET_OF_CLAY, 28); + } } \ No newline at end of file