diff --git a/docs/02-Domain/✅ Completed Goal.md b/docs/02-Domain/✅ Completed Goal.md index f1f3689..a440272 100644 --- a/docs/02-Domain/✅ Completed Goal.md +++ b/docs/02-Domain/✅ Completed Goal.md @@ -11,7 +11,7 @@ Must be configurable. Shipped: - Manual: `[−]` at 1, or Clear -- Inventory detection (opt-in): `/satistaskory auto-remove` — picking up the goal item counts that many as done. Player inventory only. Dumping the item in a chest does not restore the quantity. Turning it on (or joining a world) baselines what you already hold; it does not wipe the list for items already on you. +- Inventory detection (opt-in): `/satistaskory auto-remove` — a **new** stack of the goal item on you counts that many as done. Dropping and picking the same items back up does not. Putting them in a chest and taking them out does not. Turning it on (or joining a world) baselines what you already hold. Ready To Craft is not completion. Auto-remove is off until the player turns it on. See [[🛠️ Ready To Craft]] and Philosophy Rule #5. diff --git a/docs/03-Architecture/📝 Decisions.md b/docs/03-Architecture/📝 Decisions.md index d2d8c5e..6dad1c6 100644 --- a/docs/03-Architecture/📝 Decisions.md +++ b/docs/03-Architecture/📝 Decisions.md @@ -354,7 +354,7 @@ A chest crafts from any `#minecraft:planks`. Picking `getItems()[0]` made spruce **Decision:** Inventory-detection completion is a **player toggle**: `/satistaskory auto-remove` `[on|off]`. Default **off**. -When on, an **increase** in how many of the goal item the player is holding counts that many toward the goal. Quantity drops. At 0 the goal is removed. Player inventory only. Putting the item in a chest does not restore quantity. Enabling the toggle, or joining a world, baselines current holdings so already-held stacks do not wipe the list. +When on, a **new** stack of the goal item in player inventory counts that many toward the goal. Quantity drops. At 0 the goal is removed. Items that left the inventory (dropped or stored) and come back are not new. Enabling the toggle, or joining a world, baselines current holdings so already-held stacks do not wipe the list. Manual `[−]` / Clear remain. Ready is still not complete. diff --git a/docs/04-Planning/🧭 Notes for the Wayfinder.md b/docs/04-Planning/🧭 Notes for the Wayfinder.md index eb1ed9e..8fb2e29 100644 --- a/docs/04-Planning/🧭 Notes for the Wayfinder.md +++ b/docs/04-Planning/🧭 Notes for the Wayfinder.md @@ -441,7 +441,7 @@ Greetings, Wayfinder. The walk: completed items stayed on the overlay. -ADR-020: `/satistaskory auto-remove`. Off by default. When on, a **gain** in held goal items reduces quantity and removes at 0. Not “held >= target” (that would eat a new goal while they are carrying the item). Not storage. Baseline on join/enable. +ADR-020: `/satistaskory auto-remove`. Off by default. When on, a **new** stack of the goal item reduces quantity and removes at 0. Drop-and-pickup is the same items, not a second craft. Not “held >= target”. Baseline on join/enable. --- diff --git a/docs/05-Experience/🖥️ Experience.md b/docs/05-Experience/🖥️ Experience.md index cd629e0..a0dd1b4 100644 --- a/docs/05-Experience/🖥️ Experience.md +++ b/docs/05-Experience/🖥️ Experience.md @@ -60,7 +60,7 @@ The overlay answers both halves of the vision question: `[-]` at quantity 1 removes that goal. -`/satistaskory auto-remove` (off by default): picking up the goal item counts it done and drops the quantity (gone at 0). Only what is on you. A chest you just filled does not count. Dumping the item does not bring the row back. +`/satistaskory auto-remove` (off by default): newly obtained goal items count as done and drop the quantity (gone at 0). Only what is on you. Dropping them and picking them back up does not tick down again. A chest you just filled does not count. Walking has no cursor. Overlay `[+]` / `[-]` / Clear are HUD hit-tests (vanilla button sprites + click sound), not a `Screen`. Open chat (`T` or `/`) to click them. Capture does not use a clickable chip you leave the item to hit. diff --git a/src/main/java/com/sufficient/satistaskory/application/ObtainedCompletion.java b/src/main/java/com/sufficient/satistaskory/application/ObtainedCompletion.java index 463eeb2..8bb7c6f 100644 --- a/src/main/java/com/sufficient/satistaskory/application/ObtainedCompletion.java +++ b/src/main/java/com/sufficient/satistaskory/application/ObtainedCompletion.java @@ -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 lastHeld = new HashMap<>(); + private final Map 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); diff --git a/src/main/resources/assets/satistaskory/lang/en_us.json b/src/main/resources/assets/satistaskory/lang/en_us.json index 776e29f..a45554e 100644 --- a/src/main/resources/assets/satistaskory/lang/en_us.json +++ b/src/main/resources/assets/satistaskory/lang/en_us.json @@ -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." } diff --git a/src/test/java/com/sufficient/satistaskory/application/ObtainedCompletionTest.java b/src/test/java/com/sufficient/satistaskory/application/ObtainedCompletionTest.java index 4e9a1e2..22f48f0 100644 --- a/src/test/java/com/sufficient/satistaskory/application/ObtainedCompletionTest.java +++ b/src/test/java/com/sufficient/satistaskory/application/ObtainedCompletionTest.java @@ -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()); + } }