mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-03-15 06:15:22 +00:00
* start migrating Utils.apiFetch to api class * move dailyranking to api * use api in title-ui-handler * remove: Utils.apiFetch * migrate `updateSystemSavedata` to api * migrate clear session savedata to api * migrate updateAllSavedata to api * migrate `updateSessionSavedata` to api * rename `api` to `pokerogue-api` * migrate unlink discord to pokerogue-api * migrate unlink google to pokerogue-api * update pokerogue-api login * migrate register account to pokerogue-api * remove Utils.apiPost * reset overrides.ts * chore: cleanup * fix env.development * fix circular dependencies with api * fix gamedata verify missing await * fix daily api calls in daily-run-scorebard * fix discord-link request body being empty there was a double `toUrlSearchParams()` call involved * add pokerogue-api test coverge * add test-utils `getApiBaseUrl()` method * add pokerogue-admin-api test coverage * add pokerogue-account-api test coverage * add pokerogue-daily-api test coverage * add pokerogue-savedata-api test coverage * fix some test describes * add pokerogue-session-savedata-api test coverage * add pokerogue-system-savedata-api test coverage * fix tests * fix tryExportData thanks @MokaStitcher * chore: fix menu-ui-handlers.ts * fix admin-ui-handler (types) * extend test-coverage for admin-api * remove outdated code * skip some clowning-around-encounter tests if events are active this is not a permanent solution * Update src/system/game-data.ts Co-authored-by: PigeonBar <56974298+PigeonBar@users.noreply.github.com> * Revert "skip some clowning-around-encounter tests if events are active" This reverts commit a97dafe8b2479e9b2ddd49d4dc9710814d7c7b67. * mark `localServerUrl` and `apiUrl` as deprecated in `utils.ts` --------- Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> Co-authored-by: PigeonBar <56974298+PigeonBar@users.noreply.github.com>
73 lines
3.0 KiB
TypeScript
73 lines
3.0 KiB
TypeScript
import { PartyMemberStrength } from "#enums/party-member-strength";
|
|
import { Species } from "#enums/species";
|
|
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";
|
|
import { pokerogueApi } from "#app/plugins/api/pokerogue-api";
|
|
|
|
export interface DailyRunConfig {
|
|
seed: integer;
|
|
starters: Starter;
|
|
}
|
|
|
|
export function fetchDailyRunSeed(): Promise<string | null> {
|
|
return new Promise<string | null>((resolve, reject) => {
|
|
pokerogueApi.daily.getSeed().then(dailySeed => {
|
|
resolve(dailySeed);
|
|
});
|
|
});
|
|
}
|
|
|
|
export function getDailyRunStarters(scene: BattleScene, seed: string): Starter[] {
|
|
const starters: Starter[] = [];
|
|
|
|
scene.executeWithSeedOffset(() => {
|
|
const startingLevel = scene.gameMode.getStartingLevel();
|
|
|
|
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.min(Math.round(3.5 + Math.abs(Utils.randSeedGauss(1))), 8));
|
|
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(speciesStarterCosts)
|
|
.map(s => parseInt(s) as Species)
|
|
.filter(s => speciesStarterCosts[s] === cost);
|
|
const randPkmSpecies = getPokemonSpecies(Utils.randSeedItem(costSpecies));
|
|
const starterSpecies = getPokemonSpecies(randPkmSpecies.getTrainerSpeciesForLevel(startingLevel, true, PartyMemberStrength.STRONGER));
|
|
starters.push(getDailyRunStarter(scene, starterSpecies, startingLevel));
|
|
}
|
|
}, 0, seed);
|
|
|
|
return starters;
|
|
}
|
|
|
|
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, undefined);
|
|
const starter: Starter = {
|
|
species: starterSpecies,
|
|
dexAttr: pokemon.getDexAttr(),
|
|
abilityIndex: pokemon.abilityIndex,
|
|
passive: false,
|
|
nature: pokemon.getNature(),
|
|
pokerus: pokemon.pokerus
|
|
};
|
|
pokemon.destroy();
|
|
return starter;
|
|
}
|