Do not count dropped items as newly obtained.
Build / build (push) Failing after 31s

Auto-remove remembers stacks that left the inventory. Picking them back up does not tick the goal down again. A stack that was never held still counts.
This commit is contained in:
Stephen Fasciani
2026-09-08 06:56:15 -04:00
parent d63f1aa745
commit 38a2df05c9
7 changed files with 54 additions and 12 deletions
@@ -9,15 +9,18 @@ import com.sufficient.satistaskory.domain.InventoryState;
import com.sufficient.satistaskory.domain.ItemId;
/**
* When auto-remove is on: an increase in held target items counts as obtained.
* Dumping items does not put quantity back. First look after enable/join is a baseline, not a gain.
* When auto-remove is on: a net new stack of the goal item counts as obtained.
* Items that left the inventory (dropped, stored) and come back are not new.
* First look after enable/join is a baseline, not a gain.
*/
public final class ObtainedCompletion {
private final Map<ItemId, Integer> lastHeld = new HashMap<>();
private final Map<ItemId, Integer> returning = new HashMap<>();
private boolean primed;
public void reset() {
lastHeld.clear();
returning.clear();
primed = false;
}
@@ -28,11 +31,27 @@ public final class ObtainedCompletion {
return;
}
for (Goal goal : List.copyOf(planner.goals())) {
int now = inventory.get(goal.targetItem());
int was = lastHeld.getOrDefault(goal.targetItem(), 0);
int gained = now - was;
if (gained > 0) {
planner.reduce(goal.targetItem(), gained);
ItemId item = goal.targetItem();
int now = inventory.get(item);
int was = lastHeld.getOrDefault(item, 0);
int delta = now - was;
if (delta < 0) {
returning.merge(item, -delta, Integer::sum);
} else if (delta > 0) {
int credit = returning.getOrDefault(item, 0);
int absorb = Math.min(delta, credit);
if (absorb > 0) {
int left = credit - absorb;
if (left == 0) {
returning.remove(item);
} else {
returning.put(item, left);
}
}
int fresh = delta - absorb;
if (fresh > 0) {
planner.reduce(item, fresh);
}
}
}
seed(planner, inventory);
@@ -5,6 +5,6 @@
"key.satistaskory.add_goal": "Add to Crafting Goals",
"satistaskory.tooltip.add": "[%s] Add to Crafting Goals",
"satistaskory.message.added": "Added %s to crafting goals",
"satistaskory.message.auto_remove.on": "Auto-remove ON: picking up a goal item counts it done. Dumping it in a chest does not bring it back.",
"satistaskory.message.auto_remove.on": "Auto-remove ON: newly obtained goal items count as done. Dropping and picking them back up does not.",
"satistaskory.message.auto_remove.off": "Auto-remove OFF: goals stay until you [-] or Clear."
}
@@ -62,4 +62,27 @@ class ObtainedCompletionTest {
completion.apply(planner, InventoryState.empty());
assertEquals(1, planner.goals().getFirst().quantity());
}
@Test
void droppingAndPickingUpDoesNotReduceAgain() {
planner.create(CHEST);
planner.increment(CHEST);
completion.apply(planner, InventoryState.empty());
completion.apply(planner, new InventoryState(Map.of(CHEST, 1)));
completion.apply(planner, InventoryState.empty());
completion.apply(planner, new InventoryState(Map.of(CHEST, 1)));
assertEquals(1, planner.goals().getFirst().quantity());
}
@Test
void pickupBeyondWhatWasDroppedStillCounts() {
planner.create(CHEST);
planner.increment(CHEST);
planner.increment(CHEST);
completion.apply(planner, InventoryState.empty());
completion.apply(planner, new InventoryState(Map.of(CHEST, 1)));
completion.apply(planner, InventoryState.empty());
completion.apply(planner, new InventoryState(Map.of(CHEST, 2)));
assertEquals(1, planner.goals().getFirst().quantity());
}
}