From da8e47dee845d1c513fec3f21a0015c48ea1632e Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sat, 16 Dec 2023 19:39:52 +0100 Subject: WIP CHECK ATTACKS --- rules.js | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/rules.js b/rules.js index c92b2ba..bca5b72 100644 --- a/rules.js +++ b/rules.js @@ -22,7 +22,38 @@ function find_card(s, n) { // for (let c of data.cards) for (let a of c.actions) console.log(a.type, a.effect) // for (let c of data.cards) console.log(c.dice) -for (let c of data.cards) for (let a of c.actions) { if (a.type === "Counterattack") console.log(c.number, a.type, a.sequence, a.target) } +//for (let c of data.cards) for (let a of c.actions) { if (a.type === "Counterattack") console.log(c.number, a.type, a.sequence, a.target) } + +function check_attack_res(c, a) { + if (a.choice) + return + if (c.rules && c.rules["attack_reserve"]) + return + if (c.rules && c.rules["ignore_reserve"]) + return + let pc = null + let dead = [] + let last = a.target_list[a.target_list.length-1] + for (let tid of a.target_list) { + let t = data.cards[tid] + if (!t.reserve) { + // all good, targetable out of reserve + dead.push(tid) + } else if (Array.isArray(t.reserve)) { + // in reserve + for (let rid of t.reserve) + if (!dead.includes(rid) && tid !== last) + console.log("BLOCK (RES)", c.scenario, c.number, a.target, "(" + t.name + ")", "\n\t" + c.rule_text_1) + dead.push(tid) + } else { + // commanded? + if (tid !== last) + console.log("BLOCK (CMD)", c.scenario, c.number, a.target, "(" + t.name + ")", "\n\t" + c.rule_text_1) + } + } +} + +for (let c of data.cards) for (let a of c.actions) { if (a.type === "Attack") check_attack_res(c, a) } const P1 = "First" const P2 = "Second" -- cgit v1.2.3