summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
Diffstat (limited to 'rules.js')
-rw-r--r--rules.js110
1 files changed, 69 insertions, 41 deletions
diff --git a/rules.js b/rules.js
index 1573b05..5fbc167 100644
--- a/rules.js
+++ b/rules.js
@@ -433,7 +433,7 @@ states.activate_icon = {
inactive: 'activate an icon',
prompt() {
view.prompt = 'Choose an icon to activate';
- const c = cards[game.selected_cards[get_active_faction_id()][0]];
+ const c = cards[game.played_card];
for (const i of c.icons) {
gen_action(i);
}
@@ -764,12 +764,17 @@ states.choose_card = {
inactive: 'choose a card',
prompt() {
view.prompt = 'Choose a card to play this turn';
- const hand = game.hands[player_faction_map[game.active]];
- for (let c of hand)
- gen_action_card(c);
+ const faction = get_active_faction();
+ const hand = game.hands[faction];
+ for (let c of hand) {
+ if (!game.selected_cards[faction].includes(c)) {
+ gen_action_card(c);
+ }
+ }
},
card(c) {
- game.selected_cards[player_faction_map[game.active]].push(c);
+ const faction = get_active_faction();
+ game.selected_cards[faction].push(c);
resolve_active_and_proceed();
},
};
@@ -824,6 +829,7 @@ states.choose_medallion = {
gain_hero_points(faction, 7);
break;
case 2:
+ insert_after_active_node(create_leaf_node('choose_card', faction));
break;
default:
game.medallions[faction].push(m);
@@ -928,32 +934,34 @@ states.game_over = {
view.prompt = game.victory;
},
};
-states.lose_hero_points = {
+function resolve_player_with_most_hero_points(faction) {
+ const value = get_active_node_args().v;
+ if (value < 0) {
+ lose_hero_point(faction, value);
+ }
+ else {
+ gain_hero_points(faction, value);
+ }
+ resolve_active_and_proceed();
+}
+states.select_player_with_most_hero_points = {
inactive: 'choose a Player',
prompt() {
- const args = get_active_node_args();
- view.prompt = 'Choose player to lose Hero Points';
- if (args.t === data_1.PLAYER_WITH_MOST_HERO_POINTS) {
- const factions = get_factions_with_most_hero_poins();
- for (let faction_id of factions) {
- gen_action(faction_player_map[faction_id]);
- }
+ const { v } = get_active_node_args();
+ view.prompt = v < 0 ? 'Choose player to lose Hero Points' : 'Choose player to gain Hero Points';
+ const factions = get_factions_with_most_hero_poins();
+ for (let faction_id of factions) {
+ gen_action(faction_player_map[faction_id]);
}
},
Anarchist() {
- const value = get_active_node_args().v;
- lose_hero_point(data_1.ANARCHISTS_ID, value);
- resolve_active_and_proceed();
+ resolve_player_with_most_hero_points(data_1.ANARCHISTS_ID);
},
Communist() {
- const value = get_active_node_args().v;
- lose_hero_point(data_1.COMMUNISTS_ID, value);
- resolve_active_and_proceed();
+ resolve_player_with_most_hero_points(data_1.COMMUNISTS_ID);
},
Moderate() {
- const value = get_active_node_args().v;
- lose_hero_point(data_1.MODERATES_ID, value);
- resolve_active_and_proceed();
+ resolve_player_with_most_hero_points(data_1.MODERATES_ID);
},
};
states.move_attacks = {
@@ -1027,8 +1035,8 @@ states.player_turn = {
inactive: 'play their turn',
prompt() {
const faction_id = get_faction_id(game.active);
- const can_spend_hp = game.hero_points[faction_id] > 0;
- const can_play_card = game.hands[faction_id].includes(game.selected_cards[faction_id][0]);
+ 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';
@@ -1036,6 +1044,9 @@ states.player_turn = {
else if (!can_play_card && can_spend_hp) {
view.prompt = 'Spend Hero Points or end turn';
}
+ else if (can_play_card && !can_spend_hp) {
+ view.prompt = 'Play a card';
+ }
if (can_play_card) {
gen_action('play_for_ap');
gen_action('play_for_event');
@@ -1053,28 +1064,20 @@ states.player_turn = {
resolve_active_and_proceed(true);
},
play_for_ap() {
- const faction_id = get_faction_id(game.active);
- const card = game.selected_cards[faction_id][0];
- game.played_card = card;
- log_h3(`${game.active} plays ${cards[card].title} for the Action Points`);
- array_remove(game.hands[faction_id], game.hands[faction_id].indexOf(card));
- game.tableaus[faction_id].push(card);
+ 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_id, {
- strength: cards[card].strength,
+ create_leaf_node('choose_area_ap', faction, {
+ strength,
}),
create_function_node('check_activate_icon'),
]));
next();
},
play_for_event() {
- const faction_id = get_faction_id(game.active);
- const card = game.selected_cards[faction_id][0];
- game.played_card = card;
- array_remove(game.hands[faction_id], game.hands[faction_id].indexOf(card));
- game.trash[faction_id].push(card);
- log_h3(`${game.active} plays ${cards[card].title} for the Event`);
- insert_before_active_node(create_effects_node(cards[card].effects));
+ const faction = get_active_faction();
+ const { effects } = play_card(faction, 'play_for_ap');
+ insert_before_active_node(create_effects_node(effects));
next();
},
spend_hp() {
@@ -1513,6 +1516,22 @@ function get_hand_limit(faction) {
}
return hand_limit;
}
+function play_card(faction, type) {
+ const index = game.selected_cards[faction].length - 1;
+ const card_id = game.selected_cards[faction][index];
+ const card = cards[card_id];
+ game.played_card = card_id;
+ log_h3(`${game.active} plays ${card.title} for the ${type === 'play_for_event' ? 'Event' : 'Action Points'}`);
+ array_remove(game.hands[faction], game.hands[faction].indexOf(card_id));
+ array_remove(game.selected_cards[faction], index);
+ if (type === 'play_for_event') {
+ game.trash[faction].push(card_id);
+ }
+ else {
+ game.tableaus[faction].push(card_id);
+ }
+ return card;
+}
function resolve_fascist_test() {
log_h2('Fascist Test', 'fascist');
const test = get_current_event().test;
@@ -1784,7 +1803,7 @@ function resolve_effect(effect) {
condition: effect.type === 'hero_points' &&
effect.target === data_1.PLAYER_WITH_MOST_HERO_POINTS,
resolve: () => {
- return create_leaf_node('lose_hero_points', faction, args);
+ return create_leaf_node('select_player_with_most_hero_points', faction, args);
},
},
{
@@ -1811,7 +1830,7 @@ function resolve_effect(effect) {
{
condition: effect.type === 'hero_points' && effect.target === data_1.INITIATIVE_PLAYER,
resolve: () => {
- return create_leaf_node('gain_hero_points', game.initiative);
+ return create_leaf_node('gain_hero_points', game.initiative, args);
},
},
{
@@ -1851,6 +1870,15 @@ function resolve_effect(effect) {
return create_seq_node(leaf_nodes);
},
},
+ {
+ condition: effect.type === 'play_card',
+ resolve: () => {
+ return create_seq_node([
+ create_leaf_node('choose_card', faction),
+ create_leaf_node('player_turn', faction),
+ ]);
+ },
+ },
];
const strategy = strategies.find((strategy) => strategy.condition);
if (strategy) {