From 4eb3c91f4c644129f6fe9f81ecd5b2c5b8838880 Mon Sep 17 00:00:00 2001 From: Mischa Untaga <99098079+MischaU8@users.noreply.github.com> Date: Fri, 24 Nov 2023 15:52:54 +0100 Subject: draw 6 cards, select which to put on top --- play.html | 4 ++++ play.js | 3 ++- rules.js | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 60 insertions(+), 7 deletions(-) diff --git a/play.html b/play.html index bfa01a0..f9f2455 100644 --- a/play.html +++ b/play.html @@ -397,6 +397,10 @@ div.button_box .button { box-shadow: 0 0 0 3px yellow; } +.card.played { + box-shadow: 0 0 0 3px blue; +} + #tooltip { position: fixed; pointer-events: none; diff --git a/play.js b/play.js index 10c3b84..e702d49 100644 --- a/play.js +++ b/play.js @@ -715,7 +715,8 @@ function on_update() { // eslint-disable-line no-unused-vars for (let i = 1; i < ui.cards.length; ++i) { ui.cards[i].classList.toggle("action", is_card_enabled(i)) - ui.cards[i].classList.toggle("selected", i === view.played_card) + ui.cards[i].classList.toggle("played", i === view.played_card) + ui.cards[i].classList.toggle("selected", view.selected_cards.includes(i)) } for (let i = 1; i < ui.regions.length; ++i) { diff --git a/rules.js b/rules.js index 00f55d9..e505bcb 100644 --- a/rules.js +++ b/rules.js @@ -506,6 +506,7 @@ exports.setup = function (seed, _scenario, _options) { state: null, played_card: 0, + selected_cards: [], turn: 0, round: 0, @@ -635,6 +636,7 @@ exports.VIEW_SCHEMA = { out_of_play: {type: "array", items: {type: "integer", minimum: 1, maximum: 128}}, hand: {type: "array", items: {type: "integer", minimum: 1, maximum: 128}}, + selected_cards: {type: "array", items: {type: "integer", minimum: 1, maximum: 128}}, }, required: [ @@ -690,12 +692,15 @@ exports.view = function(state, player) { out_of_play: game.out_of_play, hand: [], + selected_cards: [], } if (player === SUF) { view.hand = game.support_hand + view.selected_cards = game.selected_cards } else if (player === OPP) { view.hand = game.opposition_hand + view.selected_cards = game.selected_cards } if (game.state === "game_over") { @@ -2116,8 +2121,18 @@ function vm_draw_2_play_1_event() { } function vm_draw_6_place_any_on_top_of_draw() { - log("TODO draw_6_place_any_on_top_of_draw") - vm_next() + clear_undo() + game.vm.draw = [] + game.selected_cards = [] + let draw_count = Math.min(player_deck().length, 6) + for (let i = 0; i < draw_count; ++i) { + let card = draw_card(player_deck()) + game.vm.draw.push(card) + player_hand().push(card) + } + + log(`${game.active} drew ${draw_count} cards.`) + game.state = "vm_draw_6_place_any_on_top_of_draw" } function vm_support_discard_2_random_draw_2() { @@ -2688,8 +2703,6 @@ states.vm_counter_strat = { } } - - states.vm_draw_2_play_1_event = { inactive: "choose which card to play.", prompt() { @@ -2711,12 +2724,12 @@ states.vm_draw_2_play_1_event = { end_play_card(game.played_card) let other = game.vm.draw.find(x => x !== c) discard_card_from_hand(other) - log(`C${other} discarded.`) + log(`Discarded C${other}.`) delete game.vm.draw play_card_event(c) }, skip() { - log(`None of the drawn cards could be played.`) + log("None of the drawn cards could be played.") for (let c of game.vm.draw) { discard_card_from_hand(c) } @@ -2725,6 +2738,41 @@ states.vm_draw_2_play_1_event = { } } +states.vm_draw_6_place_any_on_top_of_draw = { + inactive: "choose which cards to put on top of their Draw Deck.", + prompt() { + event_prompt(`Select which cards to put on top of your Draw Deck. ${game.selected_cards.length} selected.`) + for (let c of game.vm.draw) { + if (!game.selected_cards.includes(c)) + gen_action_card(c) + } + + gen_action("done") + }, + card(c) { + push_undo() + game.selected_cards.push(c) + }, + done() { + log(`${game.active} selected ${pluralize(game.selected_cards.length, 'card')} to put on top of their Draw Deck.`) + + // XXX does this order make sense? first selected card goes on top. + for (let c of game.selected_cards.reverse()) { + player_deck().push(c) + array_remove_item(game.vm.draw, c) + array_remove_item(player_hand(), c) + } + for (let c of game.vm.draw) { + player_deck().unshift(c) + array_remove_item(player_hand(), c) + } + + delete game.vm.draw + game.selected_cards = [] + vm_next() + } +} + // #endregion // #region LOGGING -- cgit v1.2.3