Class WithdrawCapacity

java.lang.Object
privbot.hooks.bank.WithdrawCapacity

public final class WithdrawCapacity extends Object
How many units of one item may be withdrawn right now, given the inventory's free space.

Withdrawing is a top-up: target means "end up holding this many", not "pull this many more", so re-running the step in a loop does not stack withdrawals. What makes it more than subtraction is that the inventory can run out of room mid-plan:

  • a stackable item already in the inventory needs no new slot at all;
  • a stackable item that is absent needs exactly one free slot;
  • a non-stackable item needs one free slot per unit, so the withdrawable amount is capped at the number of free slots.

An unreadable inventory is not an empty one. have and freeSlots are -1 when the client did not answer, and this class reports WithdrawCapacity.Outcome.UNREADABLE rather than computing against a zero. That distinction matters most here: an unreadable inventory scored as empty looks like 28 free slots and would happily withdraw into a full pack. The buy path learned the same lesson in a milder form — see the "using last known count" guard in the Builder's buy-items step.

Pure arithmetic, no client access, so every branch is unit-testable.

  • Field Details

    • INVENTORY_SLOTS

      public static final int INVENTORY_SLOTS
      Slots in a player inventory.
      See Also:
  • Method Details

    • outcome

      public WithdrawCapacity.Outcome outcome()
    • amount

      public int amount()
      Units withdrawable now; 0 unless outcome() is WithdrawCapacity.Outcome.WITHDRAW.
    • shouldWithdraw

      public boolean shouldWithdraw()
      True when a withdraw should be dispatched.
    • of

      public static WithdrawCapacity of(int target, int have, int freeSlots, boolean stackable, boolean alreadyHeld)
      Parameters:
      target - units to end up holding; must be positive
      have - units currently held, or -1 when the inventory is unreadable
      freeSlots - empty inventory slots, or -1 when the inventory is unreadable
      stackable - whether one slot holds any quantity of this item
      alreadyHeld - whether at least one is already in the inventory (a stack to add to)
    • forAll

      public static WithdrawCapacity forAll(int freeSlots, boolean stackable, boolean alreadyHeld)
      Capacity for an explicit "withdraw everything" request, which has no numeric target.

      Reports WithdrawCapacity.Outcome.INVENTORY_FULL when no room exists at all — a Withdraw-All into a full pack banks nothing and only looks like a working click.

    • toString

      public String toString()
      Overrides:
      toString in class Object