82 lines
5.7 KiB
TypeScript
82 lines
5.7 KiB
TypeScript
'use client';
|
|
|
|
import type { Action, GameView } from '@/game/engine';
|
|
import { phaseAnyBidClaimText } from '@/game/phase-any-bid-promises';
|
|
import { Button } from './ui/button';
|
|
|
|
type Props = { game: GameView; busy: boolean; send: (action: Action) => void };
|
|
|
|
/** Use only the exact server-selected declaration for the live source and owner. */
|
|
export function PhaseAnyBidGuideButton(props: Props) {
|
|
const game = props.game, guide = game.phaseAnyBidGuide;
|
|
if (!guide) return null;
|
|
const actor = game.me, turn = game.turn, action = guide.action;
|
|
const signature = JSON.stringify(action), ordinary = game.auction, special = game.richeseAuction;
|
|
const ordinarySignature = ordinary && JSON.stringify([ordinary.bid, ordinary.bidder, ordinary.active, ordinary.remaining]);
|
|
const specialSignature = special && JSON.stringify([special.event, special.method, special.active,
|
|
special.bid, special.bidder, special.submitted, special.ownBid]);
|
|
const canAct = () => {
|
|
const current = props.game, me = current.players.find(player => player.id === actor);
|
|
if (props.busy || current !== game || current.me !== actor || current.turn !== turn ||
|
|
current.status !== 'playing' || current.phase !== 3 || current.phaseAnyBidGuide !== guide ||
|
|
guide.action !== action || JSON.stringify(action) !== signature || !me || me.autopilot ||
|
|
current.truthtrance || current.response || current.decision || current.phaseOpening ||
|
|
current.automaticContinuationPending || current.roomControl?.paused || current.roomControl?.closed ||
|
|
typeof action.phaseAnyBidPromiseEvent !== 'string' ||
|
|
!current.phaseAnyBidPromises.some(promise => promise.event === action.phaseAnyBidPromiseEvent &&
|
|
promise.player === actor && promise.turn === turn && !promise.fulfilled && !promise.released)) return false;
|
|
if (action.richeseBidPromiseId !== undefined) {
|
|
if (action.type !== 'richeseBid' || typeof action.richeseBidPromiseId !== 'string' || !special ||
|
|
![...current.richeseBidPromises, ...current.mixedRicheseBidPromises].some(promise =>
|
|
promise.id === action.richeseBidPromiseId && promise.player === actor && promise.turn === turn &&
|
|
promise.event === special.event && !promise.fulfilled && !promise.released)) return false;
|
|
}
|
|
if (action.bidPromiseEvent !== undefined) {
|
|
if ((action.type !== 'bid' && action.type !== 'passBid') || typeof action.bidPromiseEvent !== 'string' ||
|
|
typeof action.phaseAnyBidLot !== 'number' || current.bidPromiseLot?.turn !== turn ||
|
|
current.bidPromiseLot.lot !== action.phaseAnyBidLot ||
|
|
![...current.bidPromises, ...current.mixedBidPromises].some(promise =>
|
|
promise.event === action.bidPromiseEvent && promise.player === actor && promise.turn === turn &&
|
|
promise.lot === action.phaseAnyBidLot && !promise.fulfilled && !promise.released)) return false;
|
|
}
|
|
if (action.type === 'bid' || action.type === 'passBid')
|
|
return !!ordinary && current.auction === ordinary && ordinary.active === actor &&
|
|
JSON.stringify([ordinary.bid, ordinary.bidder, ordinary.active, ordinary.remaining]) === ordinarySignature &&
|
|
typeof action.phaseAnyBidLot === 'number' && current.bidPromiseLot?.turn === turn &&
|
|
current.bidPromiseLot.lot === action.phaseAnyBidLot;
|
|
if (action.type !== 'richeseBid' || !special || current.richeseAuction !== special ||
|
|
special.event !== action.event || special.event !== action.phaseAnyBidLotEvent ||
|
|
JSON.stringify([special.event, special.method, special.active, special.bid, special.bidder,
|
|
special.submitted, special.ownBid]) !== specialSignature) return false;
|
|
return special.method === 'silent' ? !special.submitted.includes(actor) : special.active === actor;
|
|
};
|
|
return <Button className="game-action min-h-11 whitespace-normal" data-testid="phase-any-bid-guide"
|
|
disabled={!canAct()} onClick={() => { if (canAct()) props.send(action); }}>
|
|
{typeof action.amount === 'number' && action.amount > 0
|
|
? `Bid ${action.amount} spice while honoring your phase answers`
|
|
: action.amount === 0 ? 'Submit zero spice while honoring your phase answers'
|
|
: 'Pass this lot while honoring your phase answers'}
|
|
</Button>;
|
|
}
|
|
|
|
export function PhaseAnyBidPromises(props: Props) {
|
|
const game = props.game, own = game.phaseAnyBidPromises.filter(promise => promise.player === game.me);
|
|
if (!own.length) return null;
|
|
const waiting = own.some(promise => promise.turn === game.turn && !promise.fulfilled && !promise.released);
|
|
return <section className="notice space-y-3" aria-label="Your Truthtrance any-auction bid promises" id="phase-any-bid-guidance">
|
|
<h3>Your any-auction bid promises</h3>
|
|
<ul>{own.map(promise => <li key={promise.event}>
|
|
Turn {promise.turn}: You answered {promise.answer ? 'Yes' : 'No'} to {phaseAnyBidClaimText(promise)}.
|
|
{promise.released ? ' Released: this commitment is no longer possible.'
|
|
: promise.fulfilled ? ' Fulfilled: this commitment is complete.' : ' This answer is binding through this Bidding phase.'}
|
|
</li>)}</ul>
|
|
<p>Yes requires a qualifying future bid while possible. No forbids qualifying bids through Bidding close.
|
|
Ordinary, Richese cache and Black Market auctions count. A bid can fulfill Yes even if another player wins;
|
|
its native funding and payment rules still apply.</p>
|
|
<p className="fine">Earlier bids do not count. The answer adds no funds or bidding opportunity.
|
|
Some combinations with other bidding commitments remain unavailable.</p>
|
|
{waiting && !game.phaseAnyBidGuide && <p>Your next supported opportunity may still be ahead.</p>}
|
|
{waiting && <PhaseAnyBidGuideButton {...props} />}
|
|
</section>;
|
|
}
|