pokerogue/src/data/daily-run.ts

74 lines
2.9 KiB
TypeScript
Raw Normal View History

import BattleScene from "../battle-scene";
import { PlayerPokemon } from "../field/pokemon";
import { Starter } from "../ui/starter-select-ui-handler";
import * as Utils from "../utils";
2024-03-30 17:10:34 -04:00
import PokemonSpecies, { PokemonSpeciesForm, getPokemonSpecies, getPokemonSpeciesForm, speciesStarters } from "./pokemon-species";
import { PartyMemberStrength, Species } from "#enums";
export interface DailyRunConfig {
seed: integer;
starters: Starter;
}
2024-03-16 22:06:56 -04:00
export function fetchDailyRunSeed(): Promise<string> {
return new Promise<string>((resolve, reject) => {
Utils.apiFetch("daily/seed").then(response => {
2024-03-16 22:06:56 -04:00
if (!response.ok) {
resolve(null);
return;
}
return response.text();
}).then(seed => resolve(seed))
.catch(err => reject(err));
2024-03-16 22:06:56 -04:00
});
}
2024-03-16 22:06:56 -04:00
export function getDailyRunStarters(scene: BattleScene, seed: string): Starter[] {
const starters: Starter[] = [];
scene.executeWithSeedOffset(() => {
Add Challenges (#1459) * Initial challenge framework * Add type localisation * Change how challenges are tracked Also fixes the difficulty total text * MVP Renames challenge types, temporarily hides difficulty, and implements challenge saving. * Attempt to fix one legal pokemon in a double battle * Make monotype ignore type changing effects * Make isOfType correctly detect normal types * Try to fix double battles again * Make challenge function more like classic * Add helper function for fainted or not allowed * Add framework for fresh start challenge and improve comments * Try to fix evolution issues * Make form changing items only usable from rewards screen * Update localisation * Additional localisation change * Add achievements for completing challenges * Fix initialisation bug with challenge achievements * Add support for gamemode specific fixed battles Also make monogen challenges face the e4 of their generation * Add better support for mobile in challenges * Localise illegal evolution/form change message * Update achievement names * Make alternate forms count for monogen * Update monotype achievement icons * Add more comments * Improve comments * Fix mid battle form changes * Reorder mode list * Remove currently unused localisation entry * Add type overrides for monotype challenges Meloetta always counts for psychic and castform always counts for normal * Change how form changes are handled Now attempts a switch at the start of each turn instead of immediately * Add start button to challenge select screen * Make starter select back out to challenge screen if using challenges * Fix daily runs * Update tests to new game mode logic
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[] = [];
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)
.map(s => parseInt(s) as Species)
2024-03-30 17:10:34 -04:00
.filter(s => speciesStarters[s] === cost);
const starterSpecies = getPokemonSpecies(getPokemonSpecies(Utils.randSeedItem(costSpecies)).getTrainerSpeciesForLevel(startingLevel, true, PartyMemberStrength.STRONGER));
starters.push(getDailyRunStarter(scene, starterSpecies, startingLevel));
}
}, 0, seed);
2024-05-24 01:45:04 +02: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;
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,
passive: false,
nature: pokemon.getNature(),
2024-03-30 17:10:34 -04:00
pokerus: pokemon.pokerus
};
pokemon.destroy();
return starter;
}