/
RouteHelper.ts
73 lines (62 loc) · 2.88 KB
/
RouteHelper.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
///<reference path="../../declarations/routes/Routes.d.ts"/>
///<reference path="../../declarations/routes/RoutePokemon.d.ts"/>
/**
* Helper class to retrieve information from RoutePokemon
*/
class RouteHelper {
/**
* Retrieves a list of all Pokémon that can be caught on that route.
* @param route
* @param region
* @param includeHeadbutt
* @returns {string[]} list of all Pokémons that can be caught
*/
public static getAvailablePokemonList(route: number, region: GameConstants.Region, includeHeadbutt = true): PokemonNameType[] {
// If the route is somehow higher than allowed, use the first route to generateWildPokemon Pokémon
const possiblePokemons = Routes.getRoute(region, route)?.pokemon;
if (!possiblePokemons) {
return ['Rattata'];
}
// Land Pokémon
let pokemonList = possiblePokemons.land;
// Water Pokémon
if (App.game.keyItems.hasKeyItem(KeyItemType.Super_rod) || possiblePokemons.land.length == 0) {
pokemonList = pokemonList.concat(possiblePokemons.water);
}
// Headbutt Pokémon
if (includeHeadbutt) {
pokemonList = pokemonList.concat(possiblePokemons.headbutt);
}
// Special requirement Pokémon
pokemonList = pokemonList.concat(...possiblePokemons.special.filter(p => p.isAvailable()).map(p => p.pokemon));
return pokemonList;
}
/**
* Checks if all Pokémons on this route are caught by the player.
* @param route
* @param region
* @param includeShiny
* @param includeHeadbutt
* @returns {boolean} true if all Pokémon on this route are caught.
*/
public static routeCompleted(route: number, region: GameConstants.Region, includeShiny: boolean, includeHeadbutt = true): boolean {
const possiblePokemon: PokemonNameType[] = RouteHelper.getAvailablePokemonList(route, region, includeHeadbutt);
return RouteHelper.listCompleted(possiblePokemon, includeShiny);
}
public static listCompleted(possiblePokemon: PokemonNameType[], includeShiny: boolean) {
for (let i = 0; i < possiblePokemon.length; i++) {
if (!App.game.party.alreadyCaughtPokemon(PokemonHelper.getPokemonByName(possiblePokemon[i]).id)) {
return false;
}
if (includeShiny && !App.game.party.alreadyCaughtPokemon(PokemonHelper.getPokemonByName(possiblePokemon[i]).id, true)) {
return false;
}
}
return true;
}
public static isAchievementsComplete(route: number, region: GameConstants.Region) {
return AchievementHandler.achievementList.every(achievement => {
return !(achievement.property instanceof RouteKillRequirement && achievement.property.region === region && achievement.property.route === route && !achievement.isCompleted());
});
}
}