diff options
-rw-r--r-- | rules.js | 70 |
1 files changed, 48 insertions, 22 deletions
@@ -127,7 +127,7 @@ exports.view = function (state, role) { dice: game.dice, } - if (game.cmd && game.cmd.attacker) { + if (game.cmd && "attacker" in game.cmd) { view.attack = { where: game.cmd.where, attacker: game.cmd.attacker, @@ -266,7 +266,7 @@ exports.setup = function (seed, scenario, _options) { } function setup_deck() { - game.deck = [ 22, 21, 4, 1, 29, 15, 17, 16, 18, 5, 3, 36, 10, 37, 11, 2, 10, 1, 12, 13, 14 ] + game.deck = [ 22, 38, 21, 39, 4, 1, 29, 15, 17, 16, 18, 5, 3, 36, 10, 37, 11, 2, 10, 1, 12, 13, 14 ] } function setup_standard() { @@ -1023,18 +1023,18 @@ function goto_attack_select() { } } -function roll_attack(faction_d) { +function roll_attack() { for (let d = 0; d < 6; ++d) game.dice[d] = random(6) + 1 - if (faction_d === BK && has_piece(game.cmd.where, BK, DISC)) + if (game.cmd.target === BK && has_piece(game.cmd.where, BK, DISC)) game.dice[3] = 0 } -function attack_use_cavalry(d) { - use_cavalry(game.current) +function attack_use_cavalry(d, f) { + use_cavalry(f) - let is_attacker = (game.current === game.cmd.attacker) + let is_attacker = (f === game.cmd.attacker) let is_a_die = (d < 4) if (is_a_die && is_attacker) { @@ -1115,7 +1115,7 @@ function goto_attack_space() { set_add(game.cmd.selected, p) set_add(game.cmd.pieces, p) game.cmd.n_units[1] += 1 - if (game.cmd.attacker === DS) + if (game.cmd.attacker === DS && game.cmd.target !== MI) to_rebel(p) } }) @@ -1200,17 +1200,15 @@ states.attack_space = { log_br() game.cmd.step = 0 - goto_attack_cavalry() + next_attack_cavalry_step() } } -function goto_attack_cavalry() { +function next_attack_cavalry_step() { if (game.cmd.step === 0) { - game.current = game.cmd.attacker - game.state = "attack_cavalry" + goto_attack_cavalry(game.cmd.attacker) } else if (game.cmd.step === 1) { - game.current = game.cmd.target - game.state = "attack_cavalry" + goto_attack_cavalry(game.cmd.target) } else { game.cmd.a_hit = game.dice.slice(0,4).filter(d => d > 0 && d <= game.cmd.n_units[0]).length game.cmd.d_hit = game.dice.slice(4).filter(d => d > 0 && d <= game.cmd.n_units[1]).length @@ -1222,6 +1220,23 @@ function goto_attack_cavalry() { } } +function goto_attack_cavalry(curr) { + if (curr === MI && curr === game.cmd.target) { + if (game.dice[4] - 1 === game.cmd.n_units[1]) { + log(`${faction_acronyms[game.current]} is using Cavalry.`) + attack_use_cavalry(4, MI) + } else if (game.dice[5] - 1 === game.cmd.n_units[1]) { + log(`${faction_acronyms[game.current]} is using Cavalry.`) + attack_use_cavalry(5, MI) + } + game.cmd.step += 1 + next_attack_cavalry_step() + } else { + game.current = curr + game.state = "attack_cavalry" + } +} + states.attack_cavalry = { prompt() { view.prompt = "Attack: Use cavalry to Charge your dice or Screen your opponent's dice." @@ -1242,11 +1257,11 @@ states.attack_cavalry = { log(`${faction_acronyms[game.current]} is using Cavalry.`) game.cmd.cavalry = true } - attack_use_cavalry(d) + attack_use_cavalry(d, game.current) }, next() { game.cmd.step += 1 - goto_attack_cavalry() + next_attack_cavalry_step() } } @@ -1260,23 +1275,32 @@ function get_attack_victor() { } function goto_attack_casualties(step) { - let next_state if (step === "target") { game.current = game.cmd.target game.cmd.count = game.cmd.a_hit - next_state = "attack_casualties" } else if (step === "attacker") { game.current = game.cmd.attacker game.cmd.count = game.cmd.d_hit - next_state = "attack_casualties" } - if (game.cmd.count > 0) - game.state = next_state - else + // Auto-remove MI casualties + if (game.current === MI) { + remove_mi_casualties(game.cmd.where) + end_attack_casualties() + } else if (game.cmd.count > 0) { + game.state = "attack_casualties" + } else end_attack_casualties() } +function remove_mi_casualties(s) { + while (game.cmd.count > 0 && count_pieces(s, MI, TROOPS) > 0) { + let p = find_piece(s, MI, TROOPS) + remove_piece(p) + game.cmd.count -= 1 + } +} + states.attack_casualties = { prompt() { if ( @@ -3464,6 +3488,8 @@ function for_each_movable(faction, f) { else if (faction === DS) { for_each_piece(DS, TROOPS, f) for_each_piece(DS, ELITE, f) + } else if (faction === MI) { + for_each_piece(MI, TROOPS, f) } } |