Work orders: gather straight into the order

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rope 2026-11-11 13:48:08 +00:00
parent 5809be59de
commit 450abc9be9
4 changed files with 79 additions and 19 deletions

2
app.py
View file

@ -451,7 +451,7 @@ class Handler(BaseHTTPRequestHandler):
if path == "/api/order/remove":
return game.remove_orders(world, player, body.get("id"))
if path == "/api/order/work":
return game.work_order(world, player, body.get("id"), now)
return game.work_order(world, player, body.get("id"), now, str(body["via"]) if body.get("via") else None)
if path == "/api/order/drop":
return game.drop_order(world, player, body.get("id"), now)
if path == "/api/order/deliver":

51
game.py
View file

@ -2377,9 +2377,8 @@ def _tally(action: dict, summary: dict) -> tuple:
for key in ("items", "overflow", "sold"):
for item, qty in summary[key].items():
got[item] = got.get(item, 0) + qty
if summary.get("delivered") and action["outputs"]:
made = next(iter(action["outputs"]))
got[made] = got.get(made, 0) + summary["delivered"]
for item, qty in summary.get("delivered", {}).items():
got[item] = got.get(item, 0) + qty
return got, sum(summary["xp"].values()), summary["gold"], summary["wins"], summary["losses"]
@ -3324,7 +3323,8 @@ def can_start(world: dict, player: dict, action: dict) -> str | None:
return f"Needs {BUILDINGS[key]['name']} level {level}"
order = working_order(world, player, action)
if order is not None or "order" in (player["action"] or {}) and player["action"]["id"] == action["id"]:
if not order or order["status"] != "open" or order["claimed"] != player["id"] and not order.get("city"):
if not order or order["status"] != "open" or order["claimed"] != player["id"] and not order.get("city") \
and order["kind"] != "gather":
return "Work order done" if order and order["status"] == "done" else "Work order closed"
short = [ITEMS[item]["name"].lower() for item, qty in fire_inputs(world, action).items()
if (order["provided"].get(item, 0) if order else 0) + player["bank"].get(item, 0) < qty]
@ -3528,7 +3528,8 @@ def _finish_action(world: dict, player: dict, action: dict, now: float, rng: ran
if sent:
outputs[order["item"]] -= sent
_deliver(world, order, player, sent, now, used, inputs)
summary["delivered"] = summary.get("delivered", 0) + sent
given = summary.setdefault("delivered", {})
given[order["item"]] = given.get(order["item"], 0) + sent
for item, qty in outputs.items():
if not qty:
continue
@ -3615,8 +3616,9 @@ def process_player(world: dict, player: dict, now: float, rng: random.Random | N
stop(player, reason)
summary["stopped"] = reason
break
if player["overflow"] == "stop" and any(bank_room(world, player, item) < qty
for item, qty in action["outputs"].items()):
order = working_order(world, player, action)
if player["overflow"] == "stop" and any(bank_room(world, player, item) < qty for item, qty in action["outputs"].items()
if not (order and order["status"] == "open" and order["item"] == item)):
stop(player, "Bank full")
summary["stopped"] = "Bank full"
break
@ -4402,17 +4404,21 @@ def drop_order(world: dict, player: dict, order_id, now: float) -> str | None:
return None
def work_order(world: dict, player: dict, order_id, now: float) -> str | None:
"""Claim a crafting order and start making it. A make that was running goes back to the
front of the queue with what it had left; anything else is what comes after."""
def work_order(world: dict, player: dict, order_id, now: float, via: str | None = None) -> str | None:
"""Claim a crafting order and start making it, or start gathering for a materials order
(`via` any gathering that turns it up): what's made or gathered goes straight to the order.
A make that was running goes back to the front of the queue with what it had left; anything
else is what comes after."""
order = order_by_id(world, order_id)
had = order and order["claimed"] == player["id"]
error = claim_order(world, player, order_id)
gather = bool(order) and order["kind"] == "gather"
via = (via or order["action"]) if gather else order and order["action"]
error = _gather_for(player, order, via) if gather else claim_order(world, player, order_id)
if error:
return error
previous = player["action"]
player["action"] = {"id": order["action"], "start": now, "order": order["id"]}
reason = can_start(world, player, ACTION_BY_ID[order["action"]])
player["action"] = {"id": via, "start": now, "order": order["id"]}
reason = can_start(world, player, ACTION_BY_ID[via])
if reason:
player["action"] = previous
if not had:
@ -4426,10 +4432,26 @@ def work_order(world: dict, player: dict, order_id, now: float) -> str | None:
elif "left" not in previous:
previous = {"resume": previous["id"], "resume_plot2": previous.get("plot2")}
player["action"].update({k: v for k, v in (previous or {}).items() if k in ("resume", "resume_plot2") and v})
if gather:
# Once the order's filled, gathering carries on into the bank unless there's something to go back to.
player["action"].setdefault("resume", via)
player["stopped"] = None
return None
def _gather_for(player: dict, order: dict, via: str) -> str | None:
"""Why the player can't gather for this materials order by action `via`, or None."""
if order["status"] != "open":
return "No such order"
if order["by"] == player["id"] and not order.get("city"):
return "That's your own order"
action = ACTION_BY_ID.get(via)
if not action or action["skill"] not in GATHERING or action.get("special") or "enemy" in action \
or order["item"] not in [*action["outputs"], *(item for item, _qty, _odds in action.get("finds", []))]:
return "That doesn't gather it"
return None
def deliver_order(world: dict, player: dict, order_id, now: float) -> str | None:
"""Hand over what's asked for straight from your bank."""
order = order_by_id(world, order_id)
@ -7901,6 +7923,9 @@ ORDER_RECIPES, ORDER_RAW = _order_sources()
# What changed, shown on the Patch notes page. Newest first; every shipped change adds a
# line here (new / balance / fix), and a new release a new entry on top.
PATCH_NOTES = [
{"date": "2026-11-11", "title": "Work orders", "notes": [
("new", "Work orders: Gather sends materials straight to the order. Gathering carries on once it's filled."),
]},
{"date": "2026-11-10", "title": "Siegeworks", "notes": [
("balance", "Rebalanced rings and fixed swing timers"),
("new", "Construction: Siegeworks. 6 traps (Lv 15–89, 1 frame) and 6 engines (Lv 19–93, 3 frames)."),

View file

@ -2760,13 +2760,15 @@ function orderSlots(o) {
}).join("");
}
// A materials order: gather it right here. A fight opens its card instead, odds and all.
// A materials order: gather for it right here, straight into the order. A fight opens its card
// instead, odds and all.
function gatherButton(o) {
const a = sourceOf(o.item);
if (!a) return "";
if (S.me.action?.id === a.id) return `<span class="tag gold">${a.enemy ? "Fighting" : "Gathering"}</span>`;
if (S.me.action?.order === o.id || a.enemy && S.me.action?.id === a.id) return `<span class="tag gold">${a.enemy ? "Fighting" : "Gathering"}</span>`;
if (a.enemy) return `<button class="btn primary"${goto(o.item)} title="${esc(a.name)}">Fight</button>`;
return startButton(a, "", S.me.blocked[a.id], "Gather");
const why = S.me.levels[o.skill] < o.level ? `Needs ${skillOf(o.skill).name.toLowerCase()} ${o.level}` : S.me.blocked[a.id];
return `<button class="btn primary" data-order-work="${o.id}" data-via="${a.id}" ${why ? `disabled title="${esc(why)}"` : `title="${esc(a.name)} → order"`}>Gather</button>`;
}
function orderCard(o) {
@ -2814,7 +2816,7 @@ function orderCard(o) {
${o.kind === "craft" ? `<div class="ro-slots">${orderSlots(o)}</div>` : ""}
${Object.keys(o.earned || {}).length ? `<div class="small muted">🤝 ${Object.entries(o.earned).map(([uid, n]) => `${esc(playerName(uid))} ${fmt(n)}`).join(", ")}</div>` : ""}
${favoured.length ? `<div class="small muted">${FAVOUR} ${favoured.map(([uid, n]) => `${esc(playerName(uid))} ${fmt(Math.round(n))}`).join(", ")}</div>` : ""}
${crafting.length ? `<div class="small muted" title="Crafting now">${skill.icon} ${crafting.map((p) => esc(p.name)).join(", ")}</div>` : ""}
${crafting.length ? `<div class="small muted" title="${o.kind === "gather" ? "Gathering" : "Crafting"} now">${skill.icon} ${crafting.map((p) => esc(p.name)).join(", ")}</div>` : ""}
${progress}
<div class="foot">${o.reward || !o.city ? `<span class="item-chip ro-reward">${COIN} ${reward}</span>` : ""}${favour}${status}<span class="btns">${buttons}</span></div>
</div>`;
@ -3463,7 +3465,7 @@ document.addEventListener("click", (e) => {
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(); }
if (d.orderWork) return act("/api/order/work", { id: Number(d.orderWork) });
if (d.orderWork) return act("/api/order/work", { id: Number(d.orderWork), via: d.via || null });
if (d.orderDrop) return act("/api/order/drop", { id: Number(d.orderDrop) });
if (d.orderDeliver) return act("/api/order/deliver", { id: Number(d.orderDeliver) });
if (d.orderCancel) return act("/api/order/cancel", { id: Number(d.orderCancel) });

View file

@ -2861,6 +2861,39 @@ class WorkOrderTest(unittest.TestCase):
self.assertEqual(order["favour"], {"mike": 120, "dave": 280})
self.assertEqual((order["status"], order["held"], self.dave["bank"]), ("done", 0, {"oak_logs": 10}))
def test_gathering_for_a_materials_order_delivers_straight_to_it(self):
self.mike["gold"] = 500
self.assertIsNone(game.post_order(self.world, self.mike, "gather", "copper_ore", 5, None, 10, T0))
order = self.world["orders"][0]
self.assertEqual(game.work_order(self.world, self.mike, order["id"], T0), "That's your own order")
self.assertEqual(game.work_order(self.world, self.fred, order["id"], T0, "mine_iron"), "That doesn't gather it")
self.assertIsNone(game.work_order(self.world, self.fred, order["id"], T0))
self.assertIsNone(game.work_order(self.world, self.dave, order["id"], T0)) # nobody holds a claim
game.process_player(self.world, self.fred, T0 + 3600, random.Random(1))
self.assertEqual((order["status"], order["from"], self.mike["bank"].get("copper_ore")), ("done", {"fred": 5}, 5))
self.assertEqual(self.fred["gold"], 50)
# Filled: gathering carries on into the bank.
self.assertEqual((self.fred["action"]["id"], "order" in self.fred["action"]), ("mine_copper", False))
self.assertGreater(self.fred["bank"].get("copper_ore", 0), 0)
got = next(e for e in self.fred["ledger"] if e.get("act") == "mine_copper")
self.assertEqual(got["items"]["copper_ore"], self.fred["bank"]["copper_ore"] + 5)
def test_gathering_for_an_order_goes_back_to_what_you_were_doing(self):
self.assertIsNone(game.post_order(self.world, self.mike, "gather", "stone", 2, None, 0, T0, city=True))
order = self.world["orders"][0]
game.start_action(self.world, self.fred, "mine_copper", T0)
self.assertIsNone(game.work_order(self.world, self.fred, order["id"], T0))
game.process_player(self.world, self.fred, T0 + 3600, random.Random(1))
self.assertEqual((order["status"], self.world["city"]["stockpile"].get("stone")), ("done", 2))
self.assertEqual(self.fred["action"]["id"], "mine_copper")
def test_a_gem_order_is_filled_by_any_rock_that_turns_it_up(self):
game.post_order(self.world, self.mike, "gather", "quartz", 1, None, 0, T0)
order = self.world["orders"][0]
self.assertIsNone(game.work_order(self.world, self.fred, order["id"], T0, "mine_copper"))
game.process_player(self.world, self.fred, T0 + 6 * 3600, random.Random(1))
self.assertEqual((order["status"], self.mike["bank"].get("quartz")), ("done", 1))
def test_several_crafters_work_a_city_order_at_once(self):
game.post_order(self.world, self.mike, "craft", "iron_warhammer", 2, [], 0, T0, city=True)
order = self.world["orders"][0]