From b05884c4412a403a8fde4e58d30d96da14a9eee9 Mon Sep 17 00:00:00 2001 From: iainp5 Date: Sun, 6 Oct 2024 19:43:29 +0100 Subject: Working on popup --- play.html | 17 ++++++++++ play.js | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- rules.js | 13 +++++--- 3 files changed, 124 insertions(+), 11 deletions(-) diff --git a/play.html b/play.html index 742ccc5..ed0fe1e 100644 --- a/play.html +++ b/play.html @@ -20,6 +20,23 @@
+ + +
  • TITLE +
  • +
  • 🎴 Event +
  • 🎴 Resolve Opponent Event +
  • 📣 Place SPs +
  • 💪 Support Check +
  • 🦻 Tiananmen Square Track +
  • + + +
  • TITLE +
  • +
  • 🎴 Select Card +
  • +
    diff --git a/play.js b/play.js index 8f3b780..31d916f 100644 --- a/play.js +++ b/play.js @@ -162,6 +162,84 @@ const spaceCharacteristicsElement = document.getElementById('space-characteristi } } +// POP UP CARD MENU + +var card_action_menu = Array.from(document.getElementById("popup").querySelectorAll("li[data-action]")).map(e => e.dataset.action) + +console.log('card_action_menu', card_action_menu) + +function show_popup_menu(evt, menu_id, target_id, title) { + let menu = document.getElementById(menu_id) + console.log('show_popup_menu called with evt',evt, 'menu_id',menu_id, 'target_id', target_id, 'title', title) + + let show = false + for (let item of menu.querySelectorAll("li")) { + let action = item.dataset.action + console.log('item', item, 'action', action) + if (action) { + console.log('in if action') + if (is_card_action(action, target_id)) { + console.log('in is_card_action') + show = true + item.classList.add("action") + item.classList.remove("disabled") + item.onclick = function () { + send_action(action, target_id) + hide_popup_menu() + evt.stopPropagation() + } + } else { + item.classList.remove("action") + item.classList.add("disabled") + item.onclick = null + } + } + } + + if (show) { + menu.onmouseleave = hide_popup_menu + menu.style.display = "block" + if (title) { + let item = menu.querySelector("li.title") + if (item) { + item.onclick = hide_popup_menu + item.textContent = title + } + } + + let w = menu.clientWidth + let h = menu.clientHeight + let x = Math.max(5, Math.min(evt.clientX - w / 2, window.innerWidth - w - 5)) + let y = Math.max(5, Math.min(evt.clientY - 12, window.innerHeight - h - 40)) + menu.style.left = x + "px" + menu.style.top = y + "px" + + evt.stopPropagation() + } else { + menu.style.display = "none" + } +} + +function hide_popup_menu() { + document.getElementById("popup").style.display = "none" + document.getElementById("popup_select_card").style.display = "none" +} + + +function is_card_enabled(card) { + if (view.actions) { + if (card_action_menu.some(a => view.actions[a] && view.actions[a].includes(card))) + return true + if (view.actions.card_select && view.actions.card_select.includes(card)) + return true + if (view.actions.card && view.actions.card.includes(card)) + return true + } + return false +} + +// SUPPORTING FUNCTIONS + function on_click_space(evt) { if (evt.button === 0) { const space = evt.target.my_space; @@ -182,10 +260,17 @@ function on_click_card(evt) { //console.log('on_click_card') if (evt.button === 0) { const card = evt.target.my_card; - // console.log('on_click_card_called with card:', card); - if (send_action('card', card)) { - evt.stopPropagation(); - } else { + console.log('on_click_card_called with card:', card); + if (is_action('card', card)) { + console.log('in action card') + if (send_action('card', card)) { + evt.stopPropagation(); + } + } else if (is_action('card_select', card)) { + console.log('in action card_select') + show_popup_menu(evt, "popup_select_card", card, cards[card].name) + } + else { // console.log('send_action failed for card:', card); } } @@ -193,11 +278,19 @@ function on_click_card(evt) { function is_action(action) { //console.log('is_action called with: ', action) + //console.log('view.actions', view.actions) if (view.actions && view.actions[action]) return true return false } +function is_card_action(action, card) { + console.log('is_card_action called with action', action, 'card', card) + console.log('view.actions', view.actions, 'view.actions[action]', view.actions[action]) + if (view.actions && view.actions[action] && view.actions[action].includes(card)) + return true + return false +} function on_log(text) { // eslint-disable-line no-unused-vars @@ -631,8 +724,8 @@ if (view.persistent_events.includes(97)) { action_button("bulgaria", "Bulgaria") action_button("extra", "Take action round") action_button("pass", "Pass") - action_button("remove", "Remove influence") - action_button("add", "Add influence") + action_button("remove", "Remove SPs") + action_button("add", "Add SPs") action_button("ops", "Operations") action_button("discard", "Discard") action_button("strike", "Strike") diff --git a/rules.js b/rules.js index 6ded040..520de48 100644 --- a/rules.js +++ b/rules.js @@ -264,15 +264,18 @@ exports.view = function(state, player) { // === ACTIONS =========== function gen_action(action, argument) { -//console.log('gen_action called with ', action, ' and ', argument) +console.log('gen_action called with ', action, ' and ', argument) if (argument === undefined) { + console.log('argument undefined') view.actions[action] = 1 } else { - if (!(action in view.actions)) + if (!(action in view.actions)) { + console.log('push argument') view.actions[action] = [] + } view.actions[action].push(argument) } - //console.log('view.actions: ', view.actions, 'view.actions[action]: ', view.actions[action]) + console.log('view.actions: ', view.actions, 'view.actions[action]: ', view.actions[action]) } function gen_action_infl(space){ @@ -425,11 +428,11 @@ states.choose_card = { available_cards = game.communist_hand } for (let card of available_cards) { - gen_action_card(card) + gen_action('card_select', card) } } }, - card(card) { + card_select(card) { push_undo() //Check if player is at risk of losing game due to held scoring card if (!scoring_cards.includes(card)) { -- cgit v1.2.3 From 1fc8bfad7cfa6028180108e9103e904fdbb6a76f Mon Sep 17 00:00:00 2001 From: iainp5 Date: Mon, 7 Oct 2024 16:55:32 +0100 Subject: Adding Stasi update --- play.html | 28 ++++- play.js | 22 ++-- rules.js | 386 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 393 insertions(+), 43 deletions(-) diff --git a/play.html b/play.html index ed0fe1e..6d674a3 100644 --- a/play.html +++ b/play.html @@ -25,10 +25,30 @@
  • TITLE
  • 🎴 Event -
  • 🎴 Resolve Opponent Event -
  • 📣 Place SPs -
  • 💪 Support Check -
  • 🦻 Tiananmen Square Track + +
  • 📣 Place SPs +
  • 💪 Support Check +
  • 🦻 Tiananmen Square Track + + + +
  • TITLE +
  • + +
  • 🎴 Resolve Opponent Event +
  • 📣 Place SPs +
  • 💪 Support Check +
  • 🦻 Tiananmen Square Track +
  • + + +
  • TITLE +
  • +
  • 🎴 Play with Common European Home +
  • 🎴 Resolve Opponent Event +
  • 📣 Place SPs +
  • 💪 Support Check +
  • 🦻 Tiananmen Square Track
  • diff --git a/play.js b/play.js index 31d916f..fcbf6e7 100644 --- a/play.js +++ b/play.js @@ -173,13 +173,14 @@ function show_popup_menu(evt, menu_id, target_id, title) { console.log('show_popup_menu called with evt',evt, 'menu_id',menu_id, 'target_id', target_id, 'title', title) let show = false + console.log(`menu.querySelectorAll("li")`, menu.querySelectorAll("li")) for (let item of menu.querySelectorAll("li")) { let action = item.dataset.action console.log('item', item, 'action', action) if (action) { - console.log('in if action') + //console.log('in if action') if (is_card_action(action, target_id)) { - console.log('in is_card_action') + console.log('in is_card_action',) show = true item.classList.add("action") item.classList.remove("disabled") @@ -222,7 +223,8 @@ function show_popup_menu(evt, menu_id, target_id, title) { function hide_popup_menu() { document.getElementById("popup").style.display = "none" - document.getElementById("popup_select_card").style.display = "none" + document.getElementById("popup_ceh_check").style.display = "none" + document.getElementById("popup_opp_event").style.display = "none" } @@ -266,19 +268,23 @@ function on_click_card(evt) { if (send_action('card', card)) { evt.stopPropagation(); } - } else if (is_action('card_select', card)) { - console.log('in action card_select') - show_popup_menu(evt, "popup_select_card", card, cards[card].name) + //Check for Common European Home + } else if (is_card_action('card_ceh', card)) { + show_popup_menu(evt, "popup_ceh_check", card, cards[card].name) + } else if (is_card_action('card_opp_event', card)) { + console.log('in action card_opp_event') + show_popup_menu(evt, "popup_opp_event", card, cards[card].name) } else { - // console.log('send_action failed for card:', card); + console.log('in action card_my_event') + show_popup_menu(evt, "popup", card, cards[card].name) } } } function is_action(action) { //console.log('is_action called with: ', action) - //console.log('view.actions', view.actions) + console.log('view.actions', view.actions) if (view.actions && view.actions[action]) return true return false diff --git a/rules.js b/rules.js index 520de48..870c061 100644 --- a/rules.js +++ b/rules.js @@ -420,7 +420,7 @@ states.choose_card = { view.prompt = 'No cards remaining: you must pass.' gen_action('pass') } else { - view.prompt = 'Choose a card.' + view.prompt = 'Play a card.' let available_cards if (game.active === DEM) { available_cards = game.democrat_hand @@ -428,11 +428,62 @@ states.choose_card = { available_cards = game.communist_hand } for (let card of available_cards) { - gen_action('card_select', card) + //gen_action('card_event', card) + + if (scoring_cards.includes(card)) { + /*view.prompt = 'Play for:'*/ + gen_action('card_event', card) + return + } + + + //Check for Tiananmen Square Track awards special abilities + if ((game.active === DEM && cards[card].side !== 'C' && game.dem_tst_position >= 8 && game.com_tst_position < 8 && !game.tst_8) || (game.active === COM && cards[card].side !== 'D' && game.com_tst_position >= 8 && game.dem_tst_position < 8 && !game.tst_8)){ + gen_action('card_tst_8', card) + } + + // Check for Reformer Rehabilitated + + //console.log('game.active', game.active, 'game.playable_cards[67].playable', game.playable_cards[67].playable) + + + if (card === 67 && game.playable_cards.includes(67)){ + if (game.active === DEM && (game.dem_tst_position > game.com_tst_position)) { + gen_action('card_event', card) + } + if (game.active === COM && (game.dem_tst_position < game.com_tst_position)) { + gen_action('card_event', card) + } + } + + //Continue with normal logic + + //Check if it is a card with an event which is always playable + + if (cards[card].playable) { + get_events(card) + } + + // Resolve cards with variable events (not Reformer) + + if (card !== 67 && game.playable_cards.includes(card)) { + get_events(card) + } /* + if ((game.active === DEM && cards[game.played_card].side === 'D' && game.playable_cards[game.played_card].playable === 1) || (game.active === COM && cards[game.played_card].side === 'C' && game.playable_cards[game.played_card].playable ===1) || (cards[game.played_card].side === 'N'&& game.playable_cards[game.played_card].playable ===1)) { + gen_action('event') + } else if ((game.active === DEM && (cards[game.played_card].side === 'C' && game.playable_cards[game.played_card].playable ===1)) || game.active === COM && (cards[game.played_card].side === 'D' && game.playable_cards[game.played_card].playable ===1)) { + gen_action('opp_event') + } */ + + gen_action('card_influence', card) + if (game.active === DEM && game.dem_tst_attempted_this_turn === 0 && game.dem_tst_position <=8 || game.active === COM && game.com_tst_attempted_this_turn === 0 && game.com_tst_position <= 8) { + gen_action('card_tst', card) + } + gen_action('card_support_check', card) } } }, - card_select(card) { + /*card_event(card) { push_undo() //Check if player is at risk of losing game due to held scoring card if (!scoring_cards.includes(card)) { @@ -445,11 +496,111 @@ states.choose_card = { } } select_card(card) - }, + },*/ pass() { log('No cards remaining. Passed') end_round() - } + }, + card_event(card) { + push_undo() + select_card(card) + console.log('played event, game.active', game.active, 'game.view_opp_hand', game.view_opp_hand) + log_gap(`Played C${cards[game.played_card].number} for the event`) + if (scoring_cards.includes(game.played_card)) {game.phase = 0} + else {game.phase = 1} + game.return = game.active + if (switch_events.includes(game.played_card)) {next_player()} + game.vm_event = game.played_card + goto_vm(game.vm_event) + }, + card_opp_event(card) { + push_undo() + select_card(card) + log_gap(`Played C${cards[game.played_card].number} for the event`) + game.phase = 1 /*Do I still need this?*/ + game.vm_infl_to_do = true + game.return = game.active + game.vm_event = game.played_card + if (auto_resolve_events.includes(game.played_card) || switch_events.includes(game.played_card)) { + goto_vm(game.vm_event)} + else { + next_player() + log(`C${game.vm_event}`) + goto_vm(game.vm_event) + } + }, + card_influence(card) { + push_undo() + select_card(card) + log_gap(`Played C${cards[game.played_card].number} to place SPs`) + + + // Check if Common European Home played for influence + if (game.played_card === 21) { + if (game.active === DEM) { + game.vp -- + log('-1 VP') + if (check_vp()) { + return + } + } else { + game.vp ++ + log('+1 VP') + if (check_vp()) { + return + } + } + } + // Check if card is opponent card with event that needs to be resolved + + if (cards[game.played_card].playable || game.playable_cards.includes(game.played_card)) { + if ((game.active === DEM && cards[game.played_card].side === "C" ) || (game.active === COM && cards[game.played_card].side === "D")) { + //game.phase = 1 /*Do I need this? */ + game.vm_event_to_do = true + } + } + + // If ABHR - Set AHBR tracker to true + if (game.persistent_events.includes(58)) { + game.austria_hungary_border_reopened_tracker = true + } + game.state='add_influence' + valid_spaces_infl() + }, + card_tst(card) { + push_undo() + select_card(card) + log_gap(`Played C${cards[game.played_card].number} to the Tiananmen Square Track`) + game.state='tiananmen_square_attempt' + }, + card_support_check(card) { + push_undo() + select_card(card) + log_gap(`Played C${cards[game.played_card].number} for support checks`) + + // Check if card is opponent card with event that needs to be resolved + /*if (game.phase === 0 && game.active === DEM && cards[game.played_card].side === "C" && game.playable_cards[game.played_card].playable === 1 || game.phase === 0 && game.active === COM && cards[game.played_card].side === "D" && game.playable_cards[game.played_card].playable === 1 ) { + game.vm_event_to_do = true + }*/ + + if (cards[game.played_card].playable || game.playable_cards.includes(game.played_card)) { + if ((game.active === DEM && cards[game.played_card].side === "C" ) || (game.active === COM && cards[game.played_card].side === "D")) { + game.vm_event_to_do = true + } + } + + game.available_ops = 2 + game.state='support_check_prep' + valid_spaces_sc() + }, + card_tst_8(card) { /*Play card for ops and event */ + select_card(card) + game.vm_event_to_do = true + game.vm_infl_to_do = true + game.tst_8 = true + game.state = 'vm_tst_8' + }, + /*done () { game.state = 'play_card' } */ @@ -2095,9 +2246,79 @@ states.stasi_play_card = { gen_action('pass') } else { view.prompt = `Stasi: you must play ${clean_name(cards[game.stasi_card].name)}.` - let available_cards = [game.stasi_card] + /*let available_cards = [game.stasi_card] for (let card of available_cards) { gen_action_card(card) + }*/ + let available_cards + if (game.active === DEM) { + available_cards = game.democrat_hand + } else { + available_cards = game.communist_hand + } + for (let card of available_cards) { + //gen_action('card_event', card) + + if (scoring_cards.includes(card)) { + /*view.prompt = 'Play for:'*/ + gen_action('card_event', card) + return + } + + //Check if Player has Common European Home in hand + if (game.active === DEM) { + if (game.democrat_hand.includes(21) && cards[card].side === "C") { + gen_action('card_ceh', card) + } + } else { + if (game.communist_hand.includes(21) && cards[card].side === "D") { + gen_action('card_ceh', card) + } + } + + //Check for Tiananmen Square Track awards special abilities + if ((game.active === DEM && cards[card].side !== 'C' && game.dem_tst_position >= 8 && game.com_tst_position < 8 && !game.tst_8) || (game.active === COM && cards[card].side !== 'D' && game.com_tst_position >= 8 && game.dem_tst_position < 8 && !game.tst_8)){ + gen_action('card_tst_8', card) + } + + // Check for Reformer Rehabilitated + + //console.log('game.active', game.active, 'game.playable_cards[67].playable', game.playable_cards[67].playable) + + + if (card === 67 && game.playable_cards.includes(67)){ + if (game.active === DEM && (game.dem_tst_position > game.com_tst_position)) { + gen_action('card_event', card) + } + if (game.active === COM && (game.dem_tst_position < game.com_tst_position)) { + gen_action('card_event', card) + } + } + + //Continue with normal logic + + //Check if it is a card with an event which is always playable + + if (cards[card].playable) { + get_events(card) + } + + // Resolve cards with variable events (not Reformer) + + if (card !== 67 && game.playable_cards.includes(card)) { + get_events(card) + } /* + if ((game.active === DEM && cards[game.played_card].side === 'D' && game.playable_cards[game.played_card].playable === 1) || (game.active === COM && cards[game.played_card].side === 'C' && game.playable_cards[game.played_card].playable ===1) || (cards[game.played_card].side === 'N'&& game.playable_cards[game.played_card].playable ===1)) { + gen_action('event') + } else if ((game.active === DEM && (cards[game.played_card].side === 'C' && game.playable_cards[game.played_card].playable ===1)) || game.active === COM && (cards[game.played_card].side === 'D' && game.playable_cards[game.played_card].playable ===1)) { + gen_action('opp_event') + } */ + + gen_action('card_influence', card) + if (game.active === DEM && game.dem_tst_attempted_this_turn === 0 && game.dem_tst_position <=8 || game.active === COM && game.com_tst_attempted_this_turn === 0 && game.com_tst_position <= 8) { + gen_action('card_tst', card) + } + gen_action('card_support_check', card) } } }, @@ -2109,24 +2330,7 @@ states.stasi_play_card = { find_card = game.democrat_hand.indexOf(card); game.democrat_hand.splice(find_card, 1); game.available_ops = get_card_ops(card) - /* - //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.prudence.DEM !== 0) { - log(`${pluralize(game.prudence.DEM, ' op')} from C8`) - game.available_ops += game.prudence.DEM - if (game.available_ops < 1) { - game.available_ops = 1 - } - }*/ game.stasi_card = 0 if (game.democrat_hand.includes(21)) { game.state = 'stasi_resolve_common_european_home' @@ -2139,6 +2343,120 @@ states.stasi_play_card = { log('No cards remaining. Passed') end_round() }, + card_ceh(card) { + push_undo() + select_card(card) + game.stasi_card = 0 + 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' + }, + + card_event(card) { + push_undo() + select_card(card) + game.stasi_card = 0 + console.log('played event, game.active', game.active, 'game.view_opp_hand', game.view_opp_hand) + log_gap(`Played C${cards[game.played_card].number} for the event`) + if (scoring_cards.includes(game.played_card)) {game.phase = 0} + else {game.phase = 1} + game.return = game.active + if (switch_events.includes(game.played_card)) {next_player()} + game.vm_event = game.played_card + goto_vm(game.vm_event) + }, + card_opp_event(card) { + push_undo() + select_card(card) + game.stasi_card = 0 + log_gap(`Played C${cards[game.played_card].number} for the event`) + game.phase = 1 /*Do I still need this?*/ + game.vm_infl_to_do = true + game.return = game.active + game.vm_event = game.played_card + if (auto_resolve_events.includes(game.played_card) || switch_events.includes(game.played_card)) { + goto_vm(game.vm_event)} + else { + next_player() + log(`C${game.vm_event}`) + goto_vm(game.vm_event) + } + }, + card_influence(card) { + push_undo() + select_card(card) + game.stasi_card = 0 + log_gap(`Played C${cards[game.played_card].number} to place SPs`) + + + // Check if Common European Home played for influence + if (game.played_card === 21) { + if (game.active === DEM) { + game.vp -- + log('-1 VP') + if (check_vp()) { + return + } + } else { + game.vp ++ + log('+1 VP') + if (check_vp()) { + return + } + } + } + // Check if card is opponent card with event that needs to be resolved + + if (cards[game.played_card].playable || game.playable_cards.includes(game.played_card)) { + if ((game.active === DEM && cards[game.played_card].side === "C" ) || (game.active === COM && cards[game.played_card].side === "D")) { + //game.phase = 1 /*Do I need this? */ + game.vm_event_to_do = true + } + } + + // If ABHR - Set AHBR tracker to true + if (game.persistent_events.includes(58)) { + game.austria_hungary_border_reopened_tracker = true + } + game.state='add_influence' + valid_spaces_infl() + }, + card_tst(card) { + push_undo() + select_card(card) + game.stasi_card = 0 + log_gap(`Played C${cards[game.played_card].number} to the Tiananmen Square Track`) + game.state='tiananmen_square_attempt' + }, + card_support_check(card) { + push_undo() + select_card(card) + log_gap(`Played C${cards[game.played_card].number} for support checks`) + + // Check if card is opponent card with event that needs to be resolved + /*if (game.phase === 0 && game.active === DEM && cards[game.played_card].side === "C" && game.playable_cards[game.played_card].playable === 1 || game.phase === 0 && game.active === COM && cards[game.played_card].side === "D" && game.playable_cards[game.played_card].playable === 1 ) { + game.vm_event_to_do = true + }*/ + + if (cards[game.played_card].playable || game.playable_cards.includes(game.played_card)) { + if ((game.active === DEM && cards[game.played_card].side === "C" ) || (game.active === COM && cards[game.played_card].side === "D")) { + game.vm_event_to_do = true + } + } + + game.available_ops = 2 + game.state='support_check_prep' + valid_spaces_sc() + }, + card_tst_8(card) { /*Play card for ops and event */ + select_card(card) + game.vm_event_to_do = true + game.vm_infl_to_do = true + game.tst_8 = true + game.state = 'vm_tst_8' + }, done () { game.stasi_card = 0 if (game.democrat_hand.includes(21)) { @@ -3253,14 +3571,14 @@ function find_event(card) { function get_events(card){ if (cards[card].side === 'D') { - if (game.active === DEM) {gen_action('event')} - if (game.active === COM) {gen_action('opp_event')} + if (game.active === DEM) {gen_action('card_event', card)} + if (game.active === COM) {gen_action('card_opp_event', card)} } else if (cards[card].side === 'C') { - if (game.active === COM) {gen_action('event')} - if (game.active === DEM) {gen_action('opp_event')} + if (game.active === COM) {gen_action('card_event', card)} + if (game.active === DEM) {gen_action('card_opp_event', card)} } else { - gen_action('event') + gen_action('card_event', card) } } @@ -3433,11 +3751,13 @@ function end_round() { } // Resolve end action round - + //Stasi check if(game.round_player === COM && game.persistent_events.includes(13)) { game.round_player = DEM if (game.active !== DEM) { next_player() + } else { + log_h3('Democratic Action Round') } if (game.democrat_hand.includes(game.stasi_card)) { game.state = 'stasi_play_card' @@ -3446,11 +3766,15 @@ function end_round() { game.state = 'choose_card' } return - } else if (game.round_player === COM && game.round === 8) { + } + //Check if in extra Action Round + else if (game.round_player === COM && game.round === 8) { clear_undo() game.state = 'end_turn_4_5_4' return - } else if (game.round_player===COM) { + } + //Normal round end + else if (game.round_player===COM) { game.round_player = DEM if (game.active !== DEM) { next_player() -- cgit v1.2.3 From c6928522ceef8da847d005942da4479b340a4851 Mon Sep 17 00:00:00 2001 From: iainp5 Date: Mon, 7 Oct 2024 17:18:05 +0100 Subject: Stasi updates --- rules.js | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/rules.js b/rules.js index 870c061..a073d27 100644 --- a/rules.js +++ b/rules.js @@ -264,18 +264,18 @@ exports.view = function(state, player) { // === ACTIONS =========== function gen_action(action, argument) { -console.log('gen_action called with ', action, ' and ', argument) +//console.log('gen_action called with ', action, ' and ', argument) if (argument === undefined) { - console.log('argument undefined') + //console.log('argument undefined') view.actions[action] = 1 } else { if (!(action in view.actions)) { - console.log('push argument') + //console.log('push argument') view.actions[action] = [] } view.actions[action].push(argument) } - console.log('view.actions: ', view.actions, 'view.actions[action]: ', view.actions[action]) + //console.log('view.actions: ', view.actions, 'view.actions[action]: ', view.actions[action]) } function gen_action_infl(space){ @@ -2267,11 +2267,11 @@ states.stasi_play_card = { //Check if Player has Common European Home in hand if (game.active === DEM) { - if (game.democrat_hand.includes(21) && cards[card].side === "C") { + if (game.democrat_hand.includes(21) && cards[card].side === "C" && card !== 21) { gen_action('card_ceh', card) } } else { - if (game.communist_hand.includes(21) && cards[card].side === "D") { + if (game.communist_hand.includes(21) && cards[card].side === "D" && card !== 21) { gen_action('card_ceh', card) } } @@ -2297,15 +2297,17 @@ states.stasi_play_card = { //Continue with normal logic - //Check if it is a card with an event which is always playable + //Check if it is a card with an event which is always playable. May not play Common European Home for event in Stasi - if (cards[card].playable) { + if (cards[card].playable && card !== 21) { + console.log('get events called normally for card', card) get_events(card) } - // Resolve cards with variable events (not Reformer) + // Resolve cards with variable events (not Reformer, not Common European Home in Stasi) - if (card !== 67 && game.playable_cards.includes(card)) { + if (card !== 67 && card !== 21 && game.playable_cards.includes(card)) { + console.log('get events called variable for card', card) get_events(card) } /* if ((game.active === DEM && cards[game.played_card].side === 'D' && game.playable_cards[game.played_card].playable === 1) || (game.active === COM && cards[game.played_card].side === 'C' && game.playable_cards[game.played_card].playable ===1) || (cards[game.played_card].side === 'N'&& game.playable_cards[game.played_card].playable ===1)) { @@ -2848,12 +2850,12 @@ function valid_spaces_sc() { if (game.active === DEM) { infl = game.comInfl[i] - //if (infl !== 0 ) { + if (infl !== 0 ) { valid_spaces_set.add(space.space_id); - //} + } } else { infl = game.demInfl[i] - //if (infl !== 0 ) { + if (infl !== 0 ) { // Check Solidarity Legalised if (game.persistent_events.includes(2) && space.space_id === 14) {continue} @@ -2869,7 +2871,7 @@ function valid_spaces_sc() { valid_spaces_set.add(space.space_id); } - //} + } } } @@ -3758,6 +3760,7 @@ function end_round() { next_player() } else { log_h3('Democratic Action Round') + log_h3('C13') } if (game.democrat_hand.includes(game.stasi_card)) { game.state = 'stasi_play_card' -- cgit v1.2.3 From f0d938b50aa2a06e4223df1c2297e7310b0c9221 Mon Sep 17 00:00:00 2001 From: iainp5 Date: Mon, 7 Oct 2024 18:12:20 +0100 Subject: Popup with scoring cards --- play.html | 8 ++++---- play.js | 3 ++- rules.js | 3 +-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/play.html b/play.html index 6d674a3..89c0e38 100644 --- a/play.html +++ b/play.html @@ -28,7 +28,7 @@
  • 📣 Place SPs
  • 💪 Support Check -
  • 🦻 Tiananmen Square Track +
  • 🛢 Tiananmen Square Track
  • @@ -38,7 +38,7 @@
  • 🎴 Resolve Opponent Event
  • 📣 Place SPs
  • 💪 Support Check -
  • 🦻 Tiananmen Square Track +
  • 🛢 Tiananmen Square Track
  • @@ -48,7 +48,7 @@
  • 🎴 Resolve Opponent Event
  • 📣 Place SPs
  • 💪 Support Check -
  • 🦻 Tiananmen Square Track +
  • 🛢 Tiananmen Square Track
  • @@ -213,7 +213,7 @@
    Set aside card
    -
    +
    diff --git a/play.js b/play.js index fcbf6e7..791026e 100644 --- a/play.js +++ b/play.js @@ -624,8 +624,9 @@ if (view.ceausescu_cards && view.ceausescu_cards.length > 0 && view.is_pwr_strug // SAMIZDAT CARD if (view.samizdat > 0 ) { + let samizdat_card = ui.cards[view.samizdat] document.getElementById("samizdat_panel").classList.remove("hide") - document.getElementById("samizdat_hand").appendChild(view.samizdat) + document.getElementById("samizdat_card").appendChild(samizdat_card) } else { document.getElementById("samizdat_panel").classList.add("hide") } diff --git a/rules.js b/rules.js index a073d27..99450a1 100644 --- a/rules.js +++ b/rules.js @@ -275,7 +275,7 @@ function gen_action(action, argument) { } view.actions[action].push(argument) } - //console.log('view.actions: ', view.actions, 'view.actions[action]: ', view.actions[action]) + console.log('view.actions: ', view.actions, 'view.actions[action]: ', view.actions[action]) } function gen_action_infl(space){ @@ -433,7 +433,6 @@ states.choose_card = { if (scoring_cards.includes(card)) { /*view.prompt = 'Play for:'*/ gen_action('card_event', card) - return } -- cgit v1.2.3 From 709c5f22e4e3c2e71f7385edbee0ce9922b25863 Mon Sep 17 00:00:00 2001 From: iainp5 Date: Mon, 7 Oct 2024 19:12:12 +0100 Subject: Final tweaks to view --- play.html | 8 ++++++-- play.js | 11 +++++++++-- rules.js | 35 ++++++++++++++++++++--------------- 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/play.html b/play.html index 89c0e38..ea43ca8 100644 --- a/play.html +++ b/play.html @@ -51,10 +51,14 @@
  • 🛢 Tiananmen Square Track
  • - +
  • TITLE
  • -
  • 🎴 Select Card +
  • 🎴 Event and Operations +
  • 🎴 Event +
  • 📣 Place SPs +
  • 💪 Support Check +
  • 🛢 Tiananmen Square Track
  • diff --git a/play.js b/play.js index 791026e..c1e4111 100644 --- a/play.js +++ b/play.js @@ -225,6 +225,7 @@ function hide_popup_menu() { document.getElementById("popup").style.display = "none" document.getElementById("popup_ceh_check").style.display = "none" document.getElementById("popup_opp_event").style.display = "none" + document.getElementById("popup_tst_8").style.display = "none" } @@ -268,8 +269,14 @@ function on_click_card(evt) { if (send_action('card', card)) { evt.stopPropagation(); } - //Check for Common European Home - } else if (is_card_action('card_ceh', card)) { + } + //First check for TST special power + else if (is_card_action('card_tst_8', card)) { + show_popup_menu(evt, "popup_tst_8", card, cards[card].name) + } + + //Check for Common European Home + else if (is_card_action('card_ceh', card)) { show_popup_menu(evt, "popup_ceh_check", card, cards[card].name) } else if (is_card_action('card_opp_event', card)) { console.log('in action card_opp_event') diff --git a/rules.js b/rules.js index 99450a1..b05c3e7 100644 --- a/rules.js +++ b/rules.js @@ -275,7 +275,7 @@ function gen_action(action, argument) { } view.actions[action].push(argument) } - console.log('view.actions: ', view.actions, 'view.actions[action]: ', view.actions[action]) + //console.log('view.actions: ', view.actions, 'view.actions[action]: ', view.actions[action]) } function gen_action_infl(space){ @@ -437,6 +437,7 @@ states.choose_card = { //Check for Tiananmen Square Track awards special abilities + console.log('game.tst_8', game.tst_8) if ((game.active === DEM && cards[card].side !== 'C' && game.dem_tst_position >= 8 && game.com_tst_position < 8 && !game.tst_8) || (game.active === COM && cards[card].side !== 'D' && game.com_tst_position >= 8 && game.dem_tst_position < 8 && !game.tst_8)){ gen_action('card_tst_8', card) } @@ -467,18 +468,17 @@ states.choose_card = { if (card !== 67 && game.playable_cards.includes(card)) { get_events(card) - } /* - if ((game.active === DEM && cards[game.played_card].side === 'D' && game.playable_cards[game.played_card].playable === 1) || (game.active === COM && cards[game.played_card].side === 'C' && game.playable_cards[game.played_card].playable ===1) || (cards[game.played_card].side === 'N'&& game.playable_cards[game.played_card].playable ===1)) { - gen_action('event') - } else if ((game.active === DEM && (cards[game.played_card].side === 'C' && game.playable_cards[game.played_card].playable ===1)) || game.active === COM && (cards[game.played_card].side === 'D' && game.playable_cards[game.played_card].playable ===1)) { - gen_action('opp_event') - } */ - - gen_action('card_influence', card) - if (game.active === DEM && game.dem_tst_attempted_this_turn === 0 && game.dem_tst_position <=8 || game.active === COM && game.com_tst_attempted_this_turn === 0 && game.com_tst_position <= 8) { - gen_action('card_tst', card) - } - gen_action('card_support_check', card) + } + + //Actions for non-scoring cards + + if (!scoring_cards.includes(card)) { + gen_action('card_influence', card) + if (game.active === DEM && game.dem_tst_attempted_this_turn === 0 && game.dem_tst_position <=8 || game.active === COM && game.com_tst_attempted_this_turn === 0 && game.com_tst_position <= 8) { + gen_action('card_tst', card) + } + gen_action('card_support_check', card) + } } } }, @@ -2603,6 +2603,7 @@ function remove_infl(space) { } function do_sc(space) { + clear_undo() log_gap(`Support check: ${space}`) let clicked_space = find_space_index(space) @@ -2612,10 +2613,12 @@ function do_sc(space) { log('+1 VP from C26') game.vp ++ if (check_vp()) { + game.state = 'game.over' + console.log('after check_vp, game.state', game.state) return } } - + console.log('continue support check, game.state', game.state) // Continue with Support Check Logic let roll = Math.floor(Math.random() * 6) + 1 @@ -2811,7 +2814,7 @@ function do_sc(space) { } } game.selected_space = 0 - clear_undo() + } @@ -3475,6 +3478,7 @@ function permanently_remove(card) { function check_vp() { if (game.vp >= 20) { goto_game_over(DEM, `${DEM} won an Automatic Victory!`) + console.log('after goto_game_over, game.state', game.state) return true } else if(game.vp <= -20) { goto_game_over(COM, `${COM} won an Automatic Victory!`) @@ -3496,6 +3500,7 @@ function goto_game_over(result, victory) { game.victory = victory log_h1("Game Over") log(game.victory) + console.log('game over, game.state', game.state) return } -- cgit v1.2.3