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), ), ); return { scenario, character, city, status: 'ongoing', wave: 1 }; } }