Files
Dune/components/mixed-richese-bid-promises.tsx
T
Quintine 9e020ccd64
Verify and publish checkpoint container / container (push) Successful in 11m13s
Compose phase-wide and Richese bid commitments
2026-11-16 19:31:35 +11:00

55 lines
3.9 KiB
TypeScript

'use client';
import type { Action, GameView } from '@/game/engine';
import { truthQuestionText } from '@/game/truthtrance';
import { CHEAP_HERO_TRAITOR } from '@/game/traitors';
import { Button } from './ui/button';
/** Only the whole question, its answer and current status are projected. */
export function MixedRicheseBidPromises(props: { game: GameView; busy: boolean; send: (action: Action) => void }) {
const game = props.game;
const own = game.mixedRicheseBidPromises.filter(promise => promise.player === game.me);
if (!own.length) return null;
const leaderName = (id: string) => id === 'kwisatz' ? 'Kwisatz Haderach'
: id === CHEAP_HERO_TRAITOR ? 'Cheap Hero / Heroine' : game.allLeaders.find(leader => leader.id === id)?.name ?? id;
const auction = game.richeseAuction, guide = game.richeseBidPromiseGuide;
const live = !!auction && own.some(promise => promise.turn === game.turn && promise.event === auction.event &&
!promise.fulfilled && !promise.released);
const action = guide?.action, signature = action && JSON.stringify(action);
const isCurrentGuide = () => {
if (props.game !== game || !auction || game.richeseAuction !== auction ||
!guide || game.richeseBidPromiseGuide !== guide || !action || guide.action !== action ||
JSON.stringify(action) !== signature || action.type !== 'richeseBid' || action.event !== auction.event ||
typeof action.richeseBidPromiseId !== 'string') return false;
if (action.phaseAnyBidPromiseEvent !== undefined &&
(typeof action.phaseAnyBidPromiseEvent !== 'string' || action.phaseAnyBidLotEvent !== auction.event ||
!game.phaseAnyBidPromises.some(promise => promise.event === action.phaseAnyBidPromiseEvent &&
promise.player === game.me && promise.turn === game.turn && !promise.fulfilled && !promise.released))) return false;
return game.mixedRicheseBidPromises.some(promise => promise.player === game.me &&
promise.id === action.richeseBidPromiseId && promise.turn === game.turn &&
promise.event === auction.event && !promise.fulfilled && !promise.released);
};
const canGuide = () => !props.busy && isCurrentGuide();
return <section className="notice space-y-3" aria-label="Your Truthtrance mixed Richese bid promises" id="mixed-richese-bid-promise-guidance">
<h3>Your mixed Richese bid promises</h3>
<ul>{own.map(promise => <li key={promise.id}>
Turn {promise.turn}: You answered {promise.answer ? 'Yes' : 'No'} to {truthQuestionText({ kind: 'mixedRicheseBid',
target: promise.player, turn: promise.turn, event: promise.event, mixed: promise.mixed }, leaderName,
id => game.combatLocations.find(location => location.id === id)?.name ?? id,
id => game.players.find(player => player.id === id)?.name ?? id)}
{promise.released ? ' Released: this whole commitment is no longer possible.'
: promise.fulfilled ? ' Fulfilled: this whole commitment is complete.' : ' This whole answer is binding for this lot.'}
</li>)}</ul>
<p>Current facts are evaluated when you answer; they do not require you to keep cards, spice or forces afterward.
AND requires every condition; OR requires at least one. No negates the whole expression.
The original bidding, funding and payment rules still apply. Silent bids remain private until the native reveal.</p>
{live && !guide && <p>Your remaining bid opportunity may still be ahead; the answer stays visible while the lot continues.</p>}
{live && isCurrentGuide() && <Button className="game-action min-h-11 whitespace-normal" data-testid="mixed-richese-bid-promise-guide"
disabled={!canGuide()} onClick={() => { if (canGuide() && action) props.send(action); }}>
{typeof action?.amount === 'number' && action.amount > 0
? `Bid ${action.amount} spice while honoring your answers`
: action?.amount === 0 ? 'Submit zero spice while honoring your answers' : 'Pass this lot while honoring your answers'}
</Button>}
</section>;
}