Fixup tests and broken assumptions

This commit is contained in:
Sirz Benjie 2025-04-10 16:42:07 -05:00
parent fee8140e21
commit e73cc310c0
No known key found for this signature in database
GPG Key ID: 4A524B4D196C759E
4 changed files with 45 additions and 22 deletions

View File

@ -1455,7 +1455,6 @@ export default class BattleScene extends SceneBase {
this.executeWithSeedOffset( this.executeWithSeedOffset(
() => { () => {
console.log(`Starting a new battle with ${BattleType[newBattleType]} and double: ${newDouble}`);
this.currentBattle = new Battle(this.gameMode, newWaveIndex, newBattleType, newTrainer, newDouble); this.currentBattle = new Battle(this.gameMode, newWaveIndex, newBattleType, newTrainer, newDouble);
}, },
newWaveIndex << 3, newWaveIndex << 3,

View File

@ -44,6 +44,7 @@ import { PokemonTransformPhase } from "#app/phases/pokemon-transform-phase";
import { allAbilities } from "#app/data/data-lists"; import { allAbilities } from "#app/data/data-lists";
import { AbAttr } from "#app/data/abilities/ab-attrs/ab-attr"; import { AbAttr } from "#app/data/abilities/ab-attrs/ab-attr";
import { Ability } from "#app/data/abilities/ability-class"; import { Ability } from "#app/data/abilities/ability-class";
import { TrainerVariant } from "#app/field/trainer";
// Enum imports // Enum imports
import { Stat, type BattleStat , BATTLE_STATS, EFFECTIVE_STATS, getStatKey, type EffectiveStat } from "#enums/stat"; import { Stat, type BattleStat , BATTLE_STATS, EFFECTIVE_STATS, getStatKey, type EffectiveStat } from "#enums/stat";
@ -61,6 +62,7 @@ import { MoveFlags } from "#enums/MoveFlags";
import { MoveTarget } from "#enums/MoveTarget"; import { MoveTarget } from "#enums/MoveTarget";
import { MoveCategory } from "#enums/MoveCategory"; import { MoveCategory } from "#enums/MoveCategory";
// Type imports // Type imports
import type { EnemyPokemon, PokemonMove } from "#app/field/pokemon"; import type { EnemyPokemon, PokemonMove } from "#app/field/pokemon";
import type Pokemon from "#app/field/pokemon"; import type Pokemon from "#app/field/pokemon";
@ -5526,8 +5528,8 @@ class ForceSwitchOutHelper {
const party = player ? globalScene.getPlayerParty() : globalScene.getEnemyParty(); const party = player ? globalScene.getPlayerParty() : globalScene.getEnemyParty();
return (!player && globalScene.currentBattle.battleType === BattleType.WILD) return (!player && globalScene.currentBattle.battleType === BattleType.WILD)
|| party.filter(p => p.isAllowedInBattle() || party.filter(p => p.isAllowedInBattle() && !p.isOnField()
&& (player || (p as EnemyPokemon).trainerSlot === (switchOutTarget as EnemyPokemon).trainerSlot)).length > globalScene.currentBattle.getBattlerCount(); && (player || (p as EnemyPokemon).trainerSlot === (switchOutTarget as EnemyPokemon).trainerSlot)).length > 0;
} }
/** /**

View File

@ -6230,10 +6230,8 @@ export class ForceSwitchOutAttr extends MoveEffectAttr {
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
// Check if the move category is not STATUS or if the switch out condition is not met // Check if the move category is not STATUS or if the switch out condition is not met
if (!this.getSwitchOutCondition()(user, target, move)) { if (!this.getSwitchOutCondition()(user, target, move)) {
console.log("=========== Switch out condition was false!===========");
return false; return false;
} }
console.log("=========== Switch out condition was true!===========");
/** The {@linkcode Pokemon} to be switched out with this effect */ /** The {@linkcode Pokemon} to be switched out with this effect */
const switchOutTarget = this.selfSwitch ? user : target; const switchOutTarget = this.selfSwitch ? user : target;
@ -6376,7 +6374,7 @@ export class ForceSwitchOutAttr extends MoveEffectAttr {
} }
getCondition(): MoveConditionFunc { getCondition(): MoveConditionFunc {
return (user, target, move) => (move.category !== MoveCategory.STATUS || this.getSwitchOutCondition()(user, target, move)); return (user, target, move) => (move.category !== MoveCategory.STATUS || this.getSwitchOutCondition(true)(user, target, move));
} }
getFailedText(_user: Pokemon, target: Pokemon, _move: Move): string | undefined { getFailedText(_user: Pokemon, target: Pokemon, _move: Move): string | undefined {
@ -6387,7 +6385,13 @@ export class ForceSwitchOutAttr extends MoveEffectAttr {
} }
} }
getSwitchOutCondition(): MoveConditionFunc {
/**
* Check if the switch out conditions are met.
*
* @param preliminary - Whether to check for failure conditions that occur before the hit check (defaults to false)
*/
getSwitchOutCondition(preliminary = false): MoveConditionFunc {
return (user, target, move) => { return (user, target, move) => {
const switchOutTarget = (this.selfSwitch ? user : target); const switchOutTarget = (this.selfSwitch ? user : target);
const player = switchOutTarget instanceof PlayerPokemon; const player = switchOutTarget instanceof PlayerPokemon;
@ -6415,22 +6419,21 @@ export class ForceSwitchOutAttr extends MoveEffectAttr {
} }
} }
if (preliminary) {
return true;
}
if (!player && globalScene.currentBattle.battleType === BattleType.WILD) { if (!player && globalScene.currentBattle.battleType === BattleType.WILD) {
// Prevent wild pokemon fr // wild pokemon cannot switch out with baton pass.
return !(this.isBatonPass() return !this.isBatonPass()
// Don't allow boss waves of wild pokemon to flee && globalScene.currentBattle.waveIndex % 10 !== 0
&& globalScene.currentBattle.waveIndex % 10 === 0
// Don't allow wild mons to flee with U-turn et al. // Don't allow wild mons to flee with U-turn et al.
&& this.selfSwitch && move.category !== MoveCategory.STATUS) && !(this.selfSwitch && MoveCategory.STATUS !== move.category);
} }
const party = player ? globalScene.getPlayerParty() : globalScene.getEnemyParty(); const party = player ? globalScene.getPlayerParty() : globalScene.getEnemyParty();
// Determine if this is a return party.filter(p => p.isAllowedInBattle() && !p.isOnField()
const currentBattle = globalScene.currentBattle; && (player || (p as EnemyPokemon).trainerSlot === (switchOutTarget as EnemyPokemon).trainerSlot)).length > 0;
// If the trainer battle is a partner, then they can switch out as long as they have at least one pokemon in the back
const MIN_BATTLE_COUNT = (!player && currentBattle.trainer?.variant === TrainerVariant.DOUBLE) ? 1 : currentBattle.getBattlerCount();
return party.filter(p => p.isAllowedInBattle()
&& (player || (p as EnemyPokemon).trainerSlot === (switchOutTarget as EnemyPokemon).trainerSlot)).length > MIN_BATTLE_COUNT;
}; };
} }

View File

@ -180,12 +180,15 @@ describe("Moves - Whirlwind", () => {
game.move.select(Moves.SPLASH); game.move.select(Moves.SPLASH);
game.move.select(Moves.SPLASH); game.move.select(Moves.SPLASH);
await game.forceEnemyMove(Moves.LUNAR_DANCE); await game.forceEnemyMove(Moves.MEMENTO);
await game.forceEnemyMove(Moves.SPLASH); await game.forceEnemyMove(Moves.SPLASH);
await game.toNextTurn(); await game.toNextTurn();
// Get the enemy pokemon id so we can check if is the same after switch.
const enemy_id = game.scene.getEnemyPokemon()!.id;
// Hit the enemy that fainted with whirlwind. // Hit the enemy that fainted with whirlwind.
game.move.select(Moves.WHIRLWIND, 0, BattlerIndex.ENEMY_2); game.move.select(Moves.WHIRLWIND, 0, BattlerIndex.ENEMY);
game.move.select(Moves.SPLASH, 1); game.move.select(Moves.SPLASH, 1);
await game.forceEnemyMove(Moves.SPLASH); await game.forceEnemyMove(Moves.SPLASH);
@ -194,6 +197,22 @@ describe("Moves - Whirlwind", () => {
await game.toNextTurn(); await game.toNextTurn();
// Expect the enemy pokemon to not have switched out. // Expect the enemy pokemon to not have switched out.
expect(game.scene.getPlayerPokemon()!.getLastXMoves(1)[0].result).toBe(MoveResult.FAIL); expect(game.scene.getEnemyPokemon()!.id).toBe(enemy_id);
});
it("should force a wild pokemon to flee", async () => {
game.override
.battleType(BattleType.WILD)
.moveset([Moves.WHIRLWIND, Moves.SPLASH])
.enemyMoveset(Moves.SPLASH)
.ability(Abilities.BALL_FETCH);
await game.classicMode.startBattle([Species.MAGIKARP]);
const user = game.scene.getPlayerPokemon()!;
game.move.select(Moves.WHIRLWIND);
await game.phaseInterceptor.to("BerryPhase");
expect(user.getLastXMoves(1)[0].result).toBe(MoveResult.SUCCESS);
}); });
}); });