summaryrefslogtreecommitdiff
path: root/rules.ts
diff options
context:
space:
mode:
authorFrans Bongers <fransbongers@franss-mbp.home>2025-01-03 22:00:01 +0100
committerFrans Bongers <fransbongers@franss-mbp.home>2025-01-03 22:00:01 +0100
commit3ed56f482596fd4bf914bea95bd3ce46c0dcad6b (patch)
treea4d3f69a3e023d2a63abf28e01a0b0b3cf0f738b /rules.ts
parentec286d358a362869ef02a263b6553ee4e527a216 (diff)
downloadland-and-freedom-3ed56f482596fd4bf914bea95bd3ce46c0dcad6b.tar.gz
fix player order display issue
Diffstat (limited to 'rules.ts')
-rw-r--r--rules.ts78
1 files changed, 56 insertions, 22 deletions
diff --git a/rules.ts b/rules.ts
index 4b06a82..d3c58ab 100644
--- a/rules.ts
+++ b/rules.ts
@@ -71,6 +71,7 @@ import data, {
ANARCHIST_EXTRA_HERO_POINT,
ARAGON,
FASCIST_ID,
+ NORTHERN,
// StaticData,
// PLAYER_WITH_MOST_HERO_POINTS,
} from './data';
@@ -291,33 +292,38 @@ function setup_player_turn() {
const next_faction =
game.first_player === null
? get_player_order()[0]
- : get_next_faction(get_active_faction());
+ : get_next_faction_in_player_order(get_active_faction());
if (game.first_player === null) {
game.first_player = next_faction;
}
- // const player_order = get_player_order();
- // game.engine = player_order.map((faction_id) =>
- // create_seq_node([
- // create_function_node('start_of_player_turn', { f: faction_id }),
- // create_leaf_node('player_turn', faction_id),
- // ])
- // );
game.engine = [
create_function_node('start_of_player_turn', { f: next_faction }),
create_leaf_node('player_turn', next_faction),
create_function_node('end_of_player_turn', { f: next_faction }),
];
- // game.engine.push(create_function_node('resolve_fascist_test'));
- // game.engine.push(create_function_node('setup_bag_of_glory'));
next();
}
+// Check if player needs to discard cards. If so inserts leaf node
+function check_end_of_year_discard() {
+ const { f: faction } = get_active_node_args();
+
+ if (
+ game.hands[faction].length > get_hand_limit(faction) ||
+ game.tableaus[faction].length > game.year
+ ) {
+ insert_after_active_node(create_leaf_node('end_of_year_discard', faction));
+ }
+
+ resolve_active_and_proceed();
+}
+
function end_of_player_turn() {
const { f: faction } = get_active_node_args();
- if (get_next_faction(faction) === game.first_player) {
+ if (get_next_faction_in_player_order(faction) === game.first_player) {
game.engine = [
create_function_node('resolve_fascist_test'),
create_function_node('setup_bag_of_glory'),
@@ -337,6 +343,7 @@ function start_of_player_turn() {
}
const engine_functions: Record<string, Function> = {
+ check_end_of_year_discard,
checkpoint,
end_of_player_turn,
end_of_turn,
@@ -513,7 +520,7 @@ function game_view(state: Game, current: Player | 'Observer') {
player_order:
current === OBSERVER
? game.player_order
- : get_player_order(faction).map((id) => faction_player_map[id]),
+ : get_player_order_in_game(faction).map((id) => faction_player_map[id]),
selectable_cards: game.selectable_cards,
selected_cards: current === OBSERVER ? [] : game.selected_cards[faction],
tableaus: game.tableaus,
@@ -1238,7 +1245,8 @@ states.end_of_year_discard = {
view.prompt = 'Discard a card';
const faction_id = get_active_faction();
const hand = game.hands[faction_id];
- if (hand.length > get_hand_limit(faction_id)) {
+ const hand_limit = get_hand_limit(faction_id);
+ if (hand.length > hand_limit) {
for (let c of hand) gen_action_card(c);
}
const tableau = game.tableaus[faction_id];
@@ -1532,7 +1540,7 @@ states.player_turn = {
prompt() {
gen_spend_hero_points();
const faction_id = get_active_faction();
- const {use_ap, use_morale_bonus} = get_active_node_args();
+ const { use_ap, use_morale_bonus } = get_active_node_args();
const can_spend_hp =
game.faction_turn === faction_id && game.hero_points[faction_id] > 0;
@@ -1543,7 +1551,7 @@ states.player_turn = {
view.prompt = 'Play a card or spend Hero points';
} else if (can_play_card && !can_spend_hp) {
view.prompt = 'Play a card';
- } else if (can_spend_hp || use_ap || use_morale_bonus) {
+ } else if (use_ap || use_morale_bonus) {
const text_options = [];
if (use_ap) {
text_options.push('Action Points');
@@ -1552,14 +1560,16 @@ states.player_turn = {
text_options.push('Morale Bonus');
}
if (can_spend_hp) {
- text_options.push('Hero points');
+ text_options.push('spend Hero points');
}
-
+
view.prompt = `Use ${text_options.join(', ')} or end turn`;
+ } else if (can_spend_hp) {
+ view.prompt = 'Spend Hero Points or end turn';
} else {
view.prompt = 'End turn';
}
-
+
if (can_play_card) {
gen_action('play_for_ap');
gen_action('play_for_event');
@@ -2051,7 +2061,7 @@ states.use_strategy_medallion = {
function card1_event2() {
const value = game.tracks[FOREIGN_AID] >= 6 ? 3 : 2;
insert_after_active_node(
- resolve_effect(create_effect('track', FOREIGN_AID, value))
+ resolve_effect(create_effect('front', NORTHERN, value))
);
resolve_active_and_proceed();
}
@@ -2210,7 +2220,6 @@ function add_glory(
}
}
-
function check_initiative() {
let initiative: FactionId;
if (game.tracks[LIBERTY] >= 6 && game.tracks[COLLECTIVIZATION] >= 6) {
@@ -2324,7 +2333,7 @@ function end_of_year() {
// Setup card discarding
game.engine = get_player_order().map((f) =>
- create_leaf_node('end_of_year_discard', f)
+ create_function_node('check_end_of_year_discard', { f })
);
game.engine.push(create_function_node('checkpoint'));
game.engine.push(create_function_node('start_year'));
@@ -2490,6 +2499,8 @@ function get_fronts_to_add_to(target: string, not: FrontId[] = []): FrontId[] {
return FRONTS.filter(
(id) => game.fronts[id].status === null && !not.includes(id)
);
+ } else if (game.fronts[target].status === DEFEAT) {
+ return get_fronts_closest_to(CLOSEST_TO_DEFEAT);
} else {
return [target as FrontId];
}
@@ -3065,7 +3076,10 @@ function get_player(faction_id: FactionId) {
return faction_player_map[faction_id];
}
-function get_player_order(first_player = game.initiative): FactionId[] {
+// Gets player order
+function get_player_order(
+ first_player: FactionId = game.initiative
+): FactionId[] {
const order = [];
let faction = first_player;
for (let i = 0; i < 3; ++i) {
@@ -3079,6 +3093,11 @@ function get_player_order(first_player = game.initiative): FactionId[] {
return order;
}
+function get_next_faction_in_player_order(faction_id: FactionId): FactionId {
+ return get_player_order(faction_id)[1];
+}
+
+// Gets previous faction in game order (so does not change for year 2)
function get_previous_faction(faction_id: FactionId): FactionId {
const index = game.player_order.indexOf(faction_player_map[faction_id]);
if (index === 0) {
@@ -3087,6 +3106,7 @@ function get_previous_faction(faction_id: FactionId): FactionId {
return player_faction_map[game.player_order[index - 1]];
}
+// Gets next faction in game order
function get_next_faction(faction_id: FactionId): FactionId {
const index = game.player_order.indexOf(faction_player_map[faction_id]);
if (index === 2) {
@@ -3095,6 +3115,20 @@ function get_next_faction(faction_id: FactionId): FactionId {
return player_faction_map[game.player_order[index + 1]];
}
+// Gets game order
+function get_player_order_in_game(
+ first_player: FactionId = game.initiative
+): FactionId[] {
+ const order = [];
+ let faction = first_player;
+ for (let i = 0; i < 3; ++i) {
+ order.push(faction);
+ faction = get_next_faction(faction);
+ }
+
+ return order;
+}
+
function get_factions_with_most_hero_poins(): FactionId[] {
let most_hero_points = null;
let faction_ids = [];