Fix Great Prophet Cities choices and resource reward UI; publish viewer 0.1.188

This commit is contained in:
coyotte508 2026-11-02 15:57:39 +01:00
commit de6803342f
7 changed files with 153 additions and 23 deletions

View file

@ -155,16 +155,24 @@ pub fn happiness_preview(game: &Game, seat: usize, input: &Value) -> Result<Valu
&kind,
&origin,
)?;
let field = input["includePayments"].as_bool().unwrap_or(false).then(|| {
super::decisions::resource_field(
&cost.cost, "Payment", false, &p.resources, false, &p.resources,
)
});
let field = input["includePayments"]
.as_bool()
.unwrap_or(false)
.then(|| {
super::decisions::resource_field(
&cost.cost,
"Payment",
false,
&p.resources,
false,
&p.resources,
)
});
let affordable = if input["payment"].is_null() {
cost.cost.first_valid_payment(&p.resources)
} else {
let selected = serde_json::from_value(input["payment"].clone())
.map_err(|e| e.to_string())?;
let selected =
serde_json::from_value(input["payment"].clone()).map_err(|e| e.to_string())?;
(p.resources.has_at_least(&selected) && cost.cost.is_valid_payment(&selected))
.then_some(selected)
};
@ -251,8 +259,15 @@ pub fn movement(game: &Game, seat: usize, units: Vec<u32>) -> Result<Value, Stri
let mut destinations = vec![];
for carrier in carriers {
for route in possible_move_routes(p, game, &units, start, carrier).unwrap_or_default() {
let payments = super::decisions::payment_choices(&route.cost, &p.resources, false, false)
.unwrap_or_else(|| route.cost.first_valid_payment(&p.resources).into_iter().collect());
let payments =
super::decisions::payment_choices(&route.cost, &p.resources, false, false)
.unwrap_or_else(|| {
route
.cost
.first_valid_payment(&p.resources)
.into_iter()
.collect()
});
for payment in payments {
let breaks_diplomacy =
route
@ -264,9 +279,15 @@ pub fn movement(game: &Game, seat: usize, units: Vec<u32>) -> Result<Value, Stri
let offer = json!({"position":route.destination,"terrain":game.map.get(route.destination),"terrainNotes":if route.ignore_terrain_movement_restrictions { vec!["Roads: ignores Mountain and Forest penalties. These units can move again in a new Move action unless they fight a battle."] } else { terrain_notes(game,p,&units,route.destination) },"payment":payment,"carrier":carrier,"attack":game.enemy_player(seat,route.destination).is_some(),"breaksDiplomacy":breaks_diplomacy,
"action":Action::Movement(MovementAction::Move(MoveUnits::new(units.clone(),route.destination,carrier,payment)))});
let mut offer = offer;
if carrier.is_none() && units.iter().any(|id| p.get_unit(*id).is_ship()) && game.map.is_land(route.destination) {
if carrier.is_none()
&& units.iter().any(|id| p.get_unit(*id).is_ship())
&& game.map.is_land(route.destination)
{
offer["label"] = json!("Convert & move ashore");
} else if carrier.is_none() && units.iter().all(|id| !p.get_unit(*id).is_ship()) && game.map.is_sea(route.destination) {
} else if carrier.is_none()
&& units.iter().all(|id| !p.get_unit(*id).is_ship())
&& game.map.is_sea(route.destination)
{
offer["label"] = json!("Convert to ships");
}
if !destinations.contains(&offer) {
@ -475,6 +496,22 @@ fn action_reason(
pub fn cities(game: &Game, seat: usize, can_play: bool) -> Vec<Value> {
let p = game.player(seat);
// Great Prophet builds through its pending card request, not a Construct
// action. Expose that same choice in Cities, including after the last action.
let prophet_cities = game.current_event_handler().and_then(|handler| {
if seat != game.active_player()
|| handler.response.is_some()
|| handler.origin != crate::events::EventOrigin::CivilCard(120)
{
return None;
}
match &handler.request {
crate::content::persistent_events::PersistentEventRequest::SelectPositions(request) => {
Some(&request.choices)
}
_ => None,
}
});
// These cards grant an action to offset the following Construct command.
// Present the extra build's net cost, not that internal action debit.
let construction_source = (seat == game.active_player())
@ -496,6 +533,21 @@ pub fn cities(game: &Game, seat: usize, can_play: bool) -> Vec<Value> {
construction_source.is_some() || PlayingActionType::Construct.cost(game, seat).free;
p.cities.iter().map(|city| {
let buildings = BUILDINGS.into_iter().map(|building| {
if building == crate::city_pieces::Building::Temple
&& let Some(eligible) = prophet_cities
{
// Match the card's payment exactly; it does not use the normal
// city activation, mood, size or Construct-action restrictions.
let cost = p.building_cost(game, building, CostTrigger::NoModifiers).cost;
let payment = cost.first_valid_payment(&p.resources).unwrap_or_else(|| cost.default_payment());
let available = eligible.contains(&city.position);
return json!({"name":"Temple", "owned":!city.pieces.can_add_building(building),
"required":game.cache.get_building_advance(building).name(game), "payment":payment,
"reason":if available { None } else { Some("Not eligible for Great Prophet") },
"choices":if available { vec![json!({"position":null,
"action":Action::Response(crate::content::persistent_events::EventResponse::SelectPositions(vec![city.position]))})] } else { vec![] },
"free":true,"activateCity":false,"source":"Great Prophet","moodWillDecrease":false});
}
let cost = p.building_cost_in_city(game, building, city.position, CostTrigger::NoModifiers);
let payment = cost.cost.first_valid_payment(&p.resources).unwrap_or_else(|| cost.cost.default_payment());
let positions = new_building_positions(game, building, city);

View file

@ -697,3 +697,14 @@ Temples neither require an impossible food discount nor consume its once-per-tur
use. Preserve normal construction, Great Engineer, Architecture substitutions,
Temple rewards and Dogma follow-ups. Regression coverage includes both card copies,
Egypt/Greece, and used/unused State Religion. Publish the matching engine and viewer.
## Viewer 0.1.188 / engine unchanged (0.4.126)
Resource reward choices use a compact Gain resources heading and accessible icon
controls for Back and Cancel. Great Prophet exposes eligible Temple choices in
Cities even after the final action, without normal construction activation or
mood-loss warnings. Choosing the city continues to the card's optional payment
rather than submitting a normal Construct action. Regression coverage includes
neutral and angry activated cities, zero actions, declining, payment, and opponent
views. These presentation changes ship in the viewer's bundled rules bridge;
the deployed game engine remains unchanged.

View file

@ -1,12 +1,12 @@
{
"name": "@boardgamers/clash-web-client",
"version": "0.1.187",
"version": "0.1.188",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@boardgamers/clash-web-client",
"version": "0.1.187",
"version": "0.1.188",
"dependencies": {
"@boardgamers/protocol": "0.9.0",
"lucide-svelte": "^0.577.0",

View file

@ -1,6 +1,6 @@
{
"name": "@boardgamers/clash-web-client",
"version": "0.1.187",
"version": "0.1.188",
"private": true,
"type": "module",
"scripts": {

View file

@ -40,8 +40,9 @@
content?.scrollTo(0, 0);
});
function submitBuild(action: Move) {
const chosen = structuredClone(action) as { Playing: { Construct: { payment: Pile } } };
if (buildPayment) chosen.Playing.Construct.payment = buildPayment;
// Card-request builds select the city first; their payment decision follows.
const chosen = structuredClone(action) as { Playing?: { Construct: { payment: Pile } } };
if (buildPayment && chosen.Playing) chosen.Playing.Construct.payment = buildPayment;
controller.submit(chosen);
}
let city = $derived($session.view?.cities.find((c) => c.position === $session.city));
@ -397,7 +398,9 @@
class="primary"
disabled={!!$session.playback || $session.pending}
onclick={() => submitBuild(choice.action)}
>Build {selected.name}{choice.position ? ` at ${choice.position}` : ''}</button
>{typeof choice.action === 'object' && 'Response' in choice.action
? (choice.position ? `Continue to payment at ${choice.position}` : 'Continue to payment')
: (choice.position ? `Build ${selected.name} at ${choice.position}` : `Build ${selected.name}`)}</button
>{/each}{/if}
</div>
</footer>{/if}

View file

@ -6,7 +6,7 @@
import { printedCardName } from './card-names';
import { onDestroy } from 'svelte';
import { untrack } from 'svelte';
import { Check, Sparkles, Layers, BookOpen, ChevronRight, Zap, Wheat } from 'lucide-svelte';
import { Check, Sparkles, Layers, BookOpen, ChevronRight, ArrowLeft, X, Zap, Wheat } from 'lucide-svelte';
import type { Controller } from './controller';
import type { Decision, Move, Pile, UnitKind } from './types';
import { unitInfo } from './city';
@ -34,6 +34,8 @@
const panelId = $props.id();
const selected = $derived($session.decisionSelection);
const opponentTactics = $derived(opponentTacticsLabel(decision));
const resourceChoice = $derived(decision.reward && decision.name === 'Select a resource to gain');
const title = $derived(resourceChoice ? 'Gain resources' : printedCardName(decision.name));
const tribalStopChoice = $derived(decision.name === 'Tribal Allies' && decision.description === 'Select armies to stop · 1 food total');
const razeChoice = $derived(decision.name === 'Raze city');
const firstPlayerChoice = $derived(decision.name === 'Determine First Player');
@ -219,18 +221,19 @@
class:unit-decision={unitChoice}
class:card-decision={decision.options.some((option) => option.card)}
class:tactics-decision={decision.tacticsSelection}
aria-label={printedCardName(decision.name)}
class:resource-decision={resourceChoice}
aria-label={title}
>
{#if decision.endOfAge && !razeChoice}<span class="tiny-label">END OF AGE</span>{/if}
<header class="decision-heading">
{#if canCancelAbility($session.game, $session.view)}
<button disabled={$session.pending} onclick={() => controller.submit('Undo')}>Cancel</button>
<button class="icon-button" aria-label="Cancel ability" title="Cancel ability" disabled={$session.pending} onclick={() => controller.submit('Undo')}><X size={18} /></button>
{:else if $session.view?.canUndo && $session.game?.events?.some((event) => typeof event.event_type === 'object' && event.event_type !== null && 'CustomAction' in event.event_type)}
<button disabled={$session.pending} onclick={() => controller.submit('Undo')}>Back</button>
<button class="icon-button" aria-label="Back" title="Back" disabled={$session.pending} onclick={() => controller.submit('Undo')}><ArrowLeft size={17} /></button>
{/if}
{#if $session.view?.influenceContext}
<InfluenceFlow context={$session.view.influenceContext} />
{:else}<h2><Sparkles size={21} />{printedCardName(decision.name)}</h2>{/if}
{:else}<h2><Sparkles size={resourceChoice ? 18 : 21} />{title}</h2>{/if}
{#if decision.eventContext}
{@const context = decision.eventContext}
<div class="decision-event-context" class:full-context={!!context.card}>
@ -523,6 +526,16 @@
</section>
<style>
:global(.game-shell) .resource-decision .decision-heading h2 {
min-width: 0;
font-size: 20px;
line-height: 1.25;
}
.resource-decision .decision-heading h2 :global(svg),
.decision-heading > .icon-button {
flex-shrink: 0;
}
.tactics-opponent-status {
display: flex;
align-items: center;

View file

@ -101,7 +101,11 @@ test('ordinary construction still spends one action, resources and a city activa
assert.equal(game.players[0].cities.find((c: any) => c.position === 'C2').mood_state, 'Angry');
});
for (const [civilization, architecture] of [['Greece', false], ['Egypt', false], ['Egypt', true]] as const) {
for (const [civilization, architecture] of [
['Greece', false],
['Egypt', false],
['Egypt', true],
] as const) {
for (const used of [false, true]) {
for (const card of [17, 18]) {
test(`${civilization} City Development ${card} Temple: State Religion ${used ? 'used' : 'unused'}, Architecture ${architecture}`, () => {
@ -145,3 +149,50 @@ for (const [civilization, architecture] of [['Greece', false], ['Egypt', false],
}
}
}
for (const mood of ['Neutral', 'Angry'])
test(`Great Prophet exposes its Temple city choice at zero actions without activating a ${mood} city`, () => {
let game = fixture('incidents/great_persons/great_prophet');
game = move(game, { Playing: { Advance: { advance: 'Storage', payment: { food: 2 } } } });
game = move(game, { Response: { Payment: [{ culture_tokens: 1 }] } });
game.actions_left = 1;
const target = game.players[0].cities.find((c: any) => c.position === 'C1');
target.mood_state = mood;
target.activations = 1;
const cityBefore = structuredClone(game.players[0].cities.find((c: any) => c.position === 'C1'));
game = move(game, { Playing: { ActionCard: 120 } });
assert.equal(game.actions_left, 0);
const building = offer(game, 'C1', 'Temple');
assert.equal(building.reason, null);
assert.equal(building.source, 'Great Prophet');
assert.equal(building.free, true);
assert.equal(building.activateCity, false);
assert.equal(building.moodWillDecrease, false);
assert.ok(building.choices.length, 'Cities action bar must have an available building');
assert.ok(
view(game).cityActions.every((c) => c.buildings.every((b) => b.name === 'Temple' || !b.choices.length)),
);
assert.ok(view(game, 1).cityActions.every((c) => c.buildings.every((b) => !b.choices.length)));
assert.deepEqual(building.choices[0].action, { Response: { SelectPositions: ['C1'] } });
assert.equal(offer(game, 'C2', 'Temple').choices.length, 0, 'An existing Temple cannot be built again');
const declined = move(game, { Response: { SelectPositions: [] } });
assert.equal(declined.actions_left, 0);
assert.ok(
view(declined).cityActions.every((c) =>
c.buildings.every((b) => b.source !== 'Great Prophet' && !b.choices.length),
),
);
const before = { ...game.players[0].resources };
game = move(game, building.choices[0].action);
assert.deepEqual(game.players[0].resources, before, 'Choosing a city does not commit the payment');
assert.ok(view(game).decision?.fields.length, 'The normal optional payment decision follows');
game = move(game, { Response: { Payment: [building.payment] } });
const cityAfter = game.players[0].cities.find((c: any) => c.position === 'C1');
assert.equal(cityAfter.city_pieces.temple, 0);
assert.equal(cityAfter.activations ?? 0, cityBefore.activations ?? 0);
assert.equal(cityAfter.mood_state, cityBefore.mood_state);
assert.equal(game.actions_left, 0);
for (const [resource, amount] of Object.entries(building.payment))
assert.equal(game.players[0].resources[resource] ?? 0, (before[resource] ?? 0) - amount);
assert.ok(view(game).cityActions.every((c) => c.buildings.every((b) => b.source !== 'Great Prophet')));
});