summaryrefslogtreecommitdiff
path: root/rules.ts
diff options
context:
space:
mode:
Diffstat (limited to 'rules.ts')
-rw-r--r--rules.ts86
1 files changed, 57 insertions, 29 deletions
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<string, Function> = {
- 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 = any>(): 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;