Respect Anarchy cubes in research forecasts and event markers
This commit is contained in:
parent
787c7671f1
commit
ce91fb25fe
9 changed files with 137 additions and 16 deletions
|
|
@ -297,7 +297,11 @@ pub(crate) fn do_advance(
|
|||
ActionLogEntry::advance(
|
||||
advance,
|
||||
ActionLogBalance::Gain,
|
||||
if take_incident_token {
|
||||
if take_incident_token
|
||||
&& !crate::content::incidents::trojan::anarchy_replaces_event_marker(
|
||||
game, player_index, advance,
|
||||
)
|
||||
{
|
||||
ActionLogIncidentToken::Take(t - 1)
|
||||
} else {
|
||||
ActionLogIncidentToken::NoChange
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::ability_initializer::AbilityInitializerSetup;
|
||||
use crate::advance::undo_unlock_special_advance;
|
||||
use crate::advance::{Advance, undo_unlock_special_advance};
|
||||
use crate::advance::{find_government_special_advance, remove_advance};
|
||||
use crate::combat::{Combat, CombatModifier, CombatRetreatState};
|
||||
use crate::combat_listeners::CombatResult;
|
||||
|
|
@ -340,31 +340,40 @@ fn anarchy() -> Incident {
|
|||
.build()
|
||||
}
|
||||
|
||||
pub(crate) fn anarchy_replaces_event_marker(game: &Game, player: usize, advance: Advance) -> bool {
|
||||
advance.info(game).government.is_some()
|
||||
&& game.permanent_effects.iter().any(|effect| {
|
||||
matches!(effect, PermanentEffect::Anarchy(a) if a.player == player && a.advances_lost > 0)
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn anarchy_advance() -> Ability {
|
||||
Ability::builder("Anarchy", "-")
|
||||
.add_simple_persistent_event_listener(
|
||||
|event| &mut event.advance,
|
||||
10,
|
||||
|game, p, i| {
|
||||
if i.advance.info(game).government.is_none() {
|
||||
if !anarchy_replaces_event_marker(game, p.index, i.advance) {
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(mut a) = remove_and_map_element_by(&mut game.permanent_effects, |e| {
|
||||
if let PermanentEffect::Anarchy(a) = e {
|
||||
if let PermanentEffect::Anarchy(a) = e
|
||||
&& a.player == p.index
|
||||
&& a.advances_lost > 0
|
||||
{
|
||||
Some(a.clone())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}) && p.index == a.player
|
||||
{
|
||||
}) {
|
||||
p.log(
|
||||
game,
|
||||
"Gain a government advance, taking a game event token \
|
||||
instead of triggering a game event (and losing 1 victory point)",
|
||||
);
|
||||
let p = p.get_mut(game);
|
||||
p.incident_tokens += 1;
|
||||
i.take_incident_token = false;
|
||||
p.gain_event_victory_points(-1_f32, &EventOrigin::Incident(44));
|
||||
a.advances_lost -= 1;
|
||||
if a.advances_lost > 0 {
|
||||
|
|
|
|||
|
|
@ -380,7 +380,8 @@ pub fn view(game: &Game, seat: Option<usize>) -> Value {
|
|||
json!({"amount":amount,"resources":resources})
|
||||
}).collect::<Vec<_>>();
|
||||
item.as_object_mut().unwrap().extend(json!({
|
||||
"triggersEvent":action.is_some() && p.incident_tokens == 1 && research_uses_event_marker,
|
||||
"triggersEvent":action.is_some() && p.incident_tokens == 1 && research_uses_event_marker
|
||||
&& !crate::content::incidents::trojan::anarchy_replaces_event_marker(game, seat, *advance),
|
||||
"owned":owned,"reason":reason,"payment":if advance_choice.is_some_and(|(_, mode)| mode != "paid") {ResourcePile::empty()} else {payment.unwrap_or_else(|| cost.default_payment())},"action":action,
|
||||
"costAmount":cost_amount,"costResources":resources,
|
||||
"costGroups":cost_groups,
|
||||
|
|
|
|||
|
|
@ -342,9 +342,7 @@
|
|||
"player": 0,
|
||||
"Advance": {
|
||||
"advance": "Dogma",
|
||||
"incident_token": {
|
||||
"Take": 2
|
||||
},
|
||||
"incident_token": "NoChange",
|
||||
"balance": "Gain"
|
||||
},
|
||||
"origin": {
|
||||
|
|
@ -404,4 +402,4 @@
|
|||
"incidents_discarded": [
|
||||
44
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -407,3 +407,7 @@ Viewer 0.1.145 enriches cultural-influence recap captions with success/failure,
|
|||
Viewer 0.1.147 / engine 0.4.101 restricts Great Gardens' resource choices to the city containing the wonder. Plains reached through Husbandry still qualify, other terrain keeps its normal resources, and both previews and submitted collections use the same city-specific rule. The rule applies to existing saves when loaded; completed historical collections are unchanged.
|
||||
|
||||
Full-game replay no longer reserves room below chat for the hidden last-turn recap. On mobile this restores a usable message viewport and composer. Last-turn recaps retain their panel spacing. Verified with collection/wonder regressions, 827 frontend tests, all locales, type checking, production build, and phone-sized embedded chat previews. The broader advances test suite still has an unrelated stale cultural-influence log expectation (`rolls a 2` versus `rolls a 1 (+1)`).
|
||||
|
||||
Viewer 0.1.148 / engine 0.4.102 uses Anarchy's remaining cubes when forecasting government research events. Eligible government advances no longer show an event warning; ordinary research still does, and the general warning is hidden when available choices have different outcomes. The journal also records the unchanged event counter. Anarchy resolution now preserves other players' cubes and does not add an event marker for card-granted advances that already bypass the counter. No historical games are rewritten.
|
||||
|
||||
Verified with 832 frontend/engine tests, Anarchy and Dogma Rust regressions, locale validation, type checking, production build, and a browser preview of Dogma with one event marker remaining. Rule source: the printed Revolution: Anarchy card in the English event deck scan linked in `docs/card-text-audit.json`.
|
||||
|
|
|
|||
4
web-client/package-lock.json
generated
4
web-client/package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "@boardgamers/clash-web-client",
|
||||
"version": "0.1.147",
|
||||
"version": "0.1.148",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@boardgamers/clash-web-client",
|
||||
"version": "0.1.147",
|
||||
"version": "0.1.148",
|
||||
"dependencies": {
|
||||
"@boardgamers/protocol": "0.9.0",
|
||||
"lucide-svelte": "^0.577.0",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@boardgamers/clash-web-client",
|
||||
"version": "0.1.147",
|
||||
"version": "0.1.148",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
|
|
|||
|
|
@ -187,7 +187,11 @@
|
|||
: { eligible: false, affordable: false },
|
||||
);
|
||||
const eventImminent = $derived(
|
||||
!reference && (selected ? !!selected.triggersEvent : advances.some((a) => a.triggersEvent)),
|
||||
!reference &&
|
||||
(selected
|
||||
? !!selected.triggersEvent
|
||||
: advances.some((a) => a.triggersEvent) &&
|
||||
!advances.some((a) => a.action && !a.triggersEvent)),
|
||||
);
|
||||
function matches(advance: PublicAdvance) {
|
||||
return `${advance.name} ${advance.description} ${researchPresentation(advance).summary}`
|
||||
|
|
|
|||
101
web-client/src/anarchy.test.ts
Normal file
101
web-client/src/anarchy.test.ts
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createRequire } from 'node:module';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import type { View } from './types.ts';
|
||||
|
||||
const engine = createRequire(import.meta.url)('../.engine/server.js');
|
||||
const npcs = JSON.parse(await engine.init(2, [], {}, 'anarchy-regression', {})).players.slice(2);
|
||||
function afterAnarchy(count = 1) {
|
||||
const game = JSON.parse(
|
||||
readFileSync(
|
||||
new URL('../../server/tests/test_games/incidents/trojan/anarchy.outcome.json', import.meta.url),
|
||||
'utf8',
|
||||
),
|
||||
);
|
||||
for (const npc of npcs)
|
||||
if (!game.players.some((p: any) => p.civilization === npc.civilization))
|
||||
game.players.push({ ...npc, id: game.players.length });
|
||||
game.players[0].incident_tokens = 1;
|
||||
game.players[0].special_victory_points[0].points = count;
|
||||
game.permanent_effects = [{ Anarchy: { player: 0, advances_lost: count } }];
|
||||
game.actions_left = 3;
|
||||
return game;
|
||||
}
|
||||
const view = (g: any): View => JSON.parse(engine.webView(engine.stripSecret(JSON.stringify(g), 0), 0));
|
||||
const move = (g: any, action: unknown) =>
|
||||
JSON.parse(engine.tryMove(JSON.stringify(g), JSON.stringify(action), 0));
|
||||
const research = (g: any, id: string) => {
|
||||
const advance = view(g).advances.find((a) => a.id === id)!;
|
||||
assert.ok(advance.action, `${id} is available`);
|
||||
return move(g, advance.action);
|
||||
};
|
||||
|
||||
test('Anarchy suppresses the government research warning and leaves the event marker untouched', () => {
|
||||
const game = afterAnarchy();
|
||||
game.players[0].advances.push('Philosophy', 'Draft');
|
||||
const options = view(game).advances;
|
||||
// Anarchy removed Voting: its cube may also fund a different government.
|
||||
for (const id of ['Voting', 'Dogma', 'Nationalism']) {
|
||||
const advance = options.find((a) => a.id === id)!;
|
||||
assert.ok(advance.action, id);
|
||||
assert.equal(advance.triggersEvent, false, id);
|
||||
}
|
||||
assert.equal(options.find((a) => a.id === 'Engineering')!.triggersEvent, true);
|
||||
const after = research(game, 'Dogma');
|
||||
assert.equal(after.players[0].incident_tokens, 1);
|
||||
assert.deepEqual(after.permanent_effects ?? [], []);
|
||||
assert.deepEqual(after.incidents_left, game.incidents_left);
|
||||
assert.equal(after.rng, game.rng);
|
||||
const entries = after.log.flatMap((a: any) =>
|
||||
a.rounds.flatMap((r: any) => r.turns.flatMap((t: any) => t.actions ?? [])),
|
||||
);
|
||||
const gained = entries.at(-1).items.find((i: any) => i.Advance?.advance === 'Dogma');
|
||||
assert.equal(
|
||||
gained.Advance.incident_token,
|
||||
'NoChange',
|
||||
'The journal must not claim an event marker was spent',
|
||||
);
|
||||
});
|
||||
|
||||
test('the warning returns only after the last Anarchy cube has been used', () => {
|
||||
let game = afterAnarchy(2);
|
||||
game = research(game, 'Dogma');
|
||||
assert.equal(game.permanent_effects[0].Anarchy.advances_lost, 1);
|
||||
assert.equal(view(game).advances.find((a) => a.id === 'Devotion')!.triggersEvent, false);
|
||||
game = research(game, 'Devotion');
|
||||
assert.equal(game.players[0].incident_tokens, 1);
|
||||
assert.deepEqual(game.permanent_effects ?? [], []);
|
||||
assert.equal(view(game).advances.find((a) => a.id === 'Fanaticism')!.triggersEvent, true);
|
||||
});
|
||||
|
||||
test('another player researching government neither uses nor removes your Anarchy cubes', () => {
|
||||
const game = afterAnarchy();
|
||||
game.permanent_effects = [{ Anarchy: { player: 1, advances_lost: 2 } }];
|
||||
assert.equal(view(game).advances.find((a) => a.id === 'Dogma')!.triggersEvent, true);
|
||||
game.players[0].incident_tokens = 2;
|
||||
const after = research(game, 'Dogma');
|
||||
assert.equal(after.players[0].incident_tokens, 1);
|
||||
assert.deepEqual(after.permanent_effects, game.permanent_effects);
|
||||
});
|
||||
|
||||
test('Anarchy uses only the researching player’s cube when multiple players are affected', () => {
|
||||
const game = afterAnarchy();
|
||||
const other = { Anarchy: { player: 1, advances_lost: 2 } };
|
||||
game.permanent_effects.unshift(other);
|
||||
const after = research(game, 'Dogma');
|
||||
assert.equal(after.players[0].incident_tokens, 1);
|
||||
assert.deepEqual(after.permanent_effects, [other]);
|
||||
});
|
||||
|
||||
test('a card-granted government advance uses an Anarchy cube without adding an event marker', () => {
|
||||
let game = afterAnarchy();
|
||||
game.players[0].action_cards = [2];
|
||||
game = move(game, { Playing: { ActionCard: 2 } });
|
||||
if (view(game).decision?.fields.length)
|
||||
game = move(game, { Response: { Payment: [{ culture_tokens: 1 }] } });
|
||||
assert.equal(view(game).advances.find((a) => a.id === 'Dogma')!.triggersEvent, false);
|
||||
game = research(game, 'Dogma');
|
||||
assert.equal(game.players[0].incident_tokens, 1);
|
||||
assert.deepEqual(game.permanent_effects ?? [], []);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue