Fix Assimilator and forced reinforcements; show inactive abilities and recruit inspection
This commit is contained in:
parent
bd29326775
commit
40fb82dc26
20 changed files with 333 additions and 29 deletions
|
|
@ -425,6 +425,15 @@ pub(crate) fn reinforce_barbarians() -> Ability {
|
|||
1,
|
||||
|game, _, cities| {
|
||||
cities.retain(|pos| !get_barbarian_reinforcement_choices(game, *pos).is_empty());
|
||||
// Empty cities have a forced Infantry placement. If the shared
|
||||
// supply can serve all of them, choosing their order changes nothing.
|
||||
if cities.iter().all(|pos| {
|
||||
get_barbarian_reinforcement_choices(game, *pos) == vec![UnitType::Infantry]
|
||||
}) && usize::from(get_barbarians_player(game).available_units().infantry)
|
||||
>= cities.len()
|
||||
{
|
||||
return None;
|
||||
}
|
||||
Some(PositionRequest::new(cities.clone(), 1..=1, "Choose a Barbarian city to reinforce"))
|
||||
},
|
||||
|_, selection, cities| {
|
||||
|
|
|
|||
|
|
@ -149,3 +149,45 @@ fn each_city_receives_one_unit_and_supply_is_rechecked_between_choices() {
|
|||
assert_eq!(get_barbarians_player(&game).get_units(first).len(), 2);
|
||||
assert_eq!(get_barbarians_player(&game).get_units(second).len(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn three_empty_cities_reinforce_automatically_when_supply_can_serve_them_all() {
|
||||
let mut game = setup();
|
||||
let cities = ["B1", "B3", "D2"].map(|pos| city(&mut game, pos, &[]));
|
||||
on_reinforce_barbarians(&mut game, 0, cities.to_vec());
|
||||
assert!(
|
||||
game.events.is_empty(),
|
||||
"forced placements must not ask for city order"
|
||||
);
|
||||
for pos in cities {
|
||||
let units = get_barbarians_player(&game).get_units(pos);
|
||||
assert_eq!(units.len(), 1);
|
||||
assert_eq!(units[0].unit_type, UnitType::Infantry);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn insufficient_infantry_supply_keeps_the_city_choice() {
|
||||
let mut game = setup();
|
||||
let first = city(&mut game, "B1", &[]);
|
||||
let second = city(&mut game, "B3", &[]);
|
||||
let barbarian = get_barbarians_player(&game).index;
|
||||
let limit = game.players[barbarian].unit_limit().infantry;
|
||||
for id in 0..u32::from(limit - 1) {
|
||||
game.players[barbarian].units.push(Unit::new(
|
||||
barbarian,
|
||||
Position::from_offset("D2"),
|
||||
UnitType::Infantry,
|
||||
id,
|
||||
));
|
||||
}
|
||||
game.players[barbarian].next_unit_id = u32::from(limit);
|
||||
on_reinforce_barbarians(&mut game, 0, vec![first, second]);
|
||||
assert!(
|
||||
matches!(&game.current_event_handler().unwrap().request, PersistentEventRequest::SelectPositions(r) if r.choices == vec![first, second])
|
||||
);
|
||||
game = choose(game, EventResponse::SelectPositions(vec![second]));
|
||||
assert!(game.events.is_empty());
|
||||
assert!(get_barbarians_player(&game).get_units(first).is_empty());
|
||||
assert_eq!(get_barbarians_player(&game).get_units(second).len(), 1);
|
||||
}
|
||||
|
|
|
|||
150
server/src/content/objectives/assimilator_tests.rs
Normal file
150
server/src/content/objectives/assimilator_tests.rs
Normal file
|
|
@ -0,0 +1,150 @@
|
|||
use crate::action::Action;
|
||||
use crate::cache::Cache;
|
||||
use crate::combat_listeners::{CombatResult, on_end_combat};
|
||||
use crate::combat_stats::{Battleground, CombatPlayerStats, CombatStats};
|
||||
use crate::content::persistent_events::{
|
||||
EventResponse, PersistentEventRequest, PersistentEventType,
|
||||
};
|
||||
use crate::game::{Game, GameContext};
|
||||
use crate::game_data::GameData;
|
||||
use crate::log::{ActionLogAction, current_turn_log_mut};
|
||||
use crate::playing_actions::PlayingAction;
|
||||
use crate::position::Position;
|
||||
use crate::unit::Units;
|
||||
|
||||
fn qualifies(
|
||||
defending: bool,
|
||||
result: CombatResult,
|
||||
defenders: Units,
|
||||
battleground: Battleground,
|
||||
barbarians: bool,
|
||||
) -> bool {
|
||||
let mut data: serde_json::Value = serde_json::from_str(include_str!(
|
||||
"../../../tests/test_games/tactics_cards/heavy_resistance.json"
|
||||
))
|
||||
.unwrap();
|
||||
for p in data["players"].as_array_mut().unwrap() {
|
||||
p["objective_cards"] = serde_json::json!([]);
|
||||
p["action_cards"] = serde_json::json!([]);
|
||||
p["advances"] = serde_json::json!(["Farming", "Mining", "Tactics"]);
|
||||
}
|
||||
data["players"][0]["objective_cards"] = serde_json::json!([24]);
|
||||
if barbarians {
|
||||
data["players"][1]["civilization"] = serde_json::json!("Barbarians");
|
||||
}
|
||||
let data: GameData = serde_json::from_value(data).unwrap();
|
||||
let cache = Cache::new(&data.options);
|
||||
let mut game = Game::from_data(data, cache, GameContext::Play);
|
||||
game.log_index = 1;
|
||||
current_turn_log_mut(&mut game)
|
||||
.actions
|
||||
.push(ActionLogAction::new(
|
||||
Action::Playing(PlayingAction::EndTurn),
|
||||
0,
|
||||
None,
|
||||
0,
|
||||
));
|
||||
let stats = CombatStats::new(
|
||||
battleground,
|
||||
false,
|
||||
CombatPlayerStats::new(
|
||||
usize::from(defending),
|
||||
Units {
|
||||
infantry: 2,
|
||||
..Units::empty()
|
||||
},
|
||||
Position::from_offset("C2"),
|
||||
),
|
||||
CombatPlayerStats::new(
|
||||
usize::from(!defending),
|
||||
defenders,
|
||||
Position::from_offset("C1"),
|
||||
),
|
||||
Some(result),
|
||||
None,
|
||||
);
|
||||
on_end_combat(&mut game, stats);
|
||||
// Barbarian rewards resolve before combat objectives are checked.
|
||||
while let Some(handler) = game.current_event_handler() {
|
||||
let PersistentEventRequest::ResourceReward(request) = &handler.request else {
|
||||
break;
|
||||
};
|
||||
let response = Action::Response(EventResponse::ResourceReward(
|
||||
request.reward.payment_options.default.clone(),
|
||||
));
|
||||
let player = game.active_player();
|
||||
game = crate::game_api::execute(game, response, player);
|
||||
}
|
||||
game.events.iter().any(|event| matches!(&event.event_type, PersistentEventType::SelectObjectives(info) if info.shown_objective.as_deref() == Some("Barbarian Conquest")))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn defending_a_city_against_barbarians_never_offers_assimilator() {
|
||||
assert!(!qualifies(
|
||||
true,
|
||||
CombatResult::DefenderWins,
|
||||
Units {
|
||||
infantry: 2,
|
||||
..Units::empty()
|
||||
},
|
||||
Battleground::City,
|
||||
true
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn assimilator_requires_winning_as_attacker_against_two_barbarian_army_units_in_a_city() {
|
||||
let army = Units {
|
||||
infantry: 1,
|
||||
cavalry: 1,
|
||||
..Units::empty()
|
||||
};
|
||||
for battleground in [Battleground::City, Battleground::CityWithFortress] {
|
||||
assert!(qualifies(
|
||||
false,
|
||||
CombatResult::AttackerWins,
|
||||
army.clone(),
|
||||
battleground,
|
||||
true
|
||||
));
|
||||
assert!(!qualifies(
|
||||
false,
|
||||
CombatResult::DefenderWins,
|
||||
army.clone(),
|
||||
battleground,
|
||||
true
|
||||
));
|
||||
assert!(!qualifies(
|
||||
false,
|
||||
CombatResult::Draw,
|
||||
army.clone(),
|
||||
battleground,
|
||||
true
|
||||
));
|
||||
assert!(!qualifies(
|
||||
false,
|
||||
CombatResult::AttackerWins,
|
||||
army.clone(),
|
||||
battleground,
|
||||
false
|
||||
));
|
||||
}
|
||||
assert!(!qualifies(
|
||||
false,
|
||||
CombatResult::AttackerWins,
|
||||
army,
|
||||
Battleground::Land,
|
||||
true
|
||||
));
|
||||
assert!(!qualifies(
|
||||
false,
|
||||
CombatResult::AttackerWins,
|
||||
Units {
|
||||
infantry: 1,
|
||||
settlers: 1,
|
||||
..Units::empty()
|
||||
},
|
||||
Battleground::City,
|
||||
true
|
||||
));
|
||||
}
|
||||
|
|
@ -13,6 +13,10 @@ use itertools::Itertools;
|
|||
#[path = "bold_tests.rs"]
|
||||
mod bold_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "assimilator_tests.rs"]
|
||||
mod assimilator_tests;
|
||||
|
||||
// English card face: https://boardgamegeek.com/image/6509349/bigleaguecreative
|
||||
pub(crate) fn conqueror() -> Objective {
|
||||
let name = "Conqueror";
|
||||
|
|
@ -297,10 +301,11 @@ pub(crate) fn barbarian_conquest() -> Objective {
|
|||
11,
|
||||
|game, p, s| {
|
||||
let player = p.index;
|
||||
if s.is_winner(player)
|
||||
if s.is_attacker(player)
|
||||
&& s.is_winner(player)
|
||||
&& s.battleground.is_city()
|
||||
&& !s.opponent_is_human(player, game)
|
||||
&& s.defender.present.amount() >= 2
|
||||
&& s.opponent_player(player, game).civilization.is_barbarian()
|
||||
&& s.defender.fighters(s.battleground).amount() >= 2
|
||||
{
|
||||
objective_is_ready(game.player_mut(player), name);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -369,13 +369,14 @@ pub fn view(game: &Game, seat: Option<usize>) -> Value {
|
|||
item
|
||||
}).collect::<Vec<_>>();
|
||||
advances.sort_by_key(|a| a["name"].as_str().unwrap_or_default().to_string());
|
||||
let special_actions = actions::special(game, seat, can_play);
|
||||
let mut result = json!({"logOriginNames":log_origin_names,"cardCatalog":card_catalog,"eventCatalog":event_catalog,"pendingEvent":pending_event,"civilizationDraft":civilization_draft,"waitingFor":waiting_for,"activePlayers":active_players,"activePlayer":active,"canPlay":can_play,"supportedPhase":supported_phase,"players":players,"cities":cities,"advances":advances,"objectiveCards":objective_cards,"objectiveDecision":objective_decision(game, seat),
|
||||
"influenceContext":decisions::influence_context(game, seat), "choiceDecision":choice, "explorationDecision":exploration, "wonderCards":wonder_cards, "wonderCatalog":wonder_catalog, "builtWonders":built_wonders, "decision":decision,
|
||||
"civilizations":crate::game_setup::civilization_choices(game, seat).iter().map(|c|json!({"name":c.name,
|
||||
"advances":c.special_advances.iter().map(|a|json!({"name":a.name,"description":a.description,"requirement":a.requirement.name(game)})).collect::<Vec<_>>(),
|
||||
"leaders":c.leaders.iter().map(|l|json!({"name":l.name,"abilities":l.abilities.iter().map(|a|json!({"name":a.name,"description":a.description})).collect::<Vec<_>>()})).collect::<Vec<_>>(),
|
||||
"action":Action::ChooseCivilization(c.name.clone())})).collect::<Vec<_>>(),
|
||||
"actionCards":actions::cards(game,seat,can_play), "specialActions":actions::special(game,seat,can_play), "influence":actions::influence(game,seat,can_play),
|
||||
"actionCards":actions::cards(game,seat,can_play), "specialActions":special_actions.iter().filter(|a| a["reason"].is_null()).collect::<Vec<_>>(), "influence":actions::influence(game,seat,can_play),
|
||||
"collectActions":if can_play {crate::collect::available_collect_actions(game,seat).iter().map(|a|{ let cost = a.cost(game,seat); json!({"value":a,"name":a.origin(p).name(game),"free":cost.free,"payment":cost.payment_options(p,a.origin(p)).default_payment()}) }).collect::<Vec<_>>()} else {vec![]},
|
||||
"happinessActions":if can_play {crate::happiness::available_happiness_actions(game,seat).iter().map(|a|json!({"value":a,"name":a.origin(p).name(game),"free":a.cost(game,seat).free,"surcharge":a.payment_options(game,seat).default})).collect::<Vec<_>>()} else {vec![]},
|
||||
"units":p.units.iter().map(|u|json!({"id":u.id,"type":u.unit_type,"position":u.position,"carrier":u.carrier_id,"pirate":u.pirate,"movementNotes":movement_notes(game,p,u)})).collect::<Vec<_>>(),
|
||||
|
|
@ -386,6 +387,7 @@ pub fn view(game: &Game, seat: Option<usize>) -> Value {
|
|||
"cityActions":actions::cities(game, seat, can_play), "settlers":actions::settlers(game, seat, (can_play && PlayingActionType::MoveUnits.is_available(game,seat).is_ok()) || (moving && seat == active)),
|
||||
"stopMovement":if moving && seat == active {Some(Action::Movement(crate::movement::MovementAction::Stop))} else {None},
|
||||
"canUndo":seat == active && game.can_undo(),"canRedo":seat == active && game.can_redo(),"canEndTurn":can_play && PlayingActionType::EndTurn.is_available(game, seat).is_ok()});
|
||||
result["unavailableSpecialActions"] = json!(special_actions.iter().filter(|a| !a["reason"].is_null()).collect::<Vec<_>>());
|
||||
result["activeEffects"] = json!(active_effects);
|
||||
result
|
||||
}
|
||||
|
|
|
|||
|
|
@ -344,15 +344,23 @@ pub fn cards(game: &Game, seat: usize, can_play: bool) -> Vec<Value> {
|
|||
|
||||
pub fn special(game: &Game, seat: usize, can_play: bool) -> Vec<Value> {
|
||||
use crate::content::custom_actions::{CustomAction, SpecialActionExecution};
|
||||
if !can_play {
|
||||
return vec![];
|
||||
}
|
||||
game.available_custom_actions(seat).iter().flat_map(|info| {
|
||||
game.player(seat).special_actions.values().flat_map(|info| {
|
||||
let SpecialActionExecution::Action(execution) = &info.execution else { return vec![]; };
|
||||
let cities = if info.city_bound().is_some() {
|
||||
let mut reason = if seat != game.active_player() {
|
||||
Some("Wait for your turn".to_string())
|
||||
} else if !can_play {
|
||||
Some("Finish the current decision first".to_string())
|
||||
} else {
|
||||
info.action.playing_action_type().is_available(game, seat).err()
|
||||
};
|
||||
let mut cities: Vec<Option<Position>> = if info.city_bound().is_some() {
|
||||
game.player(seat).cities.iter().filter(|c|info.is_city_available(game,c)).map(|c|Some(c.position)).collect()
|
||||
} else { vec![None] };
|
||||
cities.into_iter().map(|city|json!({"name":info.event_origin.name(game),"description":execution.ability.description,"position":city,
|
||||
if cities.is_empty() {
|
||||
reason.get_or_insert_with(|| "Custom action cannot be played".to_string());
|
||||
cities.push(None);
|
||||
}
|
||||
cities.into_iter().map(|city|json!({"name":info.event_origin.name(game),"description":execution.ability.description,"position":city,"reason":reason,
|
||||
"cost":info.cost.cost.payment_options(game.player(seat),info.event_origin.clone()).default_payment(),
|
||||
"free":info.cost.cost.free,
|
||||
"activatesCity":(info.custom_action_type() == crate::content::custom_actions::CustomActionType::GoldenAge)
|
||||
|
|
|
|||
|
|
@ -108,3 +108,9 @@ Single-route trade rewards include Alphabet's 2-idea option. The compact reward
|
|||
# Viewer 0.1.52
|
||||
|
||||
The action bar selects an available free Collect or Increase happiness variant first, including Free Economy and Voting. Drawn action cards appear in the existing card reveal queue with their action and battle rules, including end-of-age draws. The Confirm unit moves preference has been removed from BGS and the viewer; moves always wait for confirmation, including for accounts with a previously disabled preference. Engine 0.4.54 is unchanged.
|
||||
|
||||
# Viewer 0.1.53 / engine 0.4.55
|
||||
|
||||
Assimilator requires winning as the attacker in a Barbarian city defended by at least two army units. Defending your own city no longer offers this objective, and non-army units do not count toward its threshold. Barbarian reinforcement skips city-order decisions when all remaining placements are forced Infantry and supply is sufficient for every city. Limited supply and unit-type choices still require a decision. Owned custom abilities remain visible with disabled controls and their engine availability reason, both in Abilities and leader details. Passive effects keep their automatic behavior. Golden Age controller coverage and all 45 leaders under each government are checked. Existing completed objectives and game history are preserved.
|
||||
|
||||
Recruit remains open for inspection when recruiting is unavailable, with a muted label and eye icon, including after all actions have been spent and during replay.
|
||||
|
|
|
|||
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.52",
|
||||
"version": "0.1.53",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@boardgamers/clash-web-client",
|
||||
"version": "0.1.52",
|
||||
"version": "0.1.53",
|
||||
"dependencies": {
|
||||
"@boardgamers/protocol": "0.9.0",
|
||||
"lucide-svelte": "^0.577.0",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@boardgamers/clash-web-client",
|
||||
"version": "0.1.52",
|
||||
"version": "0.1.53",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<script lang="ts">
|
||||
import { X, Sparkles, Zap, ArrowLeft, MapPin, Drama, ArrowRight } from 'lucide-svelte';
|
||||
import { activeCityAbility, groupAbilities } from './abilities';
|
||||
import { activeCityAbility, groupAbilities, abilityReason } from './abilities';
|
||||
import CityFacts from './CityFacts.svelte';
|
||||
import InfluencePicker from './InfluencePicker.svelte';
|
||||
import { activeInfluence } from './influence';
|
||||
|
|
@ -14,7 +14,12 @@
|
|||
}: { controller: Controller; onHighlight: (position: string | null) => void } = $props();
|
||||
const session = $derived(controller.session);
|
||||
const drafts = $derived($session.view && controller.shogunateDraftOffers());
|
||||
const groups = $derived(groupAbilities($session.view?.specialActions));
|
||||
const groups = $derived(
|
||||
groupAbilities([
|
||||
...($session.view?.specialActions ?? []),
|
||||
...($session.availableOnly ? [] : ($session.view?.unavailableSpecialActions ?? [])),
|
||||
]),
|
||||
);
|
||||
const active = $derived(activeCityAbility($session));
|
||||
const influence = $derived(activeInfluence($session));
|
||||
const influenceTargets = $derived($session.view?.influence ?? []);
|
||||
|
|
@ -84,13 +89,14 @@
|
|||
{#each groups as group}
|
||||
{@const action = group.offer}
|
||||
{@const city = $session.view?.cities.find((c) => c.position === action.activatesCity)}
|
||||
<article class="ability-offer">
|
||||
<article class="ability-offer" class:unavailable={!!action.reason}>
|
||||
<h3>{action.name}</h3>
|
||||
<p><ResourceText text={action.description} /></p>
|
||||
{#if action.reason}<p class="settler-empty">{abilityReason(action.reason)}</p>{/if}
|
||||
{#if city && city.activations > 0}<ActivationStatus {city} warning />{/if}
|
||||
<button
|
||||
class="primary wide"
|
||||
disabled={!!$session.playback || $session.pending}
|
||||
disabled={!!action.reason || !!$session.playback || $session.pending}
|
||||
onclick={() =>
|
||||
action.position
|
||||
? controller.chooseAbility(group.key)
|
||||
|
|
|
|||
|
|
@ -282,6 +282,13 @@
|
|||
c.happiness.some((h) => !!h.action),
|
||||
),
|
||||
);
|
||||
let recruitAvailable = $derived(
|
||||
!$session.playback &&
|
||||
$session.view?.cityActions.some(
|
||||
(c) =>
|
||||
c.recruits.some((r) => !r.reason && r.available > 0) || c.leaders?.some((l) => l.reason === null),
|
||||
),
|
||||
);
|
||||
let settlersAvailable = $derived(
|
||||
!!$session.view?.stopMovement ||
|
||||
(!!$session.view?.canPlay &&
|
||||
|
|
@ -290,6 +297,7 @@
|
|||
);
|
||||
let abilitiesAvailable = $derived(
|
||||
!!$session.view?.specialActions?.length ||
|
||||
!!$session.view?.unavailableSpecialActions?.length ||
|
||||
!!$session.view?.influence?.length ||
|
||||
!!($session.view && controller.shogunateDraftOffers().length),
|
||||
);
|
||||
|
|
@ -1175,7 +1183,8 @@
|
|||
<button
|
||||
class:active={$session.mode === 'collect'}
|
||||
title={collectAvailable
|
||||
? ($session.view?.collectActions?.find((offer) => offer.free)?.name ?? 'Collect resources · 1 action')
|
||||
? ($session.view?.collectActions?.find((offer) => offer.free)?.name ??
|
||||
'Collect resources · 1 action')
|
||||
: (city?.reason ?? 'No city can collect resources')}
|
||||
data-tutorial="collect"
|
||||
aria-label="Collect resources"
|
||||
|
|
@ -1222,14 +1231,22 @@
|
|||
<button
|
||||
class="desktop-action"
|
||||
class:active={$session.mode === 'city' && $session.cityTab === 'recruit'}
|
||||
class:inspect-only={!recruitAvailable}
|
||||
data-tutorial="recruit"
|
||||
aria-label="Recruit units"
|
||||
title="Recruit units · 1 action"
|
||||
disabled={!city || (!$session.playback && (!$session.view?.canPlay || $session.pending))}
|
||||
title={recruitAvailable
|
||||
? 'Recruit units · 1 action'
|
||||
: 'View cities · Browse buildings, units and costs'}
|
||||
disabled={!city}
|
||||
onclick={() => {
|
||||
confirmEnd = false;
|
||||
controller.openCities(undefined, 'recruit');
|
||||
}}><Users size={21} /><span>Recruit</span></button
|
||||
}}
|
||||
><Users size={21} /><span>Recruit</span>{#if !recruitAvailable}<Eye
|
||||
class="action-inspect"
|
||||
size={10}
|
||||
aria-hidden="true"
|
||||
/>{/if}</button
|
||||
>
|
||||
<button
|
||||
class="desktop-action"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
<script lang="ts">
|
||||
import { Crown, Sparkles, ChevronRight, ArrowRight } from 'lucide-svelte';
|
||||
import type { PlayerView, View, Move, Pile } from './types';
|
||||
import { abilityReason } from './abilities';
|
||||
import ResourceText from './ResourceText.svelte';
|
||||
let {
|
||||
leader,
|
||||
|
|
@ -32,9 +33,14 @@
|
|||
<strong><Sparkles size={13} />{ability.name}</strong>
|
||||
<p><ResourceText text={ability.description} /></p>
|
||||
{#if action && onUse}
|
||||
<button class="primary wide" disabled={pending} onclick={() => onUse?.(action.action, action.cost)}>
|
||||
<button
|
||||
class="primary wide"
|
||||
disabled={pending || !!action.reason}
|
||||
onclick={() => onUse?.(action.action, action.cost)}
|
||||
>
|
||||
Use {ability.name}<ArrowRight size={16} />
|
||||
</button>
|
||||
{#if action.reason}<small>{abilityReason(action.reason)}</small>{/if}
|
||||
{/if}
|
||||
</div>
|
||||
{/each}
|
||||
|
|
|
|||
|
|
@ -158,7 +158,10 @@
|
|||
<LeaderDetails
|
||||
{leader}
|
||||
compact
|
||||
actions={$session.view?.specialActions}
|
||||
actions={[
|
||||
...($session.view?.specialActions ?? []),
|
||||
...($session.view?.unavailableSpecialActions ?? []),
|
||||
]}
|
||||
pending={$session.pending}
|
||||
onUse={(action, payment) => controller.submit(action, payment)}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -141,7 +141,9 @@
|
|||
<LeaderDetails
|
||||
{leader}
|
||||
civilization={player.civilization}
|
||||
actions={player.index === $session.seat ? $session.view?.specialActions : []}
|
||||
actions={player.index === $session.seat
|
||||
? [...($session.view?.specialActions ?? []), ...($session.view?.unavailableSpecialActions ?? [])]
|
||||
: []}
|
||||
pending={$session.pending}
|
||||
onUse={(action, payment) => controller.submit(action, payment)}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -21,3 +21,10 @@ export function activeCityAbility(s: Session) {
|
|||
(group) => group.key === s.abilityChoice && group.offers.every((offer) => offer.position),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
export function abilityReason(reason?: string | null) {
|
||||
if (reason === 'Custom action cannot be played' || reason === 'Custom action not available') return 'Unavailable';
|
||||
if (reason === 'Not enough resources for action type') return 'Not enough resources';
|
||||
return reason ?? '';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2378,3 +2378,34 @@ test('automatic next movement group selects all its units after a group finishes
|
|||
assert.deepEqual(app.sent, [], 'preselection does not perform a move');
|
||||
} finally { app.close(); }
|
||||
});
|
||||
|
||||
|
||||
test('Sri Gupta Golden Age opens the research tree and can be selected through the controller', async () => {
|
||||
const app = paymentController(), c = app.controller;
|
||||
try {
|
||||
let game = JSON.parse(await engine.init(2, [], { civilization: 'Random' }, 'golden-age-ui', {}));
|
||||
const seat = engine.currentPlayer(JSON.stringify(game)), player = game.players[seat];
|
||||
player.civilization = 'India';
|
||||
player.units.push({ id: player.next_unit_id++, position: player.cities[0].position, unit_type: { Leader: 'SriGupta' } });
|
||||
player.resources = { food: 7, wood: 7, ore: 7, ideas: 7, gold: 7, mood_tokens: 8, culture_tokens: 8 };
|
||||
player.resource_limit.food = 7;
|
||||
game.actions_left = 0;
|
||||
c.setPlayer(seat);
|
||||
await c.load(engine.stripSecret(JSON.stringify(game), seat));
|
||||
const offer = app.session().view!.specialActions!.find((action) => action.name === 'Golden Age')!;
|
||||
assert.ok(offer);
|
||||
assert.equal(offer.free, true);
|
||||
c.patch({ abilitiesOpen: true });
|
||||
c.submit(offer.action, offer.cost);
|
||||
let processed = 0;
|
||||
while (processed < app.sent.length) {
|
||||
game = JSON.parse(engine.tryMove(JSON.stringify(game), app.sent[processed++], seat));
|
||||
await c.load(engine.stripSecret(JSON.stringify(game), seat));
|
||||
}
|
||||
assert.equal(app.session().mode, 'research');
|
||||
assert.equal(app.session().view!.decision!.advanceMode, 'paid');
|
||||
const writing = app.session().view!.advances.find((advance) => advance.id === 'Writing')!;
|
||||
c.submit(writing.action!);
|
||||
assert.deepEqual(JSON.parse(app.sent[processed]), { Response: { SelectAdvance: 'Writing' } });
|
||||
} finally { app.close(); }
|
||||
});
|
||||
|
|
|
|||
|
|
@ -529,7 +529,7 @@ export class Controller {
|
|||
cardsOpen: old.pending || view.decision ? false : old.cardsOpen,
|
||||
wondersOpen: old.pending || view.decision ? false : old.wondersOpen,
|
||||
abilitiesOpen:
|
||||
old.pending || view.decision || (!view.specialActions?.length && !view.influence?.length)
|
||||
old.pending || view.decision || (!view.specialActions?.length && !view.unavailableSpecialActions?.length && !view.influence?.length)
|
||||
? false
|
||||
: old.abilitiesOpen,
|
||||
cardDraws: [...old.cardDraws, ...drawn].filter((draw) =>
|
||||
|
|
|
|||
|
|
@ -127,6 +127,7 @@ test('Golden Age researches a new category for culture plus resources, activates
|
|||
!view(g).specialActions?.some((a) => a.name === 'Golden Age'),
|
||||
'No dead-end action when research is unaffordable',
|
||||
);
|
||||
assert.ok(view(g).unavailableSpecialActions?.some((a) => a.name === 'Golden Age' && a.reason), 'owned Golden Age stays visible with a disabled reason');
|
||||
});
|
||||
|
||||
async function influence(leader = false) {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ async function setup(civ: string, leader?: string) {
|
|||
{},
|
||||
);
|
||||
g = move(g, { ChooseCivilization: civ });
|
||||
g = move(g, { ChooseCivilization: 'Rome' });
|
||||
g = move(g, { ChooseCivilization: civ === 'Rome' ? 'India' : 'Rome' });
|
||||
const p = g.players[seat(g)];
|
||||
p.resources = { food: 7, wood: 7, ore: 7, ideas: 7, gold: 7, mood_tokens: 8, culture_tokens: 8 };
|
||||
p.resource_limit.food = 7;
|
||||
|
|
@ -82,6 +82,7 @@ test('Beloved charges once and records protected city tokens', async () => {
|
|||
assert.equal(after.players[index].resources.culture_tokens, 7);
|
||||
assert.equal(after.players[index].custom_data[`Beloved:${city}`].Number, 1);
|
||||
assert.ok(!view(after).specialActions.some((a: any) => a.name === 'Beloved'));
|
||||
assert.ok(view(after).unavailableSpecialActions.some((a: any) => a.name === 'Beloved' && /already played/.test(a.reason)));
|
||||
});
|
||||
test('Imhotep discounts an Academy and Innovator pays once on activation', async () => {
|
||||
const g = await setup('Egypt', 'Imhotep'),
|
||||
|
|
@ -1335,11 +1336,17 @@ test('An allied pirate is removed before a colored ship in a naval battle', asyn
|
|||
assert.equal(after.players[pirates.id].held_units?.ships ?? 0, 0);
|
||||
});
|
||||
|
||||
test('all 27 new leaders load with full research under each government', async (t) => {
|
||||
test('all 45 leaders load with full research under each government', async (t) => {
|
||||
const picker = view(
|
||||
await engine.init(2, [], { civilization: 'ChooseCivilization' }, 'all-leader-abilities', {}),
|
||||
);
|
||||
for (const name of [
|
||||
'Rome',
|
||||
'Greece',
|
||||
'China',
|
||||
'Vikings',
|
||||
'Babylonia',
|
||||
'India',
|
||||
'Aztecs',
|
||||
'Carthage',
|
||||
'Celts',
|
||||
|
|
@ -1378,9 +1385,9 @@ test('all 27 new leaders load with full research under each government', async (
|
|||
const visible = view(state, index);
|
||||
assert.equal(visible.players[index].leaders[0].name, leader.name);
|
||||
assert.equal(
|
||||
visible.players[index].civilizationAdvances.filter((a: any) => a.owned).length,
|
||||
visible.players[index].civilizationAdvances.length,
|
||||
4,
|
||||
`${name}: all civilization advances unlock`,
|
||||
`${name}: all civilization advances remain visible`,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -289,7 +289,9 @@ export interface View {
|
|||
leaders: { name: string; abilities: { name: string; description: string }[] }[];
|
||||
}[];
|
||||
actionCards?: ActionCard[];
|
||||
unavailableSpecialActions?: View['specialActions'];
|
||||
specialActions?: {
|
||||
reason?: string | null;
|
||||
name: string;
|
||||
description: string;
|
||||
position: string | null;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue