Class WithdrawCapacity
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.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionintamount()Units withdrawable now; 0 unlessoutcome()isWithdrawCapacity.Outcome.WITHDRAW.static WithdrawCapacityforAll(int freeSlots, boolean stackable, boolean alreadyHeld) Capacity for an explicit "withdraw everything" request, which has no numeric target.static WithdrawCapacityof(int target, int have, int freeSlots, boolean stackable, boolean alreadyHeld) outcome()booleanTrue when a withdraw should be dispatched.toString()
-
Field Details
-
INVENTORY_SLOTS
public static final int INVENTORY_SLOTSSlots in a player inventory.- See Also:
-
-
Method Details
-
outcome
-
amount
public int amount()Units withdrawable now; 0 unlessoutcome()isWithdrawCapacity.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 positivehave- units currently held, or -1 when the inventory is unreadablefreeSlots- empty inventory slots, or -1 when the inventory is unreadablestackable- whether one slot holds any quantity of this itemalreadyHeld- whether at least one is already in the inventory (a stack to add to)
-
forAll
Capacity for an explicit "withdraw everything" request, which has no numeric target.Reports
WithdrawCapacity.Outcome.INVENTORY_FULLwhen no room exists at all — aWithdraw-Allinto a full pack banks nothing and only looks like a working click. -
toString
-