2024-03-16 01:59:34 +00:00
|
|
|
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";
|
|
|
|
|
|
|
|
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-16 01:59:34 +00:00
|
|
|
}
|
|
|
|
|
2024-03-17 02:06:56 +00:00
|
|
|
export function getDailyRunStarters(scene: BattleScene, seed: string): Starter[] {
|
2024-03-16 01:59:34 +00:00
|
|
|
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();
|
|
|
|
|
2024-03-16 01:59:34 +00:00
|
|
|
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-17 02:06:56 +00:00
|
|
|
const starterSpecies = getPokemonSpecies(getPokemonSpecies(Utils.randSeedItem(weightSpecies)).getSpeciesForLevel(startingLevel, true, true, false, true));
|
|
|
|
const pokemon = new PlayerPokemon(scene, starterSpecies, startingLevel, undefined, undefined, undefined, undefined, undefined, undefined, undefined);
|
2024-03-16 01:59:34 +00:00
|
|
|
const starter: Starter = {
|
|
|
|
species: starterSpecies,
|
|
|
|
dexAttr: pokemon.getDexAttr(),
|
|
|
|
nature: pokemon.nature,
|
|
|
|
pokerus: pokemon.pokerus
|
|
|
|
};
|
|
|
|
starters.push(starter);
|
|
|
|
pokemon.destroy();
|
|
|
|
}
|
|
|
|
}, 0, seed);
|
|
|
|
return starters;
|
|
|
|
}
|