From 47b91ab24f6476aea134fff4516e7510e8fdefba Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Wed, 13 Dec 2023 00:38:41 +0100 Subject: attack_choose_target --- rules.js | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/rules.js b/rules.js index 3f20f9b..5ae8fcb 100644 --- a/rules.js +++ b/rules.js @@ -1383,7 +1383,10 @@ function goto_take_action(c, ix) { game.action = ix switch (a.type) { case "Attack": - goto_attack() + if (card_has_rule(game.selected, "attack_choose_target")) + goto_attack_choose_target() + else + goto_attack(find_target_of_attack(a)) break case "Bombard": game.state = "bombard" @@ -1449,7 +1452,38 @@ states.bombard = { }, } -function goto_attack() { +function goto_attack_choose_target() { + let a = current_action() + let candidates = [] + for (let c of a.target_list) { + if (set_has(game.front[0], c)) + candidates.push(c) + if (set_has(game.front[1], c)) + candidates.push(c) + } + if (candidates.length > 1) + game.state = "attack_choose_target" + else + goto_attack(candidates[0]) +} + +states.attack_choose_target = { + prompt() { + view.prompt = "Choose the target of your attack." + let a = current_action() + for (let c of a.target_list) { + if (set_has(game.front[0], c)) + gen_action_card(c) + if (set_has(game.front[1], c)) + gen_action_card(c) + } + }, + card(c) { + goto_attack(c) + }, +} + +function goto_attack(target) { let a = current_action() let take_from = card_has_rule(game.selected, "take_from") @@ -1459,7 +1493,7 @@ function goto_attack() { } game.state = "attack" - game.target = find_target_of_attack(a) + game.target = target game.hits = get_attack_hits(game.selected, a) game.self = get_attack_self(game.selected, a) @@ -1902,6 +1936,7 @@ function get_attack_hits(c, a) { throw new Error("invalid attack effect: " + a.effect) case "1 hit.": case "1 hit. Warwick Retires upon completing this Attack Action.": + case "1 hit. You CHOOSE the target.": case "1 hit. 1 self per action.": return 1 case "1 hit per die.": @@ -1923,6 +1958,7 @@ function get_attack_self(c, a) { throw new Error("invalid attack effect: " + a.effect) case "1 hit.": case "1 hit. Warwick Retires upon completing this Attack Action.": + case "1 hit. You CHOOSE the target.": case "1 hit per die.": case "1 hit per die. Ignore first target until it comes out of Reserve.": case "1 hit per pair.": -- cgit v1.2.3