From fe861a54da448078aac87288a1e8929a8bc2c5fb Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Thu, 29 Dec 2022 13:51:23 +0100 Subject: Event discard helper. --- rules.js | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/rules.js b/rules.js index 8aaf2ed..1504fb5 100644 --- a/rules.js +++ b/rules.js @@ -1470,6 +1470,18 @@ function discard_card(c) { set_add(game.deck2, c) } +function discard_events(when) { + for (let i = 0; i < game.events.length; ) { + let c = game.events[i] + if (data.cards[c].when === when) { + array_remove(game.events, i) + discard_card(c) + } else { + ++i + } + } +} + exports.setup = function (seed, scenario, options) { game = { seed, @@ -2606,15 +2618,7 @@ function end_levy_call_to_arms() { function goto_levy_discard_events() { // Discard "This Levy" events from play. - for (let i = 0; i < game.events.length; ) { - let c = game.events[i] - if (data.cards[c].when === "this_levy") { - array_remove(game.events, i) - discard_card(c) - } else { - ++i - } - } + discard_events("this_levy") set_active(P1) goto_capability_discard() @@ -7480,15 +7484,7 @@ function goto_reset() { } // Discard "This Campaign" events from play. - for (let i = 0; i < game.events.length; ) { - let c = game.events[i] - if (data.cards[c].when === "this_campaign") { - array_remove(game.events, i) - discard_card(c) - } else { - ++i - } - } + discard_events("this_campaign") goto_advance_campaign() } -- cgit v1.2.3