summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--play.css8
-rw-r--r--play.js19
-rw-r--r--rules.js201
3 files changed, 223 insertions, 5 deletions
diff --git a/play.css b/play.css
index 1aa535f..3f9e331 100644
--- a/play.css
+++ b/play.css
@@ -205,6 +205,14 @@ body.America header.your_turn { background-color: hsl(211, 50%, 75%) }
box-shadow: 1px 1px 4px #0008;
}
+.card.action {
+ box-shadow: 0 0 0 3px white;
+}
+
+.card.selected {
+ box-shadow: 0 0 0 3px yellow;
+}
+
.card.shrink {
width: 187px;
height: 262px;
diff --git a/play.js b/play.js
index a386b5a..e2e966d 100644
--- a/play.js
+++ b/play.js
@@ -243,6 +243,7 @@ function on_init() {
if (c > 0) {
e.my_id = c
e.onclick = on_click_card
+ register_action(e, "card", c)
}
}
@@ -621,9 +622,12 @@ function on_update() {
show_marker_at_xy(ui.french_alliance, data.layout.french_alliance_track[view.french_alliance])
ui.hand.replaceChildren()
- if (view.hand)
- for (let c of view.hand)
+ if (view.hand) {
+ for (let c of view.hand) {
+ ui.cards[c].classList.toggle("selected", view.selected_card === c)
ui.hand.appendChild(ui.cards[c])
+ }
+ }
e = document.getElementById("war_ends")
if (view.war_ends)
@@ -654,6 +658,15 @@ function on_update() {
animate_positions()
+ action_button("exchange", "Exchange")
+ action_button("queue", "Queue")
+ action_button("reinforce", "Reinforce")
+ action_button("activate", "Activate")
+ action_button("pc_action", "PC Action")
+ action_button("event", "Event")
+ action_button("campaign", "Campaign")
+
+
action_button("pickup_french_cu", "Take French CU")
action_button("pickup_british_cu", "Take CU")
action_button("pickup_american_cu", "Take CU")
@@ -1068,7 +1081,7 @@ function on_update() {
let cards = view.hand
for (let c = 1; c <= 110; ++c) {
- ui.cards[c].classList.remove("enabled")
+ ui.cards[c].classList.toggle("selected", view.selected_card === c)
if (cards && cards.includes(c))
ui.cards[c].classList.add("show")
else
diff --git a/rules.js b/rules.js
index 28435af..ac0bd39 100644
--- a/rules.js
+++ b/rules.js
@@ -1165,7 +1165,7 @@ function goto_strategy_phase(new_active) {
log("=b Britain")
}
-states.strategy_phase = {
+states.strategy_phase_OLD = {
inactive: "to play a strategy card",
prompt() {
view.prompt = "Play a strategy card."
@@ -1263,6 +1263,151 @@ states.strategy_phase = {
},
}
+states.strategy_phase = {
+ inactive: "to play a strategy card",
+ prompt() {
+ view.prompt = "Play a strategy card."
+ for (let c of active_hand())
+ gen_action_card("card", c)
+ },
+ card(c) {
+ push_undo()
+ let card = CARDS[c]
+ game.card = c
+ switch (card.type) {
+ case "ops":
+ game.state = "strategy_phase_ops"
+ break
+ default:
+ game.state = "strategy_phase_event"
+ break
+ }
+ },
+}
+
+states.strategy_phase_ops = {
+ inactive: "to play a strategy card",
+ prompt() {
+ let c = game.card
+ view.selected_card = game.card
+ view.prompt = "Use " + CARDS[c].title + "."
+ if (can_exchange_for_discard(c))
+ view.actions.exchange = 1
+ if (can_activate_general(c))
+ view.actions.activate = 1
+ if (can_play_reinforcements())
+ view.actions.reinforce = 1
+ if (game.active === P_AMERICA && game.a_queue < 2 && CARDS[c].count < 3)
+ view.actions.queue = 1
+ if (game.active === P_BRITAIN && game.b_queue < 2 && CARDS[c].count < 3)
+ view.actions.queue = 1
+ view.actions.pc_action = 1
+ },
+
+ pc_action() {
+ let c = game.card
+ game.did_discard_event = 0
+ clear_queue()
+ play_card(c, "for PC")
+ goto_ops_pc(CARDS[c].count)
+ },
+ activate() {
+ let c = game.card
+ game.did_discard_event = 0
+ goto_ops_general(c)
+ },
+ reinforce() {
+ let c = game.card
+ game.did_discard_event = 0
+ clear_queue()
+ goto_ops_reinforcements(c)
+ },
+ queue() {
+ let c = game.card
+ game.did_discard_event = 0
+ play_card(c, "to queue")
+ if (game.active === P_BRITAIN)
+ game.b_queue += CARDS[c].count
+ else
+ game.a_queue += CARDS[c].count
+ end_strategy_card()
+ },
+ exchange() {
+ let c = game.card
+ let d = game.did_discard_event
+ game.did_discard_event = 0
+ discard_card(c, "exchange")
+ set_add(active_hand(), d)
+ logp("picked up up #" + d)
+ },
+}
+
+states.strategy_phase_event = {
+ inactive: "to play a strategy card",
+ prompt() {
+ let c = game.card
+ view.selected_card = game.card
+ view.prompt = "Use event card."
+
+ view.actions.event = 0
+ view.actions.pc_action = 0
+
+ let card = CARDS[c]
+ switch (card.type) {
+ case "mandatory-event":
+ view.actions.event = 1
+ view.actions.pc_action = 0
+ break
+ case "campaign":
+ view.actions.campaign = 1
+ view.actions.pc_action = 0
+ break
+ case "british-event":
+ case "british-event-or-battle":
+ if (game.active === P_BRITAIN) {
+ if (can_play_event(c))
+ view.actions.event = 1
+ else
+ view.actions.event = 0
+ }
+ view.actions.pc_action = 1
+ break
+ case "american-event":
+ if (game.active === P_AMERICA) {
+ if (can_play_event(c))
+ view.actions.event = 1
+ else
+ view.actions.event = 0
+ }
+ view.actions.pc_action = 1
+ break
+ case "british-battle":
+ case "american-battle":
+ view.actions.pc_action = 1
+ break
+ }
+ },
+ campaign() {
+ let c = game.card
+ game.did_discard_event = 0
+ clear_queue()
+ goto_campaign(c)
+ },
+ event() {
+ let c = game.card
+ game.did_discard_event = 0
+ clear_queue()
+ do_event(c)
+ },
+ pc_action() {
+ let c = game.card
+ game.did_discard_event = c
+ clear_queue()
+ discard_card(c, "PC action")
+ game.state = "discard_event_pc_action"
+ },
+}
+
function end_strategy_card() {
if (automatic_victory()) {
clear_undo()
@@ -2329,6 +2474,10 @@ states.play_attacker_battle_card = {
view.actions.pass = 1
gen_battle_card()
},
+ card(c) {
+ play_battle_card(this, c)
+ // TODO: pause!
+ },
card_battle_play(c) {
play_card(c, "for +2 DRM")
if (game.active === P_BRITAIN) {
@@ -2369,6 +2518,10 @@ states.play_defender_battle_card = {
view.actions.pass = 1
gen_battle_card()
},
+ card(c) {
+ play_battle_card(this, c)
+ // TODO: pause!
+ },
card_battle_play(c) {
play_card(c, "for +2 DRM")
if (game.active === P_BRITAIN) {
@@ -2398,7 +2551,7 @@ states.play_defender_battle_card = {
},
}
-function gen_battle_card() {
+function gen_battle_card_OLD() {
for (let c of active_hand()) {
let card = CARDS[c]
if (game.active === P_BRITAIN) {
@@ -2429,6 +2582,50 @@ function gen_battle_card() {
}
}
+function play_battle_card(st, c) {
+ let card = CARDS[c]
+ if (game.active === P_BRITAIN) {
+ switch (card.type) {
+ case "british-battle":
+ case "british-event-or-battle":
+ st.card_battle_play(c)
+ break
+ case "british-event":
+ case "american-event":
+ case "american-battle":
+ st.card_battle_discard(c)
+ break
+ }
+ } else {
+ switch (card.type) {
+ case "british-battle":
+ case "british-event-or-battle":
+ case "british-event":
+ case "american-event":
+ st.card_battle_discard(c)
+ break
+ case "american-battle":
+ st.card_battle_play(c)
+ break
+ }
+ }
+}
+
+function gen_battle_card() {
+ for (let c of active_hand()) {
+ let card = CARDS[c]
+ switch (card.type) {
+ case "british-battle":
+ case "british-event-or-battle":
+ case "british-event":
+ case "american-event":
+ case "american-battle":
+ gen_action_card("card", c)
+ break
+ }
+ }
+}
+
/* RESOLVE BATTLE */
function roll_loser_combat_losses(log) {