diff --git a/src/lib/components/Battle/Chapter3.story.svelte b/src/lib/components/Battle/Chapter3.story.svelte
new file mode 100644
index 0000000..6cc1360
--- /dev/null
+++ b/src/lib/components/Battle/Chapter3.story.svelte
@@ -0,0 +1,53 @@
+
+
+
+
+
+ [s, s]))}
+ />
+
+
+
+
+
diff --git a/src/lib/store/genNextBattle.js b/src/lib/store/genNextBattle.js
index 7e4a7fb..34acce8 100644
--- a/src/lib/store/genNextBattle.js
+++ b/src/lib/store/genNextBattle.js
@@ -59,6 +59,48 @@ export function genChapter2Battle(battles) {
additionalCharacters: [{ choices, selection: R.first(choices) }],
};
}
+export function genChapter3Battle(battles) {
+ const chapter = 3;
+
+ 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),
+ ),
+ );
+
+ let choices1 = battles.slice(0, 2).map(R.prop('character'));
+ let choices2 = battles.slice(2, 4).map(R.prop('character'));
+ if (battles.length == 5) {
+ choices1 = choices1.filter(
+ (n) => n !== R.last(battles).additionalCharacters[0].selection,
+ );
+ choices2 = choices2.filter(
+ (n) => n !== R.last(battles).additionalCharacters[1].selection,
+ );
+ }
+
+ return {
+ scenario,
+ character,
+ city,
+ status: 'ongoing',
+ wave: 1,
+ additionalCharacters: [choices1, choices2].map((choices) => ({
+ choices,
+ selection: R.first(choices),
+ })),
+ };
+}
export function genNextBattle(battles = []) {
let chapter = R.clamp(1 + parseInt(battles.length / 2), { min: 1, max: 4 });
@@ -66,4 +108,6 @@ export function genNextBattle(battles = []) {
if (chapter === 1) return genChapter1Battle(battles);
if (chapter === 2) return genChapter2Battle(battles);
+
+ if (chapter === 3) return genChapter3Battle(battles);
}
diff --git a/src/lib/store/genNextBattle.test.js b/src/lib/store/genNextBattle.test.js
index fa2bbe8..b184b9c 100644
--- a/src/lib/store/genNextBattle.test.js
+++ b/src/lib/store/genNextBattle.test.js
@@ -1,6 +1,10 @@
import { test, expect } from 'vitest';
-import { genNextBattle, genChapter2Battle } from './genNextBattle.js';
+import {
+ genNextBattle,
+ genChapter2Battle,
+ genChapter3Battle,
+} from './genNextBattle.js';
test('generate for the first chapter', () => {
const next = genNextBattle();
@@ -31,3 +35,34 @@ test('chapter 2, second battle', () => {
expect(result.additionalCharacters[0].selection).toEqual('one');
expect(result.additionalCharacters[0].choices).toEqual(['one']);
});
+
+test('chapter 3, first battle', () => {
+ const result = genChapter3Battle([
+ { character: 'one' },
+ { character: 'two' },
+ { character: 'three' },
+ { character: 'four' },
+ ]);
+
+ expect(result.additionalCharacters[0].selection).toEqual('one');
+ expect(result.additionalCharacters[1].selection).toEqual('three');
+});
+
+test('chapter 3, second battle', () => {
+ const result = genChapter3Battle([
+ { character: 'one' },
+ { character: 'two' },
+ { character: 'three' },
+ { character: 'four' },
+ {
+ character: 'five',
+ additionalCharacters: [
+ { selection: 'one' },
+ { selection: 'three' },
+ ],
+ },
+ ]);
+
+ expect(result.additionalCharacters[0].selection).toEqual('two');
+ expect(result.additionalCharacters[1].selection).toEqual('four');
+});