Place Festival workers on the board and preview all rewards
This commit is contained in:
parent
0b3dabbf50
commit
68380b21da
4 changed files with 176 additions and 26 deletions
|
|
@ -1,7 +1,10 @@
|
|||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import * as E from "../engine/index.js";
|
||||
import { actionVictoryPoints } from "../viewer/action-bonuses.js";
|
||||
import {
|
||||
actionVictoryPoints,
|
||||
festivalRewards,
|
||||
} from "../viewer/action-bonuses.js";
|
||||
import { RELEASE } from "../release-config.js";
|
||||
|
||||
function fixture(role) {
|
||||
|
|
@ -78,11 +81,20 @@ test("Church, Pension Office, Park Authority and Assembly Hall show their immedi
|
|||
verify(s, { type: "pension", good: "corn" });
|
||||
});
|
||||
test("action previews include Festival VP earned by production, shipping and plantations", () => {
|
||||
const festival = (goal, targets) => ({ id: "twins", goal, targets: { goods: [], estates: [], ...targets }, reward: { vp: 3 }, amount: 1 });
|
||||
const festival = (goal, targets) => ({
|
||||
id: "twins",
|
||||
goal,
|
||||
targets: { goods: [], estates: [], ...targets },
|
||||
reward: { vp: 3 },
|
||||
amount: 1,
|
||||
});
|
||||
const produced = fixture("craftsman");
|
||||
produced.players[0].estates = [{ id: "corn", w: 1, c: 0 }];
|
||||
produced.festivals = [festival("produce", { goods: ["corn"] })];
|
||||
verify(produced, E.legal(produced).find((m) => m.type === "produce" && !m.decline));
|
||||
verify(
|
||||
produced,
|
||||
E.legal(produced).find((m) => m.type === "produce" && !m.decline),
|
||||
);
|
||||
const shipped = fixture("captain");
|
||||
shipped.tasks = [{ kind: "ship", p: 0 }];
|
||||
shipped.players[0].goods.corn = 2;
|
||||
|
|
@ -94,3 +106,34 @@ test("action previews include Festival VP earned by production, shipping and pla
|
|||
planted.festivals = [festival("estates", { estates: ["fruit"] })];
|
||||
verify(planted, { type: "plant", id: "fruit" });
|
||||
});
|
||||
|
||||
test("bonus production previews every Festival reward and respects remaining worker supply", () => {
|
||||
const s = fixture("craftsman");
|
||||
s.tasks = [{ kind: "produceBonus", p: 0 }];
|
||||
s.production[0].fruit = 2;
|
||||
s.festivals = [
|
||||
{
|
||||
id: "crop",
|
||||
goal: "produce",
|
||||
amount: 3,
|
||||
targets: { goods: ["fruit"], estates: [] },
|
||||
reward: { vp: 1, coins: 2, workers: 3 },
|
||||
},
|
||||
];
|
||||
const move = { type: "produceBonus", good: "fruit" };
|
||||
s.workerSupply = 2;
|
||||
assert.deepEqual(festivalRewards(s, 0, move), {
|
||||
vp: 1,
|
||||
coins: 2,
|
||||
workers: 2,
|
||||
});
|
||||
const after = verify(s, move);
|
||||
assert.equal(after.players[0].coins - s.players[0].coins, 2);
|
||||
assert.equal(after.players[0].reserve.w - s.players[0].reserve.w, 2);
|
||||
s.workerSupply = 0;
|
||||
assert.deepEqual(festivalRewards(s, 0, move), {
|
||||
vp: 1,
|
||||
coins: 2,
|
||||
workers: 0,
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -151,7 +151,7 @@ try {
|
|||
await dock.locator("[data-custom-production]").click();
|
||||
assert.equal(await page.locator(".cargo-form").count(), 1);
|
||||
await page.locator('.cargo-form input[name="corn"]').fill("1");
|
||||
await page.locator('.cargo-form [data-cargo-confirm]').click();
|
||||
await page.locator(".cargo-form [data-cargo-confirm]").click();
|
||||
assert.equal(await page.evaluate(() => played[0].goods.corn), 1);
|
||||
}
|
||||
}
|
||||
|
|
@ -985,7 +985,11 @@ try {
|
|||
path: `.local/qa/${width}-production-comparison.png`,
|
||||
});
|
||||
await page.keyboard.press("Escape");
|
||||
const chapelProduction = E.move(original, { type: "role", id: "craftsman" }, 0);
|
||||
const chapelProduction = E.move(
|
||||
original,
|
||||
{ type: "role", id: "craftsman" },
|
||||
0,
|
||||
);
|
||||
chapelProduction.tasks = [{ kind: "produce", p: 0 }];
|
||||
chapelProduction.role = "craftsman";
|
||||
chapelProduction.owner = 0;
|
||||
|
|
@ -1078,6 +1082,55 @@ try {
|
|||
0,
|
||||
"ordered request waits for earlier player",
|
||||
);
|
||||
const bonusPlacement = structuredClone(original);
|
||||
bonusPlacement.tasks = [{ kind: "bonusAssign", p: 0, remaining: 2 }];
|
||||
bonusPlacement.players[0].reserve.w = 2;
|
||||
bonusPlacement.players[0].estates = [
|
||||
{ id: "fruit", w: 1, c: 0 },
|
||||
{ id: "coffee", w: 0, c: 0 },
|
||||
];
|
||||
bonusPlacement.players[0].buildings = [{ id: "canal", w: 0, c: 0 }];
|
||||
await page.evaluate(
|
||||
(s) => {
|
||||
host.emit("player", { index: 0 });
|
||||
host.emit("state", s);
|
||||
},
|
||||
E.stripSecret(bonusPlacement, 0),
|
||||
);
|
||||
await page.locator(".action-dock [data-actions]").click();
|
||||
assert.equal(
|
||||
await page.locator(".placement-editor [data-slot]").count(),
|
||||
0,
|
||||
"existing workers cannot be rearranged",
|
||||
);
|
||||
assert.equal(
|
||||
await page.locator(".placement-editor button.worker-slot").count(),
|
||||
2,
|
||||
);
|
||||
await page.locator(".placement-editor button.worker-slot").first().click();
|
||||
assert.deepEqual(await page.evaluate(() => played.at(-1)), {
|
||||
type: "bonusAssign",
|
||||
target: "e1",
|
||||
});
|
||||
const bonusAfter = E.move(
|
||||
bonusPlacement,
|
||||
{ type: "bonusAssign", target: "e1" },
|
||||
0,
|
||||
);
|
||||
await page.evaluate(
|
||||
(s) => host.emit("state", s),
|
||||
E.stripSecret(bonusAfter, 0),
|
||||
);
|
||||
assert.equal(
|
||||
await page.locator(".placement-editor button.worker-slot").count(),
|
||||
1,
|
||||
"bonus placement stays open for the remaining worker",
|
||||
);
|
||||
await page.locator(".placement-editor button.worker-slot").click();
|
||||
assert.deepEqual(await page.evaluate(() => played.at(-1)), {
|
||||
type: "bonusAssign",
|
||||
target: "b0",
|
||||
});
|
||||
assert.deepEqual(errors, [], `No browser errors at ${width}`);
|
||||
console.log(
|
||||
`Browser ${width}px: actions, allocation, layout, journal, chat and scrolling OK`,
|
||||
|
|
|
|||
|
|
@ -57,12 +57,13 @@ export function actionVictoryPoints(state, seat, move) {
|
|||
(n, amount) => n + Math.floor(amount / 2),
|
||||
0,
|
||||
);
|
||||
return points + festivalPoints(state, seat, move);
|
||||
return points + festivalRewards(state, seat, move).vp;
|
||||
}
|
||||
|
||||
// Forecast only public, deterministic outcomes; never inspect future plantation draws.
|
||||
function festivalPoints(state, seat, move) {
|
||||
if (!state.festivals?.length) return 0;
|
||||
export function festivalRewards(state, seat, move) {
|
||||
const rewards = { vp: 0, coins: 0, workers: 0 };
|
||||
if (!state.festivals?.length) return rewards;
|
||||
const preview = { ...state };
|
||||
let event;
|
||||
if (move.type === "build") event = { type: "build", id: move.id };
|
||||
|
|
@ -131,12 +132,13 @@ function festivalPoints(state, seat, move) {
|
|||
capacity: ship?.capacity ?? null,
|
||||
};
|
||||
}
|
||||
return event
|
||||
? completedFestivals(preview, seat, event).reduce(
|
||||
(n, f) => n + (f.reward.vp ?? 0),
|
||||
0,
|
||||
)
|
||||
: 0;
|
||||
if (event)
|
||||
for (const f of completedFestivals(preview, seat, event)) {
|
||||
for (const key of Object.keys(rewards))
|
||||
rewards[key] += f.reward[key] ?? 0;
|
||||
}
|
||||
rewards.workers = Math.min(rewards.workers, state.workerSupply ?? 0);
|
||||
return rewards;
|
||||
}
|
||||
|
||||
function playerGoods(state, seat) {
|
||||
|
|
|
|||
76
viewer/ui.js
76
viewer/ui.js
|
|
@ -1,5 +1,9 @@
|
|||
import { buildingEffects } from "./building-effects.js";
|
||||
import { actionBonuses, actionVictoryPoints } from "./action-bonuses.js";
|
||||
import {
|
||||
actionBonuses,
|
||||
actionVictoryPoints,
|
||||
festivalRewards,
|
||||
} from "./action-bonuses.js";
|
||||
import { recruitmentShares, recruitmentBonus } from "./recruitment.js";
|
||||
import { showBuildingPayment } from "./building-payment.js";
|
||||
import { FORCE_DARK_THEME } from "./theme.js";
|
||||
|
|
@ -249,13 +253,30 @@ export function mountGame(
|
|||
]
|
||||
.filter(Boolean)
|
||||
.join(" · ");
|
||||
const coins = bonuses.reduce((n, b) => n + b.coins, 0);
|
||||
const bonus =
|
||||
vp || coins
|
||||
? `<span class="action-bonus" title="${esc(bonusTitle)}">(+${vp ? metric("vp", vp) : ""}${vp && coins ? " +" : ""}${coins ? metric("coin", coins) : ""})</span>`
|
||||
: "";
|
||||
const bonus = rewardPreview(m);
|
||||
return `<button type="button" class="move ${classes}" data-move="${encode(m)}" ${hint ? `title="${esc(hint)}" ${description ? `aria-label="${esc(hint)}"` : ""}` : ""} ${allowed() || (enabled && !pending && m.type === "bohio") ? "" : "disabled"}>${pictogram ? icon(pictogram, 26) : ""}<span>${label}${bonus}</span></button>`;
|
||||
};
|
||||
function rewardPreview(move) {
|
||||
const festival = festivalRewards(state, seat, move);
|
||||
const title = actionBonuses(state, seat, move)
|
||||
.map(
|
||||
(b) =>
|
||||
`${t(b.building)}: +${b.vp || b.coins} ${t(b.vp ? "vp" : "coins")}`,
|
||||
)
|
||||
.join(" · ");
|
||||
const rewards = [
|
||||
["vp", actionVictoryPoints(state, seat, move)],
|
||||
[
|
||||
"coin",
|
||||
festival.coins +
|
||||
actionBonuses(state, seat, move).reduce((n, b) => n + b.coins, 0),
|
||||
],
|
||||
["worker", festival.workers],
|
||||
].filter(([, n]) => n);
|
||||
return rewards.length
|
||||
? `<span class="action-bonus" title="${esc(title)}">(+${rewards.map(([id, n]) => metric(id, n)).join(" ")})</span>`
|
||||
: "";
|
||||
}
|
||||
function show(title, html, mode = "") {
|
||||
if (!modal.open) lastFocus = document.activeElement;
|
||||
if (mode !== "building") marketReturn = null;
|
||||
|
|
@ -512,6 +533,8 @@ export function mountGame(
|
|||
.join("")}</div>`;
|
||||
if (task.kind === "assign")
|
||||
return `<div class="placement-editor">${assignmentTools()}${playerAreas(state.players[seat])}</div><footer class="action-editor-footer">${confirmation()}</footer>`;
|
||||
if (task.kind === "bonusAssign")
|
||||
return `<div class="placement-editor"><div class="assignment-tools">${metric("worker", task.remaining)}</div>${playerAreas(state.players[seat])}</div>`;
|
||||
if (task.kind === "store")
|
||||
return `${storageEditor()}<footer class="action-editor-footer">${confirmation()}</footer>`;
|
||||
return `<div class="action-choices">${moves.map(actionButton).join("")}</div>`;
|
||||
|
|
@ -559,6 +582,17 @@ export function mountGame(
|
|||
const k = i < values.c ? "c" : i < values.c + values.w ? "w" : null;
|
||||
const unavailable =
|
||||
editable && !k && (tool === "erase" || remaining()[tool] === 0);
|
||||
const bonusMove =
|
||||
!k &&
|
||||
view === seat &&
|
||||
allowed() &&
|
||||
state.tasks[0]?.kind === "bonusAssign"
|
||||
? state.legal.find(
|
||||
(m) => m.type === "bonusAssign" && m.target === key,
|
||||
)
|
||||
: null;
|
||||
if (bonusMove)
|
||||
return `<button type="button" class="worker-slot" data-move="${encode(bonusMove)}" aria-label="${esc(`${t("workers")} · ${t(x.id)}`)}">+</button>`;
|
||||
return editable
|
||||
? `<button class="worker-slot ${k ?? ""}" data-slot="${key}:${i}" ${unavailable ? "disabled" : ""} aria-label="${esc(`${t(k === "c" ? "citizens" : k === "w" ? "workers" : "empty")} · ${t(x.id)}`)}">${k ? icon(k === "c" ? "citizen" : "worker", 20) : unavailable ? "·" : "+"}</button>`
|
||||
: `<span class="worker-slot ${k ?? ""}">${k ? icon(k === "c" ? "citizen" : "worker", 20) : "·"}</span>`;
|
||||
|
|
@ -840,6 +874,7 @@ export function mountGame(
|
|||
"role",
|
||||
"plant",
|
||||
"assign",
|
||||
"bonusAssign",
|
||||
"store",
|
||||
"achievementChoose",
|
||||
"achievementDraft",
|
||||
|
|
@ -851,11 +886,12 @@ export function mountGame(
|
|||
role: "roleChoices",
|
||||
plant: "plantationChoices",
|
||||
assign: "editAssignment",
|
||||
bonusAssign: "editAssignment",
|
||||
store: "editStorage",
|
||||
achievementChoose: "achievements",
|
||||
achievementDraft: "achievements",
|
||||
}[task.kind] ?? "chooseAction";
|
||||
choices = `<button class="primary" data-actions>${icon({ role: "governor", plant: "planter", assign: "worker", store: "storage", achievementChoose: "festival", achievementDraft: "festival" }[task.kind] ?? state.role ?? "check")} ${t(label)}</button>`;
|
||||
choices = `<button class="primary" data-actions>${icon({ role: "governor", plant: "planter", assign: "worker", bonusAssign: "worker", store: "storage", achievementChoose: "festival", achievementDraft: "festival" }[task.kind] ?? state.role ?? "check")} ${t(label)}</button>`;
|
||||
} else choices = moves.map(actionButton).join("");
|
||||
}
|
||||
const special =
|
||||
|
|
@ -891,12 +927,16 @@ export function mountGame(
|
|||
}
|
||||
function openActions() {
|
||||
if (!allowed()) return;
|
||||
if (state.tasks[0].kind === "assign") {
|
||||
if (["assign", "bonusAssign"].includes(state.tasks[0].kind)) {
|
||||
view = seat;
|
||||
render();
|
||||
}
|
||||
actionContext = draftKey;
|
||||
show(title(), actionPanel(), "actions");
|
||||
show(
|
||||
title(),
|
||||
actionPanel(),
|
||||
state.tasks[0]?.kind === "bonusAssign" ? "bonus-placement" : "actions",
|
||||
);
|
||||
}
|
||||
let summaryFrame = 0;
|
||||
let observedDock;
|
||||
|
|
@ -971,6 +1011,13 @@ export function mountGame(
|
|||
}
|
||||
if (modal.open && modalMode === "comparison")
|
||||
body.innerHTML = productionComparison();
|
||||
if (modal.open && modalMode === "bonus-placement") {
|
||||
if (!isTurn() || state.tasks[0]?.kind !== "bonusAssign") hide(modal);
|
||||
else
|
||||
morphdom(body, `<div class="modal-body">${actionPanel()}</div>`, {
|
||||
childrenOnly: true,
|
||||
});
|
||||
}
|
||||
if (modal.open && modalMode === "actions") {
|
||||
if (!allowed() || actionContext !== draftKey) hide(modal);
|
||||
else {
|
||||
|
|
@ -1236,7 +1283,12 @@ export function mountGame(
|
|||
render();
|
||||
try {
|
||||
await onMove(m);
|
||||
if (modal.open && modalMode !== "journal") hide(modal);
|
||||
if (
|
||||
modal.open &&
|
||||
modalMode !== "journal" &&
|
||||
!(m.type === "bonusAssign" && state.tasks[0]?.kind === "bonusAssign")
|
||||
)
|
||||
hide(modal);
|
||||
} catch (err) {
|
||||
error.textContent = t("error");
|
||||
error.hidden = false;
|
||||
|
|
@ -1497,9 +1549,9 @@ export function mountGame(
|
|||
);
|
||||
const updateReward = () => {
|
||||
const goods = chosenGoods();
|
||||
const points = actionVictoryPoints(state, seat, { ...m, goods });
|
||||
const rewards = rewardPreview({ ...m, goods });
|
||||
const button = form.querySelector("[data-cargo-confirm]");
|
||||
button.innerHTML = `${t("confirm")} ${goodsRow(goods)}${points ? ` <span class="action-bonus">(+${metric("vp", points)})</span>` : ""}`;
|
||||
button.innerHTML = `${t("confirm")} ${goodsRow(goods)}${rewards}`;
|
||||
button.disabled = m.type === "smallWharf" && !sum(Object.values(goods));
|
||||
};
|
||||
form.oninput = updateReward;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue