diff options
author | Tor Andersson <tor@ccxvii.net> | 2023-12-16 03:38:40 +0100 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2024-01-08 16:36:48 +0100 |
commit | 511f63e26b2d150396d917bef2cfbfc32593e81c (patch) | |
tree | 7775c2bd1c4a95bbe891f3020d83e76fe91bd72e /rules.js | |
parent | bcac31232a4c4c44d2eec5fcbe514d06f364a681 (diff) | |
download | table-battles-511f63e26b2d150396d917bef2cfbfc32593e81c.tar.gz |
fix counterattack order
Diffstat (limited to 'rules.js')
-rw-r--r-- | rules.js | 43 |
1 files changed, 32 insertions, 11 deletions
@@ -2419,21 +2419,32 @@ function current_action() { function find_target_of_attack(c, a) { let in_res = card_has_rule(c, "attack_reserve") - for (let c of a.target_list) { - if (set_has(game.front[0], c)) - return c - if (set_has(game.front[1], c)) - return c + for (let t of a.target_list) { + if (set_has(game.front[0], t)) + return t + if (set_has(game.front[1], t)) + return t if (in_res) { - if (set_has(game.reserve[0], c)) - return c - if (set_has(game.reserve[1], c)) - return c + if (set_has(game.reserve[0], t)) + return t + if (set_has(game.reserve[1], t)) + return t } } return -1 } +function find_target_of_counterattack(a) { + // Note: only used for no-choice counterattacks + for (let t of a.target_list) { + if (set_has(game.front[0], t)) + return t + if (set_has(game.front[1], t)) + return t + } + return -1 +} + function find_first_target_of_command(c, a) { if (game.scenario === S37_INKERMAN) { @@ -2998,20 +3009,30 @@ function can_take_reaction(c, a, wild) { switch (a.type) { default: throw new Error("invalid reaction: " + a.type) + case "Screen": // if a friendly formation is attacked by a listed enemy formation // ... or a listed formation is attacked (Wheatfield Road Artillery, etc) if (!a.target_list.includes(game.selected) && !a.target_list.includes(game.target)) return false break + case "Counterattack": // if this formation is attacked if (game.target !== c) return false // ... by one of the listed targets - if (!a.target_list.includes(game.selected)) - return false + if (a.choice) { + // if "any" or "or" choice + if (!a.target_list.includes(game.selected)) + return false + } else { + // if strict order + if (find_target_of_counterattack(a) !== game.selected) + return false + } break + case "Absorb": // if attack target is listed on absorb action if (!a.target_list.includes(game.target)) |