Merge pull request #7969 from TheStonedTurtle/binding-necklace

Move Binding necklace tracking from Runecrafting to Item Charge plugin
This commit is contained in:
Adam
2019-04-08 20:56:29 -04:00
committed by GitHub
10 changed files with 261 additions and 188 deletions

View File

@@ -204,11 +204,51 @@ public interface ItemChargeConfig extends Config
return false;
}
@ConfigItem(
keyName = "showBindingNecklaceCharges",
name = "Show Binding Necklace Charges",
description = "Configures if binding necklace item charge is shown",
position = 15
)
default boolean showBindingNecklaceCharges()
{
return true;
}
@ConfigItem(
keyName = "bindingNecklace",
name = "",
description = "",
hidden = true
)
default int bindingNecklace()
{
return -1;
}
@ConfigItem(
keyName = "bindingNecklace",
name = "",
description = ""
)
void bindingNecklace(int bindingNecklace);
@ConfigItem(
keyName = "bindingNotification",
name = "Binding Necklace Notification",
description = "Configures if the binding necklace breaking notification is shown",
position = 16
)
default boolean bindingNotification()
{
return true;
}
@ConfigItem(
keyName = "showInfoboxes",
name = "Show Infoboxes",
description = "Configures whether to show an infobox equipped charge items",
position = 15
position = 17
)
default boolean showInfoboxes()
{

View File

@@ -84,6 +84,15 @@ class ItemChargeOverlay extends Overlay
charges = config.dodgyNecklace();
}
else if (item.getId() == ItemID.BINDING_NECKLACE)
{
if (!config.showBindingNecklaceCharges())
{
continue;
}
charges = config.bindingNecklace();
}
else
{
ItemWithCharge chargeItem = ItemWithCharge.findItem(item.getId());

View File

@@ -41,6 +41,9 @@ import net.runelite.api.ItemID;
import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.ConfigChanged;
import net.runelite.api.events.ItemContainerChanged;
import net.runelite.api.events.ScriptCallbackEvent;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.Notifier;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe;
@@ -64,8 +67,14 @@ public class ItemChargePlugin extends Plugin
private static final Pattern DODGY_BREAK_PATTERN = Pattern.compile(
"Your dodgy necklace protects you\\..*It then crumbles to dust\\.");
private static final String RING_OF_RECOIL_BREAK_MESSAGE = "<col=7f007f>Your Ring of Recoil has shattered.</col>";
private static final Pattern BINDING_CHECK_PATTERN = Pattern.compile(
"You have ([0-9]+|one) charges? left before your Binding necklace disintegrates\\.");
private static final Pattern BINDING_USED_PATTERN = Pattern.compile(
"You bind the temple's power into (mud|lava|steam|dust|smoke|mist) runes\\.");
private static final String BINDING_BREAK_TEXT = "Your Binding necklace has disintegrated.";
private static final int MAX_DODGY_CHARGES = 10;
private static final int MAX_BINDING_CHARGES = 16;
@Inject
private Client client;
@@ -88,6 +97,9 @@ public class ItemChargePlugin extends Plugin
@Inject
private ItemChargeConfig config;
// Limits destroy callback to once per tick
private int lastCheckTick;
@Provides
ItemChargeConfig getConfig(ConfigManager configManager)
{
@@ -105,6 +117,7 @@ public class ItemChargePlugin extends Plugin
{
overlayManager.remove(overlay);
infoBoxManager.removeIf(ItemChargeInfobox.class::isInstance);
lastCheckTick = -1;
}
@Subscribe
@@ -135,6 +148,11 @@ public class ItemChargePlugin extends Plugin
{
removeInfobox(ItemWithSlot.DODGY_NECKLACE);
}
if (!config.showBindingNecklaceCharges())
{
removeInfobox(ItemWithSlot.BINDING_NECKLACE);
}
}
@Subscribe
@@ -144,6 +162,9 @@ public class ItemChargePlugin extends Plugin
Matcher dodgyCheckMatcher = DODGY_CHECK_PATTERN.matcher(message);
Matcher dodgyProtectMatcher = DODGY_PROTECT_PATTERN.matcher(message);
Matcher dodgyBreakMatcher = DODGY_BREAK_PATTERN.matcher(message);
Matcher bindingNecklaceCheckMatcher = BINDING_CHECK_PATTERN.matcher(event.getMessage());
Matcher bindingNecklaceUsedMatcher = BINDING_USED_PATTERN.matcher(event.getMessage());
if (event.getType() == ChatMessageType.GAMEMESSAGE || event.getType() == ChatMessageType.SPAM)
{
if (config.recoilNotification() && message.contains(RING_OF_RECOIL_BREAK_MESSAGE))
@@ -167,6 +188,32 @@ public class ItemChargePlugin extends Plugin
{
updateDodgyNecklaceCharges(Integer.parseInt(dodgyProtectMatcher.group(1)));
}
else if (message.contains(BINDING_BREAK_TEXT))
{
if (config.bindingNotification())
{
notifier.notify(BINDING_BREAK_TEXT);
}
// This chat message triggers before the used message so add 1 to the max charges to ensure proper sync
updateBindingNecklaceCharges(MAX_BINDING_CHARGES + 1);
}
else if (bindingNecklaceUsedMatcher.find())
{
updateBindingNecklaceCharges(config.bindingNecklace() - 1);
}
else if (bindingNecklaceCheckMatcher.find())
{
final String match = bindingNecklaceCheckMatcher.group(1);
int charges = 1;
if (!match.equals("one"))
{
charges = Integer.parseInt(match);
}
updateBindingNecklaceCharges(charges);
}
}
}
@@ -194,6 +241,26 @@ public class ItemChargePlugin extends Plugin
{
updateJewelleryInfobox(ItemWithSlot.ABYSSAL_BRACELET, items);
}
if (config.showBindingNecklaceCharges())
{
updateJewelleryInfobox(ItemWithSlot.BINDING_NECKLACE, items);
}
}
@Subscribe
private void onScriptCallbackEvent(ScriptCallbackEvent event)
{
if (!"destroyOnOpKey".equals(event.getEventName()))
{
return;
}
final int yesOption = client.getIntStack()[client.getIntStackSize() - 1];
if (yesOption == 1)
{
checkDestroyWidget();
}
}
private void updateDodgyNecklaceCharges(final int value)
@@ -213,6 +280,49 @@ public class ItemChargePlugin extends Plugin
}
}
private void updateBindingNecklaceCharges(final int value)
{
config.bindingNecklace(value);
if (config.showInfoboxes() && config.showBindingNecklaceCharges())
{
final ItemContainer itemContainer = client.getItemContainer(InventoryID.EQUIPMENT);
if (itemContainer == null)
{
return;
}
updateJewelleryInfobox(ItemWithSlot.BINDING_NECKLACE, itemContainer.getItems());
}
}
private void checkDestroyWidget()
{
final int currentTick = client.getTickCount();
if (lastCheckTick == currentTick)
{
return;
}
lastCheckTick = currentTick;
final Widget widgetDestroyItemName = client.getWidget(WidgetInfo.DESTROY_ITEM_NAME);
if (widgetDestroyItemName == null)
{
return;
}
switch (widgetDestroyItemName.getText())
{
case "Binding necklace":
updateBindingNecklaceCharges(MAX_BINDING_CHARGES);
break;
case "Dodgy necklace":
updateDodgyNecklaceCharges(MAX_DODGY_CHARGES);
break;
}
}
private void updateJewelleryInfobox(ItemWithSlot item, Item[] items)
{
for (final EquipmentInventorySlot equipmentInventorySlot : item.getSlots())
@@ -245,6 +355,10 @@ public class ItemChargePlugin extends Plugin
{
charges = config.dodgyNecklace();
}
else if (id == ItemID.BINDING_NECKLACE && type == ItemWithSlot.BINDING_NECKLACE)
{
charges = config.bindingNecklace();
}
}
else if (itemWithCharge.getType() == type.getType())
{

View File

@@ -33,5 +33,6 @@ enum ItemChargeType
TELEPORT,
WATERCAN,
WATERSKIN,
DODGY_NECKLACE
DODGY_NECKLACE,
BINDING_NECKLACE
}

View File

@@ -34,6 +34,7 @@ enum ItemWithSlot
{
ABYSSAL_BRACELET(ItemChargeType.ABYSSAL_BRACELET, EquipmentInventorySlot.GLOVES),
DODGY_NECKLACE(ItemChargeType.DODGY_NECKLACE, EquipmentInventorySlot.AMULET),
BINDING_NECKLACE(ItemChargeType.BINDING_NECKLACE, EquipmentInventorySlot.AMULET),
TELEPORT(ItemChargeType.TELEPORT, EquipmentInventorySlot.WEAPON, EquipmentInventorySlot.AMULET, EquipmentInventorySlot.GLOVES, EquipmentInventorySlot.RING);
private final ItemChargeType type;

View File

@@ -1,107 +0,0 @@
/*
* Copyright (c) 2017, Seth <Sethtroll3@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.runecraft;
import static net.runelite.api.ItemID.BINDING_NECKLACE;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import javax.inject.Inject;
import net.runelite.api.Query;
import net.runelite.api.queries.EquipmentItemQuery;
import net.runelite.api.queries.InventoryWidgetItemQuery;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.api.widgets.WidgetItem;
import net.runelite.client.ui.FontManager;
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.components.TextComponent;
import net.runelite.client.util.QueryRunner;
public class BindNeckOverlay extends Overlay
{
private final QueryRunner queryRunner;
private final RunecraftConfig config;
int bindingCharges;
@Inject
BindNeckOverlay(QueryRunner queryRunner, RunecraftConfig config)
{
setPosition(OverlayPosition.DYNAMIC);
setLayer(OverlayLayer.ABOVE_WIDGETS);
this.queryRunner = queryRunner;
this.config = config;
}
@Override
public Dimension render(Graphics2D graphics)
{
if (!config.showBindNeck())
{
return null;
}
graphics.setFont(FontManager.getRunescapeSmallFont());
for (WidgetItem necklace : getNecklaceWidgetItems())
{
final Color color = bindingCharges == 1 ? Color.RED : Color.WHITE;
final Rectangle bounds = necklace.getCanvasBounds();
final String text = bindingCharges <= 0 ? "?" : bindingCharges + "";
final TextComponent textComponent = new TextComponent();
textComponent.setPosition(new Point(bounds.x, bounds.y + 16));
textComponent.setText(text);
textComponent.setColor(color);
textComponent.render(graphics);
}
return null;
}
private Collection<WidgetItem> getNecklaceWidgetItems()
{
Query inventoryQuery = new InventoryWidgetItemQuery()
.idEquals(BINDING_NECKLACE);
WidgetItem[] inventoryWidgetItems = queryRunner.runQuery(inventoryQuery);
Query equipmentQuery = new EquipmentItemQuery()
.slotEquals(WidgetInfo.EQUIPMENT_AMULET)
.idEquals(BINDING_NECKLACE);
WidgetItem[] equipmentWidgetItems = queryRunner.runQuery(equipmentQuery);
Collection<WidgetItem> necklaces = new ArrayList<>();
necklaces.addAll(Arrays.asList(inventoryWidgetItems));
necklaces.addAll(Arrays.asList(equipmentWidgetItems));
return necklaces;
}
}

View File

@@ -32,17 +32,6 @@ import net.runelite.client.config.ConfigItem;
@ConfigGroup("runecraft")
public interface RunecraftConfig extends Config
{
@ConfigItem(
keyName = "showBindNeck",
name = "Show Binding Neck charges",
description = "Configures whether the binding neck charge is displayed",
position = 2
)
default boolean showBindNeck()
{
return true;
}
@ConfigItem(
keyName = "showRifts",
name = "Show Rifts in Abyss",

View File

@@ -29,8 +29,6 @@ import com.google.inject.Provides;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;
import javax.inject.Inject;
import lombok.AccessLevel;
@@ -50,11 +48,8 @@ import net.runelite.api.events.DecorativeObjectDespawned;
import net.runelite.api.events.DecorativeObjectSpawned;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.ItemContainerChanged;
import net.runelite.api.events.MenuOptionClicked;
import net.runelite.api.events.NpcDespawned;
import net.runelite.api.events.NpcSpawned;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.Notifier;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe;
@@ -69,10 +64,8 @@ import net.runelite.client.ui.overlay.OverlayManager;
)
public class RunecraftPlugin extends Plugin
{
private static Pattern bindNeckString = Pattern.compile("You have ([0-9]+|one) charges? left before your Binding necklace disintegrates.");
private static final String POUCH_DECAYED_NOTIFICATION_MESSAGE = "Your rune pouch has decayed.";
private static final String POUCH_DECAYED_MESSAGE = "Your pouch has decayed through use.";
private static final int DESTROY_ITEM_WIDGET_ID = WidgetInfo.DESTROY_ITEM_YES.getId();
private static final List<Integer> DEGRADED_POUCHES = ImmutableList.of(
ItemID.MEDIUM_POUCH_5511,
ItemID.LARGE_POUCH_5513,
@@ -94,9 +87,6 @@ public class RunecraftPlugin extends Plugin
@Inject
private OverlayManager overlayManager;
@Inject
private BindNeckOverlay bindNeckOverlay;
@Inject
private AbyssOverlay abyssOverlay;
@@ -115,7 +105,6 @@ public class RunecraftPlugin extends Plugin
@Override
protected void startUp() throws Exception
{
overlayManager.add(bindNeckOverlay);
overlayManager.add(abyssOverlay);
abyssOverlay.updateConfig();
}
@@ -123,7 +112,6 @@ public class RunecraftPlugin extends Plugin
@Override
protected void shutDown() throws Exception
{
overlayManager.remove(bindNeckOverlay);
overlayManager.remove(abyssOverlay);
abyssObjects.clear();
darkMage = null;
@@ -144,71 +132,15 @@ public class RunecraftPlugin extends Plugin
return;
}
if (config.showBindNeck())
{
Matcher match = bindNeckString.matcher(event.getMessage());
if (match.find())
{
if (match.group(1).equals("one"))
{
bindNeckOverlay.bindingCharges = 1;
}
else
{
bindNeckOverlay.bindingCharges = Integer.parseInt(match.group(1));
}
return;
}
if (event.getMessage().contains("You bind the temple's power"))
{
if (event.getMessage().contains("mud")
|| event.getMessage().contains("lava")
|| event.getMessage().contains("steam")
|| event.getMessage().contains("dust")
|| event.getMessage().contains("smoke")
|| event.getMessage().contains("mist"))
{
bindNeckOverlay.bindingCharges -= 1;
return;
}
}
if (event.getMessage().contains("Your Binding necklace has disintegrated."))
{
//set it to 17 because this message is triggered first before the above chat event
bindNeckOverlay.bindingCharges = 17;
return;
}
}
if (config.degradingNotification())
{
if (event.getMessage().contains(POUCH_DECAYED_MESSAGE))
{
notifier.notify(POUCH_DECAYED_NOTIFICATION_MESSAGE);
return;
}
}
}
@Subscribe
public void onMenuOptionClicked(MenuOptionClicked event)
{
if (event.getWidgetId() != DESTROY_ITEM_WIDGET_ID)
{
return;
}
Widget widgetDestroyItemName = client.getWidget(WidgetInfo.DESTROY_ITEM_NAME);
if (widgetDestroyItemName == null || !widgetDestroyItemName.getText().equals("Binding necklace"))
{
return;
}
bindNeckOverlay.bindingCharges = 16;
}
@Subscribe
public void onDecorativeObjectSpawned(DecorativeObjectSpawned event)
{

View File

@@ -0,0 +1 @@
DA7BFF3D4B1135F264904DDCED76BC0CD56CEF4B41E1D7852097E9EECC235B9A

View File

@@ -0,0 +1,93 @@
.id 1651
.int_stack_count 5
.string_stack_count 2
.int_var_count 5
.string_var_count 2
iload 0
iconst 1
if_icmpeq LABEL13
iload 1
iconst -1
if_icmpne LABEL7
jump LABEL74
LABEL7:
sload 1
iload 1
string_indexof_char
iconst -1
if_icmpne LABEL13
jump LABEL74
LABEL13:
iload 0
iconst 1
if_icmpne LABEL17
jump LABEL24
LABEL17:
iconst 584
iconst -1
invoke 1701
iconst 0
if_icmpeq LABEL23
jump LABEL24
LABEL23:
return
LABEL24:
iload 3
sconst "destroyOnOpKey" ; load event name
runelite_callback ; invoke callback
pop_int
iconst 2266
iconst 1
iconst 0
sound_synth
iload 2
iload 4
cc_find
iconst 1
if_icmpeq LABEL34
jump LABEL38
LABEL34:
iconst 16777215
cc_setcolour
sconst "..."
cc_settext
LABEL38:
iconst -1
sconst ""
iload 2
if_setonmouserepeat
iconst -1
sconst ""
iload 2
if_setonmouseleave
iload 2
if_clearops
iconst -1
sconst ""
iload 2
if_setonop
iconst -1
sconst ""
iload 2
if_setonkey
iconst 1652
iload 2
sload 0
iload 3
sload 1
clientclock
iconst 40
add
sconst "Isisi"
iload 2
if_setontimer
iconst 38273024
iload 3
cc_find
iconst 1
if_icmpeq LABEL73
jump LABEL74
LABEL73:
cc_resume_pausebutton
LABEL74:
return