feat: allow revising sealed bids and Mega choices
This commit is contained in:
parent
511d935add
commit
dc8bb76b9d
29 changed files with 285 additions and 48 deletions
|
|
@ -1,4 +1,5 @@
|
|||
export * from "./src/types.js";
|
||||
export * from "./src/choice-revisions.js";
|
||||
export * from "./src/data.js";
|
||||
export * from "./src/prng.js";
|
||||
export * from "./src/sanitize.js";
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "outpost-engine",
|
||||
"version": "0.10.22",
|
||||
"version": "0.10.23",
|
||||
"description": "Unofficial Outpost rules engine for boardgamers.space",
|
||||
"license": "AGPL-3.0",
|
||||
"files": [
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ export function sealedAuctionHistory(log: LogEntry[]): {
|
|||
} {
|
||||
const revealed = new Set<number>();
|
||||
const results = new Map<number, SealedAuctionResult>();
|
||||
let pending: number[] = [];
|
||||
let pending = new Map<number, number>();
|
||||
let bids = new Map<number, number>();
|
||||
let awaitingPayment: SealedAuctionResult | undefined;
|
||||
for (const [index, entry] of log.entries()) {
|
||||
|
|
@ -21,7 +21,7 @@ export function sealedAuctionHistory(log: LogEntry[]): {
|
|||
}
|
||||
if (entry.move.action === "auction") {
|
||||
awaitingPayment = undefined;
|
||||
pending = [];
|
||||
pending = new Map();
|
||||
bids = new Map([[entry.player, entry.move.bid]]);
|
||||
} else if (entry.move.action === "bid") {
|
||||
bids.set(entry.player, entry.move.amount);
|
||||
|
|
@ -36,12 +36,12 @@ export function sealedAuctionHistory(log: LogEntry[]): {
|
|||
} else {
|
||||
continue;
|
||||
}
|
||||
pending.push(index);
|
||||
pending.set(entry.player, index);
|
||||
for (const seat of entry.info?.autoPassed ?? []) {
|
||||
bids.set(seat, 0);
|
||||
}
|
||||
if (entry.info?.winningBid !== undefined) {
|
||||
for (const bidIndex of pending) {
|
||||
for (const bidIndex of pending.values()) {
|
||||
revealed.add(bidIndex);
|
||||
}
|
||||
const winner = entry.info.winner ?? entry.player;
|
||||
|
|
@ -56,7 +56,7 @@ export function sealedAuctionHistory(log: LogEntry[]): {
|
|||
),
|
||||
};
|
||||
results.set(index, awaitingPayment);
|
||||
pending = [];
|
||||
pending = new Map();
|
||||
bids.clear();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
71
packages/engine/src/choice-revisions.spec.ts
Normal file
71
packages/engine/src/choice-revisions.spec.ts
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
import assert from "node:assert/strict";
|
||||
import { test } from "node:test";
|
||||
import { UPGRADE_SPECS } from "./data.js";
|
||||
import { applyMove, initGame } from "./moves.js";
|
||||
import { choiceRevision } from "./choice-revisions.js";
|
||||
import { canMoveOutOfTurn, currentPlayer, isLiveUpdate, stripSecret } from "../wrapper.js";
|
||||
import { replay } from "./replay.js";
|
||||
import type { ProductionCard } from "./types.js";
|
||||
|
||||
test("sealed bids can be replaced or passed without reopening turns or earning time", () => {
|
||||
const state = initGame(3, { fastBid: true }, "revise-bids");
|
||||
for (const p of state.players) {
|
||||
p.hand = Array.from({ length: 6 }, (): ProductionCard => ({ t: "research", v: 10 }));
|
||||
}
|
||||
const opener = state.activeSeat;
|
||||
const [bidder, last] = state.players.map((_, i) => i).filter((i) => i !== opener) as [number, number];
|
||||
applyMove(
|
||||
state,
|
||||
{ action: "auction", marketIndex: state.market.findIndex((u) => UPGRADE_SPECS[u].price === 25), bid: 25 },
|
||||
opener
|
||||
);
|
||||
applyMove(state, { action: "bid", amount: 45 }, bidder);
|
||||
const revision = choiceRevision(state, bidder)!;
|
||||
const move = { action: "bid" as const, amount: 30, revision };
|
||||
assert(canMoveOutOfTurn(state, move, bidder));
|
||||
assert(!canMoveOutOfTurn(state, move, last));
|
||||
assert(!canMoveOutOfTurn(state, { ...move, revision: "old" }, bidder));
|
||||
const before = structuredClone(state);
|
||||
assert.throws(() => applyMove(state, { ...move, amount: 500 }, bidder));
|
||||
assert.deepEqual(state, before);
|
||||
applyMove(state, move, bidder);
|
||||
assert(isLiveUpdate(state));
|
||||
assert.equal(currentPlayer(state), last);
|
||||
assert.equal(state.auction?.bids?.[bidder], 30);
|
||||
assert.equal(stripSecret(state, last).auction?.bids?.[bidder], -1);
|
||||
applyMove(state, { action: "bidPass", revision }, bidder);
|
||||
assert(isLiveUpdate(state));
|
||||
applyMove(state, move, bidder);
|
||||
applyMove(state, { action: "bid", amount: 35 }, last);
|
||||
assert(!isLiveUpdate(state));
|
||||
assert.equal(state.auction?.highBidder, last);
|
||||
assert.equal(state.auction?.highBid, 31);
|
||||
assert(!canMoveOutOfTurn(state, move, bidder));
|
||||
assert.throws(() => applyMove(state, move, bidder));
|
||||
const view = stripSecret(state, last);
|
||||
const bids = view.log.filter((e) => e.type === "move" && e.player === bidder && e.move.action === "bid");
|
||||
assert.equal(bids[0]?.type === "move" && bids[0].move.action === "bid" && bids[0].move.amount, -1);
|
||||
assert.equal(replay(state).auction?.highBid, 31);
|
||||
assert.equal(replay(view).auction?.highBid, 31);
|
||||
});
|
||||
|
||||
test("blind mega elections remain editable until the last election, without revealing draws", () => {
|
||||
const state = initGame(3, {}, "revise-mega");
|
||||
state.phase = "mega";
|
||||
for (const p of state.players) {
|
||||
p.pendingMega = Array.from({ length: 4 }, (): ProductionCard => ({ t: "water", v: 7 }));
|
||||
p.megaGroups = { water: 1 };
|
||||
delete p.megaChoice;
|
||||
}
|
||||
applyMove(state, { action: "mega", take: { water: 1 } }, 0);
|
||||
const move = { action: "mega" as const, take: {}, revision: choiceRevision(state, 0)! };
|
||||
assert(canMoveOutOfTurn(state, move, 0));
|
||||
applyMove(state, move, 0);
|
||||
assert(isLiveUpdate(state));
|
||||
assert.deepEqual(currentPlayer(state), [1, 2]);
|
||||
assert(stripSecret(state, 0).players[0]!.pendingMega!.every((c) => c.v === -1));
|
||||
applyMove(state, { action: "mega", take: {} }, 1);
|
||||
applyMove(state, { action: "mega", take: {} }, 2);
|
||||
assert(!canMoveOutOfTurn(state, move, 0));
|
||||
assert.throws(() => applyMove(state, move, 0));
|
||||
});
|
||||
35
packages/engine/src/choice-revisions.ts
Normal file
35
packages/engine/src/choice-revisions.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import { needsMegaChoice } from "./state.js";
|
||||
import type { GameState, Move } from "./types.js";
|
||||
|
||||
export function choiceRevision(state: GameState, seat: number): string | undefined {
|
||||
const player = state.players[seat];
|
||||
if (state.ended || !player || player.dropped) {
|
||||
return undefined;
|
||||
}
|
||||
if (state.phase === "mega" && player.megaChoice !== undefined && state.players.some(needsMegaChoice)) {
|
||||
return `mega:${state.round}`;
|
||||
}
|
||||
if (
|
||||
state.phase === "auction" &&
|
||||
state.auction?.bids?.[seat] !== undefined &&
|
||||
state.players.some((p, i) => !p.dropped && state.auction?.bids?.[i] === undefined)
|
||||
) {
|
||||
const start = state.log.map((e) => e.type === "move" && e.move.action === "auction").lastIndexOf(true);
|
||||
return `auction:${state.round}:${start}`;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function canReviseChoice(state: GameState, raw: unknown, seat: number): boolean {
|
||||
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
||||
return false;
|
||||
}
|
||||
const move = raw as Move;
|
||||
const key = choiceRevision(state, seat);
|
||||
if (!key || !("revision" in move) || move.revision !== key) {
|
||||
return false;
|
||||
}
|
||||
return state.phase === "mega"
|
||||
? move.action === "mega"
|
||||
: move.action === "bid" || (move.action === "bidPass" && seat !== state.auction?.auctioneer);
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
import { canReviseChoice } from "./choice-revisions.js";
|
||||
import { FACTORIES, KICKER_SPECS, MEGA_CARDS, ROBOT_COST, UPGRADE_SPECS, VICTORY_VP } from "./data.js";
|
||||
import { colonyEra, refillKickers, refillMarket, updateEraStreaks } from "./market.js";
|
||||
import { dealStartingHand, producePlayer } from "./production.js";
|
||||
|
|
@ -340,6 +341,10 @@ export function applyMove(state: GameState, rawMove: Move | unknown, seat: numbe
|
|||
err("invalid player");
|
||||
}
|
||||
const player = getPlayer(state, seat);
|
||||
const revision = "revision" in move && move.revision !== undefined;
|
||||
if (revision && !canReviseChoice(state, move, seat)) {
|
||||
err("this choice can no longer be changed");
|
||||
}
|
||||
let info: MoveInfo | undefined;
|
||||
|
||||
switch (move.action) {
|
||||
|
|
@ -374,6 +379,7 @@ export function applyMove(state: GameState, rawMove: Move | unknown, seat: numbe
|
|||
err(`unknown action ${String((move as { action: string }).action)}`);
|
||||
}
|
||||
|
||||
state.liveUpdate = revision;
|
||||
state.moveCount += 1;
|
||||
state.log.push(info ? { type: "move", player: seat, move, info } : { type: "move", player: seat, move });
|
||||
postMove(state, move);
|
||||
|
|
@ -397,7 +403,7 @@ function postMove(state: GameState, move: Move): void {
|
|||
}
|
||||
|
||||
function moveMega(state: GameState, move: Move & { action: "mega" }, player: PlayerState): MoveInfo {
|
||||
if (state.phase !== "mega" || !needsMegaChoice(player)) {
|
||||
if (state.phase !== "mega" || (!needsMegaChoice(player) && !move.revision)) {
|
||||
err("no production pending for this player");
|
||||
}
|
||||
// The election is blind (rule 12.1): the player commits to a number of Mega
|
||||
|
|
@ -660,13 +666,13 @@ function moveBid(state: GameState, move: Move & { action: "bid" }, seat: number,
|
|||
return autoPassed.length > 0 ? { ...info, autoPassed } : info;
|
||||
}
|
||||
|
||||
function moveBidPass(state: GameState, _move: Move & { action: "bidPass" }, seat: number): MoveInfo {
|
||||
function moveBidPass(state: GameState, move: Move & { action: "bidPass" }, seat: number): MoveInfo {
|
||||
const auction = state.auction;
|
||||
if (state.phase !== "auction" || !auction) {
|
||||
err("not this player's turn to bid");
|
||||
}
|
||||
if (auction.bids) {
|
||||
return moveFastBidPass(state, seat, auction);
|
||||
return moveFastBidPass(state, seat, auction, move.revision !== undefined);
|
||||
}
|
||||
if (auction.activeBidder !== seat) {
|
||||
err("not this player's turn to bid");
|
||||
|
|
@ -733,15 +739,16 @@ function moveFastBid(
|
|||
if (!bids) {
|
||||
err("not a sealed-bid auction");
|
||||
}
|
||||
if (bids[seat] !== undefined) {
|
||||
if (bids[seat] !== undefined && !move.revision) {
|
||||
err("this player has already bid");
|
||||
}
|
||||
// A stripped log masks other players' sealed bids as -1; replay stores the
|
||||
// placeholder (the resolution comes from the recorded MoveInfo) and skips
|
||||
// validation, which the server already did live.
|
||||
if (!replayMode) {
|
||||
if (!Number.isInteger(move.amount) || move.amount < auctionPrice(auction) + 1) {
|
||||
err(`bid must be at least ${auctionPrice(auction) + 1}`);
|
||||
const minimum = auctionPrice(auction) + (seat === auction.auctioneer ? 0 : 1);
|
||||
if (!Number.isInteger(move.amount) || move.amount < minimum) {
|
||||
err(`bid must be at least ${minimum}`);
|
||||
}
|
||||
assertCanPayBidFor(player, auction, move.amount);
|
||||
}
|
||||
|
|
@ -749,9 +756,14 @@ function moveFastBid(
|
|||
return fastBidMaybeResolve(state, auction);
|
||||
}
|
||||
|
||||
function moveFastBidPass(state: GameState, seat: number, auction: NonNullable<GameState["auction"]>): MoveInfo {
|
||||
function moveFastBidPass(
|
||||
state: GameState,
|
||||
seat: number,
|
||||
auction: NonNullable<GameState["auction"]>,
|
||||
revision = false
|
||||
): MoveInfo {
|
||||
const bids = auction.bids;
|
||||
if (!bids || bids[seat] !== undefined) {
|
||||
if (!bids || (bids[seat] !== undefined && !revision)) {
|
||||
err("not this player's turn to bid");
|
||||
}
|
||||
bids[seat] = 0;
|
||||
|
|
|
|||
|
|
@ -81,6 +81,12 @@ export function sanitizeMove(raw: unknown): Move {
|
|||
if (typeof action !== "string") {
|
||||
fail("missing action");
|
||||
}
|
||||
const revision =
|
||||
move.revision === undefined
|
||||
? {}
|
||||
: typeof move.revision === "string" && move.revision.length <= 100
|
||||
? { revision: move.revision }
|
||||
: fail("invalid revision");
|
||||
switch (action) {
|
||||
case "mega": {
|
||||
// Blind mega election (rule 12.1): a record of mega resource -> count.
|
||||
|
|
@ -91,7 +97,7 @@ export function sanitizeMove(raw: unknown): Move {
|
|||
take[resource] = int(rawTake[resource], `take.${resource}`, 0, 100);
|
||||
}
|
||||
}
|
||||
return { action, take };
|
||||
return { action, take, ...revision };
|
||||
}
|
||||
case "discard":
|
||||
return { action, cards: intArray(move.cards, "cards") };
|
||||
|
|
@ -107,9 +113,9 @@ export function sanitizeMove(raw: unknown): Move {
|
|||
case "bid":
|
||||
// -1 is the masked value of another player's sealed bid in a stripped
|
||||
// log (fastBid); the live game never sends it, replay does.
|
||||
return { action, amount: int(move.amount, "amount", -1) };
|
||||
return { action, amount: int(move.amount, "amount", -1), ...revision };
|
||||
case "bidPass":
|
||||
return { action };
|
||||
return { action, ...revision };
|
||||
case "pay":
|
||||
return { action, cards: intArray(move.cards, "cards") };
|
||||
case "exchange":
|
||||
|
|
|
|||
|
|
@ -163,11 +163,11 @@ export type TurnBuy =
|
|||
export type Move =
|
||||
// Mega election (rule 12.1): how many Mega cards to take per resource, blind
|
||||
// (before the pending draw values are revealed). The rest are kept as draws.
|
||||
| { action: "mega"; take: Partial<Record<Resource, number>> }
|
||||
| { action: "mega"; take: Partial<Record<Resource, number>>; revision?: string }
|
||||
| { action: "discard"; cards: number[] }
|
||||
| { action: "auction"; marketIndex: number; bid: number; kicker?: boolean }
|
||||
| { action: "bid"; amount: number }
|
||||
| { action: "bidPass" }
|
||||
| { action: "bid"; amount: number; revision?: string }
|
||||
| { action: "bidPass"; revision?: string }
|
||||
| { action: "pay"; cards: number[] }
|
||||
// Wily Trader / Merchant House: hand one of your own cards (index into the
|
||||
// hand) to `target`, who must return a higher-valued card of the same type.
|
||||
|
|
@ -245,6 +245,7 @@ export interface MoveInfo {
|
|||
}
|
||||
|
||||
export interface GameState {
|
||||
liveUpdate?: boolean;
|
||||
analysisKnowledge?: { hands: ProductionCard[][]; bidFloors: number[]; parked?: { min: number; max?: number }[] };
|
||||
players: PlayerState[];
|
||||
round: number;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { canReviseChoice } from "./src/choice-revisions.js";
|
||||
import { PRODUCTION_DECKS, KICKER_SPECS, UPGRADE_SPECS } from "./src/data.js";
|
||||
import { nextInt, shuffle } from "./src/prng.js";
|
||||
import { RESOURCES } from "./src/types.js";
|
||||
|
|
@ -40,6 +41,9 @@ export async function move(data: GameState, mv: unknown, player: number): Promis
|
|||
return applyMove(data, mv as Move, player);
|
||||
}
|
||||
|
||||
export const canMoveOutOfTurn = canReviseChoice;
|
||||
export const isLiveUpdate = (data: GameState): boolean => data.liveUpdate === true;
|
||||
|
||||
export function ended(data: GameState): boolean {
|
||||
return data.ended;
|
||||
}
|
||||
|
|
@ -53,10 +57,12 @@ export function rankings(data: GameState): number[] {
|
|||
}
|
||||
|
||||
export async function dropPlayer(data: GameState, player: number): Promise<GameState> {
|
||||
data.liveUpdate = false;
|
||||
return dropPlayerCore(data, player);
|
||||
}
|
||||
|
||||
export async function moveAI(data: GameState, player: number): Promise<GameState> {
|
||||
data.liveUpdate = false;
|
||||
return moveAICore(data, player);
|
||||
}
|
||||
|
||||
|
|
@ -123,7 +129,7 @@ function hideProduced(
|
|||
// fastBid: another player's sealed bid stays hidden while its auction
|
||||
// runs; once the auction resolves every bid is revealed, including
|
||||
// losing ones. Sequential auctions keep every bid public throughout.
|
||||
return { ...entry, move: { action: "bid", amount: -1 } };
|
||||
return { ...entry, move: { ...entry.move, amount: -1 } };
|
||||
}
|
||||
if (
|
||||
fastBid &&
|
||||
|
|
@ -285,7 +291,7 @@ function maskLog(
|
|||
entry.move.action === "mega" &&
|
||||
entry.player !== viewer
|
||||
) {
|
||||
return { ...entry, move: { action: "mega" as const, take: {} }, info: { megaSealed: true as const } };
|
||||
return { ...entry, move: { ...entry.move, take: {} }, info: { megaSealed: true as const } };
|
||||
}
|
||||
return hideProduced(
|
||||
entry,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "outpost-viewer",
|
||||
"version": "0.1.18",
|
||||
"version": "0.1.19",
|
||||
"description": "Browser viewer for the Outpost game on boardgamers.space",
|
||||
"license": "AGPL-3.0",
|
||||
"files": [
|
||||
|
|
|
|||
|
|
@ -131,6 +131,7 @@
|
|||
</span>
|
||||
</div>
|
||||
{/each}
|
||||
{#if store.changingChoice}<button class="cancel" onclick={() => store.cancel()}>Cancel</button>{/if}
|
||||
<button class="confirm" onclick={() => store.confirmMega()}>
|
||||
{store.megaTakeCount > 0 ? `Take ${store.megaTakeCount} mega` : "Take all as singles"}
|
||||
</button>
|
||||
|
|
@ -284,7 +285,9 @@
|
|||
{:else}
|
||||
<div class="flow">
|
||||
{#if state?.phase === "mega" && me?.megaChoice !== undefined}
|
||||
<span class="hint">Production choice locked.</span>
|
||||
<span class="hint">Production choice submitted.</span>
|
||||
{#if store.revisableChoice}<button class="end" onclick={() => store.changeChoice()}>Change choice</button
|
||||
>{/if}
|
||||
<span class="hint dim">Choices stay hidden until everyone has confirmed.</span>
|
||||
{/if}
|
||||
<span class="hint dim">{waitingOn}</span>
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
);
|
||||
const due = $derived(store.auctionDue());
|
||||
const fast = $derived(!!auction?.bids);
|
||||
const minBid = $derived(fast ? (spec?.price ?? 0) + 1 : (auction?.highBid ?? 0) + 1);
|
||||
const minBid = $derived(store.minBid);
|
||||
const maxBid = $derived(store.maxBid);
|
||||
const pendingSeats = $derived(
|
||||
state.players.flatMap((player, seat) => (!player.dropped && auction?.bids?.[seat] === undefined ? [seat] : []))
|
||||
|
|
@ -108,7 +108,10 @@
|
|||
>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button class="pass" onclick={() => store.passBid()}>Pass</button>
|
||||
{#if store.changingChoice}<button class="pass" onclick={() => store.cancel()}>Cancel</button>{/if}
|
||||
{#if !fast || auction.auctioneer !== meIndex}<button class="pass" onclick={() => store.passBid()}
|
||||
>Pass</button
|
||||
>{/if}
|
||||
<button class="confirm" disabled={!validBid} onclick={() => store.confirmBid()}
|
||||
>Bid ◈ {store.bidAmount}</button
|
||||
>
|
||||
|
|
@ -127,6 +130,8 @@
|
|||
{:else if fast}
|
||||
{#if meIndex !== undefined && auction.bids?.[meIndex] !== undefined}
|
||||
<div class="turn">Bid submitted</div>
|
||||
{#if store.revisableChoice}<button class="confirm" onclick={() => store.changeChoice()}>Change bid</button
|
||||
>{/if}
|
||||
{/if}
|
||||
<div class="waiting">Waiting for {pendingNames} to bid…</div>
|
||||
{:else}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import {
|
|||
bestPayment,
|
||||
canBuyFactory,
|
||||
countingHandSize,
|
||||
choiceRevision,
|
||||
describeLog,
|
||||
describeLogEntry,
|
||||
exchangeResources,
|
||||
|
|
@ -226,6 +227,7 @@ export class ViewerStore {
|
|||
|
||||
cardPick = $state<number[]>([]);
|
||||
/** Mega cards to take per resource (rule 12.1 blind election). */
|
||||
editingChoice = $state<string | undefined>();
|
||||
megaTake = $state<Partial<Record<string, number>>>({});
|
||||
pending = $state<PendingKind | null>(null);
|
||||
auctionPick = $state<{ marketIndex: number; bid: number; kicker?: boolean } | null>(null);
|
||||
|
|
@ -275,7 +277,12 @@ export class ViewerStore {
|
|||
private automaticMegaRound = "";
|
||||
|
||||
submitAutomaticMega(): void {
|
||||
if (!this.canEditSettings || !this.myMega || !["maximum", "singles"].includes(this.autoMega)) {
|
||||
if (
|
||||
this.editingChoice ||
|
||||
!this.canEditSettings ||
|
||||
!this.myMega ||
|
||||
!["maximum", "singles"].includes(this.autoMega)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
const key = `${this.playerIndex}:${this.liveState?.round}`;
|
||||
|
|
@ -422,10 +429,34 @@ export class ViewerStore {
|
|||
return !!s && !s.ended && s.phase === "discard" && !this.replay.active && (this.me?.mustDiscard ?? false);
|
||||
}
|
||||
|
||||
get revisableChoice(): string | undefined {
|
||||
return this.liveState && this.playerIndex !== undefined && !this.replay.active
|
||||
? choiceRevision(this.liveState, this.playerIndex)
|
||||
: undefined;
|
||||
}
|
||||
get changingChoice(): boolean {
|
||||
return !!this.editingChoice && this.editingChoice === this.revisableChoice;
|
||||
}
|
||||
changeChoice(): void {
|
||||
const key = this.revisableChoice;
|
||||
if (!key) {
|
||||
return;
|
||||
}
|
||||
this.editingChoice = key;
|
||||
this.megaTake = { ...this.me?.megaChoice };
|
||||
this.prepareBid();
|
||||
}
|
||||
/** Mega phase: I have staged production draws awaiting the mega-vs-singles choice. */
|
||||
get myMega(): boolean {
|
||||
const s = this.liveState;
|
||||
return !!s && !s.ended && s.phase === "mega" && !this.replay.active && !!this.me && needsMegaChoice(this.me);
|
||||
return (
|
||||
!!s &&
|
||||
!s.ended &&
|
||||
s.phase === "mega" &&
|
||||
!this.replay.active &&
|
||||
!!this.me &&
|
||||
(needsMegaChoice(this.me) || this.changingChoice)
|
||||
);
|
||||
}
|
||||
|
||||
/** Mega conversions available from my staged draws (resource -> groups of 4). */
|
||||
|
|
@ -458,7 +489,7 @@ export class ViewerStore {
|
|||
}
|
||||
// fastBid: I owe a sealed bid while mine isn't in yet.
|
||||
if (s.auction?.bids) {
|
||||
return s.auction.bids[this.playerIndex] === undefined;
|
||||
return s.auction.bids[this.playerIndex] === undefined || this.changingChoice;
|
||||
}
|
||||
return s.auction?.activeBidder === this.playerIndex;
|
||||
}
|
||||
|
|
@ -776,13 +807,27 @@ export class ViewerStore {
|
|||
});
|
||||
}
|
||||
|
||||
get minBid(): number {
|
||||
const auction = this.liveState?.auction;
|
||||
if (!auction) {
|
||||
return 0;
|
||||
}
|
||||
return auction.bids
|
||||
? auctionCard(auction).price + (auction.auctioneer === this.playerIndex ? 0 : 1)
|
||||
: auction.highBid + 1;
|
||||
}
|
||||
|
||||
prepareBid(): void {
|
||||
const s = this.liveState;
|
||||
if (!s?.auction) {
|
||||
return;
|
||||
}
|
||||
// fastBid: the floor is the list price, not the (hidden) high bid.
|
||||
this.bidAmount = s.auction.bids ? auctionCard(s.auction).price + 1 : s.auction.highBid + 1;
|
||||
this.bidAmount = this.changingChoice
|
||||
? Math.max(this.minBid, s.auction.bids?.[this.playerIndex!] ?? 0)
|
||||
: s.auction.bids
|
||||
? auctionCard(s.auction).price + 1
|
||||
: s.auction.highBid + 1;
|
||||
}
|
||||
|
||||
/** Clamp a typed bid into [min, maxBid] so the input never holds an unaffordable/illegal value. */
|
||||
|
|
@ -791,7 +836,7 @@ export class ViewerStore {
|
|||
if (!s?.auction || !Number.isFinite(value)) {
|
||||
return;
|
||||
}
|
||||
const min = s.auction.bids ? auctionCard(s.auction).price + 1 : s.auction.highBid + 1;
|
||||
const min = this.minBid;
|
||||
this.bidAmount = Math.min(this.maxBid, Math.max(min, Math.floor(value)));
|
||||
}
|
||||
|
||||
|
|
@ -801,7 +846,7 @@ export class ViewerStore {
|
|||
return;
|
||||
}
|
||||
const amount = Math.floor(this.bidAmount);
|
||||
const min = s.auction.bids ? auctionCard(s.auction).price + 1 : s.auction.highBid + 1;
|
||||
const min = this.minBid;
|
||||
if (!Number.isInteger(amount) || amount < min || amount > this.maxBid) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -1045,6 +1090,7 @@ export class ViewerStore {
|
|||
}
|
||||
|
||||
cancel(): void {
|
||||
this.editingChoice = undefined;
|
||||
this.cardPick = [];
|
||||
this.megaTake = {};
|
||||
this.pending = null;
|
||||
|
|
@ -1065,6 +1111,9 @@ export class ViewerStore {
|
|||
}
|
||||
|
||||
private send(move: Move): void {
|
||||
if (this.changingChoice && (move.action === "mega" || move.action === "bid" || move.action === "bidPass")) {
|
||||
move = { ...move, revision: this.editingChoice };
|
||||
}
|
||||
this.commands.move($state.snapshot(move));
|
||||
this.cancel();
|
||||
if (this.optimistic) {
|
||||
|
|
|
|||
|
|
@ -1198,5 +1198,8 @@
|
|||
"Auction details": "Auktionsdetaljer",
|
||||
"Revealed bids": "Afslørede bud",
|
||||
"Paid ◈ {p0}": "Betalt ◈ {p0}",
|
||||
"Due ◈ {p0}": "At betale ◈ {p0}"
|
||||
"Due ◈ {p0}": "At betale ◈ {p0}",
|
||||
"Change bid": "Ændr bud",
|
||||
"Change choice": "Ændr valg",
|
||||
"Production choice submitted.": "Produktionsvalg indsendt."
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1198,5 +1198,8 @@
|
|||
"Auction details": "Auktionsdetails",
|
||||
"Revealed bids": "Aufgedeckte Gebote",
|
||||
"Paid ◈ {p0}": "Bezahlt ◈ {p0}",
|
||||
"Due ◈ {p0}": "Fällig ◈ {p0}"
|
||||
"Due ◈ {p0}": "Fällig ◈ {p0}",
|
||||
"Change bid": "Gebot ändern",
|
||||
"Change choice": "Auswahl ändern",
|
||||
"Production choice submitted.": "Produktionsauswahl gesendet."
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1198,5 +1198,8 @@
|
|||
"Auction details": "Λεπτομέρειες δημοπρασίας",
|
||||
"Revealed bids": "Αποκαλυμμένες προσφορές",
|
||||
"Paid ◈ {p0}": "Πληρώθηκαν ◈ {p0}",
|
||||
"Due ◈ {p0}": "Προς πληρωμή ◈ {p0}"
|
||||
"Due ◈ {p0}": "Προς πληρωμή ◈ {p0}",
|
||||
"Change bid": "Αλλαγή προσφοράς",
|
||||
"Change choice": "Αλλαγή επιλογής",
|
||||
"Production choice submitted.": "Η επιλογή παραγωγής υποβλήθηκε."
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1198,5 +1198,8 @@
|
|||
"Auction details": "Auction details",
|
||||
"Revealed bids": "Revealed bids",
|
||||
"Paid ◈ {p0}": "Paid ◈ {p0}",
|
||||
"Due ◈ {p0}": "Due ◈ {p0}"
|
||||
"Due ◈ {p0}": "Due ◈ {p0}",
|
||||
"Change bid": "Change bid",
|
||||
"Change choice": "Change choice",
|
||||
"Production choice submitted.": "Production choice submitted."
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1198,5 +1198,8 @@
|
|||
"Auction details": "جزئیات حراج",
|
||||
"Revealed bids": "پیشنهادهای آشکارشده",
|
||||
"Paid ◈ {p0}": "پرداختشده ◈ {p0}",
|
||||
"Due ◈ {p0}": "مبلغ قابل پرداخت ◈ {p0}"
|
||||
"Due ◈ {p0}": "مبلغ قابل پرداخت ◈ {p0}",
|
||||
"Change bid": "تغییر پیشنهاد",
|
||||
"Change choice": "تغییر انتخاب",
|
||||
"Production choice submitted.": "انتخاب تولید ارسال شد."
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1198,5 +1198,8 @@
|
|||
"Auction details": "Détails de l’enchère",
|
||||
"Revealed bids": "Enchères révélées",
|
||||
"Paid ◈ {p0}": "Payé ◈ {p0}",
|
||||
"Due ◈ {p0}": "À payer ◈ {p0}"
|
||||
"Due ◈ {p0}": "À payer ◈ {p0}",
|
||||
"Change bid": "Modifier l’enchère",
|
||||
"Change choice": "Modifier mon choix",
|
||||
"Production choice submitted.": "Choix de production envoyé."
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1198,5 +1198,8 @@
|
|||
"Auction details": "नीलामी का विवरण",
|
||||
"Revealed bids": "प्रकट की गई बोलियाँ",
|
||||
"Paid ◈ {p0}": "भुगतान ◈ {p0}",
|
||||
"Due ◈ {p0}": "देय ◈ {p0}"
|
||||
"Due ◈ {p0}": "देय ◈ {p0}",
|
||||
"Change bid": "बोली बदलें",
|
||||
"Change choice": "चयन बदलें",
|
||||
"Production choice submitted.": "उत्पादन का चयन भेज दिया गया।"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1198,5 +1198,8 @@
|
|||
"Auction details": "Dettagli dell’asta",
|
||||
"Revealed bids": "Offerte rivelate",
|
||||
"Paid ◈ {p0}": "Pagato ◈ {p0}",
|
||||
"Due ◈ {p0}": "Da pagare ◈ {p0}"
|
||||
"Due ◈ {p0}": "Da pagare ◈ {p0}",
|
||||
"Change bid": "Modifica offerta",
|
||||
"Change choice": "Modifica scelta",
|
||||
"Production choice submitted.": "Scelta di produzione inviata."
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1198,5 +1198,8 @@
|
|||
"Auction details": "경매 안내",
|
||||
"Revealed bids": "공개된 입찰",
|
||||
"Paid ◈ {p0}": "지불 ◈ {p0}",
|
||||
"Due ◈ {p0}": "지불할 금액 ◈ {p0}"
|
||||
"Due ◈ {p0}": "지불할 금액 ◈ {p0}",
|
||||
"Change bid": "입찰 변경",
|
||||
"Change choice": "선택 변경",
|
||||
"Production choice submitted.": "생산 선택을 제출했습니다."
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1198,5 +1198,8 @@
|
|||
"Auction details": "Veilingdetails",
|
||||
"Revealed bids": "Onthulde biedingen",
|
||||
"Paid ◈ {p0}": "Betaald ◈ {p0}",
|
||||
"Due ◈ {p0}": "Te betalen ◈ {p0}"
|
||||
"Due ◈ {p0}": "Te betalen ◈ {p0}",
|
||||
"Change bid": "Bod wijzigen",
|
||||
"Change choice": "Keuze wijzigen",
|
||||
"Production choice submitted.": "Productiekeuze ingediend."
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1198,5 +1198,8 @@
|
|||
"Auction details": "Szczegóły aukcji",
|
||||
"Revealed bids": "Ujawnione oferty",
|
||||
"Paid ◈ {p0}": "Zapłacono ◈ {p0}",
|
||||
"Due ◈ {p0}": "Do zapłaty ◈ {p0}"
|
||||
"Due ◈ {p0}": "Do zapłaty ◈ {p0}",
|
||||
"Change bid": "Zmień ofertę",
|
||||
"Change choice": "Zmień wybór",
|
||||
"Production choice submitted.": "Wybór produkcji przesłany."
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1198,5 +1198,8 @@
|
|||
"Auction details": "Detalhes do leilão",
|
||||
"Revealed bids": "Lances revelados",
|
||||
"Paid ◈ {p0}": "Pago ◈ {p0}",
|
||||
"Due ◈ {p0}": "A pagar ◈ {p0}"
|
||||
"Due ◈ {p0}": "A pagar ◈ {p0}",
|
||||
"Change bid": "Alterar lance",
|
||||
"Change choice": "Alterar escolha",
|
||||
"Production choice submitted.": "Escolha de produção enviada."
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1198,5 +1198,8 @@
|
|||
"Auction details": "Detaliile licitației",
|
||||
"Revealed bids": "Oferte dezvăluite",
|
||||
"Paid ◈ {p0}": "Plătit ◈ {p0}",
|
||||
"Due ◈ {p0}": "De plătit ◈ {p0}"
|
||||
"Due ◈ {p0}": "De plătit ◈ {p0}",
|
||||
"Change bid": "Modifică oferta",
|
||||
"Change choice": "Modifică alegerea",
|
||||
"Production choice submitted.": "Alegerea producției a fost trimisă."
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1198,5 +1198,8 @@
|
|||
"Auction details": "Подробности аукциона",
|
||||
"Revealed bids": "Раскрытые ставки",
|
||||
"Paid ◈ {p0}": "Уплачено ◈ {p0}",
|
||||
"Due ◈ {p0}": "К оплате ◈ {p0}"
|
||||
"Due ◈ {p0}": "К оплате ◈ {p0}",
|
||||
"Change bid": "Изменить ставку",
|
||||
"Change choice": "Изменить выбор",
|
||||
"Production choice submitted.": "Выбор производства отправлен."
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1198,5 +1198,8 @@
|
|||
"Auction details": "Chi tiết đấu giá",
|
||||
"Revealed bids": "Giá đấu đã công bố",
|
||||
"Paid ◈ {p0}": "Đã trả ◈ {p0}",
|
||||
"Due ◈ {p0}": "Cần trả ◈ {p0}"
|
||||
"Due ◈ {p0}": "Cần trả ◈ {p0}",
|
||||
"Change bid": "Đổi giá đấu",
|
||||
"Change choice": "Đổi lựa chọn",
|
||||
"Production choice submitted.": "Đã gửi lựa chọn sản xuất."
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1198,5 +1198,8 @@
|
|||
"Auction details": "拍賣詳情",
|
||||
"Revealed bids": "已揭曉的出價",
|
||||
"Paid ◈ {p0}": "已支付 ◈ {p0}",
|
||||
"Due ◈ {p0}": "應付 ◈ {p0}"
|
||||
"Due ◈ {p0}": "應付 ◈ {p0}",
|
||||
"Change bid": "更改出價",
|
||||
"Change choice": "更改選擇",
|
||||
"Production choice submitted.": "已提交生產選擇。"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue