diff options
Diffstat (limited to 'rules.ts')
-rw-r--r-- | rules.ts | 193 |
1 files changed, 143 insertions, 50 deletions
@@ -30,6 +30,7 @@ import data, { SOVIET_SUPPORT, FOREIGN_AID, PLAYER_WITH_MOST_HERO_POINTS, + PlayerCard, // StaticData, // PLAYER_WITH_MOST_HERO_POINTS, } from './data'; @@ -74,6 +75,14 @@ const front_names: Record<string, string> = { v: 'the Front closest to Victory', }; +const tracks = [ + LIBERTY, + COLLECTIVIZATION, + GOVERNMENT, + SOVIET_SUPPORT, + FOREIGN_AID, +]; + const track_names: Record<number, string> = { [LIBERTY]: 'Liberty', [COLLECTIVIZATION]: 'Collectivization', @@ -118,6 +127,10 @@ function gen_action_card(card_id: CardId) { gen_action('card', card_id); } +function gen_action_standee(track_id: number) { + gen_action('standee', track_id); +} + // function gen_action_space(space) { // gen_action('space', space); // } @@ -248,7 +261,9 @@ function get_active( // return null; // } -function get_active_node(engine: EngineNode[]): FunctionNode | LeafNode | null { +function get_active_node( + engine: EngineNode[] = game.engine +): FunctionNode | LeafNode | null { const a = get_active(engine); return a === null ? null : a.node; // for (let i of engine) { @@ -395,6 +410,12 @@ export function setup(seed: number, _scenario: string, _options: unknown) { blank_markers: [[], [], [], [], []], bonuses: [ON, ON], current_events: [], + discard: { + [ANARCHISTS_ID]: [], + [COMMUNISTS_ID]: [], + [MODERATES_ID]: [], + f: [], + }, engine: [], fronts: { a: -2, @@ -513,62 +534,48 @@ states.add_glory = { }, }; -states.resolve_event = { - inactive: 'resolve Fascist Event', +states.choose_area_ap = { + inactive: 'choose area to use Action Points', prompt() { - const card = get_current_event(); - const node = get_active_node(game.engine) as LeafNode; - const effect: CardEffect = 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') { - gen_action('standee', effect.target); - } else if ( - effect.type === 'hero_points' && - effect.target === PLAYER_WITH_MOST_HERO_POINTS - ) { - const factions = get_factions_with_most_hero_poins(); - for (let faction_id of factions) { - gen_action(get_player(faction_id)); - } + view.prompt = 'Choose area of the board to affect'; + for (let track_id of tracks) { + gen_action_standee(track_id); } - // for (let p = 0; p < 5; ++p) gen_action('standee', p); - }, - front(f: string) { - 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: string) { - 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)}`); + standee(track_id: number) { + console.log('standee', track_id); + insert_after_active_node({ + t: leaf_node, + p: get_active_faction_id(), + s: 'move_track_up_or_down', + a: { + track_id, + strength: get_active_node()?.a.strength, + }, + }); resolve_active_and_proceed(); }, - Anarchist() { - lose_hero_point(ANARCHISTS_ID, 1); - resolve_active_and_proceed(); +}; + +states.move_track_up_or_down = { + inactive: 'move a track', + prompt() { + const node = get_active_node(); + view.prompt = `Move ${get_track_name(node.a.track_id)} up or down` + gen_action('up'); + gen_action('down'); }, - Communist() { - lose_hero_point(ANARCHISTS_ID, 1); + down() { + const node = get_active_node(); + move_track(node.a.track_id, -1 * node.a.strength); resolve_active_and_proceed(); }, - Moderate() { - lose_hero_point(ANARCHISTS_ID, 1); + up() { + 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', @@ -602,16 +609,39 @@ states.player_turn = { // gen_action_card(); gen_action('play_for_ap'); gen_action('play_for_event'); + } else { + gen_action('done'); } if (hero_points > 0) { gen_action('spend_hp'); } }, + done() { + resolve_active_and_proceed(); + }, play_for_ap() { const faction_id = get_faction_id(game.active); const card = game.cards_in_play[faction_id]; log_h3(`${game.active} plays ${cards[card].title} for the Action Points`); - resolve_active_and_proceed(); + if (!game.discard) { + game.discard = { + [ANARCHISTS_ID]: [], + [COMMUNISTS_ID]: [], + [MODERATES_ID]: [], + f: [], + }; + } + array_remove(game.hands[faction_id], game.hands[faction_id].indexOf(card)); + game.discard[faction_id].push(card); + insert_before_active_node({ + t: leaf_node, + p: faction_id, + s: 'choose_area_ap', + a: { + strength: (cards[card] as PlayerCard).strength, + }, + }); + next(); }, play_for_event() { const faction_id = get_faction_id(game.active); @@ -647,6 +677,63 @@ states.player_turn = { }, }; +states.resolve_event = { + inactive: 'resolve Fascist Event', + prompt() { + const card = get_current_event(); + const node = get_active_node(game.engine) as LeafNode; + const effect: CardEffect = 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') { + gen_action('standee', effect.target); + } else if ( + effect.type === 'hero_points' && + effect.target === PLAYER_WITH_MOST_HERO_POINTS + ) { + const factions = get_factions_with_most_hero_poins(); + for (let faction_id of factions) { + gen_action(get_player(faction_id)); + } + } + // for (let p = 0; p < 5; ++p) gen_action('standee', p); + }, + front(f: string) { + 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: string) { + 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(); + }, + Communist() { + lose_hero_point(ANARCHISTS_ID, 1); + resolve_active_and_proceed(); + }, + Moderate() { + lose_hero_point(ANARCHISTS_ID, 1); + resolve_active_and_proceed(); + }, +}; + states.spend_hero_points = { inactive: 'spend Hero points', prompt() { @@ -716,7 +803,9 @@ function resolve_fascist_test() { next(); } -function move_track(track: number, change: number) {} +function move_track(track: number, change: number) { + +} // #endregion @@ -977,6 +1066,10 @@ function get_factions_with_most_hero_poins() { return faction_ids; } +function get_track_name(track_id: number): string { + return track_names[track_id]; +} + function make_list(first: number, last: number) { let list = []; for (let i = first; i <= last; i++) list.push(i); |