summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
Diffstat (limited to 'rules.js')
-rw-r--r--rules.js148
1 files changed, 117 insertions, 31 deletions
diff --git a/rules.js b/rules.js
index 697ec13..f9cd8e8 100644
--- a/rules.js
+++ b/rules.js
@@ -113,18 +113,27 @@ function setup_bag_of_glory() {
next();
}
function setup_choose_card() {
- console.log('setup_choose_card');
const player_order = get_player_order();
game.engine = player_order.map((faction_id) => create_leaf_node('choose_card', faction_id));
game.engine.push(create_function_node('setup_player_turn'));
- resolve_active_and_proceed();
+ next();
}
function setup_player_turn() {
- console.log('setup_player_turn');
const player_order = get_player_order();
- game.engine = player_order.map((faction_id) => create_seq_node([create_leaf_node('player_turn', faction_id)]));
+ 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.push(create_function_node('resolve_fascist_test'));
game.engine.push(create_function_node('setup_bag_of_glory'));
+ next();
+}
+function start_of_player_turn() {
+ const args = get_active_node_args();
+ console.log('args', args);
+ console.log('args');
+ const player = faction_player_map[args.f];
+ log_h2(player, player);
resolve_active_and_proceed();
}
const engine_functions = {
@@ -134,6 +143,7 @@ const engine_functions = {
setup_bag_of_glory,
setup_choose_card,
setup_player_turn,
+ start_of_player_turn,
resolve_fascist_test,
};
function get_active(engine) {
@@ -156,7 +166,7 @@ function get_active_node(engine = game.engine) {
}
function get_active_node_args() {
const node = get_active_node(game.engine);
- if (node.t === leaf_node) {
+ if (node.t === leaf_node || node.t === function_node) {
return node.a;
}
return null;
@@ -223,11 +233,13 @@ function game_view(state, player) {
glory: game.glory,
hand: game.hands[faction_id],
hero_points: game.hero_points,
+ initiative: game.initiative,
medaillons: game.medaillons,
selected_card: game.chosen_cards[faction_id],
tableaus: game.tableaus,
tracks: game.tracks,
triggered_track_effects: game.triggered_track_effects,
+ year: game.year,
};
if (player !== game.active) {
let inactive = states[game.state].inactive || game.state;
@@ -260,10 +272,22 @@ function setup(seed, _scenario, _options) {
},
engine: [],
fronts: {
- a: -2,
- m: -2,
- n: -2,
- s: -2,
+ a: {
+ value: -2,
+ contributions: [],
+ },
+ m: {
+ value: -2,
+ contributions: [],
+ },
+ n: {
+ value: -2,
+ contributions: [],
+ },
+ s: {
+ value: -2,
+ contributions: [],
+ },
},
glory: [],
hands: {
@@ -313,27 +337,24 @@ function setup(seed, _scenario, _options) {
}
function draw_hand_cards() {
role_ids.forEach((role) => {
- const deck = faction_cards[role];
+ const deck = list_deck(role);
for (let i = 0; i < 5; i++) {
- game.hands[role];
game.hands[role].push(draw_card(deck));
}
});
}
function start_year() {
- console.log('start year');
- log_h1('Year ' + game.year);
game.current_events = [];
draw_hand_cards();
start_turn();
}
function start_turn() {
- log_h2('Turn ' + game.turn);
- const deck = fascist_decks[game.year];
- const cardId = draw_card(deck);
+ log_h1(`Year ${game.year} - Turn ${game.turn}`);
+ const cardId = draw_card(list_deck('fascist'));
game.current_events.push(cardId);
const card = cards[cardId];
- log_h3('Fascist Event: ' + card.title);
+ log_h2('Fascist Event', 'fascist');
+ log(card.title);
game.engine = card.effects.map((effect) => resolve_effect(effect, game.initiative));
game.engine.push({
t: 'f',
@@ -475,10 +496,19 @@ states.choose_area_ap = {
for (const front of fronts) {
gen_action_front(front);
}
+ for (const bonus of bonuses) {
+ if (game.bonuses[bonus] === data_1.OFF) {
+ gen_action_bonus(bonus);
+ }
+ }
+ },
+ bonus(b) {
+ update_bonus(b, data_1.ON);
+ resolve_active_and_proceed();
},
front(f) {
const s = get_active_node_args().strength;
- update_front(f, s);
+ update_front(f, s, get_active_faction_id());
resolve_active_and_proceed();
},
standee(track_id) {
@@ -520,8 +550,7 @@ states.change_bonus = {
},
bonus(b) {
const value = get_active_node_args().v;
- game.bonuses[b] = value;
- log(`${bonus_names[b]} ${value === data_1.ON ? 'on' : 'off'}`);
+ update_bonus(b, value);
resolve_active_and_proceed();
},
skip() {
@@ -712,8 +741,27 @@ function check_activate_icon() {
}
resolve_active_and_proceed();
}
+function check_initiative() {
+ let initiative;
+ if (game.tracks[data_1.LIBERTY] >= 6 && game.tracks[data_1.COLLECTIVIZATION] >= 6) {
+ initiative = data_1.ANARCHISTS_ID;
+ }
+ else if (game.tracks[data_1.GOVERNMENT] <= 5) {
+ initiative = data_1.COMMUNISTS_ID;
+ }
+ else {
+ initiative = data_1.MODERATES_ID;
+ }
+ if (game.initiative === initiative) {
+ return;
+ }
+ game.initiative = initiative;
+ logi(`${faction_player_map[initiative]} claims the Initiative`);
+}
function end_of_turn() {
- log_h2('End of turn');
+ Object.keys(game.fronts).forEach((front_id) => {
+ game.fronts[front_id].contributions = [];
+ });
if (game.turn === 4) {
end_of_year();
}
@@ -734,9 +782,9 @@ function end_of_year() {
}
function resolve_fascist_test() {
console.log('resolve fascist test');
- log_h2('Fascist test is resolved');
+ log_h2('Fascist Test', 'fascist');
const test = get_current_event().test;
- const test_passed = game.fronts[test.front] >= test.value;
+ const test_passed = game.fronts[test.front].value >= test.value;
if (test_passed) {
log('The Test is passed');
}
@@ -768,7 +816,8 @@ function move_track(track_id, change) {
new_value = Math.max(new_value, track_id === data_1.GOVERNMENT ? 1 : 0);
new_value = Math.min(new_value, 10);
game.tracks[track_id] = new_value;
- log(`${get_track_name(track_id)} to ${new_value}`);
+ logi(`${get_track_name(track_id)} to ${new_value}`);
+ check_initiative();
const triggered_spaces = change > 0
? make_list(current_value + 1, new_value).reverse()
: make_list(new_value, current_value - 1);
@@ -786,9 +835,28 @@ function move_track(track_id, change) {
}
});
}
-function update_front(f, change) {
- game.fronts[f] += change;
- log(`${front_names[f]}: ${change > 0 ? '+' : ''}${change}`);
+function update_bonus(bonus_id, status) {
+ if (game.bonuses[bonus_id] === status) {
+ return;
+ }
+ game.bonuses[bonus_id] = status;
+ logi(`${bonus_names[bonus_id]} ${status === data_1.ON ? 'on' : 'off'}`);
+}
+function update_front(f, change, faction_id = null) {
+ const player_token_on_front = faction_id !== null && game.fronts[f].contributions.includes(faction_id);
+ if (game.bonuses[data_1.TEAMWORK_BONUS] === data_1.ON &&
+ change > 0 &&
+ faction_id !== null &&
+ !player_token_on_front &&
+ game.fronts[f].contributions.length > 0) {
+ change += 1;
+ }
+ game.fronts[f].value += change;
+ logi(`${front_names[f]}: ${change > 0 ? '+' : ''}${change}`);
+ if (faction_id !== null &&
+ !game.fronts[f].contributions.includes(faction_id)) {
+ game.fronts[f].contributions.push(faction_id);
+ }
}
function create_effects_node(effects) {
const nodes = effects.reduce((accrued, current) => {
@@ -855,9 +923,9 @@ function lose_hero_point(faction, value) {
}
}
function get_fronts_closest_to(target) {
- const values = Object.values(game.fronts);
+ const values = Object.values(game.fronts).map((front) => front.value);
const targetValue = target === 'd' ? Math.min(...values) : Math.max(...values);
- return Object.keys(game.fronts).filter((frontId) => game.fronts[frontId] === targetValue);
+ return Object.keys(game.fronts).filter((frontId) => game.fronts[frontId].value === targetValue);
}
function log_br() {
if (game.log.length > 0 && game.log[game.log.length - 1] !== '')
@@ -866,16 +934,20 @@ function log_br() {
function log(msg) {
game.log.push(msg);
}
+function logi(msg) {
+ log('>' + msg);
+}
function log_h1(msg) {
log_br();
log('.h1 ' + msg);
log_br();
}
-function log_h2(msg) {
+function log_h2(msg, player) {
log_br();
- log('.h2 ' + msg);
+ log(`.h2${player ? `.${player}` : ''} ${msg}`);
log_br();
}
+log;
function log_h3(msg) {
log_br();
log('.h3 ' + msg);
@@ -983,6 +1055,20 @@ function set_delete(set, item) {
}
}
}
+function list_deck(id) {
+ const deck = [];
+ const card_list = id === 'fascist' ? fascist_decks[game.year] : faction_cards[id];
+ card_list.forEach((card) => {
+ if (id === 'fascist' && (game.discard.f.includes(card))) {
+ return;
+ }
+ else if (id !== 'fascist' && (game.hands[id].includes(card) || game.discard[id].includes(card))) {
+ return;
+ }
+ deck.push(card);
+ });
+ return deck;
+}
function array_remove(array, index) {
let n = array.length;
for (let i = index + 1; i < n; ++i)