Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.duckblade.osrs.sailing.features.util.BoatTracker;
import com.duckblade.osrs.sailing.features.util.SailingUtil;
import com.duckblade.osrs.sailing.model.Boat;
import com.duckblade.osrs.sailing.model.CargoHoldTier;
import com.duckblade.osrs.sailing.module.PluginLifecycleComponent;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
Expand All @@ -29,6 +30,7 @@
import net.runelite.api.GameState;
import net.runelite.api.Item;
import net.runelite.api.ItemContainer;
import net.runelite.api.MenuAction;
import net.runelite.api.NPC;
import net.runelite.api.Point;
import net.runelite.api.Skill;
Expand Down Expand Up @@ -113,8 +115,10 @@ public class CargoHoldTracker
private Color colourFull;

private int pendingInventoryAction;
private boolean pendingQuickDepositAction;
private boolean sawItemContainerUpdate;
private boolean sawInventoryContainerUpdate;
private boolean lastClickWasQuickDeposit;

private int lastXp;
private boolean pendingJenkinsAction;
Expand Down Expand Up @@ -158,6 +162,7 @@ public void shutDown()
cargoHoldItems.clear();
memoizedInventory = null;
pendingJenkinsAction = false;
lastClickWasQuickDeposit = false;
}

@Override
Expand Down Expand Up @@ -246,6 +251,11 @@ public void onItemContainerChanged(ItemContainerChanged e)
if (e.getContainerId() == InventoryID.INV)
{
sawInventoryContainerUpdate = true;
if (pendingQuickDepositAction)
{
pendingInventoryAction = 1; // tick goes last
log.debug("inv change queued pendingInventoryAction with inventory {}", memoizedInventory);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still failure prone to inventory changes after clicking Deposit-all and before the deposit action occurs
IE dropping an item while running to the chest.

I don't think a proximity check will be perfect here either. Any inventory changes that occur on the same tick as the deposit will be included in the UI storage status even if adjacent to the chest.

}
return;
}

Expand Down Expand Up @@ -282,6 +292,10 @@ public void onItemContainerChanged(ItemContainerChanged e)
public void onGameTick(GameTick e)
{
pendingJenkinsAction = false;
if (!lastClickWasQuickDeposit)
{
pendingQuickDepositAction = false;
}

if (--pendingInventoryAction < 0)
{
Expand Down Expand Up @@ -326,11 +340,27 @@ public void onGameTick(GameTick e)
@Subscribe
public void onMenuOptionClicked(MenuOptionClicked e)
{
// CC_OP won't actually cancel the deposit-all action
if (e.getMenuEntry().getType() != MenuAction.CC_OP)
{
lastClickWasQuickDeposit = false;
}

if (!e.getMenuOption().contains("Withdraw") && !e.getMenuOption().contains("Deposit"))
{
return;
}

if (e.getMenuOption().equals("Deposit-all")
&& e.getMenuEntry().getType() == MenuAction.GAME_OBJECT_SECOND_OPTION
&& CargoHoldTier.fromGameObjectId(e.getId()) != null)
{
lastClickWasQuickDeposit = true;
pendingQuickDepositAction = true;
memoizedInventory = getInventoryMap();
log.debug("queued pendingQuickDepositAction with inventory {}", memoizedInventory);
}

Widget cargoHoldWidget = client.getWidget(InterfaceID.SailingBoatCargohold.UNIVERSE); // todo confirm
if (cargoHoldWidget != null && !cargoHoldWidget.isHidden())
{
Expand Down