Skip to content

Commit

Permalink
[Tests] Enemy Held Item overrides are now applied after generateEnemy…
Browse files Browse the repository at this point in the history
…Modifiers() (#4922)

* Moved overrideModifiers and overrideHeldItems to after generateEnemyModifiers

* Removed functions from scene

* Fixed the test. Thank you pigeonbar.
  • Loading branch information
frutescens authored Dec 1, 2024
1 parent 38d7a26 commit d6854c4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
4 changes: 1 addition & 3 deletions src/battle-scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Pokemon, { EnemyPokemon, PlayerPokemon } from "#app/field/pokemon";
import PokemonSpecies, { allSpecies, getPokemonSpecies, PokemonSpeciesFilter } from "#app/data/pokemon-species";
import { Constructor, isNullOrUndefined, randSeedInt } from "#app/utils";
import * as Utils from "#app/utils";
import { ConsumableModifier, ConsumablePokemonModifier, DoubleBattleChanceBoosterModifier, ExpBalanceModifier, ExpShareModifier, FusePokemonModifier, HealingBoosterModifier, Modifier, ModifierBar, ModifierPredicate, MultipleParticipantExpBonusModifier, overrideHeldItems, overrideModifiers, PersistentModifier, PokemonExpBoosterModifier, PokemonFormChangeItemModifier, PokemonHeldItemModifier, PokemonHpRestoreModifier, PokemonIncrementingStatModifier, RememberMoveModifier, TerastallizeModifier, TurnHeldItemTransferModifier } from "./modifier/modifier";
import { ConsumableModifier, ConsumablePokemonModifier, DoubleBattleChanceBoosterModifier, ExpBalanceModifier, ExpShareModifier, FusePokemonModifier, HealingBoosterModifier, Modifier, ModifierBar, ModifierPredicate, MultipleParticipantExpBonusModifier, PersistentModifier, PokemonExpBoosterModifier, PokemonFormChangeItemModifier, PokemonHeldItemModifier, PokemonHpRestoreModifier, PokemonIncrementingStatModifier, RememberMoveModifier, TerastallizeModifier, TurnHeldItemTransferModifier } from "./modifier/modifier";
import { PokeballType } from "#enums/pokeball";
import { initCommonAnims, initMoveAnim, loadCommonAnimAssets, loadMoveAnimAssets, populateAnims } from "#app/data/battle-anims";
import { Phase } from "#app/phase";
Expand Down Expand Up @@ -933,8 +933,6 @@ export default class BattleScene extends SceneBase {
pokemon.generateFusionSpecies();
}

overrideModifiers(this, false);
overrideHeldItems(this, pokemon, false);
if (boss && !dataSource) {
const secondaryIvs = Utils.getIvsFromId(Utils.randSeedInt(4294967296));

Expand Down
6 changes: 6 additions & 0 deletions src/phases/encounter-phase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { Biome } from "#enums/biome";
import { MysteryEncounterMode } from "#enums/mystery-encounter-mode";
import { PlayerGender } from "#enums/player-gender";
import { Species } from "#enums/species";
import { overrideHeldItems, overrideModifiers } from "#app/modifier/modifier";
import i18next from "i18next";
import { WEIGHT_INCREMENT_ON_SPAWN_MISS } from "#app/data/mystery-encounters/mystery-encounters";

Expand Down Expand Up @@ -216,6 +217,11 @@ export class EncounterPhase extends BattlePhase {
if (!this.loaded && battle.battleType !== BattleType.MYSTERY_ENCOUNTER) {
regenerateModifierPoolThresholds(this.scene.getEnemyField(), battle.battleType === BattleType.TRAINER ? ModifierPoolType.TRAINER : ModifierPoolType.WILD);
this.scene.generateEnemyModifiers();
overrideModifiers(this.scene, false);
this.scene.getEnemyField().forEach(enemy => {
overrideHeldItems(this.scene, enemy, false);
});

}

this.scene.ui.setMode(Mode.MESSAGE).then(() => {
Expand Down
14 changes: 8 additions & 6 deletions src/test/moves/effectiveness.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Abilities } from "#app/enums/abilities";
import { Moves } from "#app/enums/moves";
import { Species } from "#app/enums/species";
import * as Messages from "#app/messages";
import { TerastallizeModifier } from "#app/modifier/modifier";
import { TerastallizeModifier, overrideHeldItems } from "#app/modifier/modifier";
import GameManager from "#test/utils/gameManager";
import Phaser from "phaser";
import { afterEach, beforeAll, describe, expect, it, vi } from "vitest";
Expand All @@ -15,15 +15,17 @@ function testMoveEffectiveness(game: GameManager, move: Moves, targetSpecies: Sp
expected: number, targetAbility: Abilities = Abilities.BALL_FETCH, teraType?: Type): void {
// Suppress getPokemonNameWithAffix because it calls on a null battle spec
vi.spyOn(Messages, "getPokemonNameWithAffix").mockReturnValue("");
game.override.enemyAbility(targetAbility);

if (teraType !== undefined) {
game.override.enemyHeldItems([{ name:"TERA_SHARD", type: teraType }]);
}
game.override
.enemyAbility(targetAbility)
.enemyHeldItems([{ name:"TERA_SHARD", type: teraType }]);

const user = game.scene.addPlayerPokemon(getPokemonSpecies(Species.SNORLAX), 5);
const target = game.scene.addEnemyPokemon(getPokemonSpecies(targetSpecies), 5, TrainerSlot.NONE);

if (teraType !== undefined) {
overrideHeldItems(game.scene, target, false);
}

expect(target.getMoveEffectiveness(user, allMoves[move])).toBe(expected);
user.destroy();
target.destroy();
Expand Down

0 comments on commit d6854c4

Please sign in to comment.