mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-09-23 15:03:24 +02:00
Claened up title scene daily run init to be less questionable
This commit is contained in:
parent
17c13115dd
commit
28575fd316
@ -193,7 +193,7 @@ export class TitlePhase extends Phase {
|
|||||||
|
|
||||||
initDailyRun(): void {
|
initDailyRun(): void {
|
||||||
globalScene.ui.clearText();
|
globalScene.ui.clearText();
|
||||||
globalScene.ui.setMode(UiMode.SAVE_SLOT, SaveSlotUiMode.SAVE, (slotId: number) => {
|
globalScene.ui.setMode(UiMode.SAVE_SLOT, SaveSlotUiMode.SAVE, async (slotId: number) => {
|
||||||
if (slotId === -1) {
|
if (slotId === -1) {
|
||||||
globalScene.phaseManager.toTitleScreen();
|
globalScene.phaseManager.toTitleScreen();
|
||||||
super.end();
|
super.end();
|
||||||
@ -202,101 +202,92 @@ export class TitlePhase extends Phase {
|
|||||||
globalScene.phaseManager.clearPhaseQueue();
|
globalScene.phaseManager.clearPhaseQueue();
|
||||||
globalScene.sessionSlotId = slotId;
|
globalScene.sessionSlotId = slotId;
|
||||||
|
|
||||||
const generateDaily = (seed: string) => {
|
let seed = "";
|
||||||
globalScene.gameMode = getGameMode(GameModes.DAILY);
|
|
||||||
// Daily runs don't support all challenges yet (starter select restrictions aren't considered)
|
|
||||||
globalScene.eventManager.startEventChallenges();
|
|
||||||
|
|
||||||
globalScene.setSeed(seed);
|
|
||||||
globalScene.resetSeed();
|
|
||||||
|
|
||||||
globalScene.money = globalScene.gameMode.getStartingMoney();
|
|
||||||
|
|
||||||
const starters = getDailyRunStarters(seed);
|
|
||||||
const startingLevel = globalScene.gameMode.getStartingLevel();
|
|
||||||
|
|
||||||
const party = globalScene.getPlayerParty();
|
|
||||||
const loadPokemonAssets: Promise<void>[] = [];
|
|
||||||
for (const starter of starters) {
|
|
||||||
const starterProps = globalScene.gameData.getSpeciesDexAttrProps(starter.species, starter.dexAttr);
|
|
||||||
const starterFormIndex = Math.min(starterProps.formIndex, Math.max(starter.species.forms.length - 1, 0));
|
|
||||||
const starterGender =
|
|
||||||
starter.species.malePercent !== null
|
|
||||||
? !starterProps.female
|
|
||||||
? Gender.MALE
|
|
||||||
: Gender.FEMALE
|
|
||||||
: Gender.GENDERLESS;
|
|
||||||
const starterPokemon = globalScene.addPlayerPokemon(
|
|
||||||
starter.species,
|
|
||||||
startingLevel,
|
|
||||||
starter.abilityIndex,
|
|
||||||
starterFormIndex,
|
|
||||||
starterGender,
|
|
||||||
starterProps.shiny,
|
|
||||||
starterProps.variant,
|
|
||||||
undefined,
|
|
||||||
starter.nature,
|
|
||||||
);
|
|
||||||
starterPokemon.setVisible(false);
|
|
||||||
party.push(starterPokemon);
|
|
||||||
loadPokemonAssets.push(starterPokemon.loadAssets());
|
|
||||||
}
|
|
||||||
|
|
||||||
regenerateModifierPoolThresholds(party, ModifierPoolType.DAILY_STARTER);
|
|
||||||
|
|
||||||
const modifiers: Modifier[] = new Array(3)
|
|
||||||
.fill(null)
|
|
||||||
.map(() => modifierTypes.EXP_SHARE().withIdFromFunc(modifierTypes.EXP_SHARE).newModifier())
|
|
||||||
.concat(
|
|
||||||
new Array(3)
|
|
||||||
.fill(null)
|
|
||||||
.map(() => modifierTypes.GOLDEN_EXP_CHARM().withIdFromFunc(modifierTypes.GOLDEN_EXP_CHARM).newModifier()),
|
|
||||||
)
|
|
||||||
.concat([modifierTypes.MAP().withIdFromFunc(modifierTypes.MAP).newModifier()])
|
|
||||||
.concat(getDailyRunStarterModifiers(party))
|
|
||||||
.filter(m => m !== null);
|
|
||||||
|
|
||||||
for (const m of modifiers) {
|
|
||||||
globalScene.addModifier(m, true, false, false, true);
|
|
||||||
}
|
|
||||||
globalScene.updateModifiers(true, true);
|
|
||||||
|
|
||||||
Promise.all(loadPokemonAssets).then(() => {
|
|
||||||
globalScene.time.delayedCall(500, () => globalScene.playBgm());
|
|
||||||
globalScene.gameData.gameStats.dailyRunSessionsPlayed++;
|
|
||||||
globalScene.newArena(globalScene.gameMode.getStartingBiome());
|
|
||||||
globalScene.newBattle();
|
|
||||||
globalScene.arena.init();
|
|
||||||
globalScene.sessionPlayTime = 0;
|
|
||||||
globalScene.lastSavePlayTime = 0;
|
|
||||||
this.end();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// If Online, calls seed fetch from db to generate daily run. If Offline, generates a daily run based on current date.
|
// If Online, calls seed fetch from db to generate daily run. If Offline, generates a daily run based on current date.
|
||||||
if (!isLocal || isLocalServerConnected) {
|
if (!isLocal || isLocalServerConnected) {
|
||||||
fetchDailyRunSeed()
|
try {
|
||||||
.then(seed => {
|
seed = (await fetchDailyRunSeed()) ?? "";
|
||||||
if (seed) {
|
if (!seed) {
|
||||||
generateDaily(seed);
|
throw new Error("Daily run seed is null!");
|
||||||
} else {
|
}
|
||||||
throw new Error("Daily run seed is null!");
|
} catch (err) {
|
||||||
}
|
// TODO: Find a better fallback for bad daily run loads
|
||||||
})
|
console.error("Failed to load daily run:\n", err);
|
||||||
.catch(err => {
|
}
|
||||||
console.error("Failed to load daily run:\n", err);
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
// Grab first 10 chars of ISO date format (YYYY-MM-DD) and convert to base64
|
// Grab first 10 chars of ISO date format (YYYY-MM-DD) and convert to base64
|
||||||
let seed: string = btoa(new Date().toISOString().substring(0, 10));
|
seed = Overrides.DAILY_RUN_SEED_OVERRIDE ?? btoa(new Date().toISOString().substring(0, 10));
|
||||||
if (Overrides.DAILY_RUN_SEED_OVERRIDE != null) {
|
|
||||||
seed = Overrides.DAILY_RUN_SEED_OVERRIDE;
|
|
||||||
}
|
|
||||||
generateDaily(seed);
|
|
||||||
}
|
}
|
||||||
|
await this.generateDaily(seed);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async generateDaily(seed: string) {
|
||||||
|
globalScene.gameMode = getGameMode(GameModes.DAILY);
|
||||||
|
// Daily runs don't support all challenges yet (starter select restrictions aren't considered)
|
||||||
|
globalScene.eventManager.startEventChallenges();
|
||||||
|
|
||||||
|
globalScene.setSeed(seed);
|
||||||
|
globalScene.resetSeed();
|
||||||
|
|
||||||
|
globalScene.money = globalScene.gameMode.getStartingMoney();
|
||||||
|
|
||||||
|
const starters = getDailyRunStarters(seed);
|
||||||
|
const startingLevel = globalScene.gameMode.getStartingLevel();
|
||||||
|
|
||||||
|
const party = globalScene.getPlayerParty();
|
||||||
|
const loadPokemonAssets: Promise<void>[] = [];
|
||||||
|
for (const starter of starters) {
|
||||||
|
const starterProps = globalScene.gameData.getSpeciesDexAttrProps(starter.species, starter.dexAttr);
|
||||||
|
const starterFormIndex = Math.min(starterProps.formIndex, Math.max(starter.species.forms.length - 1, 0));
|
||||||
|
const starterGender =
|
||||||
|
starter.species.malePercent !== null ? (!starterProps.female ? Gender.MALE : Gender.FEMALE) : Gender.GENDERLESS;
|
||||||
|
const starterPokemon = globalScene.addPlayerPokemon(
|
||||||
|
starter.species,
|
||||||
|
startingLevel,
|
||||||
|
starter.abilityIndex,
|
||||||
|
starterFormIndex,
|
||||||
|
starterGender,
|
||||||
|
starterProps.shiny,
|
||||||
|
starterProps.variant,
|
||||||
|
undefined,
|
||||||
|
starter.nature,
|
||||||
|
);
|
||||||
|
starterPokemon.setVisible(false);
|
||||||
|
party.push(starterPokemon);
|
||||||
|
loadPokemonAssets.push(starterPokemon.loadAssets());
|
||||||
|
}
|
||||||
|
|
||||||
|
regenerateModifierPoolThresholds(party, ModifierPoolType.DAILY_STARTER);
|
||||||
|
|
||||||
|
const modifiers: Modifier[] = new Array(3)
|
||||||
|
.fill(null)
|
||||||
|
.map(() => modifierTypes.EXP_SHARE().withIdFromFunc(modifierTypes.EXP_SHARE).newModifier())
|
||||||
|
.concat(
|
||||||
|
new Array(3)
|
||||||
|
.fill(null)
|
||||||
|
.map(() => modifierTypes.GOLDEN_EXP_CHARM().withIdFromFunc(modifierTypes.GOLDEN_EXP_CHARM).newModifier()),
|
||||||
|
)
|
||||||
|
.concat([modifierTypes.MAP().withIdFromFunc(modifierTypes.MAP).newModifier()])
|
||||||
|
.concat(getDailyRunStarterModifiers(party))
|
||||||
|
.filter(m => m !== null);
|
||||||
|
|
||||||
|
for (const m of modifiers) {
|
||||||
|
globalScene.addModifier(m, true, false, false, true);
|
||||||
|
}
|
||||||
|
globalScene.updateModifiers(true, true);
|
||||||
|
|
||||||
|
await Promise.all(loadPokemonAssets);
|
||||||
|
globalScene.time.delayedCall(500, () => globalScene.playBgm());
|
||||||
|
globalScene.gameData.gameStats.dailyRunSessionsPlayed++;
|
||||||
|
globalScene.newArena(globalScene.gameMode.getStartingBiome());
|
||||||
|
globalScene.newBattle();
|
||||||
|
globalScene.arena.init();
|
||||||
|
globalScene.sessionPlayTime = 0;
|
||||||
|
globalScene.lastSavePlayTime = 0;
|
||||||
|
this.end();
|
||||||
|
}
|
||||||
|
|
||||||
end(): void {
|
end(): void {
|
||||||
if (!this.loaded && !globalScene.gameMode.isDaily) {
|
if (!this.loaded && !globalScene.gameMode.isDaily) {
|
||||||
globalScene.arena.preloadBgm();
|
globalScene.arena.preloadBgm();
|
||||||
|
Loading…
Reference in New Issue
Block a user