Compare commits

...

8 Commits

Author SHA1 Message Date
Bertie690
08ed35e4a9
Merge 1bb688f284 into 1ff2701964 2025-06-19 22:29:37 -04:00
lnuvy
1ff2701964
[Bug] Fix when using arrow keys in Pokédex after catching a Pokémon from mystery event (#6000)
fix: wrap setOverlayMode args in array to mystery-encounter

Co-authored-by: Sirz Benjie <142067137+SirzBenjie@users.noreply.github.com>
2025-06-19 20:45:54 -04:00
Bertie690
1e306e25b5
[Move] Fixed Chilly Reception displaying message when used virtually
https://github.com/pagefaultgames/pokerogue/pull/5843

* Fixed Chilly Reception displaying message when used virtually

* Fixed lack of message causing Chilly Reception to fail

* Fixed tests

* Reverted bool change + fixed test

* Fixed test
2025-06-19 17:14:05 -07:00
Madmadness65
43aa772603
[UI/UX] Add Pokémon category flavor text to Pokédex (#5957)
* Add Pokémon category flavor text to Pokédex

* Append `_category` to locale entry
2025-06-20 00:04:57 +00:00
Bertie690
1bb688f284
Update pokemon-info-container.ts 2025-06-15 11:17:06 -04:00
Bertie690
957b898a2c
Update pokemon-info-container.ts 2025-06-15 11:15:05 -04:00
Bertie690
cce6acec6f IV safety part 0.5 2025-06-15 09:56:31 -04:00
Bertie690
887f750253 Added utility types for strong typing IVs and stats 2025-06-14 23:37:24 -04:00
23 changed files with 290 additions and 114 deletions

View File

@ -1,3 +1,5 @@
import type { IVTuple } from "#app/@types/stat-types";
export interface DexData { export interface DexData {
[key: number]: DexEntry; [key: number]: DexEntry;
} }
@ -9,5 +11,5 @@ export interface DexEntry {
seenCount: number; seenCount: number;
caughtCount: number; caughtCount: number;
hatchedCount: number; hatchedCount: number;
ivs: number[]; ivs: IVTuple;
} }

60
src/@types/stat-types.ts Normal file
View File

@ -0,0 +1,60 @@
import type { Head, Tail } from "#app/@types/utility-types/tuple";
// biome-ignore lint/correctness/noUnusedImports: Type Imports
import type { PermanentStat, BattleStat } from "#enums/stat";
type StatTuple = [
hp: number,
atk: number,
def: number,
spAtk: number,
spDef: number,
spd: number,
acc: number,
eva: number,
];
/** Tuple containing all {@linkcode PermanentStat}s of a Pokemon. */
export type PermanentStatTuple = Head<Head<StatTuple>>;
/** Tuple containing all {@linkcode BattleStat}s of a Pokemon. */
export type BattleStatTuple = Tail<PermanentStatTuple>;
/** Integer literal union containing all numbers from 0-31 inclusive; used to strongly type Pokemon IVs. */
export type IVType =
| 0
| 1
| 2
| 3
| 4
| 5
| 6
| 7
| 8
| 9
| 10
| 11
| 12
| 13
| 14
| 15
| 16
| 17
| 18
| 19
| 20
| 21
| 22
| 23
| 24
| 25
| 26
| 27
| 28
| 29
| 30
| 31;
type toIvTuple<T extends [...any]> = { [k in keyof T]: IVType };
/** A 6-length tuple of integers in the range [0-31]; used to strongly type Pokemon IVs. */
export type IVTuple = toIvTuple<PermanentStatTuple>;

View File

@ -0,0 +1,9 @@
export {};
declare global {
// Array global augments to allow semi-easy working with tuples...???
interface Array<T> {
map<U>(callbackfn: (value: T, index: number, array: this) => U, thisArg?: any): { [K in keyof this]: U };
slice(start: 0): { [K in keyof this]: T };
}
}

View File

@ -0,0 +1,5 @@
/** Extract the elements of a tuple type, excluding the first element. */
export type Tail<T extends any[]> = Required<T> extends [any, ...infer Head] ? Head : never;
/** Extract the elements of a tuple type, excluding the last element. */
export type Head<T extends [...any]> = Required<T> extends [...infer Head, any] ? Head : never;

View File

@ -161,12 +161,16 @@ import { timedEventManager } from "./global-event-manager";
import { starterColors } from "./global-vars/starter-colors"; import { starterColors } from "./global-vars/starter-colors";
import { startingWave } from "./starting-wave"; import { startingWave } from "./starting-wave";
import { PhaseManager } from "./phase-manager"; import { PhaseManager } from "./phase-manager";
import type { IVTuple, IVType } from "#app/@types/stat-types";
const DEBUG_RNG = false; const DEBUG_RNG = false;
const OPP_IVS_OVERRIDE_VALIDATED: number[] = ( const OPP_IVS_OVERRIDE_VALIDATED: IVTuple | null =
Array.isArray(Overrides.OPP_IVS_OVERRIDE) ? Overrides.OPP_IVS_OVERRIDE : new Array(6).fill(Overrides.OPP_IVS_OVERRIDE) Overrides.OPP_IVS_OVERRIDE === null
).map(iv => (Number.isNaN(iv) || iv === null || iv > 31 ? -1 : iv)); ? null
: Array.isArray(Overrides.OPP_IVS_OVERRIDE)
? Overrides.OPP_IVS_OVERRIDE
: (new Array(6).fill(Overrides.OPP_IVS_OVERRIDE) as IVTuple);
export interface PokeballCounts { export interface PokeballCounts {
[pb: string]: number; [pb: string]: number;
@ -907,7 +911,7 @@ export default class BattleScene extends SceneBase {
gender?: Gender, gender?: Gender,
shiny?: boolean, shiny?: boolean,
variant?: Variant, variant?: Variant,
ivs?: number[], ivs?: IVTuple,
nature?: Nature, nature?: Nature,
dataSource?: Pokemon | PokemonData, dataSource?: Pokemon | PokemonData,
postProcess?: (playerPokemon: PlayerPokemon) => void, postProcess?: (playerPokemon: PlayerPokemon) => void,
@ -955,28 +959,22 @@ export default class BattleScene extends SceneBase {
} }
if (boss && !dataSource) { if (boss && !dataSource) {
// Generate a 2nd higher roll and linearly interpolate between the two.
const secondaryIvs = getIvsFromId(randSeedInt(4294967296)); const secondaryIvs = getIvsFromId(randSeedInt(4294967296));
for (let s = 0; s < pokemon.ivs.length; s++) { pokemon.ivs = pokemon.ivs.map(
pokemon.ivs[s] = Math.round( (iv, i) =>
Phaser.Math.Linear( Math.round(Phaser.Math.Linear(Math.min(iv, secondaryIvs[i]), Math.max(iv, secondaryIvs[i]), 0.75)) as IVType, // ts doesn't know the number will be between 0-31
Math.min(pokemon.ivs[s], secondaryIvs[s]), );
Math.max(pokemon.ivs[s], secondaryIvs[s]),
0.75,
),
);
}
} }
if (postProcess) { if (postProcess) {
postProcess(pokemon); postProcess(pokemon);
} }
for (let i = 0; i < pokemon.ivs.length; i++) { if (OPP_IVS_OVERRIDE_VALIDATED !== null) {
if (OPP_IVS_OVERRIDE_VALIDATED[i] > -1) { pokemon.ivs = OPP_IVS_OVERRIDE_VALIDATED;
pokemon.ivs[i] = OPP_IVS_OVERRIDE_VALIDATED[i];
}
} }
pokemon.init(); pokemon.init();
return pokemon; return pokemon;
} }
@ -2084,7 +2082,7 @@ export default class BattleScene extends SceneBase {
let scoreIncrease = let scoreIncrease =
enemy.getSpeciesForm().getBaseExp() * enemy.getSpeciesForm().getBaseExp() *
(enemy.level / this.getMaxExpLevel()) * (enemy.level / this.getMaxExpLevel()) *
((enemy.ivs.reduce((iv: number, total: number) => (total += iv), 0) / 93) * 0.2 + 0.8); ((enemy.ivs.reduce((total, iv) => total + iv, 0) / 93) * 0.2 + 0.8);
this.findModifiers(m => m instanceof PokemonHeldItemModifier && m.pokemonId === enemy.id, false).map( this.findModifiers(m => m instanceof PokemonHeldItemModifier && m.pokemonId === enemy.id, false).map(
m => (scoreIncrease *= (m as PokemonHeldItemModifier).getScoreMultiplier()), m => (scoreIncrease *= (m as PokemonHeldItemModifier).getScoreMultiplier()),
); );

View File

@ -38,6 +38,7 @@ import {
HATCH_WAVES_LEGENDARY_EGG, HATCH_WAVES_LEGENDARY_EGG,
} from "#app/data/balance/rates"; } from "#app/data/balance/rates";
import { speciesEggTiers } from "#app/data/balance/species-egg-tiers"; import { speciesEggTiers } from "#app/data/balance/species-egg-tiers";
import type { IVType } from "#app/@types/stat-types";
export const EGG_SEED = 1073741824; export const EGG_SEED = 1073741824;
@ -270,9 +271,9 @@ export class Egg {
const secondaryIvs = getIvsFromId(randSeedInt(4294967295)); const secondaryIvs = getIvsFromId(randSeedInt(4294967295));
for (let s = 0; s < ret.ivs.length; s++) { ret.ivs = ret.ivs.map(
ret.ivs[s] = Math.max(ret.ivs[s], secondaryIvs[s]); (iv, i) => Math.max(iv, secondaryIvs[i]) as IVType, // ts doesn't know the number will be between 0-31
} );
}; };
ret = ret!; // Tell TS compiler it's defined now ret = ret!; // Tell TS compiler it's defined now

View File

@ -93,6 +93,10 @@ import { ChargingMove, MoveAttrMap, MoveAttrString, MoveKindString, MoveClassMap
import { applyMoveAttrs } from "./apply-attrs"; import { applyMoveAttrs } from "./apply-attrs";
import { frenzyMissFunc, getMoveTargets } from "./move-utils"; import { frenzyMissFunc, getMoveTargets } from "./move-utils";
/**
* A function used to conditionally determine execution of a given {@linkcode MoveAttr}.
* Conventionally returns `true` for success and `false` for failure.
*/
type MoveConditionFunc = (user: Pokemon, target: Pokemon, move: Move) => boolean; type MoveConditionFunc = (user: Pokemon, target: Pokemon, move: Move) => boolean;
export type UserMoveConditionFunc = (user: Pokemon, move: Move) => boolean; export type UserMoveConditionFunc = (user: Pokemon, move: Move) => boolean;
@ -1390,18 +1394,31 @@ export class BeakBlastHeaderAttr extends AddBattlerTagHeaderAttr {
} }
} }
/**
* Attribute to display a message before a move is executed.
*/
export class PreMoveMessageAttr extends MoveAttr { export class PreMoveMessageAttr extends MoveAttr {
private message: string | ((user: Pokemon, target: Pokemon, move: Move) => string); /** The message to display or a function returning one */
private message: string | ((user: Pokemon, target: Pokemon, move: Move) => string | undefined);
/**
* Create a new {@linkcode PreMoveMessageAttr} to display a message before move execution.
* @param message - The message to display before move use, either as a string or a function producing one.
* @remarks
* If {@linkcode message} evaluates to an empty string (`''`), no message will be displayed
* (though the move will still succeed).
*/
constructor(message: string | ((user: Pokemon, target: Pokemon, move: Move) => string)) { constructor(message: string | ((user: Pokemon, target: Pokemon, move: Move) => string)) {
super(); super();
this.message = message; this.message = message;
} }
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { apply(user: Pokemon, target: Pokemon, move: Move, _args: any[]): boolean {
const message = typeof this.message === "string" const message = typeof this.message === "function"
? this.message as string ? this.message(user, target, move)
: this.message(user, target, move); : this.message;
// TODO: Consider changing if/when MoveAttr `apply` return values become significant
if (message) { if (message) {
globalScene.phaseManager.queueMessage(message, 500); globalScene.phaseManager.queueMessage(message, 500);
return true; return true;
@ -11299,7 +11316,11 @@ export function initMoves() {
.attr(ForceSwitchOutAttr, true, SwitchType.SHED_TAIL) .attr(ForceSwitchOutAttr, true, SwitchType.SHED_TAIL)
.condition(failIfLastInPartyCondition), .condition(failIfLastInPartyCondition),
new SelfStatusMove(MoveId.CHILLY_RECEPTION, PokemonType.ICE, -1, 10, -1, 0, 9) new SelfStatusMove(MoveId.CHILLY_RECEPTION, PokemonType.ICE, -1, 10, -1, 0, 9)
.attr(PreMoveMessageAttr, (user, move) => i18next.t("moveTriggers:chillyReception", { pokemonName: getPokemonNameWithAffix(user) })) .attr(PreMoveMessageAttr, (user, _target, _move) =>
// Don't display text if current move phase is follow up (ie move called indirectly)
isVirtual((globalScene.phaseManager.getCurrentPhase() as MovePhase).useMode)
? ""
: i18next.t("moveTriggers:chillyReception", { pokemonName: getPokemonNameWithAffix(user) }))
.attr(ChillyReceptionAttr, true), .attr(ChillyReceptionAttr, true),
new SelfStatusMove(MoveId.TIDY_UP, PokemonType.NORMAL, -1, 10, -1, 0, 9) new SelfStatusMove(MoveId.TIDY_UP, PokemonType.NORMAL, -1, 10, -1, 0, 9)
.attr(StatStageChangeAttr, [ Stat.ATK, Stat.SPD ], 1, true) .attr(StatStageChangeAttr, [ Stat.ATK, Stat.SPD ], 1, true)

View File

@ -512,7 +512,7 @@ async function postProcessTransformedPokemon(
const hiddenAbilityChance = new NumberHolder(256); const hiddenAbilityChance = new NumberHolder(256);
globalScene.applyModifiers(HiddenAbilityRateBoosterModifier, true, hiddenAbilityChance); globalScene.applyModifiers(HiddenAbilityRateBoosterModifier, true, hiddenAbilityChance);
const hasHiddenAbility = !randSeedInt(hiddenAbilityChance.value); const hasHiddenAbility = randSeedInt(hiddenAbilityChance.value) === 0;
if (hasHiddenAbility) { if (hasHiddenAbility) {
newPokemon.abilityIndex = hiddenIndex; newPokemon.abilityIndex = hiddenIndex;

View File

@ -53,6 +53,7 @@ import { PokemonType } from "#enums/pokemon-type";
import { getNatureName } from "#app/data/nature"; import { getNatureName } from "#app/data/nature";
import { getPokemonNameWithAffix } from "#app/messages"; import { getPokemonNameWithAffix } from "#app/messages";
import { timedEventManager } from "#app/global-event-manager"; import { timedEventManager } from "#app/global-event-manager";
import type { IVTuple } from "#app/@types/stat-types";
/** /**
* Animates exclamation sprite over trainer's head at start of encounter * Animates exclamation sprite over trainer's head at start of encounter
@ -95,7 +96,7 @@ export interface EnemyPokemonConfig {
passive?: boolean; passive?: boolean;
moveSet?: MoveId[]; moveSet?: MoveId[];
nature?: Nature; nature?: Nature;
ivs?: [number, number, number, number, number, number]; ivs?: IVTuple;
shiny?: boolean; shiny?: boolean;
/** Is only checked if Pokemon is shiny */ /** Is only checked if Pokemon is shiny */
variant?: Variant; variant?: Variant;

View File

@ -751,7 +751,7 @@ export async function catchPokemon(
UiMode.POKEDEX_PAGE, UiMode.POKEDEX_PAGE,
pokemon.species, pokemon.species,
pokemon.formIndex, pokemon.formIndex,
attributes, [attributes],
null, null,
() => { () => {
globalScene.ui.setMode(UiMode.MESSAGE).then(() => { globalScene.ui.setMode(UiMode.MESSAGE).then(() => {

View File

@ -764,7 +764,7 @@ export default class PokemonSpecies extends PokemonSpeciesForm implements Locali
readonly subLegendary: boolean; readonly subLegendary: boolean;
readonly legendary: boolean; readonly legendary: boolean;
readonly mythical: boolean; readonly mythical: boolean;
readonly species: string; public category: string;
readonly growthRate: GrowthRate; readonly growthRate: GrowthRate;
/** The chance (as a decimal) for this Species to be male, or `null` for genderless species */ /** The chance (as a decimal) for this Species to be male, or `null` for genderless species */
readonly malePercent: number | null; readonly malePercent: number | null;
@ -778,7 +778,7 @@ export default class PokemonSpecies extends PokemonSpeciesForm implements Locali
subLegendary: boolean, subLegendary: boolean,
legendary: boolean, legendary: boolean,
mythical: boolean, mythical: boolean,
species: string, category: string,
type1: PokemonType, type1: PokemonType,
type2: PokemonType | null, type2: PokemonType | null,
height: number, height: number,
@ -829,7 +829,7 @@ export default class PokemonSpecies extends PokemonSpeciesForm implements Locali
this.subLegendary = subLegendary; this.subLegendary = subLegendary;
this.legendary = legendary; this.legendary = legendary;
this.mythical = mythical; this.mythical = mythical;
this.species = species; this.category = category;
this.growthRate = growthRate; this.growthRate = growthRate;
this.malePercent = malePercent; this.malePercent = malePercent;
this.genderDiffs = genderDiffs; this.genderDiffs = genderDiffs;
@ -968,6 +968,7 @@ export default class PokemonSpecies extends PokemonSpeciesForm implements Locali
localize(): void { localize(): void {
this.name = i18next.t(`pokemon:${SpeciesId[this.speciesId].toLowerCase()}`); this.name = i18next.t(`pokemon:${SpeciesId[this.speciesId].toLowerCase()}`);
this.category = i18next.t(`pokemonCategory:${SpeciesId[this.speciesId].toLowerCase()}_category`);
} }
getWildSpeciesForLevel(level: number, allowEvolving: boolean, isBoss: boolean, gameMode: GameMode): SpeciesId { getWildSpeciesForLevel(level: number, allowEvolving: boolean, isBoss: boolean, gameMode: GameMode): SpeciesId {

View File

@ -190,6 +190,7 @@ import { AiType } from "#enums/ai-type";
import type { MoveResult } from "#enums/move-result"; import type { MoveResult } from "#enums/move-result";
import { PokemonMove } from "#app/data/moves/pokemon-move"; import { PokemonMove } from "#app/data/moves/pokemon-move";
import type { AbAttrMap, AbAttrString } from "#app/@types/ability-types"; import type { AbAttrMap, AbAttrString } from "#app/@types/ability-types";
import type { IVTuple, PermanentStatTuple } from "#app/@types/stat-types";
/** Base typeclass for damage parameter methods, used for DRY */ /** Base typeclass for damage parameter methods, used for DRY */
type damageParams = { type damageParams = {
@ -244,8 +245,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
public levelExp: number; public levelExp: number;
public gender: Gender; public gender: Gender;
public hp: number; public hp: number;
public stats: number[]; public stats: PermanentStatTuple;
public ivs: number[]; public ivs: IVTuple;
public nature: Nature; public nature: Nature;
public moveset: PokemonMove[]; public moveset: PokemonMove[];
public status: Status | null; public status: Status | null;
@ -314,7 +315,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
gender?: Gender, gender?: Gender,
shiny?: boolean, shiny?: boolean,
variant?: Variant, variant?: Variant,
ivs?: number[], ivs?: IVTuple,
nature?: Nature, nature?: Nature,
dataSource?: Pokemon | PokemonData, dataSource?: Pokemon | PokemonData,
) { ) {
@ -5492,7 +5493,7 @@ export class PlayerPokemon extends Pokemon {
gender?: Gender, gender?: Gender,
shiny?: boolean, shiny?: boolean,
variant?: Variant, variant?: Variant,
ivs?: number[], ivs?: IVTuple,
nature?: Nature, nature?: Nature,
dataSource?: Pokemon | PokemonData, dataSource?: Pokemon | PokemonData,
) { ) {
@ -6091,10 +6092,12 @@ export class EnemyPokemon extends Pokemon {
if (this.hasTrainer() && globalScene.currentBattle) { if (this.hasTrainer() && globalScene.currentBattle) {
const { waveIndex } = globalScene.currentBattle; const { waveIndex } = globalScene.currentBattle;
const ivs: number[] = []; const ivs = Array.from(
while (ivs.length < 6) { {
ivs.push(randSeedIntRange(Math.floor(waveIndex / 10), 31)); length: 6,
} },
() => randSeedIntRange(Math.floor(waveIndex / 10), 31),
) as IVTuple;
this.ivs = ivs; this.ivs = ivs;
} }
} }

View File

@ -22,6 +22,7 @@ import { TimeOfDay } from "#enums/time-of-day";
import { TrainerType } from "#enums/trainer-type"; import { TrainerType } from "#enums/trainer-type";
import { VariantTier } from "#enums/variant-tier"; import { VariantTier } from "#enums/variant-tier";
import { WeatherType } from "#enums/weather-type"; import { WeatherType } from "#enums/weather-type";
import type { IVTuple, IVType } from "#app/@types/stat-types";
/** /**
* This comment block exists to prevent IDEs from automatically removing unused imports * This comment block exists to prevent IDEs from automatically removing unused imports
@ -181,7 +182,11 @@ class DefaultOverrides {
readonly OPP_MOVESET_OVERRIDE: MoveId | Array<MoveId> = []; readonly OPP_MOVESET_OVERRIDE: MoveId | Array<MoveId> = [];
readonly OPP_SHINY_OVERRIDE: boolean | null = null; readonly OPP_SHINY_OVERRIDE: boolean | null = null;
readonly OPP_VARIANT_OVERRIDE: Variant | null = null; readonly OPP_VARIANT_OVERRIDE: Variant | null = null;
readonly OPP_IVS_OVERRIDE: number | number[] = []; /**
* An array of IVs to give the opposing pokemon.
* Specifying a single number will use it for all 6 IVs, while `null` will disable the override.
*/
readonly OPP_IVS_OVERRIDE: IVType | IVTuple | null = null;
readonly OPP_FORM_OVERRIDES: Partial<Record<SpeciesId, number>> = {}; readonly OPP_FORM_OVERRIDES: Partial<Record<SpeciesId, number>> = {};
/** /**
* Override to give the enemy Pokemon a given amount of health segments * Override to give the enemy Pokemon a given amount of health segments

View File

@ -121,7 +121,8 @@ export class EncounterPhase extends BattlePhase {
!!globalScene.getEncounterBossSegments(battle.waveIndex, level, enemySpecies), !!globalScene.getEncounterBossSegments(battle.waveIndex, level, enemySpecies),
); );
if (globalScene.currentBattle.battleSpec === BattleSpec.FINAL_BOSS) { if (globalScene.currentBattle.battleSpec === BattleSpec.FINAL_BOSS) {
battle.enemyParty[e].ivs = new Array(6).fill(31); // max IVs for eternatus
battle.enemyParty[e].ivs = [31, 31, 31, 31, 31, 31];
} }
globalScene globalScene
.getPlayerParty() .getPlayerParty()

View File

@ -668,6 +668,9 @@ export class MovePhase extends BattlePhase {
}), }),
500, 500,
); );
// Moves with pre-use messages (Magnitude, Chilly Reception, Fickle Beam, etc.) always display their messages even on failure
// TODO: This assumes single target for message funcs - is this sustainable?
applyMoveAttrs("PreMoveMessageAttr", this.pokemon, this.pokemon.getOpponents(false)[0], this.move.getMove()); applyMoveAttrs("PreMoveMessageAttr", this.pokemon, this.pokemon.getOpponents(false)[0], this.move.getMove());
} }

View File

@ -245,6 +245,7 @@ export async function initI18n(): Promise<void> {
"pokeball", "pokeball",
"pokedexUiHandler", "pokedexUiHandler",
"pokemon", "pokemon",
"pokemonCategory",
"pokemonEvolutions", "pokemonEvolutions",
"pokemonForm", "pokemonForm",
"pokemonInfo", "pokemonInfo",

View File

@ -69,6 +69,7 @@ import { DexAttr } from "#enums/dex-attr";
import { AbilityAttr } from "#enums/ability-attr"; import { AbilityAttr } from "#enums/ability-attr";
import { defaultStarterSpecies, saveKey } from "#app/constants"; import { defaultStarterSpecies, saveKey } from "#app/constants";
import { encrypt, decrypt } from "#app/utils/data"; import { encrypt, decrypt } from "#app/utils/data";
import type { IVTuple } from "#app/@types/stat-types";
function getDataTypeKey(dataType: GameDataType, slotId = 0): string { function getDataTypeKey(dataType: GameDataType, slotId = 0): string {
switch (dataType) { switch (dataType) {
@ -1946,7 +1947,13 @@ export class GameData {
_unlockSpeciesNature(species.speciesId); _unlockSpeciesNature(species.speciesId);
} }
updateSpeciesDexIvs(speciesId: SpeciesId, ivs: number[]): void { /**
* When a pokemon is caught or added, maximize its lowest pre-evolution's {@linkcode DexData}
* with the IVs of the newly caught pokemon.
* @param speciesId - The {@linkcode SpeciesId} to update dex data for.
* @param ivs - The {@linkcode IVTuple | IVs} of the caught pokemon.
*/
updateSpeciesDexIvs(speciesId: SpeciesId, ivs: IVTuple): void {
let dexEntry: DexEntry; let dexEntry: DexEntry;
do { do {
dexEntry = globalScene.gameData.dexData[speciesId]; dexEntry = globalScene.gameData.dexData[speciesId];
@ -1956,7 +1963,7 @@ export class GameData {
dexIvs[i] = ivs[i]; dexIvs[i] = ivs[i];
} }
} }
if (dexIvs.filter(iv => iv === 31).length === 6) { if (dexIvs.every(iv => iv === 31)) {
globalScene.validateAchv(achvs.PERFECT_IVS); globalScene.validateAchv(achvs.PERFECT_IVS);
} }
} while (pokemonPrevolutions.hasOwnProperty(speciesId) && (speciesId = pokemonPrevolutions[speciesId])); } while (pokemonPrevolutions.hasOwnProperty(speciesId) && (speciesId = pokemonPrevolutions[speciesId]));

View File

@ -15,6 +15,7 @@ import type { MoveId } from "#enums/move-id";
import type { SpeciesId } from "#enums/species-id"; import type { SpeciesId } from "#enums/species-id";
import { CustomPokemonData } from "#app/data/custom-pokemon-data"; import { CustomPokemonData } from "#app/data/custom-pokemon-data";
import type { PokemonType } from "#enums/pokemon-type"; import type { PokemonType } from "#enums/pokemon-type";
import type { IVTuple, PermanentStatTuple } from "#app/@types/stat-types";
export default class PokemonData { export default class PokemonData {
public id: number; public id: number;
@ -32,8 +33,8 @@ export default class PokemonData {
public levelExp: number; public levelExp: number;
public gender: Gender; public gender: Gender;
public hp: number; public hp: number;
public stats: number[]; public stats: PermanentStatTuple;
public ivs: number[]; public ivs: IVTuple;
public nature: Nature; public nature: Nature;
public moveset: PokemonMove[]; public moveset: PokemonMove[];
public status: Status | null; public status: Status | null;

View File

@ -174,6 +174,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
private pokemonCaughtHatchedContainer: Phaser.GameObjects.Container; private pokemonCaughtHatchedContainer: Phaser.GameObjects.Container;
private pokemonCaughtCountText: Phaser.GameObjects.Text; private pokemonCaughtCountText: Phaser.GameObjects.Text;
private pokemonFormText: Phaser.GameObjects.Text; private pokemonFormText: Phaser.GameObjects.Text;
private pokemonCategoryText: Phaser.GameObjects.Text;
private pokemonHatchedIcon: Phaser.GameObjects.Sprite; private pokemonHatchedIcon: Phaser.GameObjects.Sprite;
private pokemonHatchedCountText: Phaser.GameObjects.Text; private pokemonHatchedCountText: Phaser.GameObjects.Text;
private pokemonShinyIcons: Phaser.GameObjects.Sprite[]; private pokemonShinyIcons: Phaser.GameObjects.Sprite[];
@ -409,6 +410,12 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
this.pokemonFormText.setOrigin(0, 0); this.pokemonFormText.setOrigin(0, 0);
this.starterSelectContainer.add(this.pokemonFormText); this.starterSelectContainer.add(this.pokemonFormText);
this.pokemonCategoryText = addTextObject(100, 18, "Category", TextStyle.WINDOW_ALT, {
fontSize: "42px",
});
this.pokemonCategoryText.setOrigin(1, 0);
this.starterSelectContainer.add(this.pokemonCategoryText);
this.pokemonCaughtHatchedContainer = globalScene.add.container(2, 25); this.pokemonCaughtHatchedContainer = globalScene.add.container(2, 25);
this.pokemonCaughtHatchedContainer.setScale(0.5); this.pokemonCaughtHatchedContainer.setScale(0.5);
this.starterSelectContainer.add(this.pokemonCaughtHatchedContainer); this.starterSelectContainer.add(this.pokemonCaughtHatchedContainer);
@ -2354,6 +2361,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
this.pokemonCaughtHatchedContainer.setVisible(true); this.pokemonCaughtHatchedContainer.setVisible(true);
this.pokemonCandyContainer.setVisible(false); this.pokemonCandyContainer.setVisible(false);
this.pokemonFormText.setVisible(false); this.pokemonFormText.setVisible(false);
this.pokemonCategoryText.setVisible(false);
const defaultDexAttr = globalScene.gameData.getSpeciesDefaultDexAttr(species, true, true); const defaultDexAttr = globalScene.gameData.getSpeciesDefaultDexAttr(species, true, true);
const props = globalScene.gameData.getSpeciesDexAttrProps(species, defaultDexAttr); const props = globalScene.gameData.getSpeciesDexAttrProps(species, defaultDexAttr);
@ -2382,6 +2390,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
this.pokemonCaughtHatchedContainer.setVisible(false); this.pokemonCaughtHatchedContainer.setVisible(false);
this.pokemonCandyContainer.setVisible(false); this.pokemonCandyContainer.setVisible(false);
this.pokemonFormText.setVisible(false); this.pokemonFormText.setVisible(false);
this.pokemonCategoryText.setVisible(false);
this.setSpeciesDetails(species!, { this.setSpeciesDetails(species!, {
// TODO: is this bang correct? // TODO: is this bang correct?
@ -2534,6 +2543,13 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
this.pokemonNameText.setText(species ? "???" : ""); this.pokemonNameText.setText(species ? "???" : "");
} }
// Setting the category
if (isFormCaught) {
this.pokemonCategoryText.setText(species.category);
} else {
this.pokemonCategoryText.setText("");
}
// Setting tint of the sprite // Setting tint of the sprite
if (isFormCaught) { if (isFormCaught) {
this.species.loadAssets(female!, formIndex, shiny, variant as Variant, true).then(() => { this.species.loadAssets(female!, formIndex, shiny, variant as Variant, true).then(() => {

View File

@ -14,6 +14,7 @@ import ConfirmUiHandler from "./confirm-ui-handler";
import { StatsContainer } from "./stats-container"; import { StatsContainer } from "./stats-container";
import { TextStyle, addBBCodeTextObject, addTextObject, getTextColor } from "./text"; import { TextStyle, addBBCodeTextObject, addTextObject, getTextColor } from "./text";
import { addWindow } from "./ui-theme"; import { addWindow } from "./ui-theme";
import type { IVTuple } from "#app/@types/stat-types";
interface LanguageSetting { interface LanguageSetting {
infoContainerTextSize: string; infoContainerTextSize: string;
@ -383,7 +384,7 @@ export default class PokemonInfoContainer extends Phaser.GameObjects.Container {
} }
const starterSpeciesId = pokemon.species.getRootSpeciesId(); const starterSpeciesId = pokemon.species.getRootSpeciesId();
const originalIvs: number[] | null = eggInfo const originalIvs: IVTuple | null = eggInfo
? dexEntry.caughtAttr ? dexEntry.caughtAttr
? dexEntry.ivs ? dexEntry.ivs
: null : null

View File

@ -3,6 +3,7 @@ import { MoveId } from "#enums/move-id";
import i18next from "i18next"; import i18next from "i18next";
import { pokerogueApi } from "#app/plugins/api/pokerogue-api"; import { pokerogueApi } from "#app/plugins/api/pokerogue-api";
import type { Variant } from "#app/sprites/variant"; import type { Variant } from "#app/sprites/variant";
import type { IVTuple, IVType } from "#app/@types/stat-types";
export type nil = null | undefined; export type nil = null | undefined;
@ -87,6 +88,8 @@ export function randInt(range: number, min = 0): number {
return Math.floor(Math.random() * range) + min; return Math.floor(Math.random() * range) + min;
} }
export function randSeedInt(range: 31, min?: IVType): IVType;
export function randSeedInt(range: number, min?: number): number;
/** /**
* Generate a random integer using the global seed, or the current battle's seed if called via `Battle.randSeedInt` * Generate a random integer using the global seed, or the current battle's seed if called via `Battle.randSeedInt`
* @param range - How large of a range of random numbers to choose from. If {@linkcode range} <= 1, returns {@linkcode min} * @param range - How large of a range of random numbers to choose from. If {@linkcode range} <= 1, returns {@linkcode min}
@ -182,7 +185,7 @@ export function getPlayTimeString(totalSeconds: number): string {
* @param id 32-bit number * @param id 32-bit number
* @returns An array of six numbers corresponding to 5-bit chunks from {@linkcode id} * @returns An array of six numbers corresponding to 5-bit chunks from {@linkcode id}
*/ */
export function getIvsFromId(id: number): number[] { export function getIvsFromId(id: number): IVTuple {
return [ return [
(id & 0x3e000000) >>> 25, (id & 0x3e000000) >>> 25,
(id & 0x01f00000) >>> 20, (id & 0x01f00000) >>> 20,
@ -190,7 +193,7 @@ export function getIvsFromId(id: number): number[] {
(id & 0x00007c00) >>> 10, (id & 0x00007c00) >>> 10,
(id & 0x000003e0) >>> 5, (id & 0x000003e0) >>> 5,
id & 0x0000001f, id & 0x0000001f,
]; ] as IVTuple; // TS doesn't know the numbers are between 0-31
} }
export function formatLargeNumber(count: number, threshold: number): string { export function formatLargeNumber(count: number, threshold: number): string {

View File

@ -1,11 +1,14 @@
import { AbilityId } from "#enums/ability-id"; import { RandomMoveAttr } from "#app/data/moves/move";
import { MoveResult } from "#enums/move-result";
import { getPokemonNameWithAffix } from "#app/messages";
import { MoveId } from "#enums/move-id"; import { MoveId } from "#enums/move-id";
import { SpeciesId } from "#enums/species-id"; import { SpeciesId } from "#enums/species-id";
import { AbilityId } from "#app/enums/ability-id";
import { WeatherType } from "#enums/weather-type"; import { WeatherType } from "#enums/weather-type";
import GameManager from "#test/testUtils/gameManager"; import GameManager from "#test/testUtils/gameManager";
import i18next from "i18next";
import Phaser from "phaser"; import Phaser from "phaser";
//import { TurnInitPhase } from "#app/phases/turn-init-phase"; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
describe("Moves - Chilly Reception", () => { describe("Moves - Chilly Reception", () => {
let phaserGame: Phaser.Game; let phaserGame: Phaser.Game;
@ -25,95 +28,121 @@ describe("Moves - Chilly Reception", () => {
game = new GameManager(phaserGame); game = new GameManager(phaserGame);
game.override game.override
.battleStyle("single") .battleStyle("single")
.moveset([MoveId.CHILLY_RECEPTION, MoveId.SNOWSCAPE]) .moveset([MoveId.CHILLY_RECEPTION, MoveId.SNOWSCAPE, MoveId.SPLASH, MoveId.METRONOME])
.enemyMoveset(MoveId.SPLASH) .enemyMoveset(MoveId.SPLASH)
.enemyAbility(AbilityId.BALL_FETCH) .enemyAbility(AbilityId.BALL_FETCH)
.ability(AbilityId.BALL_FETCH); .ability(AbilityId.BALL_FETCH);
}); });
it("should still change the weather if user can't switch out", async () => { it("should display message before use, switch the user out and change the weather to snow", async () => {
await game.classicMode.startBattle([SpeciesId.SLOWKING, SpeciesId.MEOWTH]);
const [slowking, meowth] = game.scene.getPlayerParty();
game.move.select(MoveId.CHILLY_RECEPTION);
game.doSelectPartyPokemon(1);
await game.toEndOfTurn();
expect(game.scene.arena.weather?.weatherType).toBe(WeatherType.SNOW);
expect(game.scene.getPlayerPokemon()).toBe(meowth);
expect(slowking.isOnField()).toBe(false);
expect(game.phaseInterceptor.log).toContain("SwitchSummonPhase");
expect(game.textInterceptor.logs).toContain(
i18next.t("moveTriggers:chillyReception", { pokemonName: getPokemonNameWithAffix(slowking) }),
);
});
it("should still change weather if user can't switch out", async () => {
await game.classicMode.startBattle([SpeciesId.SLOWKING]); await game.classicMode.startBattle([SpeciesId.SLOWKING]);
game.move.select(MoveId.CHILLY_RECEPTION); game.move.select(MoveId.CHILLY_RECEPTION);
await game.toEndOfTurn();
await game.phaseInterceptor.to("BerryPhase", false);
expect(game.scene.arena.weather?.weatherType).toBe(WeatherType.SNOW); expect(game.scene.arena.weather?.weatherType).toBe(WeatherType.SNOW);
expect(game.phaseInterceptor.log).not.toContain("SwitchSummonPhase");
expect(game.scene.getPlayerPokemon()?.getLastXMoves()[0].result).toBe(MoveResult.SUCCESS);
}); });
it("should switch out even if it's snowing", async () => { it("should still switch out even if weather cannot be changed", async () => {
await game.classicMode.startBattle([SpeciesId.SLOWKING, SpeciesId.MEOWTH]); await game.classicMode.startBattle([SpeciesId.SLOWKING, SpeciesId.MEOWTH]);
// first turn set up snow with snowscape, try chilly reception on second turn
expect(game.scene.arena.weather?.weatherType).not.toBe(WeatherType.SNOW);
const [slowking, meowth] = game.scene.getPlayerParty();
game.move.select(MoveId.SNOWSCAPE); game.move.select(MoveId.SNOWSCAPE);
await game.phaseInterceptor.to("BerryPhase", false); await game.toNextTurn();
expect(game.scene.arena.weather?.weatherType).toBe(WeatherType.SNOW); expect(game.scene.arena.weather?.weatherType).toBe(WeatherType.SNOW);
await game.phaseInterceptor.to("TurnInitPhase", false);
game.move.select(MoveId.CHILLY_RECEPTION); game.move.select(MoveId.CHILLY_RECEPTION);
game.doSelectPartyPokemon(1); game.doSelectPartyPokemon(1);
// TODO: Uncomment lines once wimp out PR fixes force switches to not reset summon data immediately
// await game.phaseInterceptor.to("SwitchSummonPhase", false);
// expect(slowking.getLastXMoves()[0].result).toBe(MoveResult.SUCCESS);
await game.toEndOfTurn();
await game.phaseInterceptor.to("BerryPhase", false);
expect(game.scene.arena.weather?.weatherType).toBe(WeatherType.SNOW); expect(game.scene.arena.weather?.weatherType).toBe(WeatherType.SNOW);
expect(game.scene.getPlayerField()[0].species.speciesId).toBe(SpeciesId.MEOWTH); expect(game.phaseInterceptor.log).toContain("SwitchSummonPhase");
expect(game.scene.getPlayerPokemon()).toBe(meowth);
expect(slowking.isOnField()).toBe(false);
}); });
it("happy case - switch out and weather changes", async () => { // Source: https://replay.pokemonshowdown.com/gen9ou-2367532550
it("should fail (while still displaying message) if neither weather change nor switch out succeeds", async () => {
await game.classicMode.startBattle([SpeciesId.SLOWKING]);
expect(game.scene.arena.weather?.weatherType).not.toBe(WeatherType.SNOW);
const slowking = game.scene.getPlayerPokemon()!;
game.move.select(MoveId.SNOWSCAPE);
await game.toNextTurn();
expect(game.scene.arena.weather?.weatherType).toBe(WeatherType.SNOW);
game.move.select(MoveId.CHILLY_RECEPTION);
game.doSelectPartyPokemon(1);
await game.toEndOfTurn();
expect(game.scene.arena.weather?.weatherType).toBe(WeatherType.SNOW);
expect(game.phaseInterceptor.log).not.toContain("SwitchSummonPhase");
expect(game.scene.getPlayerPokemon()).toBe(slowking);
expect(slowking.getLastXMoves()[0].result).toBe(MoveResult.FAIL);
expect(game.textInterceptor.logs).toContain(
i18next.t("moveTriggers:chillyReception", { pokemonName: getPokemonNameWithAffix(slowking) }),
);
});
it("should succeed without message if called indirectly", async () => {
vi.spyOn(RandomMoveAttr.prototype, "getMoveOverride").mockReturnValue(MoveId.CHILLY_RECEPTION);
await game.classicMode.startBattle([SpeciesId.SLOWKING, SpeciesId.MEOWTH]); await game.classicMode.startBattle([SpeciesId.SLOWKING, SpeciesId.MEOWTH]);
game.move.select(MoveId.CHILLY_RECEPTION); const [slowking, meowth] = game.scene.getPlayerParty();
game.doSelectPartyPokemon(1);
game.move.select(MoveId.METRONOME);
game.doSelectPartyPokemon(1);
await game.toEndOfTurn();
await game.phaseInterceptor.to("BerryPhase", false);
expect(game.scene.arena.weather?.weatherType).toBe(WeatherType.SNOW); expect(game.scene.arena.weather?.weatherType).toBe(WeatherType.SNOW);
expect(game.scene.getPlayerField()[0].species.speciesId).toBe(SpeciesId.MEOWTH); expect(game.scene.getPlayerPokemon()).toBe(meowth);
expect(slowking.isOnField()).toBe(false);
expect(game.phaseInterceptor.log).toContain("SwitchSummonPhase");
expect(game.textInterceptor.logs).not.toContain(
i18next.t("moveTriggers:chillyReception", { pokemonName: getPokemonNameWithAffix(slowking) }),
);
}); });
// enemy uses another move and weather doesn't change // Bugcheck test for enemy AI bug
it("check case - enemy not selecting chilly reception doesn't change weather ", async () => { it("check case - enemy not selecting chilly reception doesn't change weather", async () => {
game.override.battleStyle("single").enemyMoveset([MoveId.CHILLY_RECEPTION, MoveId.TACKLE]).moveset(MoveId.SPLASH); game.override.enemyMoveset([MoveId.CHILLY_RECEPTION, MoveId.TACKLE]);
await game.classicMode.startBattle([SpeciesId.SLOWKING, SpeciesId.MEOWTH]); await game.classicMode.startBattle([SpeciesId.SLOWKING, SpeciesId.MEOWTH]);
game.move.select(MoveId.SPLASH); game.move.select(MoveId.SPLASH);
await game.move.selectEnemyMove(MoveId.TACKLE); await game.move.selectEnemyMove(MoveId.TACKLE);
await game.toEndOfTurn();
await game.phaseInterceptor.to("BerryPhase", false); expect(game.scene.arena.weather?.weatherType).toBeUndefined();
expect(game.scene.arena.weather?.weatherType).toBe(undefined);
});
it("enemy trainer - expected behavior ", async () => {
game.override
.battleStyle("single")
.startingWave(8)
.enemyMoveset(MoveId.CHILLY_RECEPTION)
.enemySpecies(SpeciesId.MAGIKARP)
.moveset([MoveId.SPLASH, MoveId.THUNDERBOLT]);
await game.classicMode.startBattle([SpeciesId.JOLTEON]);
const RIVAL_MAGIKARP1 = game.scene.getEnemyPokemon()?.id;
game.move.select(MoveId.SPLASH);
await game.phaseInterceptor.to("BerryPhase", false);
expect(game.scene.arena.weather?.weatherType).toBe(WeatherType.SNOW);
expect(game.scene.getEnemyPokemon()?.id !== RIVAL_MAGIKARP1);
await game.phaseInterceptor.to("TurnInitPhase", false);
game.move.select(MoveId.SPLASH);
// second chilly reception should still switch out
await game.phaseInterceptor.to("BerryPhase", false);
expect(game.scene.arena.weather?.weatherType).toBe(WeatherType.SNOW);
await game.phaseInterceptor.to("TurnInitPhase", false);
expect(game.scene.getEnemyPokemon()?.id === RIVAL_MAGIKARP1);
game.move.select(MoveId.THUNDERBOLT);
// enemy chilly recep move should fail: it's snowing and no option to switch out
// no crashing
await game.phaseInterceptor.to("BerryPhase", false);
expect(game.scene.arena.weather?.weatherType).toBe(WeatherType.SNOW);
await game.phaseInterceptor.to("TurnInitPhase", false);
expect(game.scene.arena.weather?.weatherType).toBe(WeatherType.SNOW);
game.move.select(MoveId.SPLASH);
await game.phaseInterceptor.to("BerryPhase", false);
expect(game.scene.arena.weather?.weatherType).toBe(WeatherType.SNOW);
}); });
}); });

View File

@ -11,6 +11,7 @@ import { SpeciesId } from "#enums/species-id";
import GameManager from "#test/testUtils/gameManager"; import GameManager from "#test/testUtils/gameManager";
import Phaser from "phaser"; import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import type { PermanentStatTuple } from "#app/@types/stat-types";
describe("Moves - Fusion Flare and Fusion Bolt", () => { describe("Moves - Fusion Flare and Fusion Bolt", () => {
let phaserGame: Phaser.Game; let phaserGame: Phaser.Game;
@ -156,6 +157,7 @@ describe("Moves - Fusion Flare and Fusion Bolt", () => {
expect(fusionFlare.calculateBattlePower).toHaveLastReturnedWith(200); expect(fusionFlare.calculateBattlePower).toHaveLastReturnedWith(200);
}); });
// TODO: Clean these tests up
it("FUSION_FLARE and FUSION_BOLT alternating throughout turn should double power of subsequent moves", async () => { it("FUSION_FLARE and FUSION_BOLT alternating throughout turn should double power of subsequent moves", async () => {
game.override.enemyMoveset(fusionFlare.id); game.override.enemyMoveset(fusionFlare.id);
await game.classicMode.startBattle([SpeciesId.ZEKROM, SpeciesId.ZEKROM]); await game.classicMode.startBattle([SpeciesId.ZEKROM, SpeciesId.ZEKROM]);
@ -168,7 +170,10 @@ describe("Moves - Fusion Flare and Fusion Bolt", () => {
game.scene.clearEnemyModifiers(); game.scene.clearEnemyModifiers();
// Mock stats by replacing entries in copy with desired values for specific stats // Mock stats by replacing entries in copy with desired values for specific stats
const stats = { const stats: {
enemy: [PermanentStatTuple, PermanentStatTuple];
player: [PermanentStatTuple, PermanentStatTuple];
} = {
enemy: [[...enemyParty[0].stats], [...enemyParty[1].stats]], enemy: [[...enemyParty[0].stats], [...enemyParty[1].stats]],
player: [[...party[0].stats], [...party[1].stats]], player: [[...party[0].stats], [...party[1].stats]],
}; };
@ -222,7 +227,10 @@ describe("Moves - Fusion Flare and Fusion Bolt", () => {
game.scene.clearEnemyModifiers(); game.scene.clearEnemyModifiers();
// Mock stats by replacing entries in copy with desired values for specific stats // Mock stats by replacing entries in copy with desired values for specific stats
const stats = { const stats: {
enemy: [PermanentStatTuple, PermanentStatTuple];
player: [PermanentStatTuple, PermanentStatTuple];
} = {
enemy: [[...enemyParty[0].stats], [...enemyParty[1].stats]], enemy: [[...enemyParty[0].stats], [...enemyParty[1].stats]],
player: [[...party[0].stats], [...party[1].stats]], player: [[...party[0].stats], [...party[1].stats]],
}; };