diff options
author | Frans Bongers <fransbongers@franss-mbp.home> | 2024-12-31 13:05:16 +0100 |
---|---|---|
committer | Frans Bongers <fransbongers@franss-mbp.home> | 2024-12-31 13:05:16 +0100 |
commit | 1298b27e451f9cbc5c784581b630577ad9d074f7 (patch) | |
tree | 08455b17627523171c91c3dc24065c4f8142dfa5 /rules.ts | |
parent | 50d95d906d7d782d155e75635be4d637c1ccfb25 (diff) | |
download | land-and-freedom-1298b27e451f9cbc5c784581b630577ad9d074f7.tar.gz |
random player order and show ui relative to player order
Diffstat (limited to 'rules.ts')
-rw-r--r-- | rules.ts | 35 |
1 files changed, 24 insertions, 11 deletions
@@ -79,6 +79,7 @@ import data, { // inactive: string; // prompt: () => void; // } +const OBSERVER = 'Observer'; const states = {} as States; let game = {} as Game; // = null @@ -487,10 +488,10 @@ function resolve_active_and_proceed(checkpoint = false) { export { game_view as view }; -function game_view(state: Game, player: Player) { +function game_view(state: Game, current: Player | 'Observer') { game = state; - const faction_id = player_faction_map[player]; + const faction: FactionId | null = current === OBSERVER ? null : player_faction_map[current]; view = { engine: game.engine, // TODO: remove @@ -498,16 +499,18 @@ function game_view(state: Game, player: Player) { prompt: null, bag_of_glory: game.bag_of_glory, bonuses: game.bonuses, + current, current_events: game.current_events, fronts: game.fronts, glory: game.glory, - hand: game.hands[faction_id], + hand: faction === null ? [] : game.hands[faction], hero_points: game.hero_points, initiative: game.initiative, medallions: game.medallions, played_card: game.played_card, + player_order: current === OBSERVER ? game.player_order : get_player_order(faction).map((id) => faction_player_map[id]), selectable_cards: game.selectable_cards, - selected_cards: game.selected_cards[faction_id], + selected_cards: current === OBSERVER ? [] : game.selected_cards[faction], tableaus: game.tableaus, tracks: game.tracks, triggered_track_effects: game.triggered_track_effects, @@ -517,7 +520,7 @@ function game_view(state: Game, player: Player) { if (game.state === 'game_over') { view.prompt = game.victory; - } else if (player !== game.active) { + } else if (current !== game.active) { let inactive = states[game.state].inactive || game.state; view.prompt = `Waiting for ${game.active} to ${inactive}.`; } else { @@ -596,6 +599,7 @@ export function setup(seed: number, _scenario: string, _options: unknown) { pool: [], }, played_card: null, + player_order: [MODERATE], selectable_cards: [], selected_cards: { a: [], @@ -622,6 +626,13 @@ export function setup(seed: number, _scenario: string, _options: unknown) { year: 0, }; + // Randomly choose second player + game.player_order.push(roles[random(2)]); + // Remaining role is 3rd player + game.player_order.push( + game.player_order[1] === ANARCHIST ? COMMUNIST : ANARCHIST + ); + draw_medallions(); start_year(); @@ -2971,19 +2982,21 @@ function get_player_order(first_player = game.initiative): FactionId[] { } function get_previous_faction(faction_id: FactionId): FactionId { - const index = role_ids.indexOf(faction_id); + const index = game.player_order.indexOf(faction_player_map[faction_id]); if (index === 0) { - return role_ids[2]; + return player_faction_map[game.player_order[2]]; } - return role_ids[index - 1]; + return player_faction_map[game.player_order[index - 1]]; } function get_next_faction(faction_id: FactionId): FactionId { - const index = role_ids.indexOf(faction_id); + console.log('get_next', faction_id) + const index = game.player_order.indexOf(faction_player_map[faction_id]); + console.log('index', index); if (index === 2) { - return role_ids[0]; + return player_faction_map[game.player_order[0]]; } - return role_ids[index + 1]; + return player_faction_map[game.player_order[index + 1]]; } function get_factions_with_most_hero_poins(): FactionId[] { |