Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/main/java/com/duckblade/osrs/sailing/SailingConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,18 @@ default Color cargoHoldColourFull()
return Color.RED;
}

@ConfigItem(
keyName = "cargoHoldFullNotification",
name = "Notify when full",
description = "Notify when your cargo hold becomes full.",
section = SECTION_CARGO_HOLD_TRACKING,
position = 2
)
default Notification cargoHoldFullNotification()
{
return Notification.OFF;
}

@ConfigItem(
keyName = "notifyGiantClamSpawn",
name = "Notify on Giant clam",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
import net.runelite.api.gameval.ItemID;
import net.runelite.api.gameval.VarbitID;
import net.runelite.api.widgets.Widget;
import net.runelite.client.Notifier;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.config.Notification;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.events.RuneScapeProfileChanged;
import net.runelite.client.ui.overlay.Overlay;
Expand Down Expand Up @@ -101,6 +103,7 @@ public class CargoHoldTracker
private final ConfigManager configManager;
private final BoatTracker boatTracker;
private final CourierTaskTracker courierTaskTracker;
private final Notifier notifier;

// boat slot -> item id+count
private final Map<Integer, Multiset<Integer>> cargoHoldItems = new HashMap<>();
Expand All @@ -119,13 +122,18 @@ public class CargoHoldTracker
private int lastXp;
private boolean pendingJenkinsAction;

private Notification fullNotification;
private boolean wasFull;
private int lastCheckedBoatSlot = -1;

@Inject
public CargoHoldTracker(Client client, ConfigManager configManager, BoatTracker boatTracker, CourierTaskTracker courierTaskTracker)
public CargoHoldTracker(Client client, ConfigManager configManager, BoatTracker boatTracker, CourierTaskTracker courierTaskTracker, Notifier notifier)
{
this.client = client;
this.configManager = configManager;
this.boatTracker = boatTracker;
this.courierTaskTracker = courierTaskTracker;
this.notifier = notifier;

setPosition(OverlayPosition.DYNAMIC);
setLayer(OverlayLayer.ABOVE_SCENE);
Expand All @@ -138,6 +146,7 @@ public boolean isEnabled(SailingConfig config)
overlayEnabled = config.cargoHoldShowCounts();
colourEmpty = config.cargoHoldColourEmpty();
colourFull = config.cargoHoldColourFull();
fullNotification = config.cargoHoldFullNotification();
return true;
}

Expand All @@ -158,6 +167,8 @@ public void shutDown()
cargoHoldItems.clear();
memoizedInventory = null;
pendingJenkinsAction = false;
wasFull = false;
lastCheckedBoatSlot = -1;
}

@Override
Expand Down Expand Up @@ -210,14 +221,14 @@ public void onOverheadTextChanged(OverheadTextChanged e)
// todo different ones? doesn't matter now since it's count only but will matter later
log.trace("crewmate salvage");
add(ItemID.SAILING_SMALL_SHIPWRECK_SALVAGE, 1);
writeToConfig();
onCargoStateUpdated();
return;
}

if (MSG_CREWMATE_SALVAGE_FULL.equals(e.getOverheadText()))
{
set(UNKNOWN_ITEM, maxCapacity() - usedCapacity());
writeToConfig();
onCargoStateUpdated();
return;
}

Expand All @@ -236,7 +247,7 @@ public void onStatChanged(StatChanged e)
{
log.trace("jenkins salvage");
add(ItemID.SAILING_SMALL_SHIPWRECK_SALVAGE, 1);
writeToConfig();
onCargoStateUpdated();
}
}

Expand Down Expand Up @@ -275,7 +286,7 @@ public void onItemContainerChanged(ItemContainerChanged e)
}

log.debug("read cargo hold inventory from event {}", trackedInv);
writeToConfig();
onCargoStateUpdated();
}

@Subscribe
Expand Down Expand Up @@ -320,7 +331,7 @@ public void onGameTick(GameTick e)
deposited.entrySet().forEach(entry -> cargoHoldToUpdate.add(entry.getElement(), entry.getCount()));

log.debug("updated cargo hold from inventory delta {}", cargoHoldToUpdate);
writeToConfig();
onCargoStateUpdated();
}

@Subscribe
Expand Down Expand Up @@ -479,6 +490,32 @@ private void loadFromConfig(int boatSlot)
}
}

private void onCargoStateUpdated()
{
writeToConfig();
checkFull();
}

private void checkFull()
{
int max = maxCapacity();
int boatSlot = currentBoatSlot();
boolean isFull = max > 0 && usedCapacity() >= max;

if (boatSlot != lastCheckedBoatSlot)
{
lastCheckedBoatSlot = boatSlot;
wasFull = isFull;
return;
}

if (isFull && !wasFull)
{
notifier.notify(fullNotification, "Your cargo hold is full!");
}
wasFull = isFull;
}

private void writeToConfig()
{
writeToConfig(currentBoatSlot());
Expand Down