under-falling-skies/src/lib/store/genNextBattle.js

29 lines
920 B
JavaScript
Raw Normal View History

2023-01-12 23:02:29 +00:00
import * as R from 'remeda';
import chapters from './chapters.js';
const pickOne = (choices) => choices[parseInt(Math.random() * choices.length)];
export function genNextBattle(battles = []) {
let chapter = R.clamp(1 + parseInt(battles.length / 2), { min: 1, max: 4 });
if (chapter === 1) {
const scenario = pickOne(
chapters[chapter - 1].scenarios.filter(
(s) => !battles.map(R.prop('scenario')).includes(s),
),
);
const character = pickOne(
chapters[chapter - 1].characters.filter(
(s) => !battles.map(R.prop('character')).includes(s),
),
);
const city = pickOne(
chapters[chapter - 1].cities.filter(
(s) => !battles.map(R.prop('city')).includes(s),
),
);
2023-01-13 17:51:02 +00:00
return { scenario, character, city, status: 'ongoing', wave: 1 };
2023-01-12 23:02:29 +00:00
}
}