diff options
Diffstat (limited to 'resources/js/game.js')
-rw-r--r-- | resources/js/game.js | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/resources/js/game.js b/resources/js/game.js index c463ab8..3e7a4c8 100644 --- a/resources/js/game.js +++ b/resources/js/game.js @@ -593,11 +593,11 @@ const Game = { Game.opponentActionTimeout = null; }), Math.max(levelDifference < 10 ? 500 : 50, Math.min(2000 - (speedDifference * 10) - (levelDifference * 100), 3000))); - console.log( + /* console.log( 'Opponent Attack Timeout', Memory.state.opponent.activeMonster.stats.speed, Memory.state.player.activeMonster.stats.speed, 2000 - (speedDifference * 10) - (levelDifference * 100) - ); + ); */ } }, @@ -680,16 +680,36 @@ const Game = { /* Progression */ async encounterWildMonster () { - const randomMonster = Memory.state.currentArea.encounters[Math.floor(Math.random() * Memory.state.currentArea.encounters.length)]; + let randomMonster = null; + const randomNumber = Math.random() * Memory.state.currentArea.encounterPercentTotal; + let accumulator = 0; + for (const encounter of Memory.state.currentArea.encounters) { + const lowerBounds = accumulator; + accumulator += encounter.encounter_percent; + const upperBounds = accumulator; + + if (randomNumber >= lowerBounds && randomNumber <= upperBounds) { + randomMonster = encounter; + break; + } + } + const randomLevel = Math.floor(Math.random() * (randomMonster.level_range[1] - randomMonster.level_range[0]) + randomMonster.level_range[0]); const monster = await fetchMonster(randomMonster.monster); monster.level = randomLevel; - const wildMonster = new Trainer({ monsters: [monster] }); - wildMonster.type = 'monster'; - await wildMonster.initialize(); - Memory.state.opponent = wildMonster; + Game.encounterMonster(monster); + }, + + /** + * @param {Monster} monster + */ + async encounterMonster (monster) { + const encounterMonster = new Trainer({ monsters: [monster] }); + encounterMonster.type = 'monster'; + await encounterMonster.initialize(); + Memory.state.opponent = encounterMonster; UI.drawOpponentMonster(); }, |