diff options
author | Daniel Weipert <code@drogueronin.de> | 2023-09-02 14:59:09 +0200 |
---|---|---|
committer | Daniel Weipert <code@drogueronin.de> | 2023-09-02 14:59:09 +0200 |
commit | 2030caa0c85102b1cf6131dd9eefef4a347cda42 (patch) | |
tree | 9188abac0d7b7730ded1e8e154c3f7c589f785cf /resources/js/story.js | |
parent | 1d29ee6d87d3794a9319bca5bf36afdfe176072c (diff) |
translations and story
Diffstat (limited to 'resources/js/story.js')
-rw-r--r-- | resources/js/story.js | 181 |
1 files changed, 152 insertions, 29 deletions
diff --git a/resources/js/story.js b/resources/js/story.js index d5e6486..bb6fc4b 100644 --- a/resources/js/story.js +++ b/resources/js/story.js @@ -1,5 +1,5 @@ const Story = { - async start () { + 'start': async () => { const settingsPopup = UI.createPopup(); settingsPopup.querySelector('[data-template-slot="content"]').append(UI.createSettingsMenu()); UI.drawPopup(settingsPopup); @@ -10,10 +10,10 @@ const Story = { })); }); - await Story.immediateProgress('start', 'introduction'); + return await Story.immediateProgress('start', 'introduction'); }, - async introduction () { + 'introduction': async () => { const story = await fetchStory('introduction'); const characterCeo = story.characters.ceo; const characterShopKeeper = story.characters.shopKeeper; @@ -55,9 +55,11 @@ const Story = { resolve(); })); }); + + return true; }, - async selectStarterMonster () { + 'select-starter-monster': async () => { const story = await fetchStory('select-starter-monster'); const characterDante = story.characters.dante; const npcDante = await fetchNpc(characterDante.slug); @@ -93,35 +95,19 @@ const Story = { })); }); - await Story.immediateProgress('selectStarterMonster', 'battleRivalOne'); + return await Story.immediateProgress('select-starter-monster', 'battle-rival-one'); }, - async battleRivalOne () { + 'battle-rival-one': async () => { const story = await fetchStory('battle-rival-one'); const characterRival = story.characters.rival; const npcRival = await fetchNpc(story.characters.rival.slug); - Memory.state.opponent = new Trainer({ - monsters: await Promise.all( - characterRival.monsters.map(async (monsterData) => { - if (monsterData.slug === 'RIVAL') { - monsterData.slug = Memory.state.rivalMonster; - } - - const monster = await fetchMonster(monsterData.slug); - monster.level = monsterData.level; - - return monster; - }) - ) - }); - await Memory.state.opponent.initialize(); - await UI.buildAndShowStoryPopup({ speaker: npcRival, text: translate(characterRival.text[0]) }); + await Story.setupBattle(npcRival, characterRival.monsters); + const didWin = await Story.battle(); - await Story.battle(); - - if (Game.didWinStoryBattle) { + if (didWin) { await UI.buildAndShowStoryPopup({ speaker: npcRival, text: translate(characterRival.text[1]) }); } else { await UI.buildAndShowStoryPopup({ speaker: npcRival, text: translate(characterRival.text[2]) }); @@ -129,6 +115,94 @@ const Story = { await UI.buildAndShowStoryPopup({ speaker: npcRival, text: translate(characterRival.text[3]) }); Game.healParty(); + + return true; + }, + + 'battle-rival-two': async () => { + const story = await fetchStory('battle-rival-two'); + const characterRival = story.characters.rival; + const npcRival = await fetchNpc(story.characters.rival.slug); + + await UI.buildAndShowStoryPopup({ speaker: npcRival, text: translate(characterRival.text[0]) }); + await Story.setupBattle(npcRival, characterRival.monsters); + const didWin = await Story.battle(); + if (didWin) { + await UI.buildAndShowStoryPopup({ speaker: npcRival, text: translate(characterRival.text[1]) }); + } + + return didWin; + }, + + 'hospital-floor-1': async () => { + const story = await fetchStory('hospital-floor-1'); + const characterAurora = story.characters.aurora; + const npcAurora = await fetchNpc(characterAurora.slug); + + await UI.buildAndShowStoryPopup({ speaker: npcAurora, text: translate(characterAurora.text[0]) }); + await Story.setupBattle(npcAurora, characterAurora.monsters); + didWin = await Story.battle(); + if (didWin) { + await UI.buildAndShowStoryPopup({ speaker: npcAurora, text: translate(characterAurora.text[1]) }); + } + + return didWin; + }, + + 'hospital-floor-2': async () => { + const story = await fetchStory('hospital-floor-2'); + const characterLuzia = story.characters.luzia; + const npcLuzia = await fetchNpc(characterLuzia.slug); + const characterRhizome = story.characters.rhizome; + const npcRhizome = await fetchNpc(characterRhizome.slug); + + await UI.buildAndShowStoryPopup({ speaker: npcLuzia, text: translate(characterLuzia.text[0]) }); + await Story.setupBattle(npcLuzia, characterLuzia.monsters); + let didWin = await Story.battle(); + if (didWin) { + await UI.buildAndShowStoryPopup({ speaker: npcLuzia, text: translate(characterLuzia.text[1]) }); + } else { + return false; + } + + await UI.buildAndShowStoryPopup({ speaker: npcRhizome, text: translate(characterRhizome.text[0]) }); + await Story.setupBattle(npcRhizome, characterRhizome.monsters); + didWin = await Story.battle(); + if (didWin) { + await UI.buildAndShowStoryPopup({ speaker: npcRhizome, text: translate(characterRhizome.text[1]) }); + } + + return didWin; + }, + + 'hospital-floor-3': async () => { + const story = await fetchStory('hospital-floor-3'); + const characterRival = story.characters.rival; + const npcRival = await fetchNpc(characterRival.slug); + + await UI.buildAndShowStoryPopup({ + speaker: npcRival, + text: translate(characterRival.text[0]).replace('${{name}}', Memory.state.Settings.name) + }); + await Story.setupBattle(npcRival, characterRival.monsters); + didWin = await Story.battle(); + if (didWin) { + await UI.buildAndShowStoryPopup({ speaker: npcRival, text: translate(characterRival.text[1]) }); + } + + return didWin; + }, + + 'drokoro': async () => { + const story = await fetchStory('drokoro'); + + const monster = await fetchMonster(story.encounters.drokoro.slug); + monster.level = story.encounters.drokoro.level; + + Memory.state.opponent = new Trainer({ monsters: [monster] }); + await Memory.state.opponent.initialize(); + + return await Story.battle(); }, @@ -136,33 +210,51 @@ const Story = { /** * @param {StorySlug} slug + * + * @returns {Promise<boolean>} */ async progress (slug) { if (!Story[slug]) { - return; + return true; + } + + // story already done + const story = await fetchStory(slug); + if (!story.canTriggerMultipleTimes && Memory.state.storyProgress[slug]) { + return true; } Memory.state.currentStory = slug; Memory.saveToLocalStorage(); - await Story[slug](); + const isDone = await Story[slug](); + + if (isDone) { + Memory.state.storyProgress[slug] = true; + } - Memory.state.storyProgress[slug] = true; Memory.state.currentStory = null; Memory.saveToLocalStorage(); + + return isDone; }, /** * @param {StorySlug} fromSlug * @param {StorySlug} toSlug + * + * @returns {Promise<boolean>} */ async immediateProgress (fromSlug, toSlug) { Memory.state.storyProgress[fromSlug] = true; Memory.saveToLocalStorage(); - await Story.progress(toSlug); + return await Story.progress(toSlug); }, + /** + * @returns {Promise<boolean>} + */ async battle () { const previousArea = Object.assign({}, Memory.state.currentArea); @@ -191,5 +283,36 @@ const Story = { UI.drawStatus(); } + + return Game.didWinStoryBattle; + }, + + /** + * @param {Npc} npc + * @param {DB_StoryEncounter[]} monsters + * @param {Object[]} inventory + */ + async setupBattle (npc, monsters, inventory = []) { + Memory.state.opponent = new Trainer({ + monsters: await Promise.all( + monsters.map(async (monsterData) => { + if (monsterData.slug === 'RIVAL') { + monsterData.slug = Memory.state.rivalMonster; + } + + const monster = await fetchMonster(monsterData.slug); + monster.level = monsterData.level; + + return monster; + }) + ), + + inventory: inventory, + + name: translate(npc.slug), + sprite: npc.spriteName + '.png', + }); + + await Memory.state.opponent.initialize(); }, }; |