Match equipment chat to journal and privately show Map transfers

This commit is contained in:
coyotte508 2026-09-12 19:13:12 +02:00
commit 2ed2c36872
4 changed files with 60 additions and 14 deletions

View file

@ -1,6 +1,6 @@
{
"name": "fuji-engine",
"version": "0.1.8",
"version": "0.1.9",
"private": true,
"license": "AGPL-3.0-only",
"files": [

View file

@ -1535,7 +1535,7 @@ test("equipment use produces one public chat message and drains once", async ()
let s = withPhase();
s.players[0]!.name = "Climber";
s = equip(s, 0, "flare");
assert.deepEqual(s.chatMessages, ["Climber used Flare gun."]);
assert.deepEqual(s.chatMessages, ["Climber used Flare gun · +3 movement value."]);
assert.equal("chatMessages" in stripSecret(s, 1), false);
const drained = wrapper.messages(s);
assert.deepEqual(drained.messages, s.chatMessages);
@ -1564,3 +1564,41 @@ test("each injury announces its effect in chat once", async () => {
assert.equal(s.chatMessages, undefined);
}
});
test("equipment chat matches the journal, including recipients without revealing borrowed dice", () => {
for (const id of ["map", "water", "lighter", "torch", "rope", "knife"]) {
let s = withPhase(id === "torch" ? "planning" : "equipment");
const die = s.players[0]!.dice[0]!;
const extra: Record<string, unknown> = { target: 1, ids: [die.id] };
if (id === "rope" || id === "knife") {
const start = cell(s, s.players[0]!.position);
const dest = s.board.find(
(c) => !c.lava && terrain(c.terrain).kind === "land" && Math.abs(c.x - start.x) + Math.abs(c.y - start.y) === 1
)!;
extra.tiles = [dest.id];
if (id === "knife") {
extra.copy = "rope";
s.players[1]!.cards = [{ id: "rope", used: 0, availableRound: 0 }];
}
}
s = equip(s, 0, id, extra);
const entry = s.log.filter((e) => e.type === "equipment").at(-1)!;
assert.deepEqual(s.chatMessages, [entry.text]);
if (id === "map") {
assert.match(entry.text, new RegExp(`lent 1 die to ${s.players[1]!.name}`));
assert.equal(stripSecret(s, 2).players[1]!.dice.find((d) => d.id === die.id)!.face, 0);
}
}
});
test("Map records the transferred face privately for lender and recipient", () => {
let s = withPhase();
const die = structuredClone(s.players[0]!.dice[0]!);
s = equip(s, 0, "map", { target: 1, ids: [die.id] });
for (const seat of [0, 1]) assert.deepEqual(stripSecret(s, seat).log.at(-1)!.dice, [die]);
for (const seat of [2, undefined]) assert.equal(stripSecret(s, seat).log.at(-1)!.dice, undefined);
// Later changes to the recipient's dice must not update the lender's snapshot.
s.players[1]!.dice.find((d) => d.id === die.id)!.face = die.face === 6 ? 1 : 6;
assert.deepEqual(stripSecret(s, 0).log.at(-1)!.dice, [die]);
assert.equal(stripSecret(s, 0).players[1]!.dice.find((d) => d.id === die.id)!.face, 0);
});

View file

@ -439,6 +439,8 @@ function useEquipment(s: State, seat: number, m: Move) {
const target = () => integer(m.target, 0, s.players.length - 1);
let setAside: Die[] | undefined;
let effectText = "";
let equipmentMessage = "";
let loan: { die: Die; recipient: number } | undefined;
switch (id) {
case "binoculars": {
const ids = strings(m.tiles, 2);
@ -467,11 +469,8 @@ function useEquipment(s: State, seat: number, m: Move) {
const c = cell(s, ids[0]!);
if (!walkable(c) || terrain(c.terrain).kind !== "land" || distance(cell(s, p.position), c) !== 1)
throw Error("Choose an adjacent land location.");
event(
s,
`${p.name} moved to ${terrain(c.terrain).name} using ${card.id === "knife" ? "Pocketknife as Rope" : "Rope"}.`,
"equipment"
);
equipmentMessage = `${p.name} moved to ${terrain(c.terrain).name} using ${card.id === "knife" ? "Pocketknife as Rope" : "Rope"}.`;
event(s, equipmentMessage, "equipment");
s.log.at(-1)!.animation = { kind: "move", seat, path: [p.position, c.id] };
p.position = c.id;
collect(s, p);
@ -545,6 +544,7 @@ function useEquipment(s: State, seat: number, m: Move) {
p.dice = p.dice.filter((x) => x.id !== d.id);
s.players[recipient]!.dice.push(d);
effectText = `lent 1 die to ${s.players[recipient]!.name} until the end of the round`;
loan = { die: structuredClone(d), recipient };
break;
}
}
@ -553,14 +553,15 @@ function useEquipment(s: State, seat: number, m: Move) {
p.cards = p.cards.filter((c) => c !== card);
s.discard.push(card.id);
}
(s.chatMessages ??= []).push(`${p.name} used ${equipment(card.id).name}${id !== card.id ? ` as ${info.name}` : ""}.`);
resetReady(s);
if (id !== "rope")
event(
s,
`${p.name} used ${equipment(card.id).name}${id !== card.id ? ` as ${info.name}` : ""}${effectText ? ` · ${effectText}` : ""}.`,
"equipment"
);
equipmentMessage = `${p.name} used ${equipment(card.id).name}${id !== card.id ? ` as ${info.name}` : ""}${effectText ? ` · ${effectText}` : ""}.`;
(s.chatMessages ??= []).push(equipmentMessage);
resetReady(s);
if (id !== "rope") event(s, equipmentMessage, "equipment");
if (loan) {
s.log.at(-1)!.dice = [loan.die];
s.log.at(-1)!.diceVisibleTo = [seat, loan.recipient];
}
if (id === "torch") s.log.at(-1)!.sound = "dice";
if (setAside) s.log.at(-1)!.setAside = structuredClone(setAside);
}
@ -1145,6 +1146,12 @@ export function stripSecret(s: State, seat?: number): View {
chatMessages: ________,
...publicState
} = structuredClone(s);
for (const entry of publicState.log) {
if (entry.diceVisibleTo && (seat === undefined || !entry.diceVisibleTo.includes(seat))) {
delete entry.dice;
}
delete entry.diceVisibleTo;
}
const revealed = s.phase === "movement" || s.phase === "eruption" || s.phase === "ended";
publicState.players.forEach((p, i) => {
p.dice.forEach((d) => {

View file

@ -68,6 +68,7 @@ export interface Event {
};
dice?: Die[];
diceLabel?: string;
diceVisibleTo?: number[];
round: number;
text: string;
type: "phase" | "move" | "equipment" | "eruption" | "injury" | "end";