From 440a6dd7874f8cf46af167c4b70dbc17bb7d996e Mon Sep 17 00:00:00 2001 From: iainp5 Date: Wed, 25 Sep 2024 17:54:57 +0100 Subject: Fix +1 bonus in Stasi --- play.js | 32 ++++++++++++++++++++- rules.js | 99 ++++++++++++++++++++++++++++++++++++++++++++++------------------ 2 files changed, 103 insertions(+), 28 deletions(-) diff --git a/play.js b/play.js index 5aedbdf..647be0f 100644 --- a/play.js +++ b/play.js @@ -202,6 +202,29 @@ function is_action(action) { function on_log(text) { // eslint-disable-line no-unused-vars let p = document.createElement("div") +//Check if adding influence the the same place as the previous influence + + //let last_log_entry = document.getElementById("log").lastElementChild + console.log('view.log', view.log) + let last_log_entry = document.querySelector(`#log div:nth-child(${view.log.length-1})`) + let last_log_entry_text + console.log('last_log_entry', last_log_entry) + if (last_log_entry) { + last_log_entry_text = last_log_entry.innerHTML + console.log('last_log_entry_text', last_log_entry_text) + } + + +/* + let last_text = last_log_entry ? last_log_entry.split(' ') : [] + console.log('last text', last_text, 'text', text.split(' ')[3]) + if (last_text[0] === 'Added' && last_text[4] === text.split(' ')[4]) { + let new_influence = parseInt(last_text[1]) + 1 + new_text = `Added ${new_influence} influence in ${last_text[4]}` + console.log('new_influence', new_influence, 'new_text', new_text) + } */ + + if (text.match(/^>/)) { text = text.substring(1) p.className = 'i' @@ -235,6 +258,13 @@ function on_log(text) { // eslint-disable-line no-unused-vars p.className = 'h3' } + //console.log('view.log', view.log) + console.log('new text', text) + if (last_log_entry_text) { + console.log('log = text', last_log_entry_text === text) + } + + p.innerHTML = text return p } @@ -595,7 +625,7 @@ if (view.persistent_events['the_tyrant_is_gone'] > 0) { action_button("done", "Done") action_button("undo", "Undo") - console.log('view.log', view.log) + //console.log('view.log', view.log) } diff --git a/rules.js b/rules.js index b5e8ede..a69bae8 100644 --- a/rules.js +++ b/rules.js @@ -450,7 +450,7 @@ states.choose_card = { log('+1 op from C50') game.available_ops ++ } - + if ((game.active === DEM && game.dem_tst_position >= 2 && game.com_tst_position <= 1 && cards[card].ops === 1) || (game.active === COM && game.com_tst_position >=2 && game.dem_tst_position <= 1 && cards[card].ops === 1)) { log('+1 op from Tiananmen Square Track') game.available_ops ++ @@ -1990,30 +1990,29 @@ states.stasi_end_round = { pass() { log('Stasi: Democrat has no remaining cards') game.stasi_card = 0 - game.round_player = COM - game.round ++ - log_h2(`Action Round ${game.round}`) - next_player() - game.valid_spaces = [] - if (game.persistent_events['general_strike']) { - log_h3('C5') - game.state = 'general_strike' - } else { - game.state = 'choose_card' - } + end_stasi_choose_card() }, done() { - game.round_player = COM - game.round ++ - log_h2(`Action Round ${game.round}`) - next_player() - game.valid_spaces = [] - if (game.persistent_events['general_strike']) { - log_h3('C5') - game.state = 'general_strike' + push_undo() + if (game.stasi_card === 21) { + game.state = 'stasi_confirm' } else { - game.state = 'choose_card' + end_stasi_choose_card() + } + } +} + +states.stasi_confirm = { + inactive: 'choose next card due to Stasi.', + prompt() { + if (game.stasi_card === 21 ) { + view.prompt = `If Common European Home selected, it must be played for Operations. Otherwise select the opponent's card instead.` + gen_action('done') } + }, + done() { + game.playable_cards[21].playable = 0 + end_stasi_choose_card() } } @@ -2038,12 +2037,23 @@ states.stasi_play_card = { }, card(card) { push_undo() - log_msg_gap(`Stasi: played C${cards[card].number}`) + log_msg_gap(`Stasi: played C${card}`) game.played_card = card let find_card find_card = game.democrat_hand.indexOf(card); const [playedCard] = game.democrat_hand.splice(find_card, 1); - game.available_ops = cards[card].ops + game.available_ops = cards[card].ops + + //Check for events which influence ops + if (game.persistent_events['sinatra_doctrine'] && game.active === DEM) { + log('+1 op from C50') + game.available_ops ++ + } + + if ((game.active === DEM && game.dem_tst_position >= 2 && game.com_tst_position <= 1 && cards[card].ops === 1) || (game.active === COM && game.com_tst_position >=2 && game.dem_tst_position <= 1 && cards[card].ops === 1)) { + log('+1 op from Tiananmen Square Track') + game.available_ops ++ + } if (game.available_ops > 1 && game.persistent_events['prudence'].DEM !== 0) { log(`${pluralize(game.persistent_events['prudence'].DEM, ' op')} from C8}`) game.available_ops += game.persistent_events['prudence'].DEM @@ -2051,19 +2061,40 @@ states.stasi_play_card = { game.available_ops = 1 } } + }, pass () { log('No cards remaining. Passed') end_round() }, done () { - game.state = 'play_card' - game.stasi_card = 0 + if (democrat_hand.includes(21)) { + game.state = 'stasi_resolve_common_european_home' + } else { + game.state = 'play_card' + game.stasi_card = 0 + } } } -states.stasi_common_european_home = { - +states.stasi_resolve_common_european_home = { + inactive: 'play a card.', + prompt () { + view.prompt = `Do you wish to play ${clean_name(cards[game.played_card].name)} with Common European Home?` + gen_action('yes') + gen_action('no') + }, + yes() { + log(`${clean_name(cards[game.played_card].name)}} played with Common European Home`) + silent_discard(21) + game.vm_infl_to_do = true + game.vm_event_to_do = false + game.state = 'resolve_opponent_event' + }, + no() { + game.state = 'play_card' + game.stasi_card = 0 + } } @@ -2992,6 +3023,20 @@ function reset_austria_hungary_border_reopened() { game.austria_hungary_border_reopened_tracker = false } +function end_stasi_choose_card() { + game.round_player = COM + game.round ++ + log_h2(`Action Round ${game.round}`) + next_player() + game.valid_spaces = [] + if (game.persistent_events['general_strike']) { + log_h3('C5') + game.state = 'general_strike' + } else { + game.state = 'choose_card' + } +} + // =========== MOVING THROUGH TURNS ============ function end_round() { -- cgit v1.2.3