Work orders: show what a lit fire pays
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
2bcda564b8
commit
517b560019
4 changed files with 51 additions and 11 deletions
|
|
@ -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 `<div class="ro-slot paid" title="${esc(`${item(id).name}: ${firePays(a, id, qty)}`)}"><span class="doll-slot empty-req">${item(id).icon}</span>
|
||||
<span class="ro-have muted"><s>${fmt(qty)}</s></span><span class="ro-name">${esc(item(id).name)}</span></div>`;
|
||||
}
|
||||
|
||||
// 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 `<div class="ro-slot open"><span class="doll-slot empty-req" title="${esc(name)}">${item(id).icon}</span>
|
||||
<span class="ro-have muted">×${fmt(per * all)}</span><span class="ro-name">${esc(name)}</span></div>`;
|
||||
}
|
||||
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 `<div class="ro-slot filled" title="${esc(tip)}"><span class="doll-slot">${item(id).icon}
|
||||
<span class="swap-qty">${fmt(need)}</span><span class="tick">✓</span></span><span class="ro-name">${esc(name)}</span></div>`;
|
||||
|
|
@ -1928,9 +1939,10 @@ function orderComposer() {
|
|||
const smiths = S.players.filter((p) => p.id !== S.uid && p.levels[a.skill] >= a.level).length;
|
||||
maker = `<div class="small muted" title="${esc(`${skillOf(a.skill).name} ${a.level} · ${smiths} can make it`)}">${skillOf(a.skill).icon} ${a.level} · 👥 ${smiths}</div>`;
|
||||
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 `<div class="ro-slot ${on ? "filled" : "open"}"><button class="doll-slot ${on ? "on" : "empty-req"}" data-provide="${id}"
|
||||
${!on && have < need ? `disabled title="${esc(`${item(id).name}: ${fmt(have)} / ${fmt(need)}`)}"` : `title="${esc(item(id).name)}"`}>
|
||||
${item(id).icon}${on ? `<span class="tick">✓</span>` : ""}</button>
|
||||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue