summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
authorFrans Bongers <fransbongers@franss-mbp.home>2024-12-01 15:09:24 +0100
committerFrans Bongers <fransbongers@franss-mbp.home>2024-12-01 15:09:24 +0100
commit74e1497d50a6ff81c74c593f2d0f7018d2995fd8 (patch)
tree9dd74df38232b1ab5f76b84f362c98abc6eaa7d1 /rules.js
parentf05a9531508822f5dfb51105334444b53fe11b3e (diff)
downloadland-and-freedom-74e1497d50a6ff81c74c593f2d0f7018d2995fd8.tar.gz
add stack data for triggers on tracks
Diffstat (limited to 'rules.js')
-rw-r--r--rules.js177
1 files changed, 131 insertions, 46 deletions
diff --git a/rules.js b/rules.js
index cf1b88f..3fa056a 100644
--- a/rules.js
+++ b/rules.js
@@ -33,6 +33,13 @@ const front_names = {
d: 'the Front closest to Defeat',
v: 'the Front closest to Victory',
};
+const tracks = [
+ data_1.LIBERTY,
+ data_1.COLLECTIVIZATION,
+ data_1.GOVERNMENT,
+ data_1.SOVIET_SUPPORT,
+ data_1.FOREIGN_AID,
+];
const track_names = {
[data_1.LIBERTY]: 'Liberty',
[data_1.COLLECTIVIZATION]: 'Collectivization',
@@ -66,6 +73,9 @@ function gen_action(action, argument) {
function gen_action_card(card_id) {
gen_action('card', card_id);
}
+function gen_action_standee(track_id) {
+ gen_action('standee', track_id);
+}
function action(state, player, action, arg) {
console.log('action', state, player, action, arg);
game = state;
@@ -156,7 +166,7 @@ function get_active(engine) {
}
return null;
}
-function get_active_node(engine) {
+function get_active_node(engine = game.engine) {
const a = get_active(engine);
return a === null ? null : a.node;
}
@@ -258,6 +268,12 @@ function setup(seed, _scenario, _options) {
blank_markers: [[], [], [], [], []],
bonuses: [data_1.ON, data_1.ON],
current_events: [],
+ discard: {
+ [ANARCHISTS_ID]: [],
+ [COMMUNISTS_ID]: [],
+ [MODERATES_ID]: [],
+ f: [],
+ },
engine: [],
fronts: {
a: -2,
@@ -359,58 +375,46 @@ states.add_glory = {
resolve_active_and_proceed();
},
};
-states.resolve_event = {
- inactive: 'resolve Fascist Event',
+states.choose_area_ap = {
+ inactive: 'choose area to use Action Points',
prompt() {
- const card = get_current_event();
- const node = get_active_node(game.engine);
- const effect = card.effects[node.a];
- view.prompt = get_event_prompt(effect);
- if (effect.type === 'attack' &&
- (effect.target === 'd' || effect.target === 'v')) {
- const fronts = get_fronts_closest_to(effect.target);
- fronts.forEach((id) => gen_action('front', id));
- }
- else if (effect.type === 'attack') {
- gen_action('front', effect.target);
- }
- else if (effect.type === 'track') {
- gen_action('standee', effect.target);
- }
- else if (effect.type === 'hero_points' &&
- effect.target === data_1.PLAYER_WITH_MOST_HERO_POINTS) {
- const factions = get_factions_with_most_hero_poins();
- for (let faction_id of factions) {
- gen_action(get_player(faction_id));
- }
+ view.prompt = 'Choose area of the board to affect';
+ for (let track_id of tracks) {
+ gen_action_standee(track_id);
}
},
- front(f) {
- const card = get_current_event();
- const value = card.effects[get_active_node_args()].value;
- game.fronts[f] -= value;
- log_h3(`${value} attacks added to ${front_names[f]}`);
+ standee(track_id) {
+ console.log('standee', track_id);
+ insert_after_active_node({
+ t: leaf_node,
+ p: get_active_faction_id(),
+ s: 'move_track_up_or_down',
+ a: {
+ track_id,
+ strength: get_active_node()?.a.strength,
+ },
+ });
resolve_active_and_proceed();
},
- standee(s) {
- const effect = get_current_event().effects[get_active_node_args()];
- const value = effect.value;
- game.tracks[s] += value;
- log_h3(`${track_names[effect.target]} decreased by ${Math.abs(value)}`);
- resolve_active_and_proceed();
+};
+states.move_track_up_or_down = {
+ inactive: 'move a track',
+ prompt() {
+ const node = get_active_node();
+ view.prompt = `Move ${get_track_name(node.a.track_id)} up or down`;
+ gen_action('up');
+ gen_action('down');
},
- Anarchist() {
- lose_hero_point(ANARCHISTS_ID, 1);
+ down() {
+ const node = get_active_node();
+ move_track(node.a.track_id, -1 * node.a.strength);
resolve_active_and_proceed();
},
- Communist() {
- lose_hero_point(ANARCHISTS_ID, 1);
+ up() {
+ const node = get_active_node();
+ move_track(node.a.track_id, node.a.strength);
resolve_active_and_proceed();
- },
- Moderate() {
- lose_hero_point(ANARCHISTS_ID, 1);
- resolve_active_and_proceed();
- },
+ }
};
states.choose_card = {
inactive: 'choose a card',
@@ -442,15 +446,39 @@ states.player_turn = {
gen_action('play_for_ap');
gen_action('play_for_event');
}
+ else {
+ gen_action('done');
+ }
if (hero_points > 0) {
gen_action('spend_hp');
}
},
+ done() {
+ resolve_active_and_proceed();
+ },
play_for_ap() {
const faction_id = get_faction_id(game.active);
const card = game.cards_in_play[faction_id];
log_h3(`${game.active} plays ${cards[card].title} for the Action Points`);
- resolve_active_and_proceed();
+ if (!game.discard) {
+ game.discard = {
+ [ANARCHISTS_ID]: [],
+ [COMMUNISTS_ID]: [],
+ [MODERATES_ID]: [],
+ f: [],
+ };
+ }
+ array_remove(game.hands[faction_id], game.hands[faction_id].indexOf(card));
+ game.discard[faction_id].push(card);
+ insert_before_active_node({
+ t: leaf_node,
+ p: faction_id,
+ s: 'choose_area_ap',
+ a: {
+ strength: cards[card].strength,
+ },
+ });
+ next();
},
play_for_event() {
const faction_id = get_faction_id(game.active);
@@ -484,6 +512,59 @@ states.player_turn = {
resolve_active_and_proceed();
},
};
+states.resolve_event = {
+ inactive: 'resolve Fascist Event',
+ prompt() {
+ const card = get_current_event();
+ const node = get_active_node(game.engine);
+ const effect = card.effects[node.a];
+ view.prompt = get_event_prompt(effect);
+ if (effect.type === 'attack' &&
+ (effect.target === 'd' || effect.target === 'v')) {
+ const fronts = get_fronts_closest_to(effect.target);
+ fronts.forEach((id) => gen_action('front', id));
+ }
+ else if (effect.type === 'attack') {
+ gen_action('front', effect.target);
+ }
+ else if (effect.type === 'track') {
+ gen_action('standee', effect.target);
+ }
+ else if (effect.type === 'hero_points' &&
+ effect.target === data_1.PLAYER_WITH_MOST_HERO_POINTS) {
+ const factions = get_factions_with_most_hero_poins();
+ for (let faction_id of factions) {
+ gen_action(get_player(faction_id));
+ }
+ }
+ },
+ front(f) {
+ const card = get_current_event();
+ const value = card.effects[get_active_node_args()].value;
+ game.fronts[f] -= value;
+ log_h3(`${value} attacks added to ${front_names[f]}`);
+ resolve_active_and_proceed();
+ },
+ standee(s) {
+ const effect = get_current_event().effects[get_active_node_args()];
+ const value = effect.value;
+ game.tracks[s] += value;
+ log_h3(`${track_names[effect.target]} decreased by ${Math.abs(value)}`);
+ resolve_active_and_proceed();
+ },
+ Anarchist() {
+ lose_hero_point(ANARCHISTS_ID, 1);
+ resolve_active_and_proceed();
+ },
+ Communist() {
+ lose_hero_point(ANARCHISTS_ID, 1);
+ resolve_active_and_proceed();
+ },
+ Moderate() {
+ lose_hero_point(ANARCHISTS_ID, 1);
+ resolve_active_and_proceed();
+ },
+};
states.spend_hero_points = {
inactive: 'spend Hero points',
prompt() {
@@ -526,7 +607,8 @@ function resolve_fascist_test() {
log_h2('Fascist test is resolved');
next();
}
-function move_track(track, change) { }
+function move_track(track, change) {
+}
function draw_card(deck) {
clear_undo();
let i = random(deck.length);
@@ -647,6 +729,9 @@ function get_factions_with_most_hero_poins() {
});
return faction_ids;
}
+function get_track_name(track_id) {
+ return track_names[track_id];
+}
function make_list(first, last) {
let list = [];
for (let i = first; i <= last; i++)