summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
authorFrans Bongers <fransbongers@franss-mbp.home>2024-12-27 20:45:12 +0100
committerFrans Bongers <fransbongers@franss-mbp.home>2024-12-27 20:45:12 +0100
commit8749fad48dfca5d4374e15539b160db28a4ed2dc (patch)
tree12c3b418a99cdb15285d3cfebf99120b96dc7af9 /rules.js
parent9d0630a33e0358f943e68008823f355bceb71be1 (diff)
downloadland-and-freedom-8749fad48dfca5d4374e15539b160db28a4ed2dc.tar.gz
refactor selected cards
Diffstat (limited to 'rules.js')
-rw-r--r--rules.js87
1 files changed, 26 insertions, 61 deletions
diff --git a/rules.js b/rules.js
index 711573c..1573b05 100644
--- a/rules.js
+++ b/rules.js
@@ -147,6 +147,7 @@ function start_of_player_turn() {
const args = get_active_node_args();
const player = faction_player_map[args.f];
log_h2(player, player);
+ game.faction_turn = args.f;
resolve_active_and_proceed();
}
const engine_functions = {
@@ -261,19 +262,17 @@ function game_view(state, player) {
engine: game.engine,
log: game.log,
prompt: null,
- location: game.location,
- selected: game.selected,
bag_of_glory: game.bag_of_glory,
bonuses: game.bonuses,
current_events: game.current_events,
- final_bid: game.final_bid[faction_id],
fronts: game.fronts,
glory: game.glory,
hand: game.hands[faction_id],
hero_points: game.hero_points,
initiative: game.initiative,
medallions: game.medallions,
- selected_card: game.chosen_cards[faction_id],
+ played_card: game.played_card,
+ selected_cards: game.selected_cards[faction_id],
tableaus: game.tableaus,
tracks: game.tracks,
triggered_track_effects: game.triggered_track_effects,
@@ -315,11 +314,7 @@ function setup(seed, _scenario, _options) {
f: [],
},
engine: [],
- final_bid: {
- a: [],
- c: [],
- m: [],
- },
+ faction_turn: null,
fronts: {
a: {
value: -2,
@@ -354,11 +349,6 @@ function setup(seed, _scenario, _options) {
m: 0,
pool: 14,
},
- chosen_cards: {
- a: null,
- c: null,
- m: null,
- },
initiative: data_1.MODERATES_ID,
medallions: {
a: [],
@@ -366,6 +356,12 @@ function setup(seed, _scenario, _options) {
m: [],
pool: [],
},
+ played_card: null,
+ selected_cards: {
+ a: [],
+ c: [],
+ m: [],
+ },
tableaus: {
a: [],
c: [],
@@ -383,7 +379,6 @@ function setup(seed, _scenario, _options) {
used_medallions: [],
turn: 0,
year: 0,
- state_data: null,
};
draw_medallions();
start_year();
@@ -438,7 +433,7 @@ states.activate_icon = {
inactive: 'activate an icon',
prompt() {
view.prompt = 'Choose an icon to activate';
- const c = cards[game.chosen_cards[get_active_faction_id()]];
+ const c = cards[game.selected_cards[get_active_faction_id()][0]];
for (const i of c.icons) {
gen_action(i);
}
@@ -774,7 +769,7 @@ states.choose_card = {
gen_action_card(c);
},
card(c) {
- game.chosen_cards[player_faction_map[game.active]] = c;
+ game.selected_cards[player_faction_map[game.active]].push(c);
resolve_active_and_proceed();
},
};
@@ -784,7 +779,7 @@ states.choose_final_bid = {
view.prompt = 'Choose a card to add to the Final Bid';
const faction = get_active_faction();
for (let c of game.hands[faction]) {
- if (!game.final_bid[faction].includes(c)) {
+ if (!game.selected_cards[faction].includes(c)) {
gen_action_card(c);
}
}
@@ -792,8 +787,8 @@ states.choose_final_bid = {
},
card(c) {
const faction = get_active_faction();
- game.final_bid[faction].push(c);
- if (game.final_bid[faction].length < 3) {
+ game.selected_cards[faction].push(c);
+ if (game.selected_cards[faction].length < 3) {
next();
}
else {
@@ -1033,7 +1028,7 @@ states.player_turn = {
prompt() {
const faction_id = get_faction_id(game.active);
const can_spend_hp = game.hero_points[faction_id] > 0;
- const can_play_card = game.hands[faction_id].includes(game.chosen_cards[faction_id]);
+ const can_play_card = game.hands[faction_id].includes(game.selected_cards[faction_id][0]);
view.prompt = 'Play a card or spend Hero points';
if (!(can_play_card || can_spend_hp)) {
view.prompt = 'End turn';
@@ -1053,11 +1048,14 @@ states.player_turn = {
}
},
done() {
+ game.faction_turn = null;
+ game.played_card = null;
resolve_active_and_proceed(true);
},
play_for_ap() {
const faction_id = get_faction_id(game.active);
- const card = game.chosen_cards[faction_id];
+ const card = game.selected_cards[faction_id][0];
+ game.played_card = card;
log_h3(`${game.active} plays ${cards[card].title} for the Action Points`);
array_remove(game.hands[faction_id], game.hands[faction_id].indexOf(card));
game.tableaus[faction_id].push(card);
@@ -1071,7 +1069,8 @@ states.player_turn = {
},
play_for_event() {
const faction_id = get_faction_id(game.active);
- const card = game.chosen_cards[faction_id];
+ const card = game.selected_cards[faction_id][0];
+ game.played_card = card;
array_remove(game.hands[faction_id], game.hands[faction_id].indexOf(card));
game.trash[faction_id].push(card);
log_h3(`${game.active} plays ${cards[card].title} for the Event`);
@@ -1219,7 +1218,6 @@ states.swap_card_tableau_hand = {
gen_action_card(c);
}
},
- card(c) { },
};
states.take_hero_points = {
inactive: 'take Hero Points',
@@ -1550,7 +1548,7 @@ function resolve_final_bid() {
let winners = [];
for (const f of get_player_order()) {
let player_bid = 0;
- for (const c of game.final_bid[f]) {
+ for (const c of game.selected_cards[f]) {
player_bid += cards[c].strength;
}
log(`${faction_player_map[f]} bids ${player_bid}`);
@@ -1561,9 +1559,9 @@ function resolve_final_bid() {
highest_bid = player_bid;
winners = [f];
}
- game.hands[f] = game.hands[f].filter((c) => !game.final_bid[f].includes(c));
- game.discard[f].concat(game.final_bid[f]);
- game.final_bid[f] = [];
+ game.hands[f] = game.hands[f].filter((c) => !game.selected_cards[f].includes(c));
+ game.discard[f].concat(game.selected_cards[f]);
+ game.selected_cards[f] = [];
}
if (winners.length === 1) {
win_final_bid(winners[0]);
@@ -2120,39 +2118,6 @@ function array_insert(array, index, item) {
array[i] = array[i - 1];
array[index] = item;
}
-function set_clear(set) {
- set.length = 0;
-}
-function set_has(set, item) {
- let a = 0;
- let b = set.length - 1;
- while (a <= b) {
- const m = (a + b) >> 1;
- const x = set[m];
- if (item < x)
- b = m - 1;
- else if (item > x)
- a = m + 1;
- else
- return true;
- }
- return false;
-}
-function set_add(set, item) {
- let a = 0;
- let b = set.length - 1;
- while (a <= b) {
- const m = (a + b) >> 1;
- const x = set[m];
- if (item < x)
- b = m - 1;
- else if (item > x)
- a = m + 1;
- else
- return set;
- }
- return array_insert(set, a, item);
-}
function set_delete(set, item) {
let a = 0;
let b = set.length - 1;