2024-06-13 18:44:23 -04:00
|
|
|
import { PartyMemberStrength } from "#enums/party-member-strength";
|
|
|
|
import { Species } from "#enums/species";
|
2024-10-02 09:20:19 -04:00
|
|
|
import BattleScene from "#app/battle-scene";
|
|
|
|
import { PlayerPokemon } from "#app/field/pokemon";
|
|
|
|
import { Starter } from "#app/ui/starter-select-ui-handler";
|
|
|
|
import * as Utils from "#app/utils";
|
|
|
|
import PokemonSpecies, { PokemonSpeciesForm, getPokemonSpecies, getPokemonSpeciesForm } from "#app/data/pokemon-species";
|
|
|
|
import { speciesStarterCosts } from "#app/data/balance/starters";
|
2024-11-04 12:57:21 -08:00
|
|
|
import { pokerogueApi } from "#app/plugins/api/pokerogue-api";
|
2024-03-15 21:59:34 -04:00
|
|
|
|
|
|
|
export interface DailyRunConfig {
|
|
|
|
seed: integer;
|
|
|
|
starters: Starter;
|
|
|
|
}
|
|
|
|
|
2024-08-07 09:23:12 -07:00
|
|
|
export function fetchDailyRunSeed(): Promise<string | null> {
|
|
|
|
return new Promise<string | null>((resolve, reject) => {
|
2024-11-04 12:57:21 -08:00
|
|
|
pokerogueApi.daily.getSeed().then(dailySeed => {
|
|
|
|
resolve(dailySeed);
|
|
|
|
});
|
2024-03-16 22:06:56 -04:00
|
|
|
});
|
2024-03-15 21:59:34 -04:00
|
|
|
}
|
|
|
|
|
2024-03-16 22:06:56 -04:00
|
|
|
export function getDailyRunStarters(scene: BattleScene, seed: string): Starter[] {
|
2024-03-15 21:59:34 -04:00
|
|
|
const starters: Starter[] = [];
|
|
|
|
|
|
|
|
scene.executeWithSeedOffset(() => {
|
2024-06-08 15:07:23 +10:00
|
|
|
const startingLevel = scene.gameMode.getStartingLevel();
|
2024-03-16 22:06:56 -04:00
|
|
|
|
2024-03-30 17:10:34 -04: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[] = [];
|
2024-08-30 20:10:38 -07:00
|
|
|
starterCosts.push(Math.min(Math.round(3.5 + Math.abs(Utils.randSeedGauss(1))), 8));
|
2024-03-30 17:10:34 -04:00
|
|
|
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];
|
2024-10-02 09:20:19 -04:00
|
|
|
const costSpecies = Object.keys(speciesStarterCosts)
|
2024-03-15 21:59:34 -04:00
|
|
|
.map(s => parseInt(s) as Species)
|
2024-10-02 09:20:19 -04:00
|
|
|
.filter(s => speciesStarterCosts[s] === cost);
|
2024-08-26 14:05:16 -07:00
|
|
|
const randPkmSpecies = getPokemonSpecies(Utils.randSeedItem(costSpecies));
|
|
|
|
const starterSpecies = getPokemonSpecies(randPkmSpecies.getTrainerSpeciesForLevel(startingLevel, true, PartyMemberStrength.STRONGER));
|
2024-03-30 17:10:34 -04:00
|
|
|
starters.push(getDailyRunStarter(scene, starterSpecies, startingLevel));
|
2024-03-15 21:59:34 -04:00
|
|
|
}
|
|
|
|
}, 0, seed);
|
2024-05-24 01:45:04 +02:00
|
|
|
|
2024-03-15 21:59:34 -04:00
|
|
|
return starters;
|
2024-03-30 17:10:34 -04: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;
|
2024-06-04 11:39:02 -04:00
|
|
|
const pokemon = new PlayerPokemon(scene, starterSpecies, startingLevel, undefined, formIndex, undefined, undefined, undefined, undefined, undefined, undefined);
|
2024-03-30 17:10:34 -04:00
|
|
|
const starter: Starter = {
|
|
|
|
species: starterSpecies,
|
|
|
|
dexAttr: pokemon.getDexAttr(),
|
2024-04-18 22:52:26 -04:00
|
|
|
abilityIndex: pokemon.abilityIndex,
|
2024-04-13 18:59:58 -04:00
|
|
|
passive: false,
|
2024-04-02 23:00:56 -04:00
|
|
|
nature: pokemon.getNature(),
|
2024-03-30 17:10:34 -04:00
|
|
|
pokerus: pokemon.pokerus
|
|
|
|
};
|
|
|
|
pokemon.destroy();
|
|
|
|
return starter;
|
2024-05-23 17:03:10 +02:00
|
|
|
}
|