From 3f2c55b151c9dcc6dca7b6ab72ca06ef885c7dc3 Mon Sep 17 00:00:00 2001 From: Jimmybald1 <147992650+IBBCalc@users.noreply.github.com> Date: Fri, 8 Aug 2025 11:51:27 +0200 Subject: [PATCH 1/4] Modify custom starters and added boss, biome and luck custom seed overrides --- src/data/daily-run.ts | 143 +++++++++++++++++++++++++++++++--- src/game-mode.ts | 7 +- src/modifier/modifier-type.ts | 8 ++ 3 files changed, 145 insertions(+), 13 deletions(-) diff --git a/src/data/daily-run.ts b/src/data/daily-run.ts index b5fb0aa8c07..139b0d78b76 100644 --- a/src/data/daily-run.ts +++ b/src/data/daily-run.ts @@ -5,10 +5,10 @@ import type { PokemonSpeciesForm } from "#data/pokemon-species"; import { PokemonSpecies } from "#data/pokemon-species"; import { BiomeId } from "#enums/biome-id"; import { PartyMemberStrength } from "#enums/party-member-strength"; -import type { SpeciesId } from "#enums/species-id"; +import { SpeciesId } from "#enums/species-id"; import { PlayerPokemon } from "#field/pokemon"; import type { Starter } from "#ui/starter-select-ui-handler"; -import { randSeedGauss, randSeedInt, randSeedItem } from "#utils/common"; +import { isNullOrUndefined, randSeedGauss, randSeedInt, randSeedItem } from "#utils/common"; import { getEnumValues } from "#utils/enums"; import { getPokemonSpecies, getPokemonSpeciesForm } from "#utils/pokemon-utils"; @@ -26,21 +26,15 @@ export function fetchDailyRunSeed(): Promise { } export function getDailyRunStarters(seed: string): Starter[] { - const starters: Starter[] = []; + let starters: Starter[] = []; globalScene.executeWithSeedOffset( () => { const startingLevel = globalScene.gameMode.getStartingLevel(); - if (/\d{18}$/.test(seed)) { - for (let s = 0; s < 3; s++) { - const offset = 6 + s * 6; - const starterSpeciesForm = getPokemonSpeciesForm( - Number.parseInt(seed.slice(offset, offset + 4)) as SpeciesId, - Number.parseInt(seed.slice(offset + 4, offset + 6)), - ); - starters.push(getDailyRunStarter(starterSpeciesForm, startingLevel)); - } + const eventStarters = getDailyEventSeedStarters(seed); + if (!isNullOrUndefined(eventStarters)) { + starters = eventStarters; return; } @@ -145,6 +139,11 @@ const dailyBiomeWeights: BiomeWeights = { }; export function getDailyStartingBiome(): BiomeId { + const eventBiome = getDailyEventSeedBiome(globalScene.seed); + if (!isNullOrUndefined(eventBiome)) { + return eventBiome; + } + const biomes = getEnumValues(BiomeId).filter(b => b !== BiomeId.TOWN && b !== BiomeId.END); let totalWeight = 0; @@ -169,3 +168,123 @@ export function getDailyStartingBiome(): BiomeId { // TODO: should this use `randSeedItem`? return biomes[randSeedInt(biomes.length)]; } + +/** + * If this is Daily Mode and the seed is longer than a default seed then it has been modified and could contain a custom event seed. + * Default seeds are always 24 characters. + * @returns True if it is a Daily Event Seed. + */ +export function isDailyEventSeed(seed: string): boolean { + return globalScene.gameMode.isDaily && seed.length > 24; +} + +/** + * Expects the seed to contain: /starters\d{18}/ + * Where each Starter is 4 digits for the SpeciesId and 2 digits for the FormIndex + * @returns An {@linkcode Starter[]} containing the starters or null if no valid match. + */ +export function getDailyEventSeedStarters(seed: string): Starter[] | null { + if (!isDailyEventSeed(seed)) { + return null; + } + + const starters: Starter[] = []; + const match = /starters(\d{4})(\d{2})(\d{4})(\d{2})(\d{4})(\d{2})/g.exec(seed); + if (match && match.length === 7) { + for (let i = 1; i < match.length; i += 2) { + const speciesId = Number.parseInt(match[i]) as SpeciesId; + const formIndex = Number.parseInt(match[i + 1]); + + if (!Object.values(SpeciesId).includes(speciesId)) { + // Incorrect event seed, abort. + return null; + } + + const starterForm = getPokemonSpeciesForm(speciesId, formIndex); + const startingLevel = globalScene.gameMode.getStartingLevel(); + const starter = getDailyRunStarter(starterForm, startingLevel); + starters.push(starter); + } + + return starters; + } + + return null; +} + +/** + * Expects the seed to contain: /boss\d{4}/ + * Where the boss is 4 digits for the SpeciesId. + * Currently does not support form index. + * @returns A {@linkcode PokemonSpecies} containing the boss species or null if no valid match. + */ +export function getDailyEventSeedBoss(seed: string): PokemonSpecies | null { + if (!isDailyEventSeed(seed)) { + return null; + } + + const match = /boss(\d{4})/g.exec(seed); + if (match && match.length === 2) { + const speciesId = Number.parseInt(match[1]) as SpeciesId; + + if (!Object.values(SpeciesId).includes(speciesId)) { + // Incorrect event seed, abort. + return null; + } + + const species = getPokemonSpecies(speciesId); + return species; + } + + return null; +} + +/** + * Expects the seed to contain: /biome\d{2}/ or /biome\d{2}/ + * Where the biome is 2 digits for the BiomeId. + * @returns A {@linkcode DailyEventSeedBiome} containing the Biome or null if no valid match. + */ +export function getDailyEventSeedBiome(seed: string): BiomeId | null { + if (!isDailyEventSeed(seed)) { + return null; + } + + const match = /biome(\d{2})/g.exec(seed); + if (match && match.length === 2) { + const startingBiome = Number.parseInt(match[1]) as BiomeId; + + if (!Object.values(BiomeId).includes(startingBiome)) { + // Incorrect event seed, abort. + return null; + } + + return startingBiome; + } + + return null; +} + +/** + * Expects the seed to contain: /luck\d{2}/ + * Where the Luck has 2 digits for the number. + * @returns A {@linkcode number} representing the Daily Luck value or null if no valid match. + */ +export function getDailyEventSeedLuck(seed: string): number | null { + if (!isDailyEventSeed(seed)) { + return null; + } + + const match = /luck(\d{2})/g.exec(seed); + if (match && match.length === 2) { + const luck = Number.parseInt(match[1]); + + if (luck < 0 || luck > 14) { + // Incorrect event seed, abort. + return null; + } + + return luck; + } + + return null; +} diff --git a/src/game-mode.ts b/src/game-mode.ts index 82f7b4fa77f..7aa1588a383 100644 --- a/src/game-mode.ts +++ b/src/game-mode.ts @@ -3,7 +3,7 @@ import { CHALLENGE_MODE_MYSTERY_ENCOUNTER_WAVES, CLASSIC_MODE_MYSTERY_ENCOUNTER_ import { globalScene } from "#app/global-scene"; import Overrides from "#app/overrides"; import { allChallenges, type Challenge, copyChallenge } from "#data/challenge"; -import { getDailyStartingBiome } from "#data/daily-run"; +import { getDailyEventSeedBoss, getDailyStartingBiome } from "#data/daily-run"; import { allSpecies } from "#data/data-lists"; import type { PokemonSpecies } from "#data/pokemon-species"; import { BiomeId } from "#enums/biome-id"; @@ -211,6 +211,11 @@ export class GameMode implements GameModeConfig { getOverrideSpecies(waveIndex: number): PokemonSpecies | null { if (this.isDaily && this.isWaveFinal(waveIndex)) { + const eventBoss = getDailyEventSeedBoss(globalScene.seed); + if (!isNullOrUndefined(eventBoss)) { + return eventBoss; + } + const allFinalBossSpecies = allSpecies.filter( s => (s.subLegendary || s.legendary || s.mythical) && diff --git a/src/modifier/modifier-type.ts b/src/modifier/modifier-type.ts index 46ed7e1e4b5..aca49313ff5 100644 --- a/src/modifier/modifier-type.ts +++ b/src/modifier/modifier-type.ts @@ -6,6 +6,7 @@ import Overrides from "#app/overrides"; import { EvolutionItem, pokemonEvolutions } from "#balance/pokemon-evolutions"; import { tmPoolTiers, tmSpecies } from "#balance/tms"; import { getBerryEffectDescription, getBerryName } from "#data/berry"; +import { getDailyEventSeedLuck } from "#data/daily-run"; import { allMoves, modifierTypes } from "#data/data-lists"; import { SpeciesFormChangeItemTrigger } from "#data/form-change-triggers"; import { getNatureName, getNatureStatMultiplier } from "#data/nature"; @@ -2921,6 +2922,12 @@ export function getPartyLuckValue(party: Pokemon[]): number { const DailyLuck = new NumberHolder(0); globalScene.executeWithSeedOffset( () => { + const eventLuck = getDailyEventSeedLuck(globalScene.seed); + if (!isNullOrUndefined(eventLuck)) { + DailyLuck.value = eventLuck; + return; + } + DailyLuck.value = randSeedInt(15); // Random number between 0 and 14 }, 0, @@ -2928,6 +2935,7 @@ export function getPartyLuckValue(party: Pokemon[]): number { ); return DailyLuck.value; } + const eventSpecies = timedEventManager.getEventLuckBoostedSpecies(); const luck = Phaser.Math.Clamp( party From 5f017597dae5a671c4811e887d81c9b1201bf7ae Mon Sep 17 00:00:00 2001 From: Jimmybald1 <147992650+IBBCalc@users.noreply.github.com> Date: Sun, 10 Aug 2025 10:36:13 +0200 Subject: [PATCH 2/4] Added form index to boss custom seed --- src/data/daily-run.ts | 18 +++++++++--------- src/field/pokemon.ts | 6 ++++++ src/game-mode.ts | 4 +++- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/data/daily-run.ts b/src/data/daily-run.ts index 139b0d78b76..1fa45c9d030 100644 --- a/src/data/daily-run.ts +++ b/src/data/daily-run.ts @@ -213,27 +213,27 @@ export function getDailyEventSeedStarters(seed: string): Starter[] | null { } /** - * Expects the seed to contain: /boss\d{4}/ - * Where the boss is 4 digits for the SpeciesId. - * Currently does not support form index. - * @returns A {@linkcode PokemonSpecies} containing the boss species or null if no valid match. + * Expects the seed to contain: /boss\d{4}\d{2}/ + * Where the boss is 4 digits for the SpeciesId and 2 digits for the form index + * @returns A {@linkcode PokemonSpeciesForm} containing the boss or null if no valid match. */ -export function getDailyEventSeedBoss(seed: string): PokemonSpecies | null { +export function getDailyEventSeedBoss(seed: string): PokemonSpeciesForm | null { if (!isDailyEventSeed(seed)) { return null; } - const match = /boss(\d{4})/g.exec(seed); - if (match && match.length === 2) { + const match = /boss(\d{4})(\d{2})/g.exec(seed); + if (match && match.length === 3) { const speciesId = Number.parseInt(match[1]) as SpeciesId; + const formIndex = Number.parseInt(match[2]); if (!Object.values(SpeciesId).includes(speciesId)) { // Incorrect event seed, abort. return null; } - const species = getPokemonSpecies(speciesId); - return species; + const starterForm = getPokemonSpeciesForm(speciesId, formIndex); + return starterForm; } return null; diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index fe85e92772c..29f775ad094 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -39,6 +39,7 @@ import { TrappedTag, TypeImmuneTag, } from "#data/battler-tags"; +import { getDailyEventSeedBoss } from "#data/daily-run"; import { allAbilities, allMoves } from "#data/data-lists"; import { getLevelTotalExp } from "#data/exp"; import { @@ -6256,6 +6257,11 @@ export class EnemyPokemon extends Pokemon { this.species.forms[Overrides.OPP_FORM_OVERRIDES[speciesId]] ) { this.formIndex = Overrides.OPP_FORM_OVERRIDES[speciesId]; + } else if (globalScene.gameMode.isDaily && globalScene.gameMode.isWaveFinal(globalScene.currentBattle.waveIndex)) { + const eventBoss = getDailyEventSeedBoss(globalScene.seed); + if (!isNullOrUndefined(eventBoss)) { + this.formIndex = eventBoss.formIndex; + } } if (!dataSource) { diff --git a/src/game-mode.ts b/src/game-mode.ts index 7aa1588a383..b44e786b3d9 100644 --- a/src/game-mode.ts +++ b/src/game-mode.ts @@ -15,6 +15,7 @@ import type { Arena } from "#field/arena"; import { classicFixedBattles, type FixedBattleConfigs } from "#trainers/fixed-battle-configs"; import { applyChallenges } from "#utils/challenge-utils"; import { BooleanHolder, isNullOrUndefined, randSeedInt, randSeedItem } from "#utils/common"; +import { getPokemonSpecies } from "#utils/pokemon-utils"; import i18next from "i18next"; interface GameModeConfig { @@ -213,7 +214,8 @@ export class GameMode implements GameModeConfig { if (this.isDaily && this.isWaveFinal(waveIndex)) { const eventBoss = getDailyEventSeedBoss(globalScene.seed); if (!isNullOrUndefined(eventBoss)) { - return eventBoss; + // Cannot set form index here, it will be overriden when adding it as enemy pokemon. + return getPokemonSpecies(eventBoss.speciesId); } const allFinalBossSpecies = allSpecies.filter( From 522539d99e240adf706a42e2ed2e256efcfdbb2a Mon Sep 17 00:00:00 2001 From: Jimmybald1 <147992650+IBBCalc@users.noreply.github.com> Date: Sun, 10 Aug 2025 10:47:07 +0200 Subject: [PATCH 3/4] Fix circular dependency in daily-run.ts --- src/data/daily-run.ts | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/data/daily-run.ts b/src/data/daily-run.ts index 1fa45c9d030..073dc76658d 100644 --- a/src/data/daily-run.ts +++ b/src/data/daily-run.ts @@ -6,7 +6,6 @@ import { PokemonSpecies } from "#data/pokemon-species"; import { BiomeId } from "#enums/biome-id"; import { PartyMemberStrength } from "#enums/party-member-strength"; import { SpeciesId } from "#enums/species-id"; -import { PlayerPokemon } from "#field/pokemon"; import type { Starter } from "#ui/starter-select-ui-handler"; import { isNullOrUndefined, randSeedGauss, randSeedInt, randSeedItem } from "#utils/common"; import { getEnumValues } from "#utils/enums"; @@ -66,18 +65,7 @@ function getDailyRunStarter(starterSpeciesForm: PokemonSpeciesForm, startingLeve const starterSpecies = starterSpeciesForm instanceof PokemonSpecies ? starterSpeciesForm : getPokemonSpecies(starterSpeciesForm.speciesId); const formIndex = starterSpeciesForm instanceof PokemonSpecies ? undefined : starterSpeciesForm.formIndex; - const pokemon = new PlayerPokemon( - starterSpecies, - startingLevel, - undefined, - formIndex, - undefined, - undefined, - undefined, - undefined, - undefined, - undefined, - ); + const pokemon = globalScene.addPlayerPokemon(starterSpecies, startingLevel, undefined, formIndex); const starter: Starter = { species: starterSpecies, dexAttr: pokemon.getDexAttr(), From d54df881179f377a9f05d26f941216957b823401 Mon Sep 17 00:00:00 2001 From: NightKev <34855794+DayKev@users.noreply.github.com> Date: Sun, 10 Aug 2025 02:55:39 -0700 Subject: [PATCH 4/4] Review for PR 6248 - Use early returns - Update TSDocs - Use `getEnumValues` instead of `Object.values` for `enum`s - Add console logging for invalid seeds --- src/data/daily-run.ts | 135 +++++++++++++++++++++--------------------- 1 file changed, 69 insertions(+), 66 deletions(-) diff --git a/src/data/daily-run.ts b/src/data/daily-run.ts index 073dc76658d..f0a20a0b02b 100644 --- a/src/data/daily-run.ts +++ b/src/data/daily-run.ts @@ -25,7 +25,7 @@ export function fetchDailyRunSeed(): Promise { } export function getDailyRunStarters(seed: string): Starter[] { - let starters: Starter[] = []; + const starters: Starter[] = []; globalScene.executeWithSeedOffset( () => { @@ -33,7 +33,7 @@ export function getDailyRunStarters(seed: string): Starter[] { const eventStarters = getDailyEventSeedStarters(seed); if (!isNullOrUndefined(eventStarters)) { - starters = eventStarters; + starters.push(...eventStarters); return; } @@ -158,18 +158,20 @@ export function getDailyStartingBiome(): BiomeId { } /** - * If this is Daily Mode and the seed is longer than a default seed then it has been modified and could contain a custom event seed. - * Default seeds are always 24 characters. - * @returns True if it is a Daily Event Seed. + * If this is Daily Mode and the seed is longer than a default seed + * then it has been modified and could contain a custom event seed. \ + * Default seeds are always exactly 24 characters. + * @returns `true` if it is a Daily Event Seed. */ export function isDailyEventSeed(seed: string): boolean { return globalScene.gameMode.isDaily && seed.length > 24; } /** - * Expects the seed to contain: /starters\d{18}/ - * Where each Starter is 4 digits for the SpeciesId and 2 digits for the FormIndex - * @returns An {@linkcode Starter[]} containing the starters or null if no valid match. + * Expects the seed to contain `/starters\d{18}/` + * where the digits alternate between 4 digits for the species ID and 2 digits for the form index + * (left padded with `0`s as necessary). + * @returns An array of {@linkcode Starter}s, or `null` if no valid match. */ export function getDailyEventSeedStarters(seed: string): Starter[] | null { if (!isDailyEventSeed(seed)) { @@ -178,32 +180,34 @@ export function getDailyEventSeedStarters(seed: string): Starter[] | null { const starters: Starter[] = []; const match = /starters(\d{4})(\d{2})(\d{4})(\d{2})(\d{4})(\d{2})/g.exec(seed); - if (match && match.length === 7) { - for (let i = 1; i < match.length; i += 2) { - const speciesId = Number.parseInt(match[i]) as SpeciesId; - const formIndex = Number.parseInt(match[i + 1]); - if (!Object.values(SpeciesId).includes(speciesId)) { - // Incorrect event seed, abort. - return null; - } - - const starterForm = getPokemonSpeciesForm(speciesId, formIndex); - const startingLevel = globalScene.gameMode.getStartingLevel(); - const starter = getDailyRunStarter(starterForm, startingLevel); - starters.push(starter); - } - - return starters; + if (!match || match.length !== 7) { + return null; } - return null; + for (let i = 1; i < match.length; i += 2) { + const speciesId = Number.parseInt(match[i]) as SpeciesId; + const formIndex = Number.parseInt(match[i + 1]); + + if (!getEnumValues(SpeciesId).includes(speciesId)) { + console.warn("Invalid species ID used for custom daily run seed starter:", speciesId); + return null; + } + + const starterForm = getPokemonSpeciesForm(speciesId, formIndex); + const startingLevel = globalScene.gameMode.getStartingLevel(); + const starter = getDailyRunStarter(starterForm, startingLevel); + starters.push(starter); + } + + return starters; } /** - * Expects the seed to contain: /boss\d{4}\d{2}/ - * Where the boss is 4 digits for the SpeciesId and 2 digits for the form index - * @returns A {@linkcode PokemonSpeciesForm} containing the boss or null if no valid match. + * Expects the seed to contain `/boss\d{4}\d{2}/` + * where the first 4 digits are the species ID and the next 2 digits are the form index + * (left padded with `0`s as necessary). + * @returns A {@linkcode PokemonSpeciesForm} to be used for the boss, or `null` if no valid match. */ export function getDailyEventSeedBoss(seed: string): PokemonSpeciesForm | null { if (!isDailyEventSeed(seed)) { @@ -211,26 +215,25 @@ export function getDailyEventSeedBoss(seed: string): PokemonSpeciesForm | null { } const match = /boss(\d{4})(\d{2})/g.exec(seed); - if (match && match.length === 3) { - const speciesId = Number.parseInt(match[1]) as SpeciesId; - const formIndex = Number.parseInt(match[2]); - - if (!Object.values(SpeciesId).includes(speciesId)) { - // Incorrect event seed, abort. - return null; - } - - const starterForm = getPokemonSpeciesForm(speciesId, formIndex); - return starterForm; + if (!match || match.length !== 3) { + return null; } - return null; + const speciesId = Number.parseInt(match[1]) as SpeciesId; + const formIndex = Number.parseInt(match[2]); + + if (!getEnumValues(SpeciesId).includes(speciesId)) { + console.warn("Invalid species ID used for custom daily run seed boss:", speciesId); + return null; + } + + const starterForm = getPokemonSpeciesForm(speciesId, formIndex); + return starterForm; } /** - * Expects the seed to contain: /biome\d{2}/ or /biome\d{2}/ - * Where the biome is 2 digits for the BiomeId. - * @returns A {@linkcode DailyEventSeedBiome} containing the Biome or null if no valid match. + * Expects the seed to contain `/biome\d{2}/` where the 2 digits are a biome ID (left padded with `0` if necessary). + * @returns The biome to use or `null` if no valid match. */ export function getDailyEventSeedBiome(seed: string): BiomeId | null { if (!isDailyEventSeed(seed)) { @@ -238,24 +241,24 @@ export function getDailyEventSeedBiome(seed: string): BiomeId | null { } const match = /biome(\d{2})/g.exec(seed); - if (match && match.length === 2) { - const startingBiome = Number.parseInt(match[1]) as BiomeId; - - if (!Object.values(BiomeId).includes(startingBiome)) { - // Incorrect event seed, abort. - return null; - } - - return startingBiome; + if (!match || match.length !== 2) { + return null; } - return null; + const startingBiome = Number.parseInt(match[1]) as BiomeId; + + if (!getEnumValues(BiomeId).includes(startingBiome)) { + console.warn("Invalid biome ID used for custom daily run seed:", startingBiome); + return null; + } + + return startingBiome; } /** - * Expects the seed to contain: /luck\d{2}/ - * Where the Luck has 2 digits for the number. - * @returns A {@linkcode number} representing the Daily Luck value or null if no valid match. + * Expects the seed to contain `/luck\d{2}/` where the 2 digits are a number between `0` and `14` + * (left padded with `0` if necessary). + * @returns The custom luck value or `null` if no valid match. */ export function getDailyEventSeedLuck(seed: string): number | null { if (!isDailyEventSeed(seed)) { @@ -263,16 +266,16 @@ export function getDailyEventSeedLuck(seed: string): number | null { } const match = /luck(\d{2})/g.exec(seed); - if (match && match.length === 2) { - const luck = Number.parseInt(match[1]); - - if (luck < 0 || luck > 14) { - // Incorrect event seed, abort. - return null; - } - - return luck; + if (!match || match.length !== 2) { + return null; } - return null; + const luck = Number.parseInt(match[1]); + + if (luck < 0 || luck > 14) { + console.warn("Invalid luck value used for custom daily run seed:", luck); + return null; + } + + return luck; }