pokerogue/src/data/daily-run.ts

56 lines
2.1 KiB
TypeScript
Raw Normal View History

import BattleScene from "../battle-scene";
import { PlayerPokemon } from "../field/pokemon";
import { GameModes, gameModes } from "../game-mode";
import { Starter } from "../ui/starter-select-ui-handler";
import * as Utils from "../utils";
import { Species } from "./enums/species";
import { getPokemonSpecies, speciesStarters } from "./pokemon-species";
2024-03-28 18:05:15 +00:00
import { PartyMemberStrength } from "./enums/party-member-strength";
export interface DailyRunConfig {
seed: integer;
starters: Starter;
}
2024-03-17 02:06:56 +00:00
export function fetchDailyRunSeed(): Promise<string> {
return new Promise<string>(resolve => {
Utils.apiFetch('daily/seed').then(response => {
if (!response.ok) {
resolve(null);
return;
}
return response.text();
}).then(seed => resolve(seed));
});
}
2024-03-17 02:06:56 +00:00
export function getDailyRunStarters(scene: BattleScene, seed: string): Starter[] {
const starters: Starter[] = [];
scene.executeWithSeedOffset(() => {
const starterWeights = [];
starterWeights.push(Math.round(3.5 + Math.abs(Utils.randSeedGauss(1))));
starterWeights.push(Utils.randSeedInt(9 - starterWeights[0], 1));
starterWeights.push(10 - (starterWeights[0] + starterWeights[1]));
2024-03-17 02:06:56 +00:00
const startingLevel = gameModes[GameModes.DAILY].getStartingLevel();
for (let s = 0; s < starterWeights.length; s++) {
const weight = starterWeights[s];
const weightSpecies = Object.keys(speciesStarters)
.map(s => parseInt(s) as Species)
.filter(s => speciesStarters[s] === weight);
2024-03-28 18:05:15 +00:00
const starterSpecies = getPokemonSpecies(getPokemonSpecies(Utils.randSeedItem(weightSpecies)).getTrainerSpeciesForLevel(startingLevel, true, PartyMemberStrength.STRONGER));
2024-03-17 02:06:56 +00:00
const pokemon = new PlayerPokemon(scene, starterSpecies, startingLevel, undefined, undefined, undefined, undefined, undefined, undefined, undefined);
const starter: Starter = {
species: starterSpecies,
dexAttr: pokemon.getDexAttr(),
nature: pokemon.nature,
pokerus: pokemon.pokerus
};
starters.push(starter);
pokemon.destroy();
}
}, 0, seed);
return starters;
}