diff --git a/game.py b/game.py index aec884b..fee2573 100644 --- a/game.py +++ b/game.py @@ -3525,11 +3525,14 @@ def post_order(world: dict, player: dict, kind: str, item: str, qty, provide, re return "Not enough gold" provided = {} if kind == "craft": - runs = _batches(action, item, qty) + # The pool holds what a run takes right now: a lit fire's share stays with the fire. + runs, inputs = _batches(action, item, qty), fire_inputs(world, action) for input_item in provide or []: if input_item not in action["inputs"]: return "That isn't in the recipe" - need = action["inputs"][input_item] * runs + if input_item not in inputs: + return f"The {FIRES[action['fire']]['name'].lower()} pays that" + need = inputs[input_item] * runs if player["bank"].get(input_item, 0) < need: return f"Not enough {ITEMS[input_item]['name'].lower()}" provided[input_item] = need @@ -3559,7 +3562,10 @@ def provide_reagent(world: dict, player: dict, order_id, item: str) -> str | Non action = ACTION_BY_ID[order["action"]] if item not in action["inputs"]: return "That isn't in the recipe" - need = action["inputs"][item] * _batches(action, order["item"], order["qty"] - order["delivered"]) + inputs = fire_inputs(world, action) + if item not in inputs: + return f"The {FIRES[action['fire']]['name'].lower()} pays that" + need = inputs[item] * _batches(action, order["item"], order["qty"] - order["delivered"]) short = need - order["provided"].get(item, 0) if short <= 0: return "Already provided" @@ -5986,6 +5992,8 @@ PATCH_NOTES = [ "and Aimed Shot 25% faster."), ("fix", "Work orders on phones: the item picker and reagent slots show names, and picking an item scrolls to " "the amount, price and Post."), + ("fix", "Work orders show what a lit fire pays: its log is struck through instead of asked for, and the forge " + "pays a coal. Orders never needed that log from the crafter, they just asked for it."), ]}, {"date": "2026-10-24", "title": "A dungeon in every area", "notes": [ ("new", "Six more dungeons for 2–4, seven pulls each with two mini-bosses and a final boss: Goblin Warren " diff --git a/static/app.js b/static/app.js index 7c0b13d..9bb50cd 100644 --- a/static/app.js +++ b/static/app.js @@ -1829,20 +1829,31 @@ function orderNews(state) { earnedSeen = Object.fromEntries(orders.map((o) => [o.id, (o.earned || {})[uid] || 0])); } +// What one run of a recipe takes right now: a lit fire pays its log (the forge a coal too). +const runInputs = (a) => S.me.fuelled?.[a.id] || a.inputs; +const firePays = (a, id, qty) => `the ${C.fires[a.fire].name.toLowerCase()} pays ${fmt(qty)}`; + +// A reagent the fire pays outright: struck through, nothing to put in. +function paidSlot(a, id, qty) { + return ``; +} + // Recipe slots on a crafting order. Anyone can put reagents in the pool; the crafter brings the rest. function orderSlots(o) { - const a = C.actions.find((x) => x.id === o.action), out = a.outputs[o.item]; + const a = C.actions.find((x) => x.id === o.action), out = a.outputs[o.item], ins = runInputs(a); const left = Math.ceil((o.qty - o.delivered) / out), all = Math.ceil(o.qty / out); - const worth = Object.entries(a.inputs).reduce((sum, [id, per]) => sum + item(id).value * per, 0); + const worth = Object.entries(ins).reduce((sum, [id, per]) => sum + item(id).value * per, 0); return Object.entries(a.inputs).map(([id, per]) => { const name = item(id).name, pool = o.provided[id] || 0, have = S.me.bank[id] || 0; if (o.status !== "open") { return `
${item(id).icon} ×${fmt(per * all)}${esc(name)}
`; } - const need = per * left; + const need = (ins[id] || 0) * left; + if (!need) return paidSlot(a, id, per * left); const who = Object.entries(o.gave || {}).filter(([, items]) => items[id]).map(([uid, items]) => `${playerName(uid)} ${fmt(items[id])}`); - const tip = [`${name}: ${fmt(pool)} / ${fmt(need)}`, ...who].join(" · "); + const tip = [`${name}: ${fmt(pool)} / ${fmt(need)}`, ...(need < per * left ? [firePays(a, id, per * left - need)] : []), ...who].join(" · "); if (pool >= need) { return `
${item(id).icon} ${fmt(need)}✓${esc(name)}
`; @@ -1928,9 +1939,10 @@ function orderComposer() { const smiths = S.players.filter((p) => p.id !== S.uid && p.levels[a.skill] >= a.level).length; maker = `
${skillOf(a.skill).icon} ${a.level} · 👥 ${smiths}
`; if (d.kind === "craft") { - const runs = Math.ceil(d.qty / a.outputs[d.item]); + const runs = Math.ceil(d.qty / a.outputs[d.item]), ins = runInputs(a); slots = Object.entries(a.inputs).map(([id, per]) => { - const need = per * runs, have = S.me.bank[id] || 0, on = d.provide.includes(id); + const need = (ins[id] || 0) * runs, have = S.me.bank[id] || 0, on = d.provide.includes(id); + if (!need) return paidSlot(a, id, per * runs); return `
@@ -2362,7 +2374,10 @@ document.addEventListener("click", (e) => { return render(); } if ("orderPost" in d) { - const body = { kind: draft.kind, item: draft.item, qty: draft.qty, provide: draft.provide, reward: draft.reward }; + // A fire lit since picking may now pay a reagent that was ticked. + const a = draft.kind === "craft" && C.actions.find((x) => x.id === C.order_recipes[draft.item]); + const provide = a ? draft.provide.filter((id) => runInputs(a)[id]) : draft.provide; + const body = { kind: draft.kind, item: draft.item, qty: draft.qty, provide, reward: draft.reward }; return api("/api/order", body).then((state) => { draft = null; orderTab = "yours"; accept(state); }).catch((err) => toast(err.message, "bad")); } if (d.otab) { orderTab = d.otab; return render(); } @@ -2460,7 +2475,7 @@ document.addEventListener("change", (e) => { if (key === "qty" && draft.kind === "craft" && draft.item) { // Drop provided reagents the bank can no longer cover at the new quantity. const a = C.actions.find((x) => x.id === C.order_recipes[draft.item]), runs = Math.ceil(draft.qty / a.outputs[draft.item]); - draft.provide = draft.provide.filter((id) => (S.me.bank[id] || 0) >= a.inputs[id] * runs); + draft.provide = draft.provide.filter((id) => (S.me.bank[id] || 0) >= (runInputs(a)[id] || 0) * runs); } } render(); diff --git a/static/styles.css b/static/styles.css index b62e4f2..ba66aee 100644 --- a/static/styles.css +++ b/static/styles.css @@ -658,6 +658,7 @@ button.sheet-skill:hover { background: var(--panel-2); } .ro-slot .doll-slot .gi { width: 30px; height: 30px; } .ro-slot.filled .doll-slot { border-color: rgba(95, 174, 90, .7); background: rgba(95, 174, 90, .1); } .doll-slot.empty-req { border-style: dashed; background: transparent; } +.ro-slot.paid .doll-slot { cursor: default; opacity: .55; } .doll-slot.empty-req .gi { opacity: .45; } .tick { position: absolute; bottom: -5px; right: -5px; background: var(--good); color: var(--bg); border-radius: 50%; width: 15px; height: 15px; font-size: 10px; display: grid; place-items: center; font-weight: 900; } diff --git a/tests/test_game.py b/tests/test_game.py index 5740b22..0c2ffe7 100644 --- a/tests/test_game.py +++ b/tests/test_game.py @@ -2606,6 +2606,22 @@ class FirekeepingTest(unittest.TestCase): self.fires["still"]["fuel"] = [{"tier": 0, "left": 600, "by": "kai"}] self.assertEqual(game.fire_inputs(self.world, brew), {"guam_leaf": 1, "logs": 1}) + def test_a_lit_fire_pays_for_work_orders_too(self): + self.fires["forge"].update(fuel=[{"tier": 0, "left": 60000, "by": "kai"}], at=T0) + self.world["players"]["mo"] = mo = game.new_player("mo", "Mo", "commoner", T0) + mo["gold"], mo["bank"] = 100, {"copper_ore": 5, "logs": 5} + self.assertEqual(game.post_order(self.world, mo, "craft", "copper_bar", 5, ["copper_ore", "logs"], 50, T0), + "The forge pays that") + self.assertIsNone(game.post_order(self.world, mo, "craft", "copper_bar", 5, ["copper_ore"], 50, T0)) + order = self.world["orders"][0] + self.assertEqual(game.provide_reagent(self.world, mo, order["id"], "logs"), "The forge pays that") + self.sam["bank"] = {} + self.assertIsNone(game.work_order(self.world, self.sam, order["id"], T0)) + game.process_player(self.world, self.sam, T0 + 600, random.Random(1)) + self.assertEqual(order["status"], "done") + self.assertEqual(mo["bank"], {"copper_bar": 5, "logs": 5}) + self.assertEqual(self.fires["forge"]["saved"], 5) + def test_warmth_goes_to_whoever_fed_the_fire(self): self.fires["kitchen"]["fuel"] = [{"tier": 0, "left": 6000, "by": "kai"}] self.fires["kitchen"]["at"] = T0