Skip to content

Commit

Permalink
mlm: update for sack size changes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Adam- committed May 10, 2024
1 parent 59e67ab commit 3950ea0
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 196 deletions.
2 changes: 2 additions & 0 deletions runelite-api/src/main/interfaces/interfaces.toml
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,8 @@ worldmap_options=53
[mlm]
id=382
container=0
sack_size_text=5
space_text=6

[moons_of_peril]
id=869
Expand Down
3 changes: 3 additions & 0 deletions runelite-api/src/main/java/net/runelite/api/ScriptID.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -97,10 +98,8 @@ public class MotherlodePlugin extends Plugin
ItemID.MITHRIL_ORE, ItemID.GOLD_ORE, ItemID.COAL, ItemID.GOLDEN_NUGGET);
private static final Set<Integer> 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;

Expand All @@ -113,9 +112,6 @@ public class MotherlodePlugin extends Plugin
@Inject
private MotherlodeSceneOverlay sceneOverlay;

@Inject
private MotherlodeSackOverlay motherlodeSackOverlay;

@Inject
private MotherlodeConfig config;

Expand All @@ -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;
Expand All @@ -161,7 +152,6 @@ protected void startUp()
{
overlayManager.add(miningOverlay);
overlayManager.add(sceneOverlay);
overlayManager.add(motherlodeSackOverlay);

inMlm = checkInMlm();

Expand All @@ -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()
Expand Down Expand Up @@ -288,8 +267,6 @@ public void checkMining()
return;
}

depositsLeft = calculateDepositsLeft();

Instant lastPayDirtMined = session.getLastPayDirtMined();
if (lastPayDirtMined == null)
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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<Integer> current = HashMultiset.create();
Arrays.stream(container.getItems())
Expand Down Expand Up @@ -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();
Expand All @@ -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;
}

/**
Expand Down

This file was deleted.

0 comments on commit 3950ea0

Please sign in to comment.