From 3950ea079149c9410225fb19b7fdf5c551b6f202 Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 10 May 2024 11:10:07 -0400 Subject: [PATCH] mlm: update for sack size changes Sack size changed from 81/162 to 108/189, but can no longer be over deposited. Use the vanilla sack size overlay because there is no longer a whole number of remaining deposits due to the over-deposit behavior change. Additionally turn the vanilla overlay text red if the number of paydirt in the inventory is at or exceeds the remaining sack capacity. --- .../src/main/interfaces/interfaces.toml | 2 + .../main/java/net/runelite/api/ScriptID.java | 3 + .../plugins/motherlode/MotherlodePlugin.java | 129 +++++++----------- .../motherlode/MotherlodeSackOverlay.java | 119 ---------------- 4 files changed, 57 insertions(+), 196 deletions(-) delete mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/motherlode/MotherlodeSackOverlay.java diff --git a/runelite-api/src/main/interfaces/interfaces.toml b/runelite-api/src/main/interfaces/interfaces.toml index 5b6ff84e9c2..65b3fc57716 100644 --- a/runelite-api/src/main/interfaces/interfaces.toml +++ b/runelite-api/src/main/interfaces/interfaces.toml @@ -559,6 +559,8 @@ worldmap_options=53 [mlm] id=382 container=0 +sack_size_text=5 +space_text=6 [moons_of_peril] id=869 diff --git a/runelite-api/src/main/java/net/runelite/api/ScriptID.java b/runelite-api/src/main/java/net/runelite/api/ScriptID.java index 062ae1a9c4d..77f1f1583c8 100644 --- a/runelite-api/src/main/java/net/runelite/api/ScriptID.java +++ b/runelite-api/src/main/java/net/runelite/api/ScriptID.java @@ -455,4 +455,7 @@ public final class ScriptID @ScriptArguments(integer = 12, string = 2) public static final int MAGIC_SPELLBOOK_INITIALISESPELLS = 2616; + + @ScriptArguments(integer = 2) + public static final int MOTHERLODE_HUD_UPDATE = 1634; } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/motherlode/MotherlodePlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/motherlode/MotherlodePlugin.java index 8130c714b4e..7e07b22d7b3 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/motherlode/MotherlodePlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/motherlode/MotherlodePlugin.java @@ -47,7 +47,6 @@ import net.runelite.api.GameObject; import net.runelite.api.GameState; import net.runelite.api.InventoryID; -import net.runelite.api.Item; import net.runelite.api.ItemContainer; import net.runelite.api.ItemID; import static net.runelite.api.ObjectID.BROKEN_STRUT; @@ -58,6 +57,7 @@ import static net.runelite.api.ObjectID.ROCKFALL; import static net.runelite.api.ObjectID.ROCKFALL_26680; import net.runelite.api.Perspective; +import net.runelite.api.ScriptID; import net.runelite.api.Varbits; import net.runelite.api.WallObject; import net.runelite.api.coords.LocalPoint; @@ -66,6 +66,7 @@ import net.runelite.api.events.GameObjectSpawned; import net.runelite.api.events.GameStateChanged; import net.runelite.api.events.ItemContainerChanged; +import net.runelite.api.events.ScriptPostFired; import net.runelite.api.events.VarbitChanged; import net.runelite.api.events.WallObjectDespawned; import net.runelite.api.events.WallObjectSpawned; @@ -97,10 +98,8 @@ public class MotherlodePlugin extends Plugin ItemID.MITHRIL_ORE, ItemID.GOLD_ORE, ItemID.COAL, ItemID.GOLDEN_NUGGET); private static final Set ROCK_OBSTACLES = ImmutableSet.of(ROCKFALL, ROCKFALL_26680); - private static final int MAX_INVENTORY_SIZE = 28; - - private static final int SACK_LARGE_SIZE = 162; - private static final int SACK_SIZE = 81; + private static final int SACK_LARGE_SIZE = 189; + private static final int SACK_SIZE = 108; private static final int UPPER_FLOOR_HEIGHT = -490; @@ -113,9 +112,6 @@ public class MotherlodePlugin extends Plugin @Inject private MotherlodeSceneOverlay sceneOverlay; - @Inject - private MotherlodeSackOverlay motherlodeSackOverlay; - @Inject private MotherlodeConfig config; @@ -131,12 +127,7 @@ public class MotherlodePlugin extends Plugin @Getter(AccessLevel.PACKAGE) private boolean inMlm; - @Getter(AccessLevel.PACKAGE) private int curSackSize; - @Getter(AccessLevel.PACKAGE) - private int maxSackSize; - @Getter(AccessLevel.PACKAGE) - private Integer depositsLeft; @Inject private MotherlodeSession session; @@ -161,7 +152,6 @@ protected void startUp() { overlayManager.add(miningOverlay); overlayManager.add(sceneOverlay); - overlayManager.add(motherlodeSackOverlay); inMlm = checkInMlm(); @@ -176,20 +166,9 @@ protected void shutDown() { overlayManager.remove(miningOverlay); overlayManager.remove(sceneOverlay); - overlayManager.remove(motherlodeSackOverlay); veins.clear(); rocks.clear(); brokenStruts.clear(); - - Widget sack = client.getWidget(ComponentID.MLM_CONTAINER); - - clientThread.invokeLater(() -> - { - if (sack != null && sack.isHidden()) - { - sack.setHidden(false); - } - }); } void reset() @@ -288,8 +267,6 @@ public void checkMining() return; } - depositsLeft = calculateDepositsLeft(); - Instant lastPayDirtMined = session.getLastPayDirtMined(); if (lastPayDirtMined == null) { @@ -306,6 +283,45 @@ public void checkMining() } } + @Subscribe + private void onScriptPostFired(ScriptPostFired event) + { + if (event.getScriptId() == ScriptID.MOTHERLODE_HUD_UPDATE) + { + recolorSackOverlay(); + } + } + + private void recolorSackOverlay() + { + ItemContainer inv = client.getItemContainer(InventoryID.INVENTORY); + if (inv == null) + { + return; + } + + int sackSize = client.getVarbitValue(Varbits.SACK_NUMBER); + boolean sackUpgraded = client.getVarbitValue(Varbits.SACK_UPGRADED) == 1; + int sackCapacity = sackUpgraded ? SACK_LARGE_SIZE : SACK_SIZE; + int payDir = inv.count(ItemID.PAYDIRT); + + Widget sackSizeWidget = client.getWidget(ComponentID.MLM_SACK_SIZE_TEXT); + Widget spaceTextWidget = client.getWidget(ComponentID.MLM_SPACE_TEXT); + if (sackSizeWidget != null && spaceTextWidget != null) + { + if (payDir >= sackCapacity - sackSize) + { + sackSizeWidget.setTextColor(0xff0000); + spaceTextWidget.setTextColor(0xff0000); + } + else + { + sackSizeWidget.setTextColor(0xc8c8c8); + spaceTextWidget.setTextColor(0xffffff); + } + } + } + @Subscribe public void onWallObjectSpawned(WallObjectSpawned event) { @@ -377,13 +393,20 @@ else if (event.getGameState() == GameState.LOGIN_SCREEN) @Subscribe public void onItemContainerChanged(ItemContainerChanged event) { - final ItemContainer container = event.getItemContainer(); + if (!inMlm) + { + return; + } + + recolorSackOverlay(); - if (!inMlm || !shouldUpdateOres || inventorySnapshot == null || container.getId() != InventoryID.INVENTORY.getId()) + if (!shouldUpdateOres || inventorySnapshot == null || event.getContainerId() != InventoryID.INVENTORY.getId()) { return; } + final ItemContainer container = event.getItemContainer(); + // Build set of current inventory Multiset current = HashMultiset.create(); Arrays.stream(container.getItems()) @@ -411,52 +434,6 @@ public void onItemContainerChanged(ItemContainerChanged event) shouldUpdateOres = false; } - private Integer calculateDepositsLeft() - { - if (maxSackSize == 0) // check if maxSackSize has been initialized - { - refreshSackValues(); - } - - double depositsLeft = 0; - int nonPayDirtItems = 0; - - ItemContainer inventory = client.getItemContainer(InventoryID.INVENTORY); - if (inventory == null) - { - return null; - } - - Item[] result = inventory.getItems(); - assert result != null; - - for (Item item : result) - { - // Assume that MLM ores are being banked and exclude them from the check, - // so the user doesn't see the Overlay switch between deposits left and N/A. - // - // Count other items at nonPayDirtItems so depositsLeft is calculated accordingly. - if (item.getId() != ItemID.PAYDIRT && item.getId() != -1 && !MLM_ORE_TYPES.contains(item.getId())) - { - nonPayDirtItems += 1; - } - } - - double inventorySpace = MAX_INVENTORY_SIZE - nonPayDirtItems; - double sackSizeRemaining = maxSackSize - curSackSize; - - if (inventorySpace > 0 && sackSizeRemaining > 0) - { - depositsLeft = Math.ceil(sackSizeRemaining / inventorySpace); - } - else if (inventorySpace == 0) - { - return null; - } - - return (int) depositsLeft; - } - private boolean checkInMlm() { GameState gameState = client.getGameState(); @@ -483,8 +460,6 @@ private boolean checkInMlm() private void refreshSackValues() { curSackSize = client.getVarbitValue(Varbits.SACK_NUMBER); - boolean sackUpgraded = client.getVarbitValue(Varbits.SACK_UPGRADED) == 1; - maxSackSize = sackUpgraded ? SACK_LARGE_SIZE : SACK_SIZE; } /** diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/motherlode/MotherlodeSackOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/motherlode/MotherlodeSackOverlay.java deleted file mode 100644 index 9a15581f28b..00000000000 --- a/runelite-client/src/main/java/net/runelite/client/plugins/motherlode/MotherlodeSackOverlay.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright (c) 2018, Seth - * Copyright (c) 2018, Adam - * Copyright (c) 2018, Lars - * 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.motherlode; - -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Graphics2D; -import javax.inject.Inject; -import net.runelite.api.Client; -import static net.runelite.api.MenuAction.RUNELITE_OVERLAY_CONFIG; -import net.runelite.api.Varbits; -import net.runelite.api.widgets.ComponentID; -import net.runelite.api.widgets.Widget; -import static net.runelite.client.ui.overlay.OverlayManager.OPTION_CONFIGURE; -import net.runelite.client.ui.overlay.OverlayPanel; -import net.runelite.client.ui.overlay.OverlayPosition; -import net.runelite.client.ui.overlay.components.ComponentConstants; -import net.runelite.client.ui.overlay.components.LineComponent; - -class MotherlodeSackOverlay extends OverlayPanel -{ - private static final Color DANGER = new Color(150, 0, 0, 150); - private final Client client; - private final MotherlodeConfig config; - private final MotherlodePlugin plugin; - - @Inject - MotherlodeSackOverlay(Client client, MotherlodeConfig config, MotherlodePlugin plugin) - { - super(plugin); - setPosition(OverlayPosition.TOP_LEFT); - this.client = client; - this.config = config; - this.plugin = plugin; - addMenuEntry(RUNELITE_OVERLAY_CONFIG, OPTION_CONFIGURE, "Sack overlay"); - } - - @Override - public Dimension render(Graphics2D graphics) - { - if (!plugin.isInMlm()) - { - return null; - } - - Widget sack = client.getWidget(ComponentID.MLM_CONTAINER); - - panelComponent.setBackgroundColor(ComponentConstants.STANDARD_BACKGROUND_COLOR); - - if (sack != null) - { - sack.setHidden(true); - - if (config.showSack()) - { - if (plugin.getCurSackSize() >= plugin.getMaxSackSize()) - { - panelComponent.setBackgroundColor(DANGER); - } - - panelComponent.getChildren().add(LineComponent.builder() - .left("Pay-dirt in sack:") - .right(String.valueOf(client.getVarbitValue(Varbits.SACK_NUMBER))) - .build()); - } - - if (config.showDepositsLeft()) - { - final Integer depositsLeft = plugin.getDepositsLeft(); - Color color = Color.WHITE; - - if (depositsLeft != null) - { - if (depositsLeft == 0) - { - panelComponent.setBackgroundColor(DANGER); - } - else if (depositsLeft == 1) - { - color = Color.RED; - } - } - - panelComponent.getChildren().add(LineComponent.builder() - .left("Deposits left:") - .leftColor(color) - .right(depositsLeft == null ? "N/A" : String.valueOf(depositsLeft)) - .rightColor(color) - .build()); - } - } - - return super.render(graphics); - } -}