Skip to content

Commit

Permalink
Fix a bug where only the first stone evolution would be triggered (#519)
Browse files Browse the repository at this point in the history
* Fix a bug where only the first stone evolution would be triggered
  • Loading branch information
Ishadijcks committed Jan 9, 2020
1 parent b603ca8 commit 83441fb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/scripts/Changelog.ts
Expand Up @@ -23,6 +23,7 @@ class Changelog {
const changelogItems = [
// v1.0.4
new Changelog(changelogType.VERSION, 'v1.0.4'),
new Changelog(changelogType.FIXED, 'Stones now work with multiple evolutions'),
new Changelog(changelogType.NEW, 'Add setting to toggle egg percentage/step count'),
new Changelog(changelogType.CHANGE, 'Total shiny Pokemon caught no longer adds to your click attack'),
new Changelog(changelogType.CHANGE, 'Halve xp needed to upgrade Oak items'),
Expand Down
4 changes: 4 additions & 0 deletions src/scripts/GameConstants.ts
Expand Up @@ -273,6 +273,10 @@ namespace GameConstants {
return Math.floor(Math.random() * (max - min + 1)) + min;
}

export function randomElement(array: any[]) {
return array[GameConstants.randomIntBetween(0, array.length - 1)]
}

export function clipNumber(num: number, min: number, max: number) {
return Math.min(Math.max(num, min), max);
}
Expand Down
6 changes: 5 additions & 1 deletion src/scripts/party/PartyPokemon.ts
Expand Up @@ -75,11 +75,15 @@ class PartyPokemon implements Saveable {
}

public useStone(type: GameConstants.StoneType): boolean {
const possibleEvolutions = [];
for (const evolution of this.evolutions) {
if (evolution instanceof StoneEvolution && evolution.stone == type) {
return evolution.evolve()
possibleEvolutions.push(evolution);
}
}
if (possibleEvolutions.length !== 0) {
return GameConstants.randomElement(possibleEvolutions).evolve();
}
return false;
}

Expand Down

0 comments on commit 83441fb

Please sign in to comment.