summaryrefslogtreecommitdiff
path: root/rules.ts
diff options
context:
space:
mode:
authorFrans Bongers <fransbongers@franss-mbp.home>2024-12-11 22:38:27 +0100
committerFrans Bongers <fransbongers@franss-mbp.home>2024-12-11 22:38:27 +0100
commit7517f0e485f63c6c97ee2871ca64373375c504b8 (patch)
treeea0dd0fce5234fc5f81ef1c10b8a451208a502cc /rules.ts
parent9ec057935b3d77cc13f898b2ede63cf180443318 (diff)
downloadland-and-freedom-7517f0e485f63c6c97ee2871ca64373375c504b8.tar.gz
resolve fascist test and end of year
Diffstat (limited to 'rules.ts')
-rw-r--r--rules.ts70
1 files changed, 53 insertions, 17 deletions
diff --git a/rules.ts b/rules.ts
index 2b84ab4..ee9b269 100644
--- a/rules.ts
+++ b/rules.ts
@@ -18,6 +18,9 @@ import {
} from './types';
import data, {
+ ANARCHIST,
+ COMMUNIST,
+ MODERATE,
ANARCHISTS_ID,
COMMUNISTS_ID,
MODERATES_ID,
@@ -56,9 +59,9 @@ const states = {} as States;
let game = {} as Game; // = null
var view = {} as View; // = null
-export const ANARCHIST = 'Anarchist' as Player;
-export const COMMUNIST = 'Communist' as Player;
-export const MODERATE = 'Moderate' as Player;
+// export const ANARCHIST = 'Anarchist' as Player;
+// export const COMMUNIST = 'Communist' as Player;
+// export const MODERATE = 'Moderate' as Player;
const role_ids = [ANARCHISTS_ID, COMMUNISTS_ID, MODERATES_ID];
@@ -104,7 +107,9 @@ const medaillons = make_list(0, 8) as number[];
console.log('medaillons', medaillons);
const fascist_decks = {
- 1: make_list(55, 62),
+ 1: make_list(55, 72),
+ 2: make_list(73, 90),
+ 3: make_list(91, 108),
};
export const scenarios = ['Standard'];
@@ -215,7 +220,7 @@ function setup_choose_card() {
create_leaf_node('choose_card', faction_id)
);
game.engine.push(create_function_node('setup_player_turn'));
- next();
+ resolve_active_and_proceed();
}
function setup_player_turn() {
@@ -226,7 +231,7 @@ function setup_player_turn() {
);
game.engine.push(create_function_node('resolve_fascist_test'));
game.engine.push(create_function_node('setup_bag_of_glory'));
- next();
+ resolve_active_and_proceed();
}
const engine_functions: Record<string, Function> = {
@@ -336,7 +341,6 @@ function next() {
const node = get_active_node(game.engine);
console.log('node', node);
if (node.t === function_node && engine_functions[node.f]) {
- resolve_active_node();
const args = node.a;
if (args) {
engine_functions[node.f](args);
@@ -379,11 +383,13 @@ function game_view(state: Game, player: Player) {
prompt: null,
location: game.location,
selected: game.selected,
-
+ bag_of_glory: game.bag_of_glory,
bonuses: game.bonuses,
current_events: game.current_events,
fronts: game.fronts,
+ glory: game.glory,
hand: game.hands[faction_id],
+ hero_points: game.hero_points,
medaillons: game.medaillons,
selected_card: game.chosen_cards[faction_id],
tableaus: game.tableaus,
@@ -414,11 +420,7 @@ export function setup(seed: number, _scenario: string, _options: unknown) {
seed: seed,
state: null,
active: ANARCHIST,
- bag_of_glory: {
- [ANARCHISTS_ID]: 1,
- [COMMUNISTS_ID]: 1,
- [MODERATES_ID]: 1,
- },
+ bag_of_glory: [ANARCHISTS_ID, COMMUNISTS_ID, MODERATES_ID],
blank_markers: [[], [], [], [], []],
bonuses: [ON, ON],
current_events: [],
@@ -435,6 +437,7 @@ export function setup(seed: number, _scenario: string, _options: unknown) {
n: -2,
s: -2,
},
+ glory: [],
hands: {
[ANARCHISTS_ID]: [],
[COMMUNISTS_ID]: [],
@@ -495,7 +498,9 @@ function draw_hand_cards() {
// #endregion
function start_year() {
+ console.log('start year')
log_h1('Year ' + game.year);
+ game.current_events = [];
draw_hand_cards();
start_turn();
}
@@ -609,7 +614,7 @@ states.add_glory = {
if (game.turn === 4) {
number++;
}
- game.bag_of_glory[get_active_faction()] += number;
+ game.bag_of_glory.push(get_active_faction());
if (number === 1) {
log_h3(`${game.active} adds 1 token to the Bag of Glory`);
} else {
@@ -1005,7 +1010,7 @@ function check_activate_icon() {
}
function end_of_turn() {
- // REMOVE playre tplems from the Fronts;
+ // REMOVE player tokens from the Fronts;
log_h2('End of turn');
if (game.turn === 4) {
end_of_year();
@@ -1015,12 +1020,37 @@ function end_of_turn() {
}
}
-function end_of_year() {}
+function end_of_year() {
+ const gloryToDraw = [0, 1, 2, 5];
+ for (let i = 0; i < gloryToDraw[game.year]; ++i) {
+ const index = random(game.bag_of_glory.length);
+ game.glory.push(game.bag_of_glory[index]);
+ array_remove(game.bag_of_glory, index);
+ }
+
+ game.year++;
+ start_year();
+}
function resolve_fascist_test() {
console.log('resolve fascist test');
log_h2('Fascist test is resolved');
- next();
+
+ const test = get_current_event().test;
+ const test_passed = game.fronts[test.front] >= test.value;
+ if (test_passed) {
+ log('The Test is passed');
+ } else {
+ log('The Test is failed');
+ }
+ const effect = test_passed ? test.pass : test.fail;
+ const node = resolve_effect(effect);
+
+ if (node !== null) {
+ insert_after_active_node(node);
+ }
+
+ resolve_active_and_proceed();
}
// TODO: check for defeated / won fronts
@@ -1338,6 +1368,12 @@ function get_faction_id(player: Player): FactionId {
return player_faction_map[player];
}
+function get_current_event(): EventCard {
+ return cards[
+ game.current_events[game.current_events.length - 1]
+ ] as EventCard;
+}
+
function get_icon_count_in_tableau(
icon: Icon,
faction: FactionId = get_active_faction_id()