From e32cc3efe1c1ef5378cef422555e8c8289449938 Mon Sep 17 00:00:00 2001 From: Frans Bongers Date: Sun, 1 Dec 2024 20:07:32 +0100 Subject: add card effects --- rules.js | 163 +++++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 113 insertions(+), 50 deletions(-) (limited to 'rules.js') diff --git a/rules.js b/rules.js index 3fa056a..62592e5 100644 --- a/rules.js +++ b/rules.js @@ -33,21 +33,7 @@ const front_names = { d: 'the Front closest to Defeat', v: 'the Front closest to Victory', }; -const tracks = [ - data_1.LIBERTY, - data_1.COLLECTIVIZATION, - data_1.GOVERNMENT, - data_1.SOVIET_SUPPORT, - data_1.FOREIGN_AID, -]; -const track_names = { - [data_1.LIBERTY]: 'Liberty', - [data_1.COLLECTIVIZATION]: 'Collectivization', - [data_1.GOVERNMENT]: 'Government', - [data_1.SOVIET_SUPPORT]: 'Soviet Support', - [data_1.FOREIGN_AID]: 'Foreign Aid', -}; -const { cards, } = data_1.default; +const { cards, tracks, } = data_1.default; const faction_cards = { [ANARCHISTS_ID]: make_list(37, 54), [COMMUNISTS_ID]: make_list(19, 36), @@ -311,6 +297,7 @@ function setup(seed, _scenario, _options) { [MODERATES_ID]: [], }, tracks: [5, 5, 6, 3, 3], + triggered_track_effects: [[], [], [], [], []], log: [], undo: [], turn: 1, @@ -341,12 +328,7 @@ function start_turn() { game.current_events.push(cardId); const card = cards[cardId]; log_h3('Fascist Event: ' + card.title); - game.engine = card.effects.map((_effect, index) => ({ - t: leaf_node, - s: 'resolve_event', - p: game.initiative, - a: index, - })); + game.engine = card.effects.map((effect) => resolve_effect(effect, game.initiative)); game.engine.push({ t: 'f', f: 'setup_choose_card', @@ -375,12 +357,34 @@ states.add_glory = { resolve_active_and_proceed(); }, }; +states.attack_front = { + inactive: 'attack a Front', + prompt() { + const node = get_active_node(); + const front = node.a.f; + view.prompt = 'Attack ' + front_names[front]; + if (front === 'd' || front === 'v') { + const fronts = get_fronts_closest_to(front); + fronts.forEach((id) => gen_action('front', id)); + } + else { + gen_action('front', front); + } + }, + front(f) { + const node = get_active_node(); + const value = node.a.v; + game.fronts[f] += value; + log_h3(`${Math.abs(value)} attacks added to ${front_names[f]}`); + resolve_active_and_proceed(); + }, +}; states.choose_area_ap = { inactive: 'choose area to use Action Points', prompt() { view.prompt = 'Choose area of the board to affect'; - for (let track_id of tracks) { - gen_action_standee(track_id); + for (let track of tracks) { + gen_action_standee(track.id); } }, standee(track_id) { @@ -414,7 +418,7 @@ states.move_track_up_or_down = { const node = get_active_node(); move_track(node.a.track_id, node.a.strength); resolve_active_and_proceed(); - } + }, }; states.choose_card = { inactive: 'choose a card', @@ -433,6 +437,28 @@ states.choose_card = { resolve_active_and_proceed(); }, }; +states.lose_hero_points = { + inactive: 'choose a Player', + prompt() { + view.prompt = 'Lose Hero Points'; + }, +}; +states.move_track = { + inactive: 'move a Track', + prompt() { + const node = get_active_node(); + const track = node.a.t; + const value = node.a.v; + view.prompt = `Move ${tracks[track].name} ${value > 0 ? 'up' : 'down'}`; + gen_action_standee(track); + }, + standee(s) { + const node = get_active_node(); + const value = node.a.v; + move_track(s, value); + resolve_active_and_proceed(); + }, +}; states.player_turn = { inactive: 'play their turn', prompt() { @@ -519,15 +545,7 @@ states.resolve_event = { const node = get_active_node(game.engine); const effect = card.effects[node.a]; view.prompt = get_event_prompt(effect); - if (effect.type === 'attack' && - (effect.target === 'd' || effect.target === 'v')) { - const fronts = get_fronts_closest_to(effect.target); - fronts.forEach((id) => gen_action('front', id)); - } - else if (effect.type === 'attack') { - gen_action('front', effect.target); - } - else if (effect.type === 'track') { + if (effect.type === 'track') { gen_action('standee', effect.target); } else if (effect.type === 'hero_points' && @@ -538,20 +556,6 @@ states.resolve_event = { } } }, - front(f) { - const card = get_current_event(); - const value = card.effects[get_active_node_args()].value; - game.fronts[f] -= value; - log_h3(`${value} attacks added to ${front_names[f]}`); - resolve_active_and_proceed(); - }, - standee(s) { - const effect = get_current_event().effects[get_active_node_args()]; - const value = effect.value; - game.tracks[s] += value; - log_h3(`${track_names[effect.target]} decreased by ${Math.abs(value)}`); - resolve_active_and_proceed(); - }, Anarchist() { lose_hero_point(ANARCHISTS_ID, 1); resolve_active_and_proceed(); @@ -607,7 +611,66 @@ function resolve_fascist_test() { log_h2('Fascist test is resolved'); next(); } -function move_track(track, change) { +function move_track(track_id, change) { + const current_value = game.tracks[track_id]; + let new_value = current_value + change; + new_value = Math.max(new_value, track_id === data_1.GOVERNMENT ? 1 : 0); + new_value = Math.min(new_value, 10); + game.tracks[track_id] = new_value; + log(`${game.active} moves ${get_track_name(track_id)} to ${new_value}`); + const triggered_spaces = change > 0 + ? make_list(current_value + 1, new_value).reverse() + : make_list(new_value, current_value - 1); + triggered_spaces.forEach((space_id) => { + const trigger = tracks[track_id].triggers[space_id]; + if (trigger !== null && + !game.triggered_track_effects[track_id].includes(space_id)) { + if (space_id !== 0) { + game.triggered_track_effects[track_id].push(space_id); + } + const node = resolve_effect(trigger); + if (node !== null) { + insert_after_active_node(node); + } + } + }); +} +function resolve_effect(effect, faction = get_active_faction()) { + if (effect.type === 'attack') { + return { + t: leaf_node, + p: faction, + s: 'attack_front', + a: { + f: effect.target, + v: effect.value, + }, + }; + } + if (effect.type === 'track') { + return { + t: leaf_node, + p: faction, + s: 'move_track', + a: { + t: effect.target, + v: effect.value, + }, + }; + } + if (effect.type === 'hero_points' && + effect.target === data_1.PLAYER_WITH_MOST_HERO_POINTS) { + return { + t: leaf_node, + p: faction, + s: 'lose_hero_points', + a: { + p: effect.target, + v: effect.value, + }, + }; + } + return null; } function draw_card(deck) { clear_undo(); @@ -646,7 +709,7 @@ function get_event_prompt(effect) { case 'hero_points': return 'Select player with most Hero points'; case 'track': - return 'Decrease ' + track_names[effect.target]; + return 'Decrease ' + tracks[effect.target].name; } return prompt; } @@ -730,7 +793,7 @@ function get_factions_with_most_hero_poins() { return faction_ids; } function get_track_name(track_id) { - return track_names[track_id]; + return tracks[track_id].name; } function make_list(first, last) { let list = []; -- cgit v1.2.3