Extend action queues to Great People and event settlers
This commit is contained in:
parent
df1d6b462a
commit
488d30de59
6 changed files with 176 additions and 3 deletions
|
|
@ -43,8 +43,42 @@ pub fn offer(game: &Game, player: usize) -> Option<(String, String)> {
|
|||
{
|
||||
"Choosing an advance"
|
||||
}
|
||||
(PersistentEventType::Incident(i), EventOrigin::Incident(id),
|
||||
PersistentEventRequest::SelectPositions(request))
|
||||
if i.active_player == player && *id == i.incident_id
|
||||
&& [27, 28, 34, 35].contains(id) && handler.priority == 11
|
||||
&& i.selected_player == Some(game.active_player())
|
||||
&& request.choices.iter().all(|position|
|
||||
game.player(game.active_player()).cities.iter().any(|city| city.position == *position)) =>
|
||||
{
|
||||
"Placing a settler"
|
||||
}
|
||||
(PersistentEventType::Incident(i), EventOrigin::Incident(id),
|
||||
PersistentEventRequest::Payment(requests))
|
||||
if i.active_player == player && *id == i.incident_id
|
||||
&& !i.consumed && !i.replaced_by_sacrifice && i.selected_player.is_none()
|
||||
&& game.cache.get_incident(*id).action_card.is_some()
|
||||
&& handler.priority == 10
|
||||
&& requests.iter().any(|request| request.name == "Pay to gain the Action Card") =>
|
||||
{
|
||||
game.cache.get_incident(*id).name.as_str()
|
||||
}
|
||||
(PersistentEventType::Incident(i), EventOrigin::Incident(id),
|
||||
PersistentEventRequest::SelectPlayer(_))
|
||||
if i.active_player == player && *id == 57 && i.incident_id == *id
|
||||
&& handler.priority == 1 && i.selected_player == Some(game.active_player()) =>
|
||||
{
|
||||
"Choose a player"
|
||||
}
|
||||
_ => return None,
|
||||
};
|
||||
// Passing a Great Person to another recipient (or choosing a Diplomat
|
||||
// partner) continues the same unresolved reaction. Preserve queued actions
|
||||
// and the explicit Wait preference while that reaction progresses.
|
||||
if let Some(plan) = game.action_plan.as_ref().filter(|plan|
|
||||
plan.player == player && plan.error.is_none()) {
|
||||
return Some((plan.key.clone(), label.into()));
|
||||
}
|
||||
let key = format!(
|
||||
"{:x}",
|
||||
Sha256::digest(
|
||||
|
|
|
|||
|
|
@ -144,3 +144,106 @@ fn event_triggering_research_is_not_queued() {
|
|||
assert!(action_queue::save(&mut game, 0, &key, vec![research], false).is_err());
|
||||
assert!(game.action_plan.is_none());
|
||||
}
|
||||
|
||||
fn pending_incident(id: u8, third_player: bool) -> Game {
|
||||
let mut value: serde_json::Value = serde_json::from_str(include_str!(
|
||||
"test_games/incidents/great_persons/great_artist.outcome.json"
|
||||
)).unwrap();
|
||||
value["events"][0]["event_type"]["Incident"]["incident_id"] = serde_json::json!(id);
|
||||
value["events"][0]["handler"]["origin"] = serde_json::json!({"Incident": id});
|
||||
value["events"][0]["handler"]["request"]["Payment"][0]["cost"]["origin"] = serde_json::json!({"Incident": id});
|
||||
if third_player {
|
||||
let mut extra = value["players"][1].clone();
|
||||
extra["id"] = serde_json::json!(2);
|
||||
extra["civilization"] = serde_json::json!("Egypt");
|
||||
extra["cities"] = serde_json::json!([]);
|
||||
extra["units"] = serde_json::json!([]);
|
||||
value["players"][2]["id"] = serde_json::json!(3);
|
||||
value["players"].as_array_mut().unwrap().insert(2, extra);
|
||||
}
|
||||
let data: GameData = serde_json::from_value(value).unwrap();
|
||||
let cache = Cache::new(&data.options);
|
||||
Game::from_data(data, cache, GameContext::Play)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn great_person_queue_and_wait_survive_pass_to_next_player() {
|
||||
let mut game = pending_incident(19, true);
|
||||
let (key, _) = action_queue::offer(&game, 0).unwrap();
|
||||
assert!(action_queue::offer(&game, 2).is_none());
|
||||
action_queue::save(&mut game, 0, &key,
|
||||
vec![action(serde_json::json!({"Playing":"EndTurn"}))], true).unwrap();
|
||||
game = board_history::execute(game, action(serde_json::json!({"Response":{"Payment":[{}]}})), 1).unwrap();
|
||||
assert_eq!(game.active_player(), 2);
|
||||
assert_eq!(action_queue::offer(&game, 0).unwrap().0, key);
|
||||
assert!(game.action_plan.as_ref().unwrap().waiting);
|
||||
assert_eq!(game.action_plan.as_ref().unwrap().actions.len(), 1);
|
||||
assert_eq!(game.current_player_index, 0);
|
||||
game = board_history::execute(game.clone(), action(serde_json::json!({"Response":{"Payment":[{"culture_tokens":2}]}})), 2).unwrap();
|
||||
assert!(game.action_plan.is_none());
|
||||
assert_eq!(game.current_player_index, 1);
|
||||
assert!(game.player(2).action_cards.contains(&119));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn population_boom_and_migration_allow_waiting_for_settler_placement() {
|
||||
use server::content::persistent_events::{PersistentEventRequest, PersistentEventType, PositionRequest};
|
||||
for id in [27, 28, 34, 35] {
|
||||
let mut game = pending_incident(id, false);
|
||||
let positions = game.player(1).cities.iter().map(|city| city.position).collect();
|
||||
let event = game.events.last_mut().unwrap();
|
||||
if let PersistentEventType::Incident(info) = &mut event.event_type {
|
||||
info.selected_player = Some(1);
|
||||
}
|
||||
event.player.last_priority_used = Some(11);
|
||||
let handler = event.player.handler.as_mut().unwrap();
|
||||
handler.priority = 11;
|
||||
handler.request = PersistentEventRequest::SelectPositions(PositionRequest::new(
|
||||
positions, 1..=1, "Select a city to gain 1 settler"));
|
||||
let (key, label) = action_queue::offer(&game, 0).unwrap();
|
||||
assert_eq!(label, "Placing a settler");
|
||||
action_queue::save(&mut game, 0, &key, vec![], true).unwrap();
|
||||
assert!(game.action_plan.as_ref().unwrap().waiting);
|
||||
assert_eq!(game.active_player(), 1);
|
||||
action_queue::save(&mut game, 0, &key,
|
||||
vec![action(serde_json::json!({"Playing":"EndTurn"}))], false).unwrap();
|
||||
let count = game.player(1).units.len();
|
||||
let position = game.player(1).cities[0].position.to_string();
|
||||
game = board_history::execute(game.clone(), action(serde_json::json!({"Response":{"SelectPositions":[position]}})), 1).unwrap();
|
||||
assert_eq!(game.player(1).units.len(), count + 1);
|
||||
assert!(game.action_plan.is_none());
|
||||
assert_eq!(game.current_player_index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn great_diplomat_partner_choice_keeps_the_queue() {
|
||||
let mut game = pending_incident(57, true);
|
||||
let (key, _) = action_queue::offer(&game, 0).unwrap();
|
||||
action_queue::save(&mut game, 0, &key,
|
||||
vec![action(serde_json::json!({"Playing":"EndTurn"}))], false).unwrap();
|
||||
game = board_history::execute(game, action(serde_json::json!({"Response":{"Payment":[{"culture_tokens":2}]}})), 1).unwrap();
|
||||
assert_eq!(game.active_player(), 1);
|
||||
assert_eq!(action_queue::offer(&game, 0).unwrap().0, key);
|
||||
assert_eq!(game.action_plan.as_ref().unwrap().actions.len(), 1);
|
||||
game = board_history::execute(game, action(serde_json::json!({"Response":{"SelectPlayer":0}})), 1).unwrap();
|
||||
assert!(game.action_plan.is_none());
|
||||
assert_eq!(game.current_player_index, 1);
|
||||
assert!(!game.permanent_effects.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn declining_a_great_person_during_research_opens_planning() {
|
||||
let data: GameData = serde_json::from_str(include_str!(
|
||||
"test_games/incidents/great_persons/great_engineer.json"
|
||||
)).unwrap();
|
||||
let cache = Cache::new(&data.options);
|
||||
let game = Game::from_data(data, cache, GameContext::Play);
|
||||
let game = board_history::execute(game, action(serde_json::json!({"Playing":{"Advance":{
|
||||
"advance":"Storage", "payment":{"food":2}
|
||||
}}})), 0).unwrap();
|
||||
assert!(action_queue::offer(&game, 0).is_none());
|
||||
let game = board_history::execute(game, action(serde_json::json!({"Response":{"Payment":[{}]}})), 0).unwrap();
|
||||
assert_eq!(game.active_player(), 1);
|
||||
assert!(action_queue::offer(&game, 0).is_some());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -614,3 +614,12 @@ Generic resource gains appear above the civilization's oldest remaining city in
|
|||
the displayed board state. Tile-specific gains keep their existing positions;
|
||||
players without cities retain the screen-position fallback. Replay uses its
|
||||
historical cities. All 14 resource tests and UI checks pass. Engine stays 0.4.121.
|
||||
|
||||
## Viewer 0.1.180 / engine 0.4.122
|
||||
|
||||
Allow the turn owner to queue safe actions while another player considers a
|
||||
passed Great Person, chooses a Great Diplomat partner, or places a settler from
|
||||
Population Boom or Migration. The existing Wait for choice control remains
|
||||
available. Preserve queued actions and the Wait preference as the unresolved
|
||||
Great Person offer passes between players. Verified 10 engine queue tests and
|
||||
3 browser-controller tests covering queueing, Undo, Wait and resumed execution.
|
||||
|
|
|
|||
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.179",
|
||||
"version": "0.1.180",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@boardgamers/clash-web-client",
|
||||
"version": "0.1.179",
|
||||
"version": "0.1.180",
|
||||
"dependencies": {
|
||||
"@boardgamers/protocol": "0.9.0",
|
||||
"lucide-svelte": "^0.577.0",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@boardgamers/clash-web-client",
|
||||
"version": "0.1.179",
|
||||
"version": "0.1.180",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
|
|
|||
|
|
@ -710,3 +710,30 @@ test('acknowledging a predicted city capture keeps movement queries on the plann
|
|||
assert.equal(app.session().view?.movementLeft, 1);
|
||||
} finally { app.close(); }
|
||||
});
|
||||
|
||||
test('Great Person offers expose the normal queue and Wait controls', async () => {
|
||||
const app = harness();
|
||||
let raw = readFileSync(new URL('../../server/tests/test_games/incidents/great_persons/great_artist.outcome.json', import.meta.url), 'utf8');
|
||||
try {
|
||||
app.controller.setPlayer(0);
|
||||
await app.controller.load(strip(raw));
|
||||
assert.equal(app.session().planning?.label, 'Great Artist');
|
||||
assert.equal(app.session().view?.canPlay, true);
|
||||
app.controller.submit({Playing: 'EndTurn'});
|
||||
assert.deepEqual(JSON.parse(app.sent.at(-1)!).QueueMoves.actions, [{Playing: 'EndTurn'}]);
|
||||
raw = engine.tryMove(raw, app.sent.at(-1)!, 0);
|
||||
await app.controller.load(strip(raw));
|
||||
app.controller.undoQueuedAction();
|
||||
raw = engine.tryMove(raw, app.sent.at(-1)!, 0);
|
||||
await app.controller.load(strip(raw));
|
||||
app.controller.waitForChoice();
|
||||
raw = engine.tryMove(raw, app.sent.at(-1)!, 0);
|
||||
await app.controller.load(strip(raw));
|
||||
assert.equal(app.session().planning?.waiting, true);
|
||||
assert.equal(app.session().view?.canPlay, false);
|
||||
raw = engine.tryMove(raw, JSON.stringify({Response: {Payment: [{}]}}), 1);
|
||||
await app.controller.load(strip(raw));
|
||||
assert.equal(app.session().planning, undefined);
|
||||
assert.equal(app.session().view?.canPlay, true);
|
||||
} finally { app.close(); }
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue