diff options
author | Frans Bongers <fransbongers@franss-mbp.home> | 2024-12-27 20:45:12 +0100 |
---|---|---|
committer | Frans Bongers <fransbongers@franss-mbp.home> | 2024-12-27 20:45:12 +0100 |
commit | 8749fad48dfca5d4374e15539b160db28a4ed2dc (patch) | |
tree | 12c3b418a99cdb15285d3cfebf99120b96dc7af9 /rules.ts | |
parent | 9d0630a33e0358f943e68008823f355bceb71be1 (diff) | |
download | land-and-freedom-8749fad48dfca5d4374e15539b160db28a4ed2dc.tar.gz |
refactor selected cards
Diffstat (limited to 'rules.ts')
-rw-r--r-- | rules.ts | 114 |
1 files changed, 57 insertions, 57 deletions
@@ -283,6 +283,7 @@ function start_of_player_turn() { const args = get_active_node_args(); const player = faction_player_map[args.f]; log_h2(player, player); + game.faction_turn = args.f; resolve_active_and_proceed(); } @@ -435,19 +436,17 @@ function game_view(state: Game, player: Player) { engine: game.engine, // TODO: remove log: game.log, prompt: null, - location: game.location, - selected: game.selected, bag_of_glory: game.bag_of_glory, bonuses: game.bonuses, current_events: game.current_events, - final_bid: game.final_bid[faction_id], fronts: game.fronts, glory: game.glory, hand: game.hands[faction_id], hero_points: game.hero_points, initiative: game.initiative, medallions: game.medallions, - selected_card: game.chosen_cards[faction_id], + played_card: game.played_card, + selected_cards: game.selected_cards[faction_id], tableaus: game.tableaus, tracks: game.tracks, triggered_track_effects: game.triggered_track_effects, @@ -493,11 +492,7 @@ export function setup(seed: number, _scenario: string, _options: unknown) { f: [], }, engine: [], - final_bid: { - a: [], - c: [], - m: [], - }, + faction_turn: null, fronts: { a: { value: -2, @@ -532,11 +527,6 @@ export function setup(seed: number, _scenario: string, _options: unknown) { m: 0, pool: 14, }, - chosen_cards: { - a: null, - c: null, - m: null, - }, initiative: MODERATES_ID, medallions: { a: [], @@ -544,6 +534,12 @@ export function setup(seed: number, _scenario: string, _options: unknown) { m: [], pool: [], }, + played_card: null, + selected_cards: { + a: [], + c: [], + m: [], + }, tableaus: { a: [], c: [], @@ -561,7 +557,6 @@ export function setup(seed: number, _scenario: string, _options: unknown) { used_medallions: [], turn: 0, year: 0, - state_data: null, }; draw_medallions(); @@ -639,7 +634,7 @@ states.activate_icon = { inactive: 'activate an icon', prompt() { view.prompt = 'Choose an icon to activate'; - const c = cards[game.chosen_cards[get_active_faction_id()]] as PlayerCard; + const c = cards[game.selected_cards[get_active_faction_id()][0]] as PlayerCard; for (const i of c.icons) { gen_action(i); } @@ -987,7 +982,7 @@ states.choose_card = { for (let c of hand) gen_action_card(c); }, card(c: CardId) { - game.chosen_cards[player_faction_map[game.active]] = c; + game.selected_cards[player_faction_map[game.active]].push(c); resolve_active_and_proceed(); }, }; @@ -998,7 +993,7 @@ states.choose_final_bid = { view.prompt = 'Choose a card to add to the Final Bid'; const faction = get_active_faction(); for (let c of game.hands[faction]) { - if (!game.final_bid[faction].includes(c)) { + if (!game.selected_cards[faction].includes(c)) { gen_action_card(c); } } @@ -1006,8 +1001,8 @@ states.choose_final_bid = { }, card(c: CardId) { const faction = get_active_faction(); - game.final_bid[faction].push(c); - if (game.final_bid[faction].length < 3) { + game.selected_cards[faction].push(c); + if (game.selected_cards[faction].length < 3) { next(); } else { resolve_active_and_proceed(); @@ -1272,8 +1267,9 @@ states.player_turn = { prompt() { const faction_id = get_faction_id(game.active as Player); const can_spend_hp = game.hero_points[faction_id] > 0; + // TODO: refactor to check selected_cards.length const can_play_card = game.hands[faction_id].includes( - game.chosen_cards[faction_id] + game.selected_cards[faction_id][0] ); view.prompt = 'Play a card or spend Hero points'; if (!(can_play_card || can_spend_hp)) { @@ -1295,11 +1291,14 @@ states.player_turn = { } }, done() { + game.faction_turn = null; + game.played_card = null; resolve_active_and_proceed(true); }, play_for_ap() { const faction_id = get_faction_id(game.active as Player); - const card = game.chosen_cards[faction_id]; + 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); @@ -1315,7 +1314,8 @@ states.player_turn = { }, play_for_event() { const faction_id = get_faction_id(game.active as Player); - const card = game.chosen_cards[faction_id]; + 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`); @@ -1497,7 +1497,7 @@ states.swap_card_tableau_hand = { gen_action_card(c); } }, - card(c: CardId) {}, + // card(c: CardId) {}, }; // TODO: implement, card 12 + card 32 + card 44 @@ -1929,7 +1929,7 @@ function resolve_final_bid() { let winners: FactionId[] = []; for (const f of get_player_order()) { let player_bid = 0; - for (const c of game.final_bid[f]) { + for (const c of game.selected_cards[f]) { player_bid += (cards[c] as PlayerCard).strength; } log(`${faction_player_map[f]} bids ${player_bid}`); @@ -1939,9 +1939,9 @@ function resolve_final_bid() { highest_bid = player_bid; winners = [f]; } - game.hands[f] = game.hands[f].filter((c) => !game.final_bid[f].includes(c)); - game.discard[f].concat(game.final_bid[f]); - game.final_bid[f] = []; + game.hands[f] = game.hands[f].filter((c) => !game.selected_cards[f].includes(c)); + game.discard[f].concat(game.selected_cards[f]); + game.selected_cards[f] = []; } if (winners.length === 1) { @@ -2731,37 +2731,37 @@ function array_insert<T>(array: T[], index: number, item: T) { // Set as plain sorted array -function set_clear<T>(set: T[]) { - // eslint-disable-line @typescript-eslint/no-unused-vars - set.length = 0; -} +// function set_clear<T>(set: T[]) { +// // eslint-disable-line @typescript-eslint/no-unused-vars +// set.length = 0; +// } -function set_has<T>(set: T[], item: T) { - let a = 0; - let b = set.length - 1; - while (a <= b) { - const m = (a + b) >> 1; - const x = set[m]; - if (item < x) b = m - 1; - else if (item > x) a = m + 1; - else return true; - } - return false; -} +// function set_has<T>(set: T[], item: T) { +// let a = 0; +// let b = set.length - 1; +// while (a <= b) { +// const m = (a + b) >> 1; +// const x = set[m]; +// if (item < x) b = m - 1; +// else if (item > x) a = m + 1; +// else return true; +// } +// return false; +// } -function set_add<T>(set: T[], item: T) { - // eslint-disable-line @typescript-eslint/no-unused-vars - let a = 0; - let b = set.length - 1; - while (a <= b) { - const m = (a + b) >> 1; - const x = set[m]; - if (item < x) b = m - 1; - else if (item > x) a = m + 1; - else return set; - } - return array_insert(set, a, item); -} +// function set_add<T>(set: T[], item: T) { +// // eslint-disable-line @typescript-eslint/no-unused-vars +// let a = 0; +// let b = set.length - 1; +// while (a <= b) { +// const m = (a + b) >> 1; +// const x = set[m]; +// if (item < x) b = m - 1; +// else if (item > x) a = m + 1; +// else return set; +// } +// return array_insert(set, a, item); +// } // function set_delete<T>(set: T[], item: T) { // let a = 0; |