diff options
Diffstat (limited to 'resources/js/game.js')
-rw-r--r-- | resources/js/game.js | 68 |
1 files changed, 41 insertions, 27 deletions
diff --git a/resources/js/game.js b/resources/js/game.js index 5a31c39..7b40015 100644 --- a/resources/js/game.js +++ b/resources/js/game.js @@ -114,7 +114,7 @@ const Game = { if (Memory.state.currentArea.encounters.length > 0) { await Game.encounterWildMonster(); } else { - await Game.progressToNextArea(); + await Game.encounterTrainer(); } } else { await Game.encounterNextTrainerMonster(); @@ -662,12 +662,21 @@ const Game = { async encounterTrainer () { Game.clearCurrentTurn(); - const nextTrainer = Memory.state.currentArea.trainers[Memory.state.currentArea.trainerProgress]; + let nextTrainerIdx = Memory.state.currentArea.trainerProgress; + while (nextTrainerIdx > Memory.state.currentArea.trainers.length - 1) { + nextTrainerIdx -= Memory.state.currentArea.trainers.length; + } - const trainer = new Trainer(nextTrainer); + const nextTrainer = Memory.state.currentArea.trainers[nextTrainerIdx]; if (nextTrainer.name === 'Rival') { - trainer.monsters.push(Memory.state.rivalMonster); + for (const idx in nextTrainer.monsters) { + if (nextTrainer.monsters[idx].slug === 'STARTER') { + nextTrainer.monsters[idx].slug = Memory.state.rivalMonster; + } + } } + + const trainer = new Trainer(nextTrainer); await trainer.initialize() Memory.state.opponent = trainer; @@ -682,40 +691,39 @@ const Game = { UI.drawOpponentMonster(); }, - async progressToNextArea () { + /** + * @param {string} areaSlug + */ + async goToArea (areaSlug) { Game.isLoadingArea = true; Game.clearCurrentTurn(); - const currentArea = Memory.state.currentArea; - const nextArea = await fetchArea(currentArea.nextArea); + if (Memory.state.currentArea) { + Memory.state.areaProgress[Memory.state.currentArea.slug] = Memory.state.currentArea; + } - await Game.jumpToArea(nextArea); + Memory.state.currentArea = await fetchArea(areaSlug); + UI.drawArea(); - if (nextArea.encounters.length > 0) { - await Game.encounterWildMonster(); + if (Game.isTown(Memory.state.currentArea)) { + UI.elements.sceneBattle.classList.add('hidden'); + UI.elements.sceneTown.classList.remove('hidden'); } else { - await Game.encounterTrainer(); + UI.elements.sceneTown.classList.add('hidden'); + UI.elements.sceneBattle.classList.remove('hidden'); + if (Memory.state.currentArea.encounters.length > 0) { + await Game.encounterWildMonster(); + } else if (Memory.state.currentArea.trainers.length > 0) { + await Game.encounterTrainer(); + } } UI.drawStatus(); + UI.drawActiveBall(); Game.isLoadingArea = false; }, - /** - * @param {Area} area - */ - async jumpToArea (area) { - Game.clearCurrentTurn(); - - if (Memory.state.currentArea) { - Memory.state.areaProgress[Memory.state.currentArea.slug] = Memory.state.currentArea; - } - Memory.state.currentArea = area; - - UI.drawArea(area); - }, - /* Menu - Inventory */ @@ -806,7 +814,7 @@ const Game = { * @returns {boolean} */ canCatchMonster () { - return Game.isBattleType('monster') && Memory.state.activeBall; + return !Game.isTown(Memory.state.currentArea) && Game.isBattleType('monster') && Memory.state.activeBall; }, async catchMonster () { @@ -866,6 +874,13 @@ const Game = { return Memory.state.opponent.type === type; }, + /** + * @param {Area} area + */ + isTown (area) { + return area.encounters.length === 0 && area.trainers.length === 0; + }, + getStageOfDaySimple () { const hours = (new Date()).getHours(); if (hours >= 6 && hours < 18) { @@ -878,7 +893,6 @@ const Game = { // Game click bindings UI.elements.nextTrainer.addEventListener('click', Game.encounterTrainer); -UI.elements.nextArea.addEventListener('click', Game.progressToNextArea); UI.elements.battleOpponent.addEventListener('click', Game.battleClick); UI.elements.techniques.addEventListener('click', Game.techniqueClick); UI.elements.menuCatch.addEventListener('click', Game.catchMonster); |