Clarify card conditions, construction costs and leader availability
This commit is contained in:
parent
02fe226a05
commit
70512d6628
26 changed files with 1863 additions and 66 deletions
1278
docs/card-text-audit.json
Normal file
1278
docs/card-text-audit.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -21,10 +21,9 @@ pub(crate) fn cultural_takeover(id: u8, tactics_card: TacticsCardFactory) -> Act
|
|||
ActionCard::builder(
|
||||
id,
|
||||
"Cultural Takeover",
|
||||
"You may influence Barbarian cities of size 1. \
|
||||
If successful, replace the Barbarian city with a city of your color. \
|
||||
Replace one of the Barbarian units with a Settler or Infantry of your color. \
|
||||
Remove the other Barbarian units.",
|
||||
"Your next cultural influence attempt may target a size-1 barbarian city. \
|
||||
Pay the usual influence action cost. On success, take control of the city. \
|
||||
If it contains barbarian units, replace 1 with your own Settler or Infantry and remove the rest.",
|
||||
|c| c.free_action().no_resources(),
|
||||
|game, p, _| any_barbarian_city_can_be_influenced(game, p),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ fn city_development(id: u8, tactics_card: TacticsCardFactory) -> ActionCard {
|
|||
ActionCard::builder(
|
||||
id,
|
||||
"City Development",
|
||||
"Construct a building without paying resources and without an action.",
|
||||
"Construct a building in one of your cities without paying resources or spending an additional action. The city activates normally.",
|
||||
|c| c.action().culture_tokens(1),
|
||||
|game, p, _| can_construct_any_building(game, p, &[ConstructDiscount::NoResourceCost]),
|
||||
)
|
||||
|
|
@ -150,7 +150,7 @@ fn explorer(id: u8, tactics_card: TacticsCardFactory) -> ActionCard {
|
|||
let b = ActionCard::builder(
|
||||
id,
|
||||
"Explorer",
|
||||
"Explore a tile adjacent to a one of your cities - \
|
||||
"Explore an unexplored region adjacent to one of your cities, \
|
||||
AND/OR gain a free settler in one of your cities.",
|
||||
|c| c.action().culture_tokens(1),
|
||||
|game, player, _| {
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ fn inspiration(id: u8, tactics_card: TacticsCardFactory) -> ActionCard {
|
|||
id,
|
||||
"Inspiration",
|
||||
"Gain 1 advance for free (without changing the Game Event counter) \
|
||||
that a player owns who has a unit or city within range 2 of your units or cities.",
|
||||
owned by another player with a unit or city within 2 spaces of one of your units or cities. Normal advance prerequisites apply.",
|
||||
|c| c.free_action().no_resources(),
|
||||
|game, player, _| !possible_inspiration_advances(game, player).is_empty(),
|
||||
)
|
||||
|
|
@ -138,8 +138,8 @@ fn hero_general(id: u8, tactics_card: TacticsCardFactory) -> ActionCard {
|
|||
let mut b = ActionCard::builder(
|
||||
id,
|
||||
"Hero General",
|
||||
"If you won a land battle this turn: Increase the mood in a city by 1. \
|
||||
You may pay 1 mood token to increase the mood in a city by 1.",
|
||||
"After winning a land battle this turn: Increase the mood of one of your cities by 1 step. \
|
||||
You may then pay 1 mood token to increase the mood of the same or another of your cities by 1 step.",
|
||||
|c| c.free_action().no_resources(),
|
||||
|_game, player, _| !cities_where_mood_can_increase(player).is_empty(),
|
||||
)
|
||||
|
|
@ -210,7 +210,7 @@ fn ideas(id: u8, tactics_card: TacticsCardFactory) -> ActionCard {
|
|||
ActionCard::builder(
|
||||
id,
|
||||
"Ideas",
|
||||
"Gain 1 idea per Academy you own.",
|
||||
"Gain 1 idea for each of your cities containing an Academy, regardless of its color.",
|
||||
|c| c.free_action().no_resources(),
|
||||
|_game, player, _| academies(player) > 0,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@ fn assassination(id: u8, tactics_card: TacticsCardFactory) -> ActionCard {
|
|||
ActionCard::builder(
|
||||
id,
|
||||
"Assassination",
|
||||
"Select a player (not affected by Assassination already) \
|
||||
"Select another player (not affected by Assassination already) \
|
||||
to lose an action in their next turn.",
|
||||
|c| c.free_action().culture_tokens(1),
|
||||
move |game, p, _| !opponents_not_affected_by_assassination(game, p.index).is_empty(),
|
||||
|
|
@ -209,7 +209,7 @@ fn mass_production(id: u8, tactics_card: TacticsCardFactory) -> ActionCard {
|
|||
ActionCard::builder(
|
||||
id,
|
||||
"Mass Production",
|
||||
"You may collect from 2 additional tiles this turn. \
|
||||
"Your next Collect action may select up to 2 additional tiles. \
|
||||
(Cannot combine with Production Focus or another Mass Production.)",
|
||||
|c| c.free_action().no_resources(),
|
||||
move |game, p, _| collect_special_action(game, p),
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ pub(crate) fn spy(id: u8, tactics_card: TacticsCardFactory) -> ActionCard {
|
|||
ActionCard::builder(
|
||||
id,
|
||||
"Spy",
|
||||
"Look at all Wonder, Action, and Objective cards of another player. \
|
||||
You may swap one card of the same type.",
|
||||
"Look at another player's hand of Wonder, Action, and Objective cards. \
|
||||
You may exchange 1 card from your hand for 1 of theirs of the same type.",
|
||||
|c| c.action().culture_tokens(1),
|
||||
|game, player, _| !players_with_cards(game, player.index).is_empty(),
|
||||
)
|
||||
|
|
@ -34,7 +34,7 @@ pub(crate) fn spy(id: u8, tactics_card: TacticsCardFactory) -> ActionCard {
|
|||
s.log(
|
||||
game,
|
||||
&format!(
|
||||
"Decided to looked at all Wonder, Action, and Objective cards of {}",
|
||||
"Looked at the Wonder, Action, and Objective cards in the hand of {}",
|
||||
game.player_name(p)
|
||||
),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -107,8 +107,9 @@ fn steel_weapons() -> AdvanceBuilder {
|
|||
"Immediately before a Land battle starts, \
|
||||
you may pay 1 ore to get +2 combat value in every Combat Round against an enemy \
|
||||
that does not have the Steel Weapons advance. \
|
||||
If the enemy also has Steel Weapons, you only +1 combat value, \
|
||||
even if the enemy does not use the ability.",
|
||||
If the enemy also has Steel Weapons, gain only +1 combat value, \
|
||||
even if the enemy does not use the ability. \
|
||||
With Metallurgy, activation is free against enemies without Steel Weapons, including barbarians.",
|
||||
)
|
||||
.add_payment_request_listener(
|
||||
|e| &mut e.combat_start,
|
||||
|
|
@ -224,8 +225,9 @@ fn use_steel_weapons(game: &Game, c: &Combat, s: &mut CombatStrength, role: Comb
|
|||
|
||||
let add_combat_value = |s: &mut CombatStrength, value: u8| {
|
||||
s.extra_combat_value += value as i8;
|
||||
s.roll_log
|
||||
.push(format!("steel weapons added {value} combat value"));
|
||||
let free = value == 2 && game.player(c.player(role)).can_use_advance(Advance::Metallurgy);
|
||||
let benefit = if free { " (Metallurgy: no ore cost)" } else { "" };
|
||||
s.roll_log.push(format!("steel weapons added {value} combat value{benefit}"));
|
||||
};
|
||||
|
||||
if role.is_attacker() {
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ pub(crate) fn great_engineer() -> ActionCard {
|
|||
26,
|
||||
"Great Engineer",
|
||||
&format!(
|
||||
"{} Then, you may build a building in a city \
|
||||
without spending an action and without activating it.",
|
||||
"{} Then, you may construct a building in one of your cities. \
|
||||
Pay its normal resource cost, without spending an additional action or activating the city.",
|
||||
great_person_description(&groups)
|
||||
),
|
||||
|c| c.action().no_resources(),
|
||||
|
|
@ -38,7 +38,7 @@ pub(crate) fn great_engineer() -> ActionCard {
|
|||
0,
|
||||
|_, _, _| {
|
||||
Some(
|
||||
"Build a building in a city without spending an action and without activating it?"
|
||||
"Construct in one of your cities at the normal resource cost, without an additional action or city activation?"
|
||||
.to_string(),
|
||||
)
|
||||
},
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ use std::vec;
|
|||
|
||||
pub(crate) const GREAT_PERSON_OFFSET: u8 = 100;
|
||||
|
||||
pub(crate) const GREAT_PERSON_DESCRIPTION: &str = "You make take the Event Card to your \
|
||||
pub(crate) const GREAT_PERSON_DESCRIPTION: &str = "You may take the Event Card to your \
|
||||
hand for 1 culture token. If you pass, any other player (in player order) may take it \
|
||||
for 2 culture tokens: Action card: ";
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ pub(crate) fn legacy() -> Objective {
|
|||
fn building_lead(objective: &'static str, building: Building) -> Objective {
|
||||
Objective::builder(
|
||||
objective,
|
||||
&format!("You have more cities with a {building} than any other player",),
|
||||
&format!("More of your cities contain a {building} than any other player's cities. The buildings may be any color.",),
|
||||
)
|
||||
.status_phase_check(move |game, player| {
|
||||
leading_player(game, player, 1, move |p, _| buildings(p, building))
|
||||
|
|
@ -52,7 +52,7 @@ fn buildings(p: &Player, b: Building) -> usize {
|
|||
}
|
||||
|
||||
pub(crate) fn large_civ() -> Objective {
|
||||
Objective::builder("Large Civilization", "You have at least 6 cities")
|
||||
Objective::builder("Large Civilization", "You own at least 6 cities.")
|
||||
.status_phase_check(|_game, player| player.cities.len() >= 6)
|
||||
.build()
|
||||
}
|
||||
|
|
@ -77,7 +77,7 @@ pub(crate) fn leading_player(
|
|||
pub(crate) fn advanced_culture() -> Objective {
|
||||
Objective::builder(
|
||||
"Advanced Culture",
|
||||
"You have more advances than any other player - at least 6.",
|
||||
"You have at least 6 standard advances, and more than every other player. Civilization advances do not count.",
|
||||
)
|
||||
.status_phase_check(|game, player| {
|
||||
player.advances.len() >= 6 && leading_player(game, player, 1, move |p, _| p.advances.len())
|
||||
|
|
@ -86,7 +86,7 @@ pub(crate) fn advanced_culture() -> Objective {
|
|||
}
|
||||
|
||||
pub(crate) fn happy_population() -> Objective {
|
||||
Objective::builder("Happy Population", "You have at least 4 happy cities.")
|
||||
Objective::builder("Happy Population", "You own at least 4 Happy cities.")
|
||||
.status_phase_check(|_game, player| {
|
||||
player
|
||||
.cities
|
||||
|
|
@ -101,8 +101,7 @@ pub(crate) fn happy_population() -> Objective {
|
|||
pub(crate) fn architecture() -> Objective {
|
||||
Objective::builder(
|
||||
"Architecture",
|
||||
"You have at least 4 different types of buildings \
|
||||
(that are not influenced by another player).",
|
||||
"Your cities contain at least 4 different building types in your color.",
|
||||
)
|
||||
.status_phase_check(|_game, player| {
|
||||
player
|
||||
|
|
@ -117,7 +116,7 @@ pub(crate) fn architecture() -> Objective {
|
|||
}
|
||||
|
||||
pub(crate) fn consulate() -> Objective {
|
||||
Objective::builder("Consulate", "2 cities are culturally influenced by you.")
|
||||
Objective::builder("Consulate", "At least 2 cities owned by other players contain buildings in your color.")
|
||||
.status_phase_check(|game, player| {
|
||||
game.players
|
||||
.iter()
|
||||
|
|
@ -131,7 +130,7 @@ pub(crate) fn consulate() -> Objective {
|
|||
}
|
||||
|
||||
pub(crate) fn metropolis() -> Objective {
|
||||
Objective::builder("Metropolis", "You have at least 1 city with size 5.")
|
||||
Objective::builder("Metropolis", "You own at least 1 city of size 5 or greater.")
|
||||
.status_phase_check(|_game, player| {
|
||||
player.cities.iter().filter(|c| c.size() >= 5).count() >= 1
|
||||
})
|
||||
|
|
@ -141,7 +140,7 @@ pub(crate) fn metropolis() -> Objective {
|
|||
pub(crate) fn expansionist() -> Objective {
|
||||
Objective::builder(
|
||||
"Expansionist",
|
||||
"You have at least 4 cities that are not adjacent to other cities.",
|
||||
"You own at least 4 cities that are not adjacent to any other city, including your own and barbarian cities.",
|
||||
)
|
||||
.status_phase_check(|game, player| {
|
||||
player
|
||||
|
|
|
|||
|
|
@ -9,19 +9,23 @@ use crate::player::Player;
|
|||
use crate::unit::{Unit, UnitType};
|
||||
use itertools::Itertools;
|
||||
|
||||
// English card face: https://boardgamegeek.com/image/6509349/bigleaguecreative
|
||||
pub(crate) fn conqueror() -> Objective {
|
||||
let name = "Conqueror";
|
||||
Objective::builder(
|
||||
name,
|
||||
"You conquered a city with at least 1 Army unit or Fortress this turn.",
|
||||
"Immediately after capturing another player's city defended by at least 1 army unit or a Fortress.",
|
||||
)
|
||||
.add_simple_persistent_event_listener(
|
||||
|event| &mut event.combat_end,
|
||||
1,
|
||||
|game, player, s| {
|
||||
if s.is_winner(player.index)
|
||||
if s.attacker.player == player.index
|
||||
&& s.is_winner(player.index)
|
||||
&& s.battleground.is_city()
|
||||
&& s.opponent_is_human(player.index, game)
|
||||
&& (s.battleground == Battleground::CityWithFortress
|
||||
|| s.defender.fighters(s.battleground).amount() > 0)
|
||||
{
|
||||
objective_is_ready(player.get_mut(game), name);
|
||||
}
|
||||
|
|
@ -34,8 +38,8 @@ pub(crate) fn warmonger() -> Objective {
|
|||
let name = "Warmonger";
|
||||
Objective::builder(
|
||||
name,
|
||||
"You've completed your second combat this turn against different armies or cities, \
|
||||
one of which you've won.",
|
||||
"You fought at least 2 land battles this turn against different armies or cities, \
|
||||
and won at least 1 of them.",
|
||||
)
|
||||
.add_simple_persistent_event_listener(
|
||||
|event| &mut event.combat_end,
|
||||
|
|
@ -64,7 +68,7 @@ pub(crate) fn general() -> Objective {
|
|||
let name = "General";
|
||||
Objective::builder(
|
||||
name,
|
||||
"You killed at least 3 enemy units in a single land combat this turn.",
|
||||
"You eliminated at least 3 enemy army units in one land battle, including barbarian army units.",
|
||||
)
|
||||
.add_simple_persistent_event_listener(
|
||||
|event| &mut event.combat_end,
|
||||
|
|
@ -140,7 +144,7 @@ pub(crate) fn naval_assault() -> Objective {
|
|||
let name = "Naval Assault";
|
||||
Objective::builder(
|
||||
name,
|
||||
"You captured a city with army units that disembarked from a ship.",
|
||||
"Immediately after capturing another player's city with your army disembarking from a ship.",
|
||||
)
|
||||
.add_simple_persistent_event_listener(
|
||||
|event| &mut event.combat_end,
|
||||
|
|
@ -200,7 +204,7 @@ pub(crate) fn legendary_battle() -> Objective {
|
|||
let name = "Legendary Battle";
|
||||
Objective::builder(
|
||||
name,
|
||||
"You fought a battle against a city of size 5 with at least 1 wonder.",
|
||||
"You attacked a city of size 5 or greater containing a Wonder, with at least 3 of your army units.",
|
||||
)
|
||||
.add_simple_persistent_event_listener(
|
||||
|event| &mut event.combat_end,
|
||||
|
|
@ -277,7 +281,7 @@ pub(crate) fn barbarian_conquest() -> Objective {
|
|||
let name = "Barbarian Conquest";
|
||||
Objective::builder(
|
||||
name,
|
||||
"You captured a barbarian city with at least 2 army units.",
|
||||
"Immediately after capturing a barbarian city defended by at least 2 barbarian army units.",
|
||||
)
|
||||
.add_simple_persistent_event_listener(
|
||||
|event| &mut event.combat_end,
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ pub(crate) fn city_founder() -> Objective {
|
|||
let name = "City Founder";
|
||||
Objective::builder(
|
||||
name,
|
||||
"You founded a city this at least 5 spaces away from your starting city position.",
|
||||
"Immediately after founding a city at least 5 spaces from your starting city position.",
|
||||
)
|
||||
.add_simple_persistent_event_listener(
|
||||
|event| &mut event.found_city,
|
||||
|
|
@ -53,7 +53,7 @@ pub(crate) fn city_founder() -> Objective {
|
|||
|
||||
pub(crate) fn terror_regime() -> Objective {
|
||||
// is handled explicitly
|
||||
Objective::builder("Terror Regime", "At least 4 cities are Angry.").build()
|
||||
Objective::builder("Terror Regime", "At least 4 of your cities are Angry.").build()
|
||||
}
|
||||
|
||||
pub(crate) fn magnificent_culture() -> Objective {
|
||||
|
|
@ -61,7 +61,7 @@ pub(crate) fn magnificent_culture() -> Objective {
|
|||
Objective::builder(
|
||||
name,
|
||||
"You just built a wonder OR \
|
||||
you built have built the only wonder in the last round.",
|
||||
you built the only Wonder built during the last round.",
|
||||
)
|
||||
.status_phase_check(|game, player| {
|
||||
last_round(game).iter().any(|p| {
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ pub(crate) fn sea_blockade() -> Objective {
|
|||
pub(crate) fn large_fleet() -> Objective {
|
||||
Objective::builder(
|
||||
"Large Fleet",
|
||||
"You have at least 4 ships - or 2 ships and more than any other player.",
|
||||
"You have at least 4 ships, OR at least 2 ships and more ships than every other player.",
|
||||
)
|
||||
.status_phase_check(|game, player| {
|
||||
let ships = ship_count(player);
|
||||
|
|
@ -68,7 +68,7 @@ pub(crate) fn large_army() -> Objective {
|
|||
pub(crate) fn standing_army() -> Objective {
|
||||
Objective::builder(
|
||||
"Standing Army",
|
||||
"You have at least 4 cities with army units. \
|
||||
"At least 4 of your cities each contain one or more of your army units. \
|
||||
Cannot be completed together with Military Might.",
|
||||
)
|
||||
.contradicting_status_phase_objective("Military Might")
|
||||
|
|
@ -91,7 +91,7 @@ pub(crate) fn standing_army() -> Objective {
|
|||
pub(crate) fn colony() -> Objective {
|
||||
Objective::builder(
|
||||
"Colony",
|
||||
"You have at least 1 city least 5 spaces away from your starting city position. \
|
||||
"You own a city at least 5 spaces from your starting city position. \
|
||||
Cannot be completed if you completed City Founder in the last round.",
|
||||
)
|
||||
.status_phase_check(|game, player| {
|
||||
|
|
@ -120,7 +120,7 @@ pub(crate) fn colony() -> Objective {
|
|||
pub(crate) fn threat() -> Objective {
|
||||
Objective::builder(
|
||||
"Threat",
|
||||
"At least 4 of your army units are adjacent to another human player's city.",
|
||||
"At least 4 of your army units are adjacent to cities owned by other players. They may be next to different cities.",
|
||||
)
|
||||
.status_phase_check(|game, player| {
|
||||
let enemy_cities = game
|
||||
|
|
@ -149,7 +149,7 @@ pub(crate) fn threat() -> Objective {
|
|||
pub(crate) fn outpost() -> Objective {
|
||||
Objective::builder(
|
||||
"Outpost",
|
||||
"You have army units on at least 3 spaces outside, and not adjacent to cities",
|
||||
"Your army units occupy at least 3 different spaces, each outside and not adjacent to any of your cities.",
|
||||
)
|
||||
.status_phase_check(|_game, player| {
|
||||
player
|
||||
|
|
@ -173,7 +173,7 @@ pub(crate) fn outpost() -> Objective {
|
|||
pub(crate) fn migration() -> Objective {
|
||||
Objective::builder(
|
||||
"Migration",
|
||||
"You have settlers on at least 3 spaces outside, and not adjacent to cities",
|
||||
"Your settlers occupy at least 3 different spaces, each outside and not adjacent to any of your cities.",
|
||||
)
|
||||
.status_phase_check(|_game, player| {
|
||||
player
|
||||
|
|
@ -210,7 +210,7 @@ pub(crate) fn military_might() -> Objective {
|
|||
pub(crate) fn trade_power() -> Objective {
|
||||
Objective::builder(
|
||||
"Trade Power",
|
||||
"You could form at least 3 trade routes if you wanted to.\
|
||||
"You could form at least 3 trade routes. \
|
||||
Cannot be completed together with Shipping Routes.",
|
||||
)
|
||||
.contradicting_status_phase_objective("Shipping Routes")
|
||||
|
|
@ -221,7 +221,7 @@ pub(crate) fn trade_power() -> Objective {
|
|||
pub(crate) fn shipping_routes() -> Objective {
|
||||
Objective::builder(
|
||||
"Shipping Routes",
|
||||
"You could form at least 2 trade routes only with ships if you wanted to.\
|
||||
"You could form at least 2 trade routes using your ships. \
|
||||
Cannot be completed together with Trade Power.",
|
||||
)
|
||||
.contradicting_status_phase_objective("Trade Power")
|
||||
|
|
@ -241,7 +241,7 @@ pub(crate) fn unit_versatility(objective: &str, unit_type: UnitType) -> Objectiv
|
|||
Objective::builder(
|
||||
objective,
|
||||
&format!(
|
||||
"You have at least 3 army groups with at least 1 {} unit each.",
|
||||
"You have at least 1 {} on each of at least 3 different spaces.",
|
||||
unit_type.non_leader_name()
|
||||
),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ pub(crate) fn peltasts(id: u8) -> TacticsCard {
|
|||
id,
|
||||
"Peltasts",
|
||||
"Roll a die for each of your Army units. \
|
||||
If you rolled a 5 or 6, ignore 1 hit",
|
||||
If any die shows 5 or 6, cancel 1 incoming hit in total.",
|
||||
)
|
||||
.fighter_requirement(FighterRequirement::Army)
|
||||
.add_reveal_listener(7, |player, game, combat, s| {
|
||||
|
|
@ -110,7 +110,7 @@ pub(crate) fn heavy_resistance(id: u8) -> TacticsCard {
|
|||
TacticsCard::builder(
|
||||
id,
|
||||
"Heavy Resistance",
|
||||
"Attacker gets -1 combat value for each fighting unit.",
|
||||
"Your opponent loses 1 combat value per attacking unit in this combat round.",
|
||||
)
|
||||
.target(TacticsCardTarget::Opponent)
|
||||
.role_requirement(CombatRole::Defender)
|
||||
|
|
@ -147,7 +147,7 @@ pub(crate) fn surprise(id: u8) -> TacticsCard {
|
|||
TacticsCard::builder(
|
||||
id,
|
||||
"Surprise",
|
||||
"Add 1 to combat value. Draw 1 action card if you killed at least 1 unit.",
|
||||
"Add 1 to combat value. Draw 1 action card if you eliminate at least 1 enemy unit in this combat round.",
|
||||
)
|
||||
.add_reveal_listener(9, |_player, _game, _c, s| {
|
||||
s.extra_combat_value += 1;
|
||||
|
|
@ -248,7 +248,7 @@ pub(crate) fn tactical_retreat(id: u8) -> TacticsCard {
|
|||
id,
|
||||
"Tactical Retreat",
|
||||
"The battle ends after all On Reveal effects are resolved. \
|
||||
Withdraw to an adjacent field without enemies. \
|
||||
Withdraw your units to an adjacent land space without enemy units or cities. \
|
||||
The opponent is considered to have won the battle.",
|
||||
)
|
||||
.fighter_requirement(FighterRequirement::Army)
|
||||
|
|
|
|||
|
|
@ -252,10 +252,33 @@ impl TacticsCardBuilder {
|
|||
|
||||
#[must_use]
|
||||
pub fn build(self) -> TacticsCard {
|
||||
// The printed cards express these restrictions with icons. Include them
|
||||
// in the text as well so every viewer and card-choice prompt shows them.
|
||||
let mut requirements = Vec::new();
|
||||
if let Some(role) = &self.role_requirement {
|
||||
requirements.push(match role {
|
||||
CombatRole::Attacker => "Attacking only".to_string(),
|
||||
CombatRole::Defender => "Defending only".to_string(),
|
||||
});
|
||||
}
|
||||
if let Some(location) = &self.location_requirement {
|
||||
requirements.push(format!("{location} battle"));
|
||||
}
|
||||
if !self.fighter_requirement.is_empty() {
|
||||
requirements.push(format!(
|
||||
"Requires your {} in the battle",
|
||||
self.fighter_requirement.iter().map(ToString::to_string).collect::<Vec<_>>().join(" or ")
|
||||
));
|
||||
}
|
||||
let description = if requirements.is_empty() {
|
||||
self.description
|
||||
} else {
|
||||
format!("{}. {}", requirements.join(" · "), self.description)
|
||||
};
|
||||
TacticsCard {
|
||||
id: self.id,
|
||||
name: self.name,
|
||||
description: self.description,
|
||||
description,
|
||||
fighter_requirement: self.fighter_requirement,
|
||||
role_requirement: self.role_requirement,
|
||||
location_requirement: self.location_requirement,
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ use crate::action::Action;
|
|||
use crate::city::MoodState;
|
||||
use crate::city_pieces::BUILDINGS;
|
||||
use crate::construct::{Construct, can_construct, new_building_positions};
|
||||
use crate::content::effects::{ConstructEffect, PermanentEffect};
|
||||
use crate::game::{Game, GameState};
|
||||
use crate::happiness::{
|
||||
IncreaseHappiness, happiness_base_event_origin, happiness_cost_for_cities, lawgiver_city,
|
||||
|
|
@ -360,6 +361,16 @@ fn action_reason(
|
|||
|
||||
pub fn cities(game: &Game, seat: usize, can_play: bool) -> Vec<Value> {
|
||||
let p = game.player(seat);
|
||||
// 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()).then(|| {
|
||||
game.permanent_effects.iter().find_map(|effect| match effect {
|
||||
PermanentEffect::Construct(ConstructEffect::GreatEngineer) => Some("Great Engineer"),
|
||||
PermanentEffect::Construct(ConstructEffect::CityDevelopment) => Some("City Development"),
|
||||
_ => None,
|
||||
})
|
||||
}).flatten();
|
||||
let free_construction = construction_source.is_some() || PlayingActionType::Construct.cost(game, seat).free;
|
||||
p.cities.iter().map(|city| {
|
||||
let buildings = BUILDINGS.into_iter().map(|building| {
|
||||
let cost = p.building_cost_in_city(game, building, city.position, CostTrigger::NoModifiers);
|
||||
|
|
@ -373,6 +384,7 @@ pub fn cities(game: &Game, seat: usize, can_play: bool) -> Vec<Value> {
|
|||
json!({"name":building.to_string(),"owned":!city.pieces.can_add_building(building),
|
||||
"required":game.cache.get_building_advance(building).name(game),"payment":payment,
|
||||
"payments":super::decisions::payment_choices(&cost.cost,&p.resources,false,false),"reason":reason,"choices":choices,
|
||||
"free":free_construction,"activateCity":cost.activate_city,"source":construction_source,
|
||||
"moodWillDecrease":cost.activate_city && city.is_activated()})
|
||||
}).collect::<Vec<_>>();
|
||||
let recruits = [UnitType::Settler,UnitType::Infantry,UnitType::Cavalry,UnitType::Elephant,UnitType::Ship].into_iter().map(|unit| {
|
||||
|
|
@ -398,7 +410,18 @@ pub fn cities(game: &Game, seat: usize, can_play: bool) -> Vec<Value> {
|
|||
});
|
||||
json!({"steps":steps,"lawgiver":lawgiver,"mood":if steps==max_steps {"Happy"} else {"Neutral"},"payment":payment,"reason":reason,"action":action})
|
||||
}).collect::<Vec<_>>();
|
||||
let leaders = p.available_leaders.iter().map(|l|json!({"id":l,"name":l.name(game),"abilities":game.cache.get_leader(l).abilities.iter().map(|a|json!({"name":a.name,"description":a.description})).collect::<Vec<_>>(),"description":game.cache.get_leader(l).abilities.iter().map(|a|format!("{}: {}",a.name,a.description)).collect::<Vec<_>>().join("\n")})).collect::<Vec<_>>();
|
||||
let leaders = p.available_leaders.iter().map(|l| {
|
||||
let mut units = Units::empty();
|
||||
units += &UnitType::Leader(*l);
|
||||
let result = crate::recruit::recruit_cost_without_replaced(game, p, &units, city.position, CostTrigger::NoModifiers);
|
||||
let reason = action_reason(game, seat, can_play, PlayingActionType::Recruit)
|
||||
.or_else(|| result.as_ref().err().cloned());
|
||||
let payment = result.map(|c| c.cost.first_valid_payment(&p.resources).unwrap_or_else(|| c.cost.default_payment()))
|
||||
.unwrap_or_else(|_| UnitType::Leader(*l).cost());
|
||||
json!({"id":l,"name":l.name(game),"payment":payment,"reason":reason,
|
||||
"abilities":game.cache.get_leader(l).abilities.iter().map(|a|json!({"name":a.name,"description":a.description})).collect::<Vec<_>>(),
|
||||
"description":game.cache.get_leader(l).abilities.iter().map(|a|format!("{}: {}",a.name,a.description)).collect::<Vec<_>>().join("\n")})
|
||||
}).collect::<Vec<_>>();
|
||||
json!({"position":city.position,"buildings":buildings,"recruits":recruits,"happiness":happiness,"leaders":leaders})
|
||||
}).collect()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -270,7 +270,7 @@
|
|||
}
|
||||
],
|
||||
"log": [
|
||||
"Player1: Spy: Pay 1 culture token, Decided to looked at all Wonder, Action, and Objective cards of Player2"
|
||||
"Player1: Spy: Pay 1 culture token, Looked at the Wonder, Action, and Objective cards in the hand of Player2"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -294,7 +294,7 @@
|
|||
"log": [
|
||||
"Player1: Move: marched 2 infantry, 1 cavalry and 1 elephant from C2 to C1",
|
||||
"Combat round 1",
|
||||
"Player1: Combat: Attacking with 2 infantry, 1 cavalry and 1 elephant, Roll 2 (elephant, -1 hits, no combat value), 2 (elephant, no bonus), 2 (elephant, no bonus), 1 (leader, no bonus) for combined combat value of 7 and gets 1 hits against defending units, Combat modifiers: steel weapons added 2 combat value, Gain 1 gold, Gain city C1",
|
||||
"Player1: Combat: Attacking with 2 infantry, 1 cavalry and 1 elephant, Roll 2 (elephant, -1 hits, no combat value), 2 (elephant, no bonus), 2 (elephant, no bonus), 1 (leader, no bonus) for combined combat value of 7 and gets 1 hits against defending units, Combat modifiers: steel weapons added 2 combat value (Metallurgy: no ore cost), Gain 1 gold, Gain city C1",
|
||||
"Player2: Combat: Defending with Gaius Julius Caesar, Roll 1 (leader, re-roll), 6 (infantry, no bonus) for combined combat value of 6 and gets 0 hits against attacking units, Lost Gaius Julius Caesar at C1, Lose city C1",
|
||||
"Player2: Choose Casualties: Remove all defending units",
|
||||
"Attacker wins",
|
||||
|
|
|
|||
98
web-client/scripts/card-rules-smoke.mjs
Normal file
98
web-client/scripts/card-rules-smoke.mjs
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
import assert from 'node:assert/strict';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import { createRequire } from 'node:module';
|
||||
import { chromium } from 'playwright';
|
||||
const engine = createRequire(import.meta.url)('../.engine/server.js');
|
||||
let initial = await engine.init(2, [], { civilization: 'ChooseCivilization' }, 'leader-ui', {});
|
||||
for (const civ of ['China', 'Greece'])
|
||||
initial = engine.tryMove(
|
||||
initial,
|
||||
JSON.stringify({ ChooseCivilization: civ }),
|
||||
engine.currentPlayer(initial),
|
||||
);
|
||||
initial = JSON.parse(initial);
|
||||
const seat = engine.currentPlayer(JSON.stringify(initial));
|
||||
initial.players[seat].cities[0].mood_state = 'Happy';
|
||||
initial.players[seat].resources = { mood_tokens: 1, culture_tokens: 1 };
|
||||
initial.players[seat].action_cards = [7, 11, 17];
|
||||
const browser = await chromium.launch({
|
||||
headless: true,
|
||||
args: ['--use-gl=angle', '--use-angle=swiftshader'],
|
||||
});
|
||||
try {
|
||||
for (const width of [1400, 390, 320]) {
|
||||
const page = await browser.newPage({ viewport: { width, height: width === 320 ? 640 : 900 } });
|
||||
let state = structuredClone(initial);
|
||||
const errors = [];
|
||||
page.on('pageerror', (e) => errors.push(e.message));
|
||||
await page.exposeFunction('applyMove', async (action) => {
|
||||
state = JSON.parse(engine.tryMove(JSON.stringify(state), action, seat));
|
||||
await page.evaluate(
|
||||
(state) => host.emit('state', state),
|
||||
engine.stripSecret(JSON.stringify(state), seat),
|
||||
);
|
||||
});
|
||||
await page.route('**/*', async (route) => {
|
||||
const path = new URL(route.request().url()).pathname;
|
||||
if (path === '/')
|
||||
return route.fulfill({
|
||||
contentType: 'text/html',
|
||||
body: '<!doctype html><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><div id="app"></div><script src="/viewer.js"></script>',
|
||||
});
|
||||
if (!['/viewer.js', '/server_bg.wasm'].includes(path)) return route.abort();
|
||||
return route.fulfill({
|
||||
contentType: path.endsWith('.wasm') ? 'application/wasm' : 'text/javascript',
|
||||
body: await readFile(new URL('../dist' + path, import.meta.url)),
|
||||
});
|
||||
});
|
||||
await page.goto('http://clash.test/');
|
||||
await page.evaluate(
|
||||
({ state, seat }) => {
|
||||
window.host = clash3d.launch('#app');
|
||||
host.on('move', (action) => window.applyMove(action));
|
||||
host.emit('player', { index: seat });
|
||||
host.emit('theme', { dark: true });
|
||||
host.emit('preferences', { sound: false });
|
||||
host.emit('state', state);
|
||||
},
|
||||
{ state: engine.stripSecret(JSON.stringify(state), seat), seat },
|
||||
);
|
||||
const cityButton = page.getByRole('button', { name: 'Manage cities', exact: true });
|
||||
await cityButton.waitFor();
|
||||
assert.ok(!(await cityButton.getAttribute('class')).includes('inspect-only'));
|
||||
await cityButton.click();
|
||||
await page.getByRole('button', { name: 'Recruit', exact: true }).click();
|
||||
const sunTzu = page.getByRole('button', { name: 'Select Sun Tzu', exact: true });
|
||||
assert.ok(await sunTzu.isEnabled());
|
||||
await sunTzu.click();
|
||||
await page.screenshot({ path: `/tmp/clash-leader-available-${width}.png` });
|
||||
assert.ok(await page.locator('.city-dialog').evaluate((el) => el.scrollWidth <= el.clientWidth + 1));
|
||||
await page.getByRole('button', { name: 'Close city management' }).click();
|
||||
await page.getByRole('button', { name: 'Action cards: 3', exact: true }).click();
|
||||
await page
|
||||
.getByText('Attacking only · City battle · Requires your Army in the battle.', { exact: false })
|
||||
.waitFor();
|
||||
assert.ok(await page.locator('.cards-dialog').evaluate((el) => el.scrollWidth <= el.clientWidth + 1));
|
||||
await page.screenshot({ path: `/tmp/clash-card-rules-${width}.png` });
|
||||
await page.getByRole('button', { name: 'Close action cards' }).click();
|
||||
state.players[seat].resources = {};
|
||||
await page.evaluate(
|
||||
(state) => host.emit('state', state),
|
||||
engine.stripSecret(JSON.stringify(state), seat),
|
||||
);
|
||||
await page.waitForFunction(() =>
|
||||
document.querySelector('[aria-label="Manage cities"]')?.classList.contains('inspect-only'),
|
||||
);
|
||||
await cityButton.click();
|
||||
await page.getByRole('button', { name: 'Recruit', exact: true }).click();
|
||||
assert.ok(!(await page.getByRole('button', { name: 'Select Sun Tzu', exact: true }).isEnabled()));
|
||||
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth));
|
||||
assert.deepEqual(errors, []);
|
||||
console.log(
|
||||
`${width}px: leader availability, eye icon, unavailable recruitment and card restrictions verified.`,
|
||||
);
|
||||
await page.close();
|
||||
}
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
116
web-client/scripts/construction-smoke.mjs
Normal file
116
web-client/scripts/construction-smoke.mjs
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
import assert from 'node:assert/strict';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import { createRequire } from 'node:module';
|
||||
import { chromium } from 'playwright';
|
||||
const engine = createRequire(import.meta.url)('../.engine/server.js');
|
||||
const npcs = JSON.parse(await engine.init(2, [], {}, 'construction-smoke', {})).players.slice(2);
|
||||
async function fixture(name) {
|
||||
const game = JSON.parse(
|
||||
await readFile(new URL(`../../server/tests/test_games/${name}.json`, import.meta.url), 'utf8'),
|
||||
);
|
||||
for (const npc of npcs)
|
||||
if (!game.players.some((p) => p.civilization === npc.civilization))
|
||||
game.players.push({ ...npc, id: game.players.length });
|
||||
return game;
|
||||
}
|
||||
const move = (game, action) =>
|
||||
JSON.parse(
|
||||
engine.tryMove(JSON.stringify(game), typeof action === 'string' ? action : JSON.stringify(action), 0),
|
||||
);
|
||||
let engineer = await fixture('incidents/great_persons/great_engineer');
|
||||
for (const action of [
|
||||
{ Playing: { Advance: { advance: 'Storage', payment: { food: 2 } } } },
|
||||
{ Response: { Payment: [{ culture_tokens: 1 }] } },
|
||||
{ Playing: { ActionCard: 126 } },
|
||||
{ Response: { SelectAdvance: 'Engineering' } },
|
||||
{ Response: { Bool: true } },
|
||||
])
|
||||
engineer = move(engineer, action);
|
||||
let development = await fixture('action_cards/city_development');
|
||||
development.players[0].cities[0].activations = 1;
|
||||
development = move(move(development, { Playing: { ActionCard: 17 } }), {
|
||||
Response: { Payment: [{ culture_tokens: 1 }] },
|
||||
});
|
||||
const ordinary = await fixture('action_cards/city_development');
|
||||
ordinary.players[0].cities[0].activations = 1;
|
||||
ordinary.players[0].resources = { food: 3, wood: 3, ore: 3 };
|
||||
const browser = await chromium.launch({
|
||||
headless: true,
|
||||
args: ['--use-gl=angle', '--use-angle=swiftshader'],
|
||||
});
|
||||
try {
|
||||
for (const [width, height, dark] of [
|
||||
[1400, 900, false],
|
||||
[390, 844, true],
|
||||
[320, 640, false],
|
||||
]) {
|
||||
for (const [name, initial, label, resources, activation] of [
|
||||
['engineer', engineer, 'Great Engineer · No extra action · No city activation', true, false],
|
||||
['development', development, 'City Development · No extra action · Activates this city', false, true],
|
||||
['ordinary', ordinary, 'Costs 1 action · Activates this city', true, true],
|
||||
]) {
|
||||
const page = await browser.newPage({ viewport: { width, height } }),
|
||||
errors = [];
|
||||
let state = structuredClone(initial),
|
||||
sent = 0;
|
||||
page.on('pageerror', (error) => errors.push(error.message));
|
||||
await page.exposeFunction('applyMove', async (action) => {
|
||||
state = move(state, action);
|
||||
sent++;
|
||||
await page.evaluate(
|
||||
(state) => host.emit('state', state),
|
||||
engine.stripSecret(JSON.stringify(state), 0),
|
||||
);
|
||||
});
|
||||
await page.route('**/*', async (route) => {
|
||||
const path = new URL(route.request().url()).pathname;
|
||||
if (path === '/')
|
||||
return route.fulfill({
|
||||
contentType: 'text/html',
|
||||
body: '<!doctype html><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><div id="app"></div><script src="/viewer.js"></script>',
|
||||
});
|
||||
if (!['/viewer.js', '/server_bg.wasm'].includes(path)) return route.abort();
|
||||
return route.fulfill({
|
||||
contentType: path.endsWith('.wasm') ? 'application/wasm' : 'text/javascript',
|
||||
body: await readFile(new URL('../dist' + path, import.meta.url)),
|
||||
});
|
||||
});
|
||||
await page.goto('http://clash.test/');
|
||||
await page.evaluate(
|
||||
({ state, dark }) => {
|
||||
window.host = clash3d.launch('#app');
|
||||
host.on('move', (action) => window.applyMove(action));
|
||||
host.emit('player', { index: 0 });
|
||||
host.emit('theme', { dark });
|
||||
host.emit('preferences', { sound: false });
|
||||
host.emit('state', state);
|
||||
},
|
||||
{ state: engine.stripSecret(JSON.stringify(state), 0), dark },
|
||||
);
|
||||
await page.getByRole('button', { name: 'Manage cities', exact: true }).click();
|
||||
await page
|
||||
.locator('.building-option')
|
||||
.filter({ has: page.getByText('Fortress', { exact: true }) })
|
||||
.click();
|
||||
const footer = page.locator('.city-confirm');
|
||||
await footer.getByText(label, { exact: true }).waitFor();
|
||||
assert.equal(await footer.locator('.resource-amount svg').count(), resources ? 3 : 0);
|
||||
assert.equal(await page.locator('.activation-status').count(), activation ? 1 : 0);
|
||||
if (activation) await page.getByText('This activation lowers mood.', { exact: false }).waitFor();
|
||||
assert.ok(await footer.evaluate((el) => el.scrollWidth <= el.clientWidth + 1));
|
||||
assert.ok(await page.locator('.city-dialog').evaluate((el) => el.scrollWidth <= el.clientWidth + 1));
|
||||
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth));
|
||||
await page.screenshot({ path: `/tmp/clash-build-${name}-${width}.png` });
|
||||
await page.getByRole('button', { name: 'Build Fortress', exact: true }).click();
|
||||
await page.waitForFunction(() => !document.querySelector('.city-confirm'));
|
||||
assert.equal(sent, 1);
|
||||
assert.equal(state.players[0].cities[0].city_pieces.fortress, 0);
|
||||
assert.equal(state.players[0].cities[0].mood_state, activation ? 'Angry' : 'Neutral');
|
||||
assert.deepEqual(errors, []);
|
||||
console.log(`${width}px ${name}: footer costs, activation warning and successful build verified.`);
|
||||
await page.close();
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
|
|
@ -169,6 +169,7 @@
|
|||
(c) =>
|
||||
c.buildings.some((b) => b.choices.length > 0) ||
|
||||
c.recruits.some((r) => !r.reason && r.available > 0) ||
|
||||
c.leaders?.some((l) => l.reason === null) ||
|
||||
c.happiness.some((h) => !!h.action),
|
||||
),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -38,6 +38,20 @@
|
|||
let city = $derived($session.view?.cities.find((c) => c.position === $session.city));
|
||||
let options = $derived($session.view?.cityActions.find((c) => c.position === $session.city));
|
||||
let selected = $derived(options?.buildings.find((b) => b.name === building));
|
||||
const buildActivatesCity = $derived(
|
||||
selected
|
||||
? selected.activateCity !== false
|
||||
: (options?.buildings.some((b) => b.activateCity !== false) ?? true),
|
||||
);
|
||||
const buildSummary = $derived(
|
||||
[
|
||||
selected?.source,
|
||||
selected?.free ? 'No extra action' : 'Costs 1 action',
|
||||
selected?.activateCity === false ? 'No city activation' : 'Activates this city',
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(' · '),
|
||||
);
|
||||
const buildPayment = $derived(
|
||||
paymentIndex >= 0 ? (selected?.payments?.[paymentIndex] ?? selected?.payment) : selected?.payment,
|
||||
);
|
||||
|
|
@ -121,7 +135,7 @@
|
|||
>{/each}
|
||||
</nav>
|
||||
<div class="city-content">
|
||||
{#if city && tab !== 'happiness'}<ActivationStatus
|
||||
{#if city && (tab === 'recruit' || (tab === 'build' && buildActivatesCity))}<ActivationStatus
|
||||
{city}
|
||||
warning={tab === 'recruit' || (tab === 'build' && !!selected?.moodWillDecrease)}
|
||||
/>{/if}
|
||||
|
|
@ -219,7 +233,10 @@
|
|||
class="leader-select"
|
||||
aria-label={`Select ${leader.name}`}
|
||||
aria-pressed={$session.recruits.leader === leader.id}
|
||||
disabled={$session.pending || (!$session.recruits.leader && occupiedCapacity >= capacity)}
|
||||
disabled={$session.pending ||
|
||||
(!!leader.reason && $session.recruits.leader !== leader.id) ||
|
||||
(!$session.recruits.leader && occupiedCapacity >= capacity)}
|
||||
title={leader.reason ?? undefined}
|
||||
onclick={() =>
|
||||
controller.setRecruits({
|
||||
...$session.recruits,
|
||||
|
|
@ -228,7 +245,9 @@
|
|||
>
|
||||
<span class="leader-name"><Crown size={16} />{leader.name}</span>
|
||||
<span class="leader-cost"
|
||||
><span>Cost</span><ResourceAmount pile={{ mood_tokens: 1, culture_tokens: 1 }} />
|
||||
><span>Cost</span><ResourceAmount
|
||||
pile={leader.payment ?? { mood_tokens: 1, culture_tokens: 1 }}
|
||||
/>
|
||||
<span class="leader-selection"
|
||||
>{#if $session.recruits.leader === leader.id}<Check size={14} />Selected{:else}<Plus
|
||||
size={14}
|
||||
|
|
@ -236,6 +255,7 @@
|
|||
>
|
||||
</span>
|
||||
</button>
|
||||
{#if leader.reason}<small class="reason">{leader.reason}</small>{/if}
|
||||
<dl class="leader-abilities">
|
||||
{#each leader.abilities as ability}{@const Icon = abilityIcon(ability.description)}
|
||||
<div>
|
||||
|
|
@ -273,7 +293,7 @@
|
|||
{#if tab === 'build' && selected && !selected.owned}<footer class="city-confirm">
|
||||
<div>
|
||||
<strong>{selected.name}</strong><ResourceAmount pile={buildPayment ?? selected.payment} /><small
|
||||
>{cityReason(selected.reason, city?.size) || 'Costs 1 action · Activates this city'}</small
|
||||
>{cityReason(selected.reason, city?.size) || buildSummary}</small
|
||||
>{#if selected.moodWillDecrease && city && city.activationMood !== city.mood}<span
|
||||
class="activation-inline"
|
||||
><strong>{city.mood} → {city.activationMood}</strong> after activation</span
|
||||
|
|
|
|||
121
web-client/src/card-rules.test.ts
Normal file
121
web-client/src/card-rules.test.ts
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { createRequire } from 'node:module';
|
||||
import { journal } from './journal.ts';
|
||||
import { combatJournal } from './combat-journal.ts';
|
||||
|
||||
const engine = createRequire(import.meta.url)('../.engine/server.js');
|
||||
const npcs = JSON.parse(await engine.init(2, [], {}, 'card-rules', {})).players.slice(2);
|
||||
function fixture(name: string) {
|
||||
const g = JSON.parse(
|
||||
readFileSync(new URL(`../../server/tests/test_games/${name}.json`, import.meta.url), 'utf8'),
|
||||
);
|
||||
g.players = [...g.players.slice(0, 2), ...structuredClone(npcs)];
|
||||
return g;
|
||||
}
|
||||
const move = (
|
||||
g: any,
|
||||
action: unknown,
|
||||
seat = engine.currentPlayer(typeof g === 'string' ? g : JSON.stringify(g)),
|
||||
) => JSON.parse(engine.tryMove(typeof g === 'string' ? g : JSON.stringify(g), JSON.stringify(action), seat));
|
||||
const view = (g: any, seat = engine.currentPlayer(JSON.stringify(g))) =>
|
||||
JSON.parse(engine.webView(engine.stripSecret(JSON.stringify(g), seat), seat));
|
||||
const attack = (g: any, units = [0, 1, 2, 3]) =>
|
||||
move(g, { Movement: { Move: { units, destination: 'C1', payment: {} } } }, 0);
|
||||
const offersConqueror = (g: any) =>
|
||||
g.events?.some((e: any) => e.event_type?.SelectObjectives?.shown_objective === 'Conqueror') ?? false;
|
||||
|
||||
for (const defense of ['army', 'fortress', 'empty', 'settler', 'barbarian']) {
|
||||
test(`Conqueror checks the captured city's owner and defenders: ${defense}`, () => {
|
||||
const g = fixture('objective_cards/instant/conqueror');
|
||||
g.players[0].objective_cards = [8];
|
||||
if (defense !== 'army') g.players[1].units = [];
|
||||
if (defense !== 'fortress') g.players[1].cities[0].city_pieces = {};
|
||||
if (defense === 'settler') g.players[1].units = [{ id: 0, position: 'C1', unit_type: 'Settler' }];
|
||||
if (defense === 'barbarian') {
|
||||
g.players[2].cities = g.players[1].cities;
|
||||
g.players[2].units = [{ id: 0, position: 'C1', unit_type: 'Infantry' }];
|
||||
g.players[1].cities = [];
|
||||
}
|
||||
const after = attack(g);
|
||||
assert.ok(
|
||||
after.players[0].cities.some((c: any) => c.position === 'C1'),
|
||||
'The attack captures the city',
|
||||
);
|
||||
assert.equal(offersConqueror(after), defense === 'army' || defense === 'fortress');
|
||||
});
|
||||
}
|
||||
|
||||
test('defending your own city does not complete Conqueror', () => {
|
||||
const g = fixture('objective_cards/instant/conqueror');
|
||||
g.players[0].objective_cards = [];
|
||||
g.players[1].objective_cards = [8];
|
||||
g.players[0].units = g.players[0].units.slice(0, 1);
|
||||
g.dice_roll_outcomes = [0, 11, 11, 11, 11, 0, 11, 11, 11, 11];
|
||||
const after = attack(g, [0]);
|
||||
assert.equal((after.players[0].units ?? []).length, 0);
|
||||
assert.ok(after.players[1].cities.some((c: any) => c.position === 'C1'));
|
||||
assert.equal(offersConqueror(after), false);
|
||||
});
|
||||
|
||||
test('Metallurgy activates Steel Weapons against barbarians for free and explains the bonus', () => {
|
||||
const g = fixture('combat/direct_capture_city_metallurgy');
|
||||
g.players[2].cities = g.players[1].cities;
|
||||
g.players[2].units = [{ id: 0, position: 'C1', unit_type: 'Infantry' }];
|
||||
g.players[1].cities = [];
|
||||
g.players[1].units = [];
|
||||
const ore = g.players[0].resources.ore;
|
||||
const after = attack(g);
|
||||
assert.equal(after.players[0].resources.ore, ore);
|
||||
assert.ok(!after.events?.some((e: any) => e.handler?.origin?.Advance === 'SteelWeapons'));
|
||||
const combat = combatJournal(journal(after)).find((entry) => entry.combat)?.combat;
|
||||
assert.ok(
|
||||
combat?.attacker.modifiers.includes('steel weapons added 2 combat value (Metallurgy: no ore cost)'),
|
||||
);
|
||||
});
|
||||
|
||||
for (const opponentHasSteel of [false, true]) {
|
||||
test(`Steel Weapons requests and spends ore when ${opponentHasSteel ? 'both players have it, even with Metallurgy' : 'Metallurgy is absent'}`, () => {
|
||||
const g = fixture('combat/direct_capture_city_metallurgy');
|
||||
if (opponentHasSteel) g.players[1].advances.push('SteelWeapons');
|
||||
else g.players[0].advances = g.players[0].advances.filter((a: string) => a !== 'Metallurgy');
|
||||
const before = g.players[0].resources.ore;
|
||||
let after = attack(g);
|
||||
const prompt = after.events.at(-1).handler;
|
||||
assert.equal(prompt.origin.Advance, 'SteelWeapons');
|
||||
assert.deepEqual(prompt.request.Payment[0].cost.default, { ore: 1 });
|
||||
after = move(after, { Response: { Payment: [{ ore: 1 }] } }, 0);
|
||||
assert.equal(after.players[0].resources.ore, before - 1);
|
||||
});
|
||||
}
|
||||
|
||||
test('leader-only recruitment is offered with a real cost, and unavailable cities explain why', async () => {
|
||||
let g: any = await engine.init(2, [], { civilization: 'ChooseCivilization' }, 'leader-availability', {});
|
||||
g = move(g, { ChooseCivilization: 'China' });
|
||||
g = move(g, { ChooseCivilization: 'Greece' });
|
||||
const seat = engine.currentPlayer(JSON.stringify(g));
|
||||
const p = g.players[seat];
|
||||
p.cities[0].mood_state = 'Happy';
|
||||
p.resources = { mood_tokens: 1, culture_tokens: 1 };
|
||||
const city = view(g).cityActions[0];
|
||||
assert.ok(city.recruits.every((r: any) => r.reason));
|
||||
assert.ok(city.buildings.every((b: any) => !b.choices.length));
|
||||
assert.equal(city.happiness.length, 0);
|
||||
const leader = city.leaders.find((l: any) => l.reason === null);
|
||||
assert.ok(leader, 'A leader remains recruitable when all other city actions are unavailable');
|
||||
assert.deepEqual(leader.payment, { mood_tokens: 1, culture_tokens: 1 });
|
||||
const q = JSON.parse(
|
||||
engine.webQuery(
|
||||
engine.stripSecret(JSON.stringify(g), seat),
|
||||
seat,
|
||||
JSON.stringify({ kind: 'recruit', city: city.position, units: { leader: leader.id }, replaced: [] }),
|
||||
),
|
||||
);
|
||||
const after = move(g, q.action);
|
||||
assert.ok(after.players[seat].units.some((u: any) => u.unit_type?.Leader === leader.id));
|
||||
assert.equal(after.players[seat].resources?.mood_tokens ?? 0, 0);
|
||||
p.resources = {};
|
||||
assert.ok(view(g).cityActions[0].leaders.every((l: any) => l.reason));
|
||||
assert.ok(view(g, 1 - seat).cityActions[0].leaders.every((l: any) => !!l.reason));
|
||||
});
|
||||
102
web-client/src/construction.test.ts
Normal file
102
web-client/src/construction.test.ts
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { createRequire } from 'node:module';
|
||||
import type { View } from './types.ts';
|
||||
|
||||
const engine = createRequire(import.meta.url)('../.engine/server.js');
|
||||
const npcs = JSON.parse(await engine.init(2, [], {}, 'construction-tests', {})).players.slice(2);
|
||||
function fixture(name: string) {
|
||||
const raw = JSON.parse(
|
||||
readFileSync(new URL(`../../server/tests/test_games/${name}.json`, import.meta.url), 'utf8'),
|
||||
);
|
||||
for (const npc of npcs)
|
||||
if (!raw.players.some((p: any) => p.civilization === npc.civilization))
|
||||
raw.players.push({ ...npc, id: raw.players.length });
|
||||
return raw;
|
||||
}
|
||||
const view = (game: any, seat = 0): View =>
|
||||
JSON.parse(engine.webView(engine.stripSecret(JSON.stringify(game), seat), seat));
|
||||
const move = (game: any, action: unknown) =>
|
||||
JSON.parse(engine.tryMove(JSON.stringify(game), JSON.stringify(action), 0));
|
||||
const offer = (game: any, position = 'C2', name = 'Fortress') =>
|
||||
view(game)
|
||||
.cityActions.find((c) => c.position === position)!
|
||||
.buildings.find((b) => b.name === name)!;
|
||||
|
||||
test('Great Engineer exposes a paid-resource build with no extra action or city activation', () => {
|
||||
let game = fixture('incidents/great_persons/great_engineer');
|
||||
for (const action of [
|
||||
{ Playing: { Advance: { advance: 'Storage', payment: { food: 2 } } } },
|
||||
{ Response: { Payment: [{ culture_tokens: 1 }] } },
|
||||
])
|
||||
game = move(game, action);
|
||||
const actionsBeforeCard = game.actions_left;
|
||||
for (const action of [
|
||||
{ Playing: { ActionCard: 126 } },
|
||||
{ Response: { SelectAdvance: 'Engineering' } },
|
||||
{ Response: { Bool: true } },
|
||||
])
|
||||
game = move(game, action);
|
||||
const building = offer(game);
|
||||
assert.equal(building.source, 'Great Engineer');
|
||||
assert.equal(building.free, true);
|
||||
assert.equal(building.activateCity, false);
|
||||
assert.equal(building.moodWillDecrease, false);
|
||||
assert.equal(building.reason, null, 'Great Engineer permits building in a city that cannot activate again');
|
||||
assert.equal(
|
||||
Object.values(building.payment).reduce((sum, n) => sum + n, 0),
|
||||
3,
|
||||
);
|
||||
assert.ok(view(game, 1).cityActions.every((c) => c.buildings.every((b) => b.source === null && !b.free)));
|
||||
const cityBefore = game.players[0].cities.find((c: any) => c.position === 'C2');
|
||||
const resourcesBefore = { ...game.players[0].resources };
|
||||
game = move(game, building.choices[0].action);
|
||||
const cityAfter = game.players[0].cities.find((c: any) => c.position === 'C2');
|
||||
assert.equal(cityAfter.mood_state, cityBefore.mood_state);
|
||||
assert.equal(cityAfter.activations ?? 0, cityBefore.activations ?? 0);
|
||||
assert.equal(game.actions_left, actionsBeforeCard - 1, 'Only playing the card uses a turn action');
|
||||
for (const [resource, amount] of Object.entries(building.payment))
|
||||
assert.equal(game.players[0].resources[resource] ?? 0, (resourcesBefore[resource] ?? 0) - amount);
|
||||
assert.ok(
|
||||
view(game).cityActions.every((c) => c.buildings.every((b) => b.source === null && !b.free)),
|
||||
'The construction benefit ends after the build',
|
||||
);
|
||||
});
|
||||
|
||||
test('City Development waives resources and the extra action while still activating the city', () => {
|
||||
let game = fixture('action_cards/city_development');
|
||||
game.players[0].cities.find((c: any) => c.position === 'C2').activations = 1;
|
||||
const actionsBeforeCard = game.actions_left;
|
||||
game = move(game, { Playing: { ActionCard: 17 } });
|
||||
game = move(game, { Response: { Payment: [{ culture_tokens: 1 }] } });
|
||||
const building = offer(game);
|
||||
assert.equal(building.source, 'City Development');
|
||||
assert.equal(building.free, true);
|
||||
assert.equal(building.activateCity, true);
|
||||
assert.equal(building.moodWillDecrease, true);
|
||||
assert.deepEqual(building.payment, {});
|
||||
assert.equal(building.reason, null);
|
||||
const resourcesBefore = { ...game.players[0].resources };
|
||||
game = move(game, building.choices[0].action);
|
||||
assert.deepEqual(game.players[0].resources ?? {}, resourcesBefore);
|
||||
assert.equal(game.players[0].cities.find((c: any) => c.position === 'C2').mood_state, 'Angry');
|
||||
assert.equal(game.actions_left, actionsBeforeCard - 1);
|
||||
});
|
||||
|
||||
test('ordinary construction still spends one action, resources and a city activation', () => {
|
||||
let game = fixture('action_cards/city_development');
|
||||
game.players[0].resources = { food: 3, wood: 3, ore: 3 };
|
||||
game.players[0].cities.find((c: any) => c.position === 'C2').activations = 1;
|
||||
const building = offer(game);
|
||||
assert.equal(building.source, null);
|
||||
assert.equal(building.free, false);
|
||||
assert.equal(building.activateCity, true);
|
||||
assert.equal(building.moodWillDecrease, true);
|
||||
assert.deepEqual(building.payment, { food: 1, wood: 1, ore: 1 });
|
||||
const actionsBefore = game.actions_left;
|
||||
game = move(game, building.choices[0].action);
|
||||
assert.equal(game.actions_left, actionsBefore - 1);
|
||||
assert.deepEqual(game.players[0].resources, { food: 2, wood: 2, ore: 2 });
|
||||
assert.equal(game.players[0].cities.find((c: any) => c.position === 'C2').mood_state, 'Angry');
|
||||
});
|
||||
|
|
@ -70,7 +70,10 @@ const advances = {
|
|||
Philosophy: [Brain, 'Gain 1 idea now, and 1 for each Science advance.'],
|
||||
Tactics: [Swords, 'Move army units and use the tactics on action cards.'],
|
||||
Siegecraft: [Castle, 'Cancel a Fortress’s extra die for 2 wood, or its hit protection for 2 ore.'],
|
||||
SteelWeapons: [Anvil, 'Pay 1 ore for +2 combat strength in land battles; +1 versus Steel Weapons.'],
|
||||
SteelWeapons: [
|
||||
Anvil,
|
||||
'Land battles: pay 1 ore for +2 combat value (+1 versus Steel Weapons). Free with Metallurgy against enemies without Steel Weapons.',
|
||||
],
|
||||
Draft: [Users, 'Recruit an infantry unit with 1 mood instead of resources.'],
|
||||
Myths: [Sun, 'Spend mood to prevent event-driven city mood loss, except Pirates.'],
|
||||
Rituals: [Flame, 'Use resources instead of mood when increasing happiness.'],
|
||||
|
|
@ -87,7 +90,10 @@ const advances = {
|
|||
Math: [Calculator, 'Engineering and Roads cost no food.'],
|
||||
Astronomy: [Telescope, 'Navigation and Cartography cost no food.'],
|
||||
Medicine: [HeartPulse, 'Recover one resource spent after recruiting.'],
|
||||
Metallurgy: [Anvil, 'Improve Steel Weapons. When collecting 2+ ore, replace 1 ore with gold.'],
|
||||
Metallurgy: [
|
||||
Anvil,
|
||||
'Steel Weapons is free against enemies without it. When collecting 2+ ore, replace 1 ore with gold.',
|
||||
],
|
||||
Voting: [Vote, 'Spend 1 mood to take a free Increase Happiness action.'],
|
||||
SeparationOfPower: [Scale, 'Culture tokens cannot boost influence attempts against your happy cities.'],
|
||||
CivilLiberties: [Heart, 'Gain 3 mood for an action. Draft now costs 2 mood per infantry.'],
|
||||
|
|
|
|||
|
|
@ -262,6 +262,8 @@ export interface CityActions {
|
|||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
reason?: string | null;
|
||||
payment?: Pile;
|
||||
abilities: { name: string; description: string }[];
|
||||
}[];
|
||||
position: string;
|
||||
|
|
@ -272,6 +274,9 @@ export interface CityActions {
|
|||
payment: Pile;
|
||||
payments?: Pile[] | null;
|
||||
reason: string | null;
|
||||
free?: boolean;
|
||||
activateCity?: boolean;
|
||||
source?: string | null;
|
||||
moodWillDecrease: boolean;
|
||||
choices: { position: string | null; action: Move }[];
|
||||
}[];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue