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";
|
2024-03-30 21:10:34 +00:00
|
|
|
import PokemonSpecies, { PokemonSpeciesForm, getPokemonSpecies, getPokemonSpeciesForm, speciesStarters } from "./pokemon-species";
|
2024-03-28 18:05:15 +00:00
|
|
|
import { PartyMemberStrength } from "./enums/party-member-strength";
|
2024-03-16 01:59:34 +00:00
|
|
|
|
|
|
|
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(() => {
|
2024-03-17 02:06:56 +00:00
|
|
|
const startingLevel = gameModes[GameModes.DAILY].getStartingLevel();
|
|
|
|
|
2024-03-30 21:10:34 +00:00
|
|
|
if (/\d{18}$/.test(seed)) {
|
|
|
|
for (let s = 0; s < 3; s++) {
|
|
|
|
const offset = 6 + s * 6;
|
|
|
|
const starterSpeciesForm = getPokemonSpeciesForm(parseInt(seed.slice(offset, offset + 4)) as Species, parseInt(seed.slice(offset + 4, offset + 6)));
|
|
|
|
starters.push(getDailyRunStarter(scene, starterSpeciesForm, startingLevel));
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const starterCosts: integer[] = [];
|
|
|
|
starterCosts.push(Math.round(3.5 + Math.abs(Utils.randSeedGauss(1))));
|
|
|
|
starterCosts.push(Utils.randSeedInt(9 - starterCosts[0], 1));
|
|
|
|
starterCosts.push(10 - (starterCosts[0] + starterCosts[1]));
|
|
|
|
|
|
|
|
for (let c = 0; c < starterCosts.length; c++) {
|
|
|
|
const cost = starterCosts[c];
|
|
|
|
const costSpecies = Object.keys(speciesStarters)
|
2024-03-16 01:59:34 +00:00
|
|
|
.map(s => parseInt(s) as Species)
|
2024-03-30 21:10:34 +00:00
|
|
|
.filter(s => speciesStarters[s] === cost);
|
|
|
|
const starterSpecies = getPokemonSpecies(getPokemonSpecies(Utils.randSeedItem(costSpecies)).getTrainerSpeciesForLevel(startingLevel, true, PartyMemberStrength.STRONGER));
|
|
|
|
starters.push(getDailyRunStarter(scene, starterSpecies, startingLevel));
|
2024-03-16 01:59:34 +00:00
|
|
|
}
|
|
|
|
}, 0, seed);
|
2024-03-30 21:10:34 +00:00
|
|
|
|
2024-03-16 01:59:34 +00:00
|
|
|
return starters;
|
2024-03-30 21:10:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getDailyRunStarter(scene: BattleScene, starterSpeciesForm: PokemonSpeciesForm, startingLevel: integer): Starter {
|
|
|
|
const starterSpecies = starterSpeciesForm instanceof PokemonSpecies ? starterSpeciesForm : getPokemonSpecies(starterSpeciesForm.speciesId);
|
|
|
|
const formIndex = starterSpeciesForm instanceof PokemonSpecies ? undefined : starterSpeciesForm.formIndex;
|
|
|
|
const pokemon = new PlayerPokemon(scene, starterSpecies, startingLevel, undefined, formIndex, undefined, undefined, undefined, undefined, undefined);
|
|
|
|
const starter: Starter = {
|
|
|
|
species: starterSpecies,
|
|
|
|
dexAttr: pokemon.getDexAttr(),
|
2024-04-03 04:00:56 +01:00
|
|
|
nature: pokemon.getNature(),
|
2024-03-30 21:10:34 +00:00
|
|
|
pokerus: pokemon.pokerus
|
|
|
|
};
|
|
|
|
pokemon.destroy();
|
|
|
|
return starter;
|
2024-03-16 01:59:34 +00:00
|
|
|
}
|