diff options
-rw-r--r-- | play.js | 20 | ||||
-rw-r--r-- | rules.js | 205 |
2 files changed, 136 insertions, 89 deletions
@@ -892,14 +892,18 @@ function on_update() { ui.persistent.appendChild(ui.cards[c]) ui.played_card.replaceChildren() - if (view.played_card > 0) - ui.played_card.appendChild(ui.cards[view.played_card]) - if (view.vm_event > 0 && view.vm_event < 111) - ui.played_card.appendChild(ui.cards[view.vm_event]) - if (view.power_card_1 > 0) - ui.played_card.appendChild(ui.power_cards[view.power_card_1]) - if (view.power_card_2 > 0) - ui.played_card.appendChild(ui.power_cards[view.power_card_2]) + if (!view.scoring_card) { + if (view.played_card > 0) + ui.played_card.appendChild(ui.cards[view.played_card]) + if (view.vm_event > 0 && view.vm_event < 111) + ui.played_card.appendChild(ui.cards[view.vm_event]) + } else { + ui.played_card.appendChild(ui.cards[view.scoring_card]) + if (view.power_card_1 > 0) + ui.played_card.appendChild(ui.power_cards[view.power_card_1]) + if (view.power_card_2 > 0) + ui.played_card.appendChild(ui.power_cards[view.power_card_2]) + } for (let e of action_register) e.classList.toggle("action", is_action(e.my_action, e.my_id)) @@ -418,6 +418,7 @@ exports.view = function (state, player) { } if (game.is_pwr_struggle) { + view.scoring_card = scoring_cards[countries.indexOf(game.pwr_struggle_in)] view.power_struggle_discard = game.power_struggle_discard view.played_power_card = game.played_power_card view.power_card_1 = game.power_card_1 @@ -1409,7 +1410,7 @@ states.power_struggle = { prompt() { if (game.phase === 0) { if (game.valid_cards.length > 0) { - view.prompt = "Play a card." + view.prompt = "Choose a card." for (let card of game.valid_cards) { gen_action_power_card(card) } @@ -1432,91 +1433,39 @@ states.power_struggle = { } else if (game.phase === 2) { view.prompt = 'You matched. Roll a die.' gen_action('roll') - } else if (game.phase === 3) { - view.prompt = 'Play leader as:' - if (game.tactics_fails !== 'Strike') { - gen_action('strike') - } - if (game.tactics_fails !== 'March') { - gen_action('march') - } - if (game.tactics_fails !== 'Rally in the Square') { - gen_action('rally') - } - if (game.tactics_fails !== 'Petition') { - gen_action('petition') - } } }, power_card(card) { push_undo() - discard(card) - if (game.phase === 0) { - game.ps_round++ - game.power_card_1 = card - delete game.power_card_2 - } - if (game.phase === 1) { - game.power_card_2 = card - } game.valid_cards = [] game.return_state = 'power_struggle' if (game.phase === 0) { - delete game.proxy_power_card - } - if (card === PC_TACTIC_FAILS) { - log_msg_gap(`${game.active}: P${PC_TACTIC_FAILS}`) - } else { - if (game.phase === 0 && leader_cards.includes(card)) { - /* Log nothing. Probably a better way to do this */ - } else if (numberless_cards.includes(card)) { - log(`${game.active}: P${card}`) - } else { - log(`${game.active}: P${card} V${power_cards[card].value}`) + delete game.power_card_1 + delete game.power_card_2 + game.played_power_card = card + if (leader_cards.includes(card)) + game.state = 'power_struggle_confirm_leader' + else { + game.state = 'power_struggle_confirm' } } - if (game.phase === 0) { - if (leader_cards.includes(card)) { - game.played_power_card = card - game.phase = 3 - } else if (card === PC_SCARE_TACTICS) { - game.return = '' - goto_vm(351) - } else if (card === PC_SUPPORT_SURGES) { - if (game.active === DEM) { - game.return = COM - } else { - game.return = DEM - } - goto_vm(350) - } else if (game.phase === 0 && card === PC_SUPPORT_FALTERS) { - change_player() - goto_vm(349) - } else { - game.played_power_card = card - game.phase = 1 - change_player() - do_valid_cards() - } - } else if (game.phase === 1) { + if (game.phase === 1) { if (card === PC_TACTIC_FAILS) { - if (game.proxy_power_card) { - game.tactics_fails = game.proxy_power_card - } else { - game.tactics_fails = power_cards[game.played_power_card].name - } - game.phase = 0 - log_gap(`Round ${game.ps_round}:`) - change_player() - do_valid_cards() - } else if (power_cards[game.played_power_card].value === 1) { + game.state = 'power_struggle_tactic_fails' + return + } else + game.power_card_2 = card + discard(card) + if (power_cards[game.played_power_card].value === 1) { + log(`${game.active}: P${card}`) log('Takes initiative.') game.phase = 0 log_gap(`Round ${game.ps_round}:`) do_valid_cards() } else { + log_power_card() game.phase = 2 } } @@ -1527,7 +1476,7 @@ states.power_struggle = { log(`Counterattack: D${roll}`) if (roll >= power_cards[game.played_power_card].value) { log(`Success: ${roll} >= ${power_cards[game.played_power_card].value}`) - log_msg_gap(`${game.active} takes initiative.`) + log(`${game.active} takes initiative.`) game.phase = 0 log_gap(`Round ${game.ps_round}:`) do_valid_cards() @@ -1555,34 +1504,105 @@ states.power_struggle = { game.phase = 0 game.state = 'support_loss' }, +} + +states.power_struggle_confirm = { + inactive: 'play a card', + prompt() { + view.prompt = `Play ${numberless_cards.includes(game.played_power_card) + ? power_cards[game.played_power_card].name + : `${power_cards[game.played_power_card].name} ${power_cards[game.played_power_card].value}`}.` + gen_action('done') + }, + done() { + select_power_card() + log_power_card() + if (game.played_power_card === PC_SCARE_TACTICS) { + game.return = '' + goto_vm(351) + } else if (game.played_power_card === PC_SUPPORT_SURGES) { + if (game.active === DEM) { + game.return = COM + } else { + game.return = DEM + } + goto_vm(350) + } else if (game.played_power_card === PC_SUPPORT_FALTERS) { + change_player() + goto_vm(349) + } else { + game.phase = 1 + confirm_power_card() + } + } +} + +states.power_struggle_confirm_leader = { + inactive: 'play a card', + prompt() { + view.prompt = view.prompt = `Play ${power_cards[game.played_power_card].name} as:` + if (game.tactics_fails !== 'Strike') { + gen_action('strike') + } + if (game.tactics_fails !== 'March') { + gen_action('march') + } + if (game.tactics_fails !== 'Rally in the Square') { + gen_action('rally') + } + if (game.tactics_fails !== 'Petition') { + gen_action('petition') + } + }, strike() { + select_power_card() log(`${game.active}: P${game.played_power_card} as Strike.`) game.proxy_power_card = 'Strike' game.phase = 1 - change_player() - do_valid_cards() + confirm_power_card() }, march() { + select_power_card() log(`${game.active}: P${game.played_power_card} as March`) game.proxy_power_card = 'March' game.phase = 1 - change_player() - do_valid_cards() + confirm_power_card() }, rally() { + select_power_card() log(`${game.active}: P${game.played_power_card} as Rally in the Square`) game.proxy_power_card = 'Rally in the Square' game.phase = 1 - change_player() - do_valid_cards() + confirm_power_card() }, petition() { + select_power_card() log(`${game.active}: P${game.played_power_card} as Petition`) game.proxy_power_card = 'Petition' game.phase = 1 - change_player() - do_valid_cards() + confirm_power_card() + } +} + +states.power_struggle_tactic_fails = { + inactive: 'play a card', + prompt() { + view.prompt = `Play ${power_cards[PC_TACTIC_FAILS].name}.` + gen_action('done') }, + done() { + discard(PC_TACTIC_FAILS) + game.power_card_2 = PC_TACTIC_FAILS + log(`${game.active}: P${PC_TACTIC_FAILS}`) + if (game.proxy_power_card) { + game.tactics_fails = game.proxy_power_card + } else { + game.tactics_fails = power_cards[game.played_power_card].name + } + game.phase = 0 + log_gap(`Round ${game.ps_round}:`) + confirm_power_card() + } } states.support_loss = { @@ -1594,7 +1614,6 @@ states.support_loss = { gen_action('roll') } else if (game.phase === 1 && game.available_ops > 0 && game.valid_spaces.length > 0) { view.prompt = `${ps_state} - ${country_name(game.pwr_struggle_in)}. Support Loss: Remove ${pluralize(game.available_ops,'SP')}.` - for (let space_id of game.valid_spaces) { gen_action_space(space_id) } @@ -1668,6 +1687,7 @@ states.vp_roll = { if (game.active === DEM) { change_player() } + log_h5('Power') game.state = 'choose_power' } }, @@ -2975,14 +2995,14 @@ function take_power(country) { function retain_power(country) { game.times_held[find_country_index(country)]++ let vp_gain = get_value(country) * game.times_held[find_country_index(country)] - log(`Communist retains power.`) + //log(`Communist retains power.`) logi(`-${vp_gain} VP`) game.vp_retain = -vp_gain game.vp -= vp_gain } function score_country(country) { - log_h5(`Scoring: ${country}`) + log_h5(`Scoring`) // Get scoring values let value_presence = get_value(country) @@ -3227,6 +3247,29 @@ function goto_struggle() { do_valid_cards() } +function confirm_power_card() { + change_player() + do_valid_cards() + game.state = 'power_struggle' +} + +function log_power_card() { + let card = game.power_card_2 ? game.power_card_2 : game.played_power_card + if (numberless_cards.includes(card)) { + log(`${game.active}: P${card}`) + } else { + log(`${game.active}: P${card} V${power_cards[card].value}`) + } +} + +function select_power_card() { + discard(game.played_power_card) + game.ps_round++ + game.power_card_1 = game.played_power_card + delete game.power_card_2 + delete game.proxy_power_card +} + function reset_austria_hungary_border_reopened() { delete game.austria_hungary_border_reopened_tracker delete game.ahbr_logged |