diff --git a/src/data/mystery-encounters/encounters/global-trade-system-encounter.ts b/src/data/mystery-encounters/encounters/global-trade-system-encounter.ts index 720e904ecdb..341db527d32 100644 --- a/src/data/mystery-encounters/encounters/global-trade-system-encounter.ts +++ b/src/data/mystery-encounters/encounters/global-trade-system-encounter.ts @@ -12,8 +12,7 @@ import PokemonSpecies, { allSpecies, getPokemonSpecies } from "#app/data/pokemon import { getTypeRgb } from "#app/data/type"; import { MysteryEncounterOptionBuilder } from "#app/data/mystery-encounters/mystery-encounter-option"; import { MysteryEncounterOptionMode } from "#enums/mystery-encounter-option-mode"; -import * as Utils from "#app/utils"; -import { IntegerHolder, isNullOrUndefined, randInt, randSeedInt, randSeedShuffle } from "#app/utils"; +import { NumberHolder, isNullOrUndefined, randInt, randSeedInt, randSeedShuffle } from "#app/utils"; import Pokemon, { EnemyPokemon, PlayerPokemon, PokemonMove } from "#app/field/pokemon"; import { HiddenAbilityRateBoosterModifier, PokemonFormChangeItemModifier, PokemonHeldItemModifier, ShinyRateBoosterModifier, SpeciesStatBoosterModifier } from "#app/modifier/modifier"; import { OptionSelectItem } from "#app/ui/abstact-option-select-ui-handler"; @@ -229,7 +228,7 @@ export const GlobalTradeSystemEncounter: MysteryEncounter = const tradePokemon = new EnemyPokemon(scene, randomTradeOption, pokemon.level, TrainerSlot.NONE, false); // Extra shiny roll at 1/128 odds (boosted by events and charms) if (!tradePokemon.shiny) { - const shinyThreshold = new Utils.IntegerHolder(WONDER_TRADE_SHINY_CHANCE); + const shinyThreshold = new NumberHolder(WONDER_TRADE_SHINY_CHANCE); if (scene.eventManager.isEventActive()) { shinyThreshold.value *= scene.eventManager.getShinyMultiplier(); } @@ -246,7 +245,7 @@ export const GlobalTradeSystemEncounter: MysteryEncounter = const hiddenIndex = tradePokemon.species.ability2 ? 2 : 1; if (tradePokemon.species.abilityHidden) { if (tradePokemon.abilityIndex < hiddenIndex) { - const hiddenAbilityChance = new IntegerHolder(64); + const hiddenAbilityChance = new NumberHolder(64); scene.applyModifiers(HiddenAbilityRateBoosterModifier, true, hiddenAbilityChance); const hasHiddenAbility = !randSeedInt(hiddenAbilityChance.value); diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 25a771c9281..dcd75f34fc5 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -1979,6 +1979,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { this.shiny = randSeedInt(65536) < shinyThreshold.value; if (this.shiny) { + this.variant = this.generateShinyVariant(); + this.luck = this.variant + 1 + (this.fusionShiny ? this.fusionVariant + 1 : 0); this.initShinySparkle(); } diff --git a/src/test/mystery-encounter/encounters/global-trade-system-encounter.test.ts b/src/test/mystery-encounter/encounters/global-trade-system-encounter.test.ts index e8d19ff50b9..2c226df3c8c 100644 --- a/src/test/mystery-encounter/encounters/global-trade-system-encounter.test.ts +++ b/src/test/mystery-encounter/encounters/global-trade-system-encounter.test.ts @@ -18,6 +18,7 @@ import { SelectModifierPhase } from "#app/phases/select-modifier-phase"; import { Mode } from "#app/ui/ui"; import ModifierSelectUiHandler from "#app/ui/modifier-select-ui-handler"; import { ModifierTier } from "#app/modifier/modifier-tier"; +import * as Utils from "#app/utils"; const namespace = "mysteryEncounters/globalTradeSystem"; const defaultParty = [ Species.LAPRAS, Species.GENGAR, Species.ABRA ]; @@ -176,6 +177,23 @@ describe("Global Trade System - Mystery Encounter", () => { expect(defaultParty.includes(speciesAfter!)).toBeFalsy(); }); + it("Should roll for shiny twice, with random variant and associated luck", async () => { + // This ensures that the first shiny roll gets ignored, to test the ME rerolling for shiny + game.override.enemyShiny(false); + + await game.runToMysteryEncounter(MysteryEncounterType.GLOBAL_TRADE_SYSTEM, defaultParty); + + vi.spyOn(Utils, "randSeedInt").mockReturnValue(1); // force shiny on reroll + + await runMysteryEncounterToEnd(game, 2, { pokemonNo: 1 }); + + const receivedPokemon = scene.getPlayerParty().at(-1)!; + + expect(receivedPokemon.shiny).toBeTruthy(); + expect(receivedPokemon.variant).toBeDefined(); + expect(receivedPokemon.luck).toBe(receivedPokemon.variant + 1); + }); + it("should leave encounter without battle", async () => { const leaveEncounterWithoutBattleSpy = vi.spyOn(EncounterPhaseUtils, "leaveEncounterWithoutBattle");