diff options
author | Frans Bongers <fransbongers@franss-mbp.home> | 2025-01-03 22:00:01 +0100 |
---|---|---|
committer | Frans Bongers <fransbongers@franss-mbp.home> | 2025-01-03 22:00:01 +0100 |
commit | 3ed56f482596fd4bf914bea95bd3ce46c0dcad6b (patch) | |
tree | a4d3f69a3e023d2a63abf28e01a0b0b3cf0f738b | |
parent | ec286d358a362869ef02a263b6553ee4e527a216 (diff) | |
download | land-and-freedom-3ed56f482596fd4bf914bea95bd3ce46c0dcad6b.tar.gz |
fix player order display issue
-rw-r--r-- | play.js | 2 | ||||
-rw-r--r-- | play.ts | 2 | ||||
-rw-r--r-- | rules.js | 44 | ||||
-rw-r--r-- | rules.ts | 78 |
4 files changed, 94 insertions, 32 deletions
@@ -388,8 +388,8 @@ function on_update() { action_button('yes', 'Yes'); action_button('no', 'No'); action_button('skip', 'Skip'); - action_button('done', 'Done'); action_button('spend_hp', 'Spend Hero Points'); + action_button('done', 'Done'); action_button('undo', 'Undo'); } function on_log(text) { @@ -499,8 +499,8 @@ function on_update() { action_button('yes', 'Yes'); action_button('no', 'No'); action_button('skip', 'Skip'); - action_button('done', 'Done'); action_button('spend_hp', 'Spend Hero Points'); + action_button('done', 'Done'); action_button('undo', 'Undo'); } @@ -150,7 +150,7 @@ function setup_final_bid() { function setup_player_turn() { const next_faction = game.first_player === null ? get_player_order()[0] - : get_next_faction(get_active_faction()); + : get_next_faction_in_player_order(get_active_faction()); if (game.first_player === null) { game.first_player = next_faction; } @@ -161,9 +161,17 @@ function setup_player_turn() { ]; next(); } +function check_end_of_year_discard() { + const { f: faction } = get_active_node_args(); + if (game.hands[faction].length > get_hand_limit(faction) || + game.tableaus[faction].length > game.year) { + insert_after_active_node(create_leaf_node('end_of_year_discard', faction)); + } + resolve_active_and_proceed(); +} function end_of_player_turn() { const { f: faction } = get_active_node_args(); - if (get_next_faction(faction) === game.first_player) { + if (get_next_faction_in_player_order(faction) === game.first_player) { game.engine = [ create_function_node('resolve_fascist_test'), create_function_node('setup_bag_of_glory'), @@ -182,6 +190,7 @@ function start_of_player_turn() { resolve_active_and_proceed(); } const engine_functions = { + check_end_of_year_discard, checkpoint, end_of_player_turn, end_of_turn, @@ -319,7 +328,7 @@ function game_view(state, current) { played_card: game.played_card, player_order: current === OBSERVER ? game.player_order - : get_player_order(faction).map((id) => faction_player_map[id]), + : get_player_order_in_game(faction).map((id) => faction_player_map[id]), selectable_cards: game.selectable_cards, selected_cards: current === OBSERVER ? [] : game.selected_cards[faction], tableaus: game.tableaus, @@ -985,7 +994,8 @@ states.end_of_year_discard = { view.prompt = 'Discard a card'; const faction_id = get_active_faction(); const hand = game.hands[faction_id]; - if (hand.length > get_hand_limit(faction_id)) { + const hand_limit = get_hand_limit(faction_id); + if (hand.length > hand_limit) { for (let c of hand) gen_action_card(c); } @@ -1246,7 +1256,7 @@ states.player_turn = { else if (can_play_card && !can_spend_hp) { view.prompt = 'Play a card'; } - else if (can_spend_hp || use_ap || use_morale_bonus) { + else if (use_ap || use_morale_bonus) { const text_options = []; if (use_ap) { text_options.push('Action Points'); @@ -1255,10 +1265,13 @@ states.player_turn = { text_options.push('Morale Bonus'); } if (can_spend_hp) { - text_options.push('Hero points'); + text_options.push('spend Hero points'); } view.prompt = `Use ${text_options.join(', ')} or end turn`; } + else if (can_spend_hp) { + view.prompt = 'Spend Hero Points or end turn'; + } else { view.prompt = 'End turn'; } @@ -1670,7 +1683,7 @@ states.use_strategy_medallion = { }; function card1_event2() { const value = game.tracks[data_1.FOREIGN_AID] >= 6 ? 3 : 2; - insert_after_active_node(resolve_effect((0, data_1.create_effect)('track', data_1.FOREIGN_AID, value))); + insert_after_active_node(resolve_effect((0, data_1.create_effect)('front', data_1.NORTHERN, value))); resolve_active_and_proceed(); } function card3_event2() { @@ -1880,7 +1893,7 @@ function end_of_year() { } const players_to_gain_hero_points = role_ids.filter((f) => !glory_this_year[f]); gain_hero_points_in_player_order(players_to_gain_hero_points, game.year); - game.engine = get_player_order().map((f) => create_leaf_node('end_of_year_discard', f)); + game.engine = get_player_order().map((f) => create_function_node('check_end_of_year_discard', { f })); game.engine.push(create_function_node('checkpoint')); game.engine.push(create_function_node('start_year')); game.top_of_events_deck = null; @@ -2005,6 +2018,9 @@ function get_fronts_to_add_to(target, not = []) { else if (target === data_1.ANY) { return data_1.FRONTS.filter((id) => game.fronts[id].status === null && !not.includes(id)); } + else if (game.fronts[target].status === data_1.DEFEAT) { + return get_fronts_closest_to(data_1.CLOSEST_TO_DEFEAT); + } else { return [target]; } @@ -2416,6 +2432,9 @@ function get_player_order(first_player = game.initiative) { } return order; } +function get_next_faction_in_player_order(faction_id) { + return get_player_order(faction_id)[1]; +} function get_previous_faction(faction_id) { const index = game.player_order.indexOf(faction_player_map[faction_id]); if (index === 0) { @@ -2430,6 +2449,15 @@ function get_next_faction(faction_id) { } return player_faction_map[game.player_order[index + 1]]; } +function get_player_order_in_game(first_player = game.initiative) { + const order = []; + let faction = first_player; + for (let i = 0; i < 3; ++i) { + order.push(faction); + faction = get_next_faction(faction); + } + return order; +} function get_factions_with_most_hero_poins() { let most_hero_points = null; let faction_ids = []; @@ -71,6 +71,7 @@ import data, { ANARCHIST_EXTRA_HERO_POINT, ARAGON, FASCIST_ID, + NORTHERN, // StaticData, // PLAYER_WITH_MOST_HERO_POINTS, } from './data'; @@ -291,33 +292,38 @@ function setup_player_turn() { const next_faction = game.first_player === null ? get_player_order()[0] - : get_next_faction(get_active_faction()); + : get_next_faction_in_player_order(get_active_faction()); if (game.first_player === null) { game.first_player = next_faction; } - // const player_order = get_player_order(); - // game.engine = player_order.map((faction_id) => - // create_seq_node([ - // create_function_node('start_of_player_turn', { f: faction_id }), - // create_leaf_node('player_turn', faction_id), - // ]) - // ); game.engine = [ create_function_node('start_of_player_turn', { f: next_faction }), create_leaf_node('player_turn', next_faction), create_function_node('end_of_player_turn', { f: next_faction }), ]; - // game.engine.push(create_function_node('resolve_fascist_test')); - // game.engine.push(create_function_node('setup_bag_of_glory')); next(); } +// Check if player needs to discard cards. If so inserts leaf node +function check_end_of_year_discard() { + const { f: faction } = get_active_node_args(); + + if ( + game.hands[faction].length > get_hand_limit(faction) || + game.tableaus[faction].length > game.year + ) { + insert_after_active_node(create_leaf_node('end_of_year_discard', faction)); + } + + resolve_active_and_proceed(); +} + function end_of_player_turn() { const { f: faction } = get_active_node_args(); - if (get_next_faction(faction) === game.first_player) { + if (get_next_faction_in_player_order(faction) === game.first_player) { game.engine = [ create_function_node('resolve_fascist_test'), create_function_node('setup_bag_of_glory'), @@ -337,6 +343,7 @@ function start_of_player_turn() { } const engine_functions: Record<string, Function> = { + check_end_of_year_discard, checkpoint, end_of_player_turn, end_of_turn, @@ -513,7 +520,7 @@ function game_view(state: Game, current: Player | 'Observer') { player_order: current === OBSERVER ? game.player_order - : get_player_order(faction).map((id) => faction_player_map[id]), + : get_player_order_in_game(faction).map((id) => faction_player_map[id]), selectable_cards: game.selectable_cards, selected_cards: current === OBSERVER ? [] : game.selected_cards[faction], tableaus: game.tableaus, @@ -1238,7 +1245,8 @@ states.end_of_year_discard = { view.prompt = 'Discard a card'; const faction_id = get_active_faction(); const hand = game.hands[faction_id]; - if (hand.length > get_hand_limit(faction_id)) { + const hand_limit = get_hand_limit(faction_id); + if (hand.length > hand_limit) { for (let c of hand) gen_action_card(c); } const tableau = game.tableaus[faction_id]; @@ -1532,7 +1540,7 @@ 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 { use_ap, use_morale_bonus } = get_active_node_args(); const can_spend_hp = game.faction_turn === faction_id && game.hero_points[faction_id] > 0; @@ -1543,7 +1551,7 @@ states.player_turn = { 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) { + } else if (use_ap || use_morale_bonus) { const text_options = []; if (use_ap) { text_options.push('Action Points'); @@ -1552,14 +1560,16 @@ states.player_turn = { text_options.push('Morale Bonus'); } if (can_spend_hp) { - text_options.push('Hero points'); + text_options.push('spend Hero points'); } - + view.prompt = `Use ${text_options.join(', ')} or end turn`; + } else if (can_spend_hp) { + view.prompt = 'Spend Hero Points or end turn'; } else { view.prompt = 'End turn'; } - + if (can_play_card) { gen_action('play_for_ap'); gen_action('play_for_event'); @@ -2051,7 +2061,7 @@ states.use_strategy_medallion = { function card1_event2() { const value = game.tracks[FOREIGN_AID] >= 6 ? 3 : 2; insert_after_active_node( - resolve_effect(create_effect('track', FOREIGN_AID, value)) + resolve_effect(create_effect('front', NORTHERN, value)) ); resolve_active_and_proceed(); } @@ -2210,7 +2220,6 @@ function add_glory( } } - function check_initiative() { let initiative: FactionId; if (game.tracks[LIBERTY] >= 6 && game.tracks[COLLECTIVIZATION] >= 6) { @@ -2324,7 +2333,7 @@ function end_of_year() { // Setup card discarding game.engine = get_player_order().map((f) => - create_leaf_node('end_of_year_discard', f) + create_function_node('check_end_of_year_discard', { f }) ); game.engine.push(create_function_node('checkpoint')); game.engine.push(create_function_node('start_year')); @@ -2490,6 +2499,8 @@ function get_fronts_to_add_to(target: string, not: FrontId[] = []): FrontId[] { return FRONTS.filter( (id) => game.fronts[id].status === null && !not.includes(id) ); + } else if (game.fronts[target].status === DEFEAT) { + return get_fronts_closest_to(CLOSEST_TO_DEFEAT); } else { return [target as FrontId]; } @@ -3065,7 +3076,10 @@ function get_player(faction_id: FactionId) { return faction_player_map[faction_id]; } -function get_player_order(first_player = game.initiative): FactionId[] { +// Gets player order +function get_player_order( + first_player: FactionId = game.initiative +): FactionId[] { const order = []; let faction = first_player; for (let i = 0; i < 3; ++i) { @@ -3079,6 +3093,11 @@ function get_player_order(first_player = game.initiative): FactionId[] { return order; } +function get_next_faction_in_player_order(faction_id: FactionId): FactionId { + return get_player_order(faction_id)[1]; +} + +// Gets previous faction in game order (so does not change for year 2) function get_previous_faction(faction_id: FactionId): FactionId { const index = game.player_order.indexOf(faction_player_map[faction_id]); if (index === 0) { @@ -3087,6 +3106,7 @@ function get_previous_faction(faction_id: FactionId): FactionId { return player_faction_map[game.player_order[index - 1]]; } +// Gets next faction in game order function get_next_faction(faction_id: FactionId): FactionId { const index = game.player_order.indexOf(faction_player_map[faction_id]); if (index === 2) { @@ -3095,6 +3115,20 @@ function get_next_faction(faction_id: FactionId): FactionId { return player_faction_map[game.player_order[index + 1]]; } +// Gets game order +function get_player_order_in_game( + first_player: FactionId = game.initiative +): FactionId[] { + const order = []; + let faction = first_player; + for (let i = 0; i < 3; ++i) { + order.push(faction); + faction = get_next_faction(faction); + } + + return order; +} + function get_factions_with_most_hero_poins(): FactionId[] { let most_hero_points = null; let faction_ids = []; |