genChapter4
This commit is contained in:
parent
621252329b
commit
931cb9d237
@ -102,6 +102,32 @@ export function genChapter3Battle(battles) {
|
||||
};
|
||||
}
|
||||
|
||||
export function genChapter4Battle(battles) {
|
||||
const chapter = 4;
|
||||
|
||||
const scenario = 'The Last Battle';
|
||||
|
||||
const cities = R.difference(
|
||||
battles
|
||||
.slice(0, 6)
|
||||
.filter(({ status }) => status !== 'lost')
|
||||
.map(R.prop('city')),
|
||||
battles.slice(6).map((b) => b.city.selection),
|
||||
);
|
||||
|
||||
const characters = battles.slice(0, 6).map(R.prop('character'));
|
||||
|
||||
return {
|
||||
scenario,
|
||||
city: { choices: cities, selection: R.first(cities) },
|
||||
status: 'ongoing',
|
||||
additionalCharacters: R.range(0, 3).map((i) => ({
|
||||
choices: characters,
|
||||
selection: characters[i],
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
export function genNextBattle(battles = []) {
|
||||
let chapter = R.clamp(1 + parseInt(battles.length / 2), { min: 1, max: 4 });
|
||||
|
||||
@ -110,4 +136,6 @@ export function genNextBattle(battles = []) {
|
||||
if (chapter === 2) return genChapter2Battle(battles);
|
||||
|
||||
if (chapter === 3) return genChapter3Battle(battles);
|
||||
|
||||
return genChapter4Battle(battles);
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import {
|
||||
genNextBattle,
|
||||
genChapter2Battle,
|
||||
genChapter3Battle,
|
||||
genChapter4Battle,
|
||||
} from './genNextBattle.js';
|
||||
|
||||
test('generate for the first chapter', () => {
|
||||
@ -66,3 +67,20 @@ test('chapter 3, second battle', () => {
|
||||
expect(result.additionalCharacters[0].selection).toEqual('two');
|
||||
expect(result.additionalCharacters[1].selection).toEqual('four');
|
||||
});
|
||||
|
||||
test.only('chapter 4, first battle', () => {
|
||||
const result = genChapter4Battle([
|
||||
{ character: 'one', city: 'a' },
|
||||
{ character: 'two', city: 'b', status: 'lost' },
|
||||
{ character: 'three', city: 'c' },
|
||||
{ character: 'four', city: 'd' },
|
||||
{ character: 'five', city: 'e' },
|
||||
{ character: 'six', city: 'f' },
|
||||
]);
|
||||
|
||||
expect(result.additionalCharacters[0].selection).toEqual('one');
|
||||
expect(result.additionalCharacters[1].selection).toEqual('two');
|
||||
expect(result.additionalCharacters[2].selection).toEqual('three');
|
||||
|
||||
expect(result.city.choices).not.toContain('b');
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user