From ec286d358a362869ef02a263b6553ee4e527a216 Mon Sep 17 00:00:00 2001 From: Frans Bongers Date: Fri, 3 Jan 2025 21:08:25 +0100 Subject: fix: player can choose order for Moral Bonus and Action Points --- play.js | 2 ++ play.ts | 2 ++ rules.js | 71 +++++++++++++++++++++++++++++++++++++---------------- rules.ts | 86 ++++++++++++++++++++++++++++++++++++++++++---------------------- 4 files changed, 111 insertions(+), 50 deletions(-) diff --git a/play.js b/play.js index f5e004f..9e21e82 100644 --- a/play.js +++ b/play.js @@ -377,6 +377,8 @@ function on_update() { action_button('draw_cards', 'Draw cards'); action_button('play_for_ap', 'Play card for Action Points'); action_button('play_for_event', 'Play card for Event'); + action_button('use_ap', 'Use Action Points'); + action_button('use_morale_bonus', 'Use Morale Bonus'); action_button('add_glory', 'Add to Bag of Glory'); action_button('up', 'Up'); action_button('down', 'Down'); diff --git a/play.ts b/play.ts index d8e135f..9e5603c 100644 --- a/play.ts +++ b/play.ts @@ -487,6 +487,8 @@ function on_update() { // action_button('draw_card', 'Draw card'); action_button('play_for_ap', 'Play card for Action Points'); action_button('play_for_event', 'Play card for Event'); + action_button('use_ap', 'Use Action Points'); + action_button('use_morale_bonus', 'Use Morale Bonus'); action_button('add_glory', 'Add to Bag of Glory'); action_button('up', 'Up'); diff --git a/rules.js b/rules.js index 3b1b8e9..89ae075 100644 --- a/rules.js +++ b/rules.js @@ -182,7 +182,6 @@ function start_of_player_turn() { resolve_active_and_proceed(); } const engine_functions = { - check_activate_icon, checkpoint, end_of_player_turn, end_of_turn, @@ -234,7 +233,7 @@ function get_active_node(engine = game.engine) { function get_active_node_args() { const node = get_active_node(game.engine); if (node.t === leaf_node || node.t === function_node) { - return node.a; + return node.a ?? {}; } return null; } @@ -1238,23 +1237,42 @@ states.player_turn = { prompt() { gen_spend_hero_points(); const faction_id = get_active_faction(); + const { use_ap, use_morale_bonus } = get_active_node_args(); const can_spend_hp = game.faction_turn === faction_id && game.hero_points[faction_id] > 0; const can_play_card = game.selected_cards[faction_id].length > 0; - view.prompt = 'Play a card or spend Hero points'; - if (!(can_play_card || can_spend_hp)) { - view.prompt = 'End turn'; - } - else if (!can_play_card && can_spend_hp) { - view.prompt = 'Spend Hero Points or end turn'; + if (can_play_card && can_spend_hp) { + view.prompt = 'Play a card or spend Hero points'; } else if (can_play_card && !can_spend_hp) { view.prompt = 'Play a card'; } + else if (can_spend_hp || use_ap || use_morale_bonus) { + const text_options = []; + if (use_ap) { + text_options.push('Action Points'); + } + if (use_morale_bonus) { + text_options.push('Morale Bonus'); + } + if (can_spend_hp) { + text_options.push('Hero points'); + } + view.prompt = `Use ${text_options.join(', ')} or end turn`; + } + else { + view.prompt = 'End turn'; + } if (can_play_card) { gen_action('play_for_ap'); gen_action('play_for_event'); } - else { + if (use_ap) { + gen_action('use_ap'); + } + if (use_morale_bonus && game.bonuses[data_1.MORALE_BONUS] === data_1.ON) { + gen_action('use_morale_bonus'); + } + if (!can_play_card && !use_ap) { gen_action('done'); } }, @@ -1269,12 +1287,11 @@ states.player_turn = { play_for_ap() { const faction = get_active_faction(); const { strength } = play_card(faction, 'play_for_ap'); - insert_before_active_node(create_seq_node([ - create_leaf_node('choose_area_ap', faction, { - strength, - }), - create_function_node('check_activate_icon'), - ])); + update_active_node_args({ + use_morale_bonus: true, + use_ap: true, + strength, + }); next(); }, play_for_event() { @@ -1283,6 +1300,24 @@ states.player_turn = { insert_before_active_node(create_effects_node(effects)); next(); }, + use_ap() { + const faction = get_active_faction(); + const { strength } = get_active_node_args(); + update_active_node_args({ + use_ap: false, + }); + insert_before_active_node(create_leaf_node('choose_area_ap', faction, { + strength, + })); + next(); + }, + use_morale_bonus() { + update_active_node_args({ + use_morale_bonus: false, + }); + insert_before_active_node(create_leaf_node('activate_icon', get_active_faction())); + next(); + }, }; states.remove_blank_marker = { inactive: 'remove a Blank marker', @@ -1741,12 +1776,6 @@ function add_glory(faction, amount, indent = false) { log_h3(text); } } -function check_activate_icon() { - if (game.bonuses[data_1.MORALE_BONUS] === data_1.ON) { - insert_after_active_node(create_leaf_node('activate_icon', get_active_faction())); - } - resolve_active_and_proceed(); -} function check_initiative() { let initiative; if (game.tracks[data_1.LIBERTY] >= 6 && game.tracks[data_1.COLLECTIVIZATION] >= 6) { diff --git a/rules.ts b/rules.ts index 8eef855..4b06a82 100644 --- a/rules.ts +++ b/rules.ts @@ -337,7 +337,6 @@ function start_of_player_turn() { } const engine_functions: Record = { - check_activate_icon, checkpoint, end_of_player_turn, end_of_turn, @@ -397,7 +396,7 @@ function get_active_node( function get_active_node_args(): T { const node = get_active_node(game.engine); if (node.t === leaf_node || node.t === function_node) { - return node.a; + return node.a ?? {}; } return null; } @@ -1533,27 +1532,45 @@ states.player_turn = { prompt() { gen_spend_hero_points(); const faction_id = get_active_faction(); + const {use_ap, use_morale_bonus} = get_active_node_args(); const can_spend_hp = game.faction_turn === faction_id && game.hero_points[faction_id] > 0; const can_play_card = game.selected_cards[faction_id].length > 0; - view.prompt = 'Play a card or spend Hero points'; - if (!(can_play_card || can_spend_hp)) { - view.prompt = 'End turn'; - } else if (!can_play_card && can_spend_hp) { - view.prompt = 'Spend Hero Points or end turn'; + if (can_play_card && can_spend_hp) { + view.prompt = 'Play a card or spend Hero points'; } else if (can_play_card && !can_spend_hp) { view.prompt = 'Play a card'; + } else if (can_spend_hp || use_ap || use_morale_bonus) { + const text_options = []; + if (use_ap) { + text_options.push('Action Points'); + } + if (use_morale_bonus) { + text_options.push('Morale Bonus'); + } + if (can_spend_hp) { + text_options.push('Hero points'); + } + + view.prompt = `Use ${text_options.join(', ')} or end turn`; + } else { + view.prompt = 'End turn'; } - - // const card = game.cards_in_play[faction_id]; + if (can_play_card) { - // gen_action_card(); gen_action('play_for_ap'); gen_action('play_for_event'); - } else { + } + if (use_ap) { + gen_action('use_ap'); + } + if (use_morale_bonus && game.bonuses[MORALE_BONUS] === ON) { + gen_action('use_morale_bonus'); + } + if (!can_play_card && !use_ap) { gen_action('done'); } }, @@ -1568,15 +1585,11 @@ states.player_turn = { play_for_ap() { const faction = get_active_faction(); const { strength } = play_card(faction, 'play_for_ap'); - - insert_before_active_node( - create_seq_node([ - create_leaf_node('choose_area_ap', faction, { - strength, - }), - create_function_node('check_activate_icon'), - ]) - ); + update_active_node_args({ + use_morale_bonus: true, + use_ap: true, + strength, + }); next(); }, play_for_event() { @@ -1587,6 +1600,30 @@ states.player_turn = { next(); }, + use_ap() { + const faction = get_active_faction(); + const { strength } = get_active_node_args(); + update_active_node_args({ + use_ap: false, + }); + insert_before_active_node( + create_leaf_node('choose_area_ap', faction, { + strength, + }) + ); + next(); + }, + use_morale_bonus() { + // Update args before inserting node before current node, + // otherwise it will update args of inserted node + update_active_node_args({ + use_morale_bonus: false, + }); + insert_before_active_node( + create_leaf_node('activate_icon', get_active_faction()) + ); + next(); + }, }; states.remove_blank_marker = { @@ -2173,15 +2210,6 @@ function add_glory( } } -// Check if Morale bonus is on so player can activate icon -function check_activate_icon() { - if (game.bonuses[MORALE_BONUS] === ON) { - insert_after_active_node( - create_leaf_node('activate_icon', get_active_faction()) - ); - } - resolve_active_and_proceed(); -} function check_initiative() { let initiative: FactionId; -- cgit v1.2.3