mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-01-18 23:11:11 +00:00
[Bug] Fix a couple small issues with uturn and friends (#3321)
* prevent double-application of status contact abilities and switch out abilities * use SwitchPhase for ForceSwitchOutAbAttr instead of switchOut() * add tests for baton pass/uturn * PR comments * Update src/test/moves/baton_pass.test.ts * add test for forced switch after mutual KO + revive * tweak condition to fix uturn/baton pass * improve docs * style/typo nits from CR Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> * CR feedback * use doSelectPartyPokemon + rename * int -> number Co-authored-by: Adrian T. <68144167+torranx@users.noreply.github.com> --------- Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> Co-authored-by: Adrian T. <68144167+torranx@users.noreply.github.com>
This commit is contained in:
parent
d2e1340c0c
commit
f555dd6dc8
@ -1,5 +1,5 @@
|
|||||||
import { ChargeAnim, MoveChargeAnim, initMoveAnim, loadMoveAnimAssets } from "./battle-anims";
|
import { ChargeAnim, MoveChargeAnim, initMoveAnim, loadMoveAnimAssets } from "./battle-anims";
|
||||||
import { BattleEndPhase, MoveEndPhase, MovePhase, NewBattlePhase, PartyStatusCurePhase, PokemonHealPhase, StatChangePhase, SwitchSummonPhase } from "../phases";
|
import { BattleEndPhase, MoveEndPhase, MovePhase, NewBattlePhase, PartyStatusCurePhase, PokemonHealPhase, StatChangePhase, SwitchPhase, SwitchSummonPhase } from "../phases";
|
||||||
import { BattleStat, getBattleStatName } from "./battle-stat";
|
import { BattleStat, getBattleStatName } from "./battle-stat";
|
||||||
import { EncoreTag, GulpMissileTag, HelpingHandTag, SemiInvulnerableTag, StockpilingTag, TypeBoostTag } from "./battler-tags";
|
import { EncoreTag, GulpMissileTag, HelpingHandTag, SemiInvulnerableTag, StockpilingTag, TypeBoostTag } from "./battler-tags";
|
||||||
import { getPokemonNameWithAffix } from "../messages";
|
import { getPokemonNameWithAffix } from "../messages";
|
||||||
@ -10,7 +10,7 @@ import { Constructor } from "#app/utils";
|
|||||||
import * as Utils from "../utils";
|
import * as Utils from "../utils";
|
||||||
import { WeatherType } from "./weather";
|
import { WeatherType } from "./weather";
|
||||||
import { ArenaTagSide, ArenaTrapTag, WeakenMoveTypeTag } from "./arena-tag";
|
import { ArenaTagSide, ArenaTrapTag, WeakenMoveTypeTag } from "./arena-tag";
|
||||||
import { UnswappableAbilityAbAttr, UncopiableAbilityAbAttr, UnsuppressableAbilityAbAttr, BlockRecoilDamageAttr, BlockOneHitKOAbAttr, IgnoreContactAbAttr, MaxMultiHitAbAttr, applyAbAttrs, BlockNonDirectDamageAbAttr, applyPreSwitchOutAbAttrs, PreSwitchOutAbAttr, applyPostDefendAbAttrs, PostDefendContactApplyStatusEffectAbAttr, MoveAbilityBypassAbAttr, ReverseDrainAbAttr, FieldPreventExplosiveMovesAbAttr, ForceSwitchOutImmunityAbAttr, BlockItemTheftAbAttr, applyPostAttackAbAttrs, ConfusionOnStatusEffectAbAttr, HealFromBerryUseAbAttr, IgnoreProtectOnContactAbAttr, IgnoreMoveEffectsAbAttr, applyPreDefendAbAttrs, MoveEffectChanceMultiplierAbAttr, WonderSkinAbAttr, applyPreAttackAbAttrs, MoveTypeChangeAttr, UserFieldMoveTypePowerBoostAbAttr, FieldMoveTypePowerBoostAbAttr, AllyMoveCategoryPowerBoostAbAttr, VariableMovePowerAbAttr } from "./ability";
|
import { UnswappableAbilityAbAttr, UncopiableAbilityAbAttr, UnsuppressableAbilityAbAttr, BlockRecoilDamageAttr, BlockOneHitKOAbAttr, IgnoreContactAbAttr, MaxMultiHitAbAttr, applyAbAttrs, BlockNonDirectDamageAbAttr, MoveAbilityBypassAbAttr, ReverseDrainAbAttr, FieldPreventExplosiveMovesAbAttr, ForceSwitchOutImmunityAbAttr, BlockItemTheftAbAttr, applyPostAttackAbAttrs, ConfusionOnStatusEffectAbAttr, HealFromBerryUseAbAttr, IgnoreProtectOnContactAbAttr, IgnoreMoveEffectsAbAttr, applyPreDefendAbAttrs, MoveEffectChanceMultiplierAbAttr, WonderSkinAbAttr, applyPreAttackAbAttrs, MoveTypeChangeAttr, UserFieldMoveTypePowerBoostAbAttr, FieldMoveTypePowerBoostAbAttr, AllyMoveCategoryPowerBoostAbAttr, VariableMovePowerAbAttr } from "./ability";
|
||||||
import { allAbilities } from "./ability";
|
import { allAbilities } from "./ability";
|
||||||
import { PokemonHeldItemModifier, BerryModifier, PreserveBerryModifier, PokemonMoveAccuracyBoosterModifier, AttackTypeBoosterModifier, PokemonMultiHitModifier } from "../modifier/modifier";
|
import { PokemonHeldItemModifier, BerryModifier, PreserveBerryModifier, PokemonMoveAccuracyBoosterModifier, AttackTypeBoosterModifier, PokemonMultiHitModifier } from "../modifier/modifier";
|
||||||
import { BattlerIndex, BattleType } from "../battle";
|
import { BattlerIndex, BattleType } from "../battle";
|
||||||
@ -4806,13 +4806,15 @@ export class ForceSwitchOutAttr extends MoveEffectAttr {
|
|||||||
this.batonPass = !!batonPass;
|
this.batonPass = !!batonPass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isBatonPass() {
|
||||||
|
return this.batonPass;
|
||||||
|
}
|
||||||
|
|
||||||
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): Promise<boolean> {
|
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): Promise<boolean> {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
|
|
||||||
// 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)) {
|
||||||
//Apply effects before switch out i.e. poison point, flame body, etc
|
|
||||||
applyPostDefendAbAttrs(PostDefendContactApplyStatusEffectAbAttr, target, user, move, null);
|
|
||||||
return resolve(false);
|
return resolve(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4820,10 +4822,11 @@ export class ForceSwitchOutAttr extends MoveEffectAttr {
|
|||||||
// This ensures that the switch out only happens when the conditions are met
|
// This ensures that the switch out only happens when the conditions are met
|
||||||
const switchOutTarget = this.user ? user : target;
|
const switchOutTarget = this.user ? user : target;
|
||||||
if (switchOutTarget instanceof PlayerPokemon) {
|
if (switchOutTarget instanceof PlayerPokemon) {
|
||||||
|
switchOutTarget.leaveField(!this.batonPass);
|
||||||
|
|
||||||
if (switchOutTarget.hp > 0) {
|
if (switchOutTarget.hp > 0) {
|
||||||
applyPreSwitchOutAbAttrs(PreSwitchOutAbAttr, switchOutTarget);
|
user.scene.prependToPhase(new SwitchPhase(user.scene, switchOutTarget.getFieldIndex(), true, true), MoveEndPhase);
|
||||||
// switchOut below sets the UI to select party(this is not a separate Phase), then adds a SwitchSummonPhase with selected 'mon
|
resolve(true);
|
||||||
(switchOutTarget as PlayerPokemon).switchOut(this.batonPass).then(() => resolve(true));
|
|
||||||
} else {
|
} else {
|
||||||
resolve(false);
|
resolve(false);
|
||||||
}
|
}
|
||||||
|
@ -4464,11 +4464,24 @@ export class PostGameOverPhase extends Phase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens the party selector UI and transitions into a {@linkcode SwitchSummonPhase}
|
||||||
|
* for the player (if a switch would be valid for the current battle state).
|
||||||
|
*/
|
||||||
export class SwitchPhase extends BattlePhase {
|
export class SwitchPhase extends BattlePhase {
|
||||||
protected fieldIndex: integer;
|
protected fieldIndex: integer;
|
||||||
private isModal: boolean;
|
private isModal: boolean;
|
||||||
private doReturn: boolean;
|
private doReturn: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new SwitchPhase
|
||||||
|
* @param scene {@linkcode BattleScene} Current battle scene
|
||||||
|
* @param fieldIndex Field index to switch out
|
||||||
|
* @param isModal Indicates if the switch should be forced (true) or is
|
||||||
|
* optional (false).
|
||||||
|
* @param doReturn Indicates if the party member on the field should be
|
||||||
|
* recalled to ball or has already left the field. Passed to {@linkcode SwitchSummonPhase}.
|
||||||
|
*/
|
||||||
constructor(scene: BattleScene, fieldIndex: integer, isModal: boolean, doReturn: boolean) {
|
constructor(scene: BattleScene, fieldIndex: integer, isModal: boolean, doReturn: boolean) {
|
||||||
super(scene);
|
super(scene);
|
||||||
|
|
||||||
@ -4480,13 +4493,17 @@ export class SwitchPhase extends BattlePhase {
|
|||||||
start() {
|
start() {
|
||||||
super.start();
|
super.start();
|
||||||
|
|
||||||
// Skip modal switch if impossible
|
// Skip modal switch if impossible (no remaining party members that aren't in battle)
|
||||||
if (this.isModal && !this.scene.getParty().filter(p => p.isAllowedInBattle() && !p.isActive(true)).length) {
|
if (this.isModal && !this.scene.getParty().filter(p => p.isAllowedInBattle() && !p.isActive(true)).length) {
|
||||||
return super.end();
|
return super.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip if the fainted party member has been revived already
|
// Skip if the fainted party member has been revived already. doReturn is
|
||||||
if (this.isModal && !this.scene.getParty()[this.fieldIndex].isFainted()) {
|
// only passed as `false` from FaintPhase (as opposed to other usages such
|
||||||
|
// as ForceSwitchOutAttr or CheckSwitchPhase), so we only want to check this
|
||||||
|
// if the mon should have already been returned but is still alive and well
|
||||||
|
// on the field. see also; battle.test.ts
|
||||||
|
if (this.isModal && !this.doReturn && !this.scene.getParty()[this.fieldIndex].isFainted()) {
|
||||||
return super.end();
|
return super.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,24 @@
|
|||||||
import { allSpecies } from "#app/data/pokemon-species";
|
import { allSpecies } from "#app/data/pokemon-species";
|
||||||
|
import { TempBattleStat } from "#app/data/temp-battle-stat.js";
|
||||||
import { GameModes } from "#app/game-mode";
|
import { GameModes } from "#app/game-mode";
|
||||||
import { getGameMode } from "#app/game-mode.js";
|
import { getGameMode } from "#app/game-mode.js";
|
||||||
import { CommandPhase, DamagePhase, EncounterPhase, EnemyCommandPhase, LoginPhase, SelectGenderPhase, SelectModifierPhase, SelectStarterPhase, SummonPhase, TitlePhase, TurnInitPhase, VictoryPhase } from "#app/phases";
|
import {
|
||||||
import GameManager from "#test/utils/gameManager";
|
BattleEndPhase,
|
||||||
import { generateStarter, getMovePosition, } from "#test/utils/gameManagerUtils";
|
CommandPhase, DamagePhase,
|
||||||
|
EncounterPhase,
|
||||||
|
EnemyCommandPhase,
|
||||||
|
LoginPhase,
|
||||||
|
NextEncounterPhase,
|
||||||
|
SelectGenderPhase,
|
||||||
|
SelectModifierPhase,
|
||||||
|
SelectStarterPhase,
|
||||||
|
SummonPhase,
|
||||||
|
SwitchPhase,
|
||||||
|
TitlePhase,
|
||||||
|
TurnInitPhase, VictoryPhase,
|
||||||
|
} from "#app/phases";
|
||||||
|
import GameManager from "#app/test/utils/gameManager";
|
||||||
|
import { generateStarter, getMovePosition, } from "#app/test/utils/gameManagerUtils";
|
||||||
import { Command } from "#app/ui/command-ui-handler";
|
import { Command } from "#app/ui/command-ui-handler";
|
||||||
import { Mode } from "#app/ui/ui";
|
import { Mode } from "#app/ui/ui";
|
||||||
import { Abilities } from "#enums/abilities";
|
import { Abilities } from "#enums/abilities";
|
||||||
@ -12,6 +27,7 @@ import { PlayerGender } from "#enums/player-gender";
|
|||||||
import { Species } from "#enums/species";
|
import { Species } from "#enums/species";
|
||||||
import Phaser from "phaser";
|
import Phaser from "phaser";
|
||||||
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
|
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
|
||||||
|
import { SPLASH_ONLY } from "../utils/testUtils";
|
||||||
|
|
||||||
describe("Test Battle Phase", () => {
|
describe("Test Battle Phase", () => {
|
||||||
let phaserGame: Phaser.Game;
|
let phaserGame: Phaser.Game;
|
||||||
@ -312,5 +328,31 @@ describe("Test Battle Phase", () => {
|
|||||||
await game.toNextWave();
|
await game.toNextWave();
|
||||||
expect(game.scene.currentBattle.waveIndex).toBeGreaterThan(waveIndex);
|
expect(game.scene.currentBattle.waveIndex).toBeGreaterThan(waveIndex);
|
||||||
}, 20000);
|
}, 20000);
|
||||||
|
|
||||||
|
it("does not force switch if active pokemon faints at same time as enemy mon and is revived in post-battle", async () => {
|
||||||
|
const moveToUse = Moves.TAKE_DOWN;
|
||||||
|
game.override
|
||||||
|
.battleType("single")
|
||||||
|
.starterSpecies(Species.SAWK)
|
||||||
|
.enemySpecies(Species.RATTATA)
|
||||||
|
.startingWave(1)
|
||||||
|
.startingLevel(100)
|
||||||
|
.moveset([moveToUse])
|
||||||
|
.enemyMoveset(SPLASH_ONLY)
|
||||||
|
.startingHeldItems([{ name: "TEMP_STAT_BOOSTER", type: TempBattleStat.ACC }]);
|
||||||
|
|
||||||
|
await game.startBattle();
|
||||||
|
game.scene.getPlayerPokemon().hp = 1;
|
||||||
|
game.doAttack(getMovePosition(game.scene, 0, moveToUse));
|
||||||
|
|
||||||
|
await game.phaseInterceptor.to(BattleEndPhase);
|
||||||
|
game.doRevivePokemon(0); // pretend max revive was picked
|
||||||
|
game.doSelectModifier();
|
||||||
|
|
||||||
|
game.onNextPrompt("SwitchPhase", Mode.PARTY, () => {
|
||||||
|
expect.fail("Switch was forced");
|
||||||
|
}, () => game.isCurrentPhase(NextEncounterPhase));
|
||||||
|
await game.phaseInterceptor.to(SwitchPhase);
|
||||||
|
}, 20000);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
93
src/test/moves/baton_pass.test.ts
Normal file
93
src/test/moves/baton_pass.test.ts
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
import { BattleStat } from "#app/data/battle-stat.js";
|
||||||
|
import { PostSummonPhase, TurnEndPhase } from "#app/phases.js";
|
||||||
|
import GameManager from "#app/test/utils/gameManager";
|
||||||
|
import { getMovePosition } from "#app/test/utils/gameManagerUtils";
|
||||||
|
import { Moves } from "#enums/moves";
|
||||||
|
import { Species } from "#enums/species";
|
||||||
|
import Phaser from "phaser";
|
||||||
|
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
|
||||||
|
import { SPLASH_ONLY } from "../utils/testUtils";
|
||||||
|
|
||||||
|
|
||||||
|
describe("Moves - Baton Pass", () => {
|
||||||
|
let phaserGame: Phaser.Game;
|
||||||
|
let game: GameManager;
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
phaserGame = new Phaser.Game({
|
||||||
|
type: Phaser.HEADLESS,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
game.phaseInterceptor.restoreOg();
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
game = new GameManager(phaserGame);
|
||||||
|
game.override
|
||||||
|
.battleType("single")
|
||||||
|
.enemySpecies(Species.DUGTRIO)
|
||||||
|
.startingLevel(1)
|
||||||
|
.startingWave(97)
|
||||||
|
.moveset([Moves.BATON_PASS, Moves.NASTY_PLOT, Moves.SPLASH])
|
||||||
|
.enemyMoveset(SPLASH_ONLY)
|
||||||
|
.disableCrits();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("passes stat stage buffs when player uses it", async() => {
|
||||||
|
// arrange
|
||||||
|
await game.startBattle([
|
||||||
|
Species.RAICHU,
|
||||||
|
Species.SHUCKLE
|
||||||
|
]);
|
||||||
|
|
||||||
|
// round 1 - buff
|
||||||
|
game.doAttack(getMovePosition(game.scene, 0, Moves.NASTY_PLOT));
|
||||||
|
await game.toNextTurn();
|
||||||
|
expect(game.scene.getPlayerPokemon().summonData.battleStats[BattleStat.SPATK]).toEqual(2);
|
||||||
|
|
||||||
|
// round 2 - baton pass
|
||||||
|
game.doAttack(getMovePosition(game.scene, 0, Moves.BATON_PASS));
|
||||||
|
game.doSelectPartyPokemon(1);
|
||||||
|
await game.phaseInterceptor.to(TurnEndPhase);
|
||||||
|
|
||||||
|
// assert
|
||||||
|
expect(game.scene.getPlayerPokemon().species.speciesId).toEqual(Species.SHUCKLE);
|
||||||
|
expect(game.scene.getPlayerPokemon().summonData.battleStats[BattleStat.SPATK]).toEqual(2);
|
||||||
|
}, 20000);
|
||||||
|
|
||||||
|
it("passes stat stage buffs when AI uses it", async() => {
|
||||||
|
// arrange
|
||||||
|
game.override
|
||||||
|
.startingWave(5)
|
||||||
|
.enemyMoveset(new Array(4).fill([Moves.NASTY_PLOT]));
|
||||||
|
await game.startBattle([
|
||||||
|
Species.RAICHU,
|
||||||
|
Species.SHUCKLE
|
||||||
|
]);
|
||||||
|
|
||||||
|
// round 1 - ai buffs
|
||||||
|
game.doAttack(getMovePosition(game.scene, 0, Moves.SPLASH));
|
||||||
|
await game.toNextTurn();
|
||||||
|
|
||||||
|
// round 2 - baton pass
|
||||||
|
game.scene.getEnemyPokemon().hp = 100;
|
||||||
|
game.override.enemyMoveset(new Array(4).fill(Moves.BATON_PASS));
|
||||||
|
game.doAttack(getMovePosition(game.scene, 0, Moves.SPLASH));
|
||||||
|
await game.phaseInterceptor.to(PostSummonPhase, false);
|
||||||
|
|
||||||
|
// assert
|
||||||
|
// check buffs are still there
|
||||||
|
expect(game.scene.getEnemyPokemon().summonData.battleStats[BattleStat.SPATK]).toEqual(2);
|
||||||
|
// confirm that a switch actually happened. can't use species because I
|
||||||
|
// can't find a way to override trainer parties with more than 1 pokemon species
|
||||||
|
expect(game.scene.getEnemyPokemon().hp).not.toEqual(100);
|
||||||
|
expect(game.phaseInterceptor.log.slice(-4)).toEqual([
|
||||||
|
"MoveEffectPhase",
|
||||||
|
"SwitchSummonPhase",
|
||||||
|
"SummonPhase",
|
||||||
|
"PostSummonPhase"
|
||||||
|
]);
|
||||||
|
}, 20000);
|
||||||
|
});
|
98
src/test/moves/u_turn.test.ts
Normal file
98
src/test/moves/u_turn.test.ts
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
import { Abilities } from "#app/enums/abilities.js";
|
||||||
|
import { SwitchPhase, TurnEndPhase } from "#app/phases";
|
||||||
|
import GameManager from "#app/test/utils/gameManager";
|
||||||
|
import { getMovePosition } from "#app/test/utils/gameManagerUtils";
|
||||||
|
import { Moves } from "#enums/moves";
|
||||||
|
import { Species } from "#enums/species";
|
||||||
|
import Phaser from "phaser";
|
||||||
|
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
|
import { StatusEffect } from "#app/enums/status-effect.js";
|
||||||
|
import { SPLASH_ONLY } from "../utils/testUtils";
|
||||||
|
|
||||||
|
describe("Moves - U-turn", () => {
|
||||||
|
let phaserGame: Phaser.Game;
|
||||||
|
let game: GameManager;
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
phaserGame = new Phaser.Game({
|
||||||
|
type: Phaser.HEADLESS,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
game.phaseInterceptor.restoreOg();
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
game = new GameManager(phaserGame);
|
||||||
|
game.override
|
||||||
|
.battleType("single")
|
||||||
|
.enemySpecies(Species.GENGAR)
|
||||||
|
.startingLevel(90)
|
||||||
|
.startingWave(97)
|
||||||
|
.moveset([Moves.U_TURN])
|
||||||
|
.enemyMoveset(SPLASH_ONLY)
|
||||||
|
.disableCrits();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("triggers regenerator a single time when a regenerator user switches out with u-turn", async() => {
|
||||||
|
// arrange
|
||||||
|
const playerHp = 1;
|
||||||
|
game.override.ability(Abilities.REGENERATOR);
|
||||||
|
await game.startBattle([
|
||||||
|
Species.RAICHU,
|
||||||
|
Species.SHUCKLE
|
||||||
|
]);
|
||||||
|
game.scene.getPlayerPokemon().hp = playerHp;
|
||||||
|
|
||||||
|
// act
|
||||||
|
game.doAttack(getMovePosition(game.scene, 0, Moves.U_TURN));
|
||||||
|
game.doSelectPartyPokemon(1);
|
||||||
|
await game.phaseInterceptor.to(TurnEndPhase);
|
||||||
|
|
||||||
|
// assert
|
||||||
|
expect(game.scene.getParty()[1].hp).toEqual(Math.floor(game.scene.getParty()[1].getMaxHp() * 0.33 + playerHp));
|
||||||
|
expect(game.phaseInterceptor.log).toContain("SwitchSummonPhase");
|
||||||
|
expect(game.scene.getPlayerPokemon().species.speciesId).toBe(Species.SHUCKLE);
|
||||||
|
}, 20000);
|
||||||
|
|
||||||
|
it("triggers rough skin on the u-turn user before a new pokemon is switched in", async() => {
|
||||||
|
// arrange
|
||||||
|
game.override.enemyAbility(Abilities.ROUGH_SKIN);
|
||||||
|
await game.startBattle([
|
||||||
|
Species.RAICHU,
|
||||||
|
Species.SHUCKLE
|
||||||
|
]);
|
||||||
|
|
||||||
|
// act
|
||||||
|
game.doAttack(getMovePosition(game.scene, 0, Moves.U_TURN));
|
||||||
|
game.doSelectPartyPokemon(1);
|
||||||
|
await game.phaseInterceptor.to(SwitchPhase, false);
|
||||||
|
|
||||||
|
// assert
|
||||||
|
expect(game.scene.getPlayerPokemon().hp).not.toEqual(game.scene.getPlayerPokemon().getMaxHp());
|
||||||
|
expect(game.scene.getEnemyPokemon().battleData.abilityRevealed).toBe(true); // proxy for asserting ability activated
|
||||||
|
expect(game.scene.getPlayerPokemon().species.speciesId).toEqual(Species.RAICHU);
|
||||||
|
expect(game.phaseInterceptor.log).not.toContain("SwitchSummonPhase");
|
||||||
|
}, 20000);
|
||||||
|
|
||||||
|
it("triggers contact abilities on the u-turn user (eg poison point) before a new pokemon is switched in", async() => {
|
||||||
|
// arrange
|
||||||
|
game.override.enemyAbility(Abilities.POISON_POINT);
|
||||||
|
await game.startBattle([
|
||||||
|
Species.RAICHU,
|
||||||
|
Species.SHUCKLE
|
||||||
|
]);
|
||||||
|
vi.spyOn(game.scene.getEnemyPokemon(), "randSeedInt").mockReturnValue(0);
|
||||||
|
|
||||||
|
// act
|
||||||
|
game.doAttack(getMovePosition(game.scene, 0, Moves.U_TURN));
|
||||||
|
await game.phaseInterceptor.to(SwitchPhase, false);
|
||||||
|
|
||||||
|
// assert
|
||||||
|
expect(game.scene.getPlayerPokemon().status?.effect).toEqual(StatusEffect.POISON);
|
||||||
|
expect(game.scene.getPlayerPokemon().species.speciesId).toEqual(Species.RAICHU);
|
||||||
|
expect(game.scene.getEnemyPokemon().battleData.abilityRevealed).toBe(true); // proxy for asserting ability activated
|
||||||
|
expect(game.phaseInterceptor.log).not.toContain("SwitchSummonPhase");
|
||||||
|
}, 20000);
|
||||||
|
});
|
@ -1,7 +1,7 @@
|
|||||||
import GameWrapper from "#test/utils/gameWrapper";
|
import GameWrapper from "#test/utils/gameWrapper";
|
||||||
import { Mode } from "#app/ui/ui";
|
import { Mode } from "#app/ui/ui";
|
||||||
import { generateStarter, waitUntil } from "#test/utils/gameManagerUtils";
|
import { generateStarter, waitUntil } from "#test/utils/gameManagerUtils";
|
||||||
import { CommandPhase, EncounterPhase, FaintPhase, LoginPhase, NewBattlePhase, SelectStarterPhase, SelectTargetPhase, TitlePhase, TurnEndPhase, TurnInitPhase, TurnStartPhase } from "#app/phases";
|
import { CommandPhase, EncounterPhase, FaintPhase, LoginPhase, MovePhase, NewBattlePhase, SelectStarterPhase, SelectTargetPhase, TitlePhase, TurnEndPhase, TurnInitPhase, TurnStartPhase } from "#app/phases";
|
||||||
import BattleScene from "#app/battle-scene.js";
|
import BattleScene from "#app/battle-scene.js";
|
||||||
import PhaseInterceptor from "#test/utils/phaseInterceptor";
|
import PhaseInterceptor from "#test/utils/phaseInterceptor";
|
||||||
import TextInterceptor from "#test/utils/TextInterceptor";
|
import TextInterceptor from "#test/utils/TextInterceptor";
|
||||||
@ -9,13 +9,12 @@ import { GameModes, getGameMode } from "#app/game-mode";
|
|||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import { AES, enc } from "crypto-js";
|
import { AES, enc } from "crypto-js";
|
||||||
import { updateUserInfo } from "#app/account";
|
import { updateUserInfo } from "#app/account";
|
||||||
import InputsHandler from "#test/utils/inputsHandler";
|
import InputsHandler from "#app/test/utils/inputsHandler";
|
||||||
import ErrorInterceptor from "#test/utils/errorInterceptor";
|
import ErrorInterceptor from "#app/test/utils/errorInterceptor";
|
||||||
import { EnemyPokemon, PlayerPokemon } from "#app/field/pokemon";
|
import { EnemyPokemon, PlayerPokemon } from "#app/field/pokemon";
|
||||||
import { MockClock } from "#test/utils/mocks/mockClock";
|
import { MockClock } from "#app/test/utils/mocks/mockClock";
|
||||||
import { Command } from "#app/ui/command-ui-handler";
|
import PartyUiHandler from "#app/ui/party-ui-handler";
|
||||||
import ModifierSelectUiHandler from "#app/ui/modifier-select-ui-handler";
|
import CommandUiHandler, { Command } from "#app/ui/command-ui-handler";
|
||||||
import PartyUiHandler, { PartyUiMode } from "#app/ui/party-ui-handler";
|
|
||||||
import Trainer from "#app/field/trainer";
|
import Trainer from "#app/field/trainer";
|
||||||
import { ExpNotification } from "#enums/exp-notification";
|
import { ExpNotification } from "#enums/exp-notification";
|
||||||
import { GameDataType } from "#enums/game-data-type";
|
import { GameDataType } from "#enums/game-data-type";
|
||||||
@ -28,6 +27,7 @@ import { OverridesHelper } from "./overridesHelper";
|
|||||||
import { ModifierTypeOption, modifierTypes } from "#app/modifier/modifier-type.js";
|
import { ModifierTypeOption, modifierTypes } from "#app/modifier/modifier-type.js";
|
||||||
import overrides from "#app/overrides.js";
|
import overrides from "#app/overrides.js";
|
||||||
import { removeEnemyHeldItems } from "./testUtils";
|
import { removeEnemyHeldItems } from "./testUtils";
|
||||||
|
import ModifierSelectUiHandler from "#app/ui/modifier-select-ui-handler.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to manage the game state and transitions between phases.
|
* Class to manage the game state and transitions between phases.
|
||||||
@ -178,7 +178,7 @@ export default class GameManager {
|
|||||||
if (move.isMultiTarget()) {
|
if (move.isMultiTarget()) {
|
||||||
handler.processInput(Button.ACTION);
|
handler.processInput(Button.ACTION);
|
||||||
}
|
}
|
||||||
}, () => this.isCurrentPhase(CommandPhase) || this.isCurrentPhase(TurnEndPhase));
|
}, () => this.isCurrentPhase(CommandPhase) || this.isCurrentPhase(MovePhase) || this.isCurrentPhase(TurnEndPhase));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -313,20 +313,20 @@ export default class GameManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Switch pokemon and transition to the enemy command phase
|
* Command an in-battle switch to another Pokemon via the main battle menu.
|
||||||
* @param pokemonIndex the index of the pokemon in your party to switch to
|
* @param pokemonIndex the index of the pokemon in your party to switch to
|
||||||
*/
|
*/
|
||||||
doSwitchPokemon(pokemonIndex: number) {
|
doSwitchPokemon(pokemonIndex: number) {
|
||||||
this.onNextPrompt("CommandPhase", Mode.COMMAND, () => {
|
this.onNextPrompt("CommandPhase", Mode.COMMAND, () => {
|
||||||
this.scene.ui.setMode(Mode.PARTY, PartyUiMode.SWITCH, (this.scene.getCurrentPhase() as CommandPhase).getPokemon().getFieldIndex(), null, PartyUiHandler.FilterNonFainted);
|
(this.scene.ui.getHandler() as CommandUiHandler).setCursor(2);
|
||||||
});
|
(this.scene.ui.getHandler() as CommandUiHandler).processInput(Button.ACTION);
|
||||||
this.onNextPrompt("CommandPhase", Mode.PARTY, () => {
|
|
||||||
(this.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.POKEMON, pokemonIndex, false);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.doSelectPartyPokemon(pokemonIndex, "CommandPhase");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Revive pokemon, currently player's only.
|
* Revive pokemon, currently players only.
|
||||||
* @param pokemonIndex the index of the pokemon in your party to revive
|
* @param pokemonIndex the index of the pokemon in your party to revive
|
||||||
*/
|
*/
|
||||||
doRevivePokemon(pokemonIndex: number) {
|
doRevivePokemon(pokemonIndex: number) {
|
||||||
@ -335,4 +335,23 @@ export default class GameManager {
|
|||||||
const modifier = candidate.type.newModifier(party[pokemonIndex]);
|
const modifier = candidate.type.newModifier(party[pokemonIndex]);
|
||||||
this.scene.addModifier(modifier, false);
|
this.scene.addModifier(modifier, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Select a pokemon from the party menu. Only really handles the basic cases
|
||||||
|
* of the party UI, where you just need to navigate to a party slot and press
|
||||||
|
* Action twice - navigating any menus that come up after you select a party member
|
||||||
|
* is not supported.
|
||||||
|
* @param slot the index of the pokemon in your party to switch to
|
||||||
|
* @param inPhase Which phase to expect the selection to occur in. Typically
|
||||||
|
* non-command switch actions happen in SwitchPhase.
|
||||||
|
*/
|
||||||
|
doSelectPartyPokemon(slot: number, inPhase = "SwitchPhase") {
|
||||||
|
this.onNextPrompt(inPhase, Mode.PARTY, () => {
|
||||||
|
const partyHandler = this.scene.ui.getHandler() as PartyUiHandler;
|
||||||
|
|
||||||
|
partyHandler.setCursor(slot);
|
||||||
|
partyHandler.processInput(Button.ACTION); // select party slot
|
||||||
|
partyHandler.processInput(Button.ACTION); // send out (or whatever option is at the top)
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ import { QuietFormChangePhase } from "#app/form-change-phase";
|
|||||||
export default class PhaseInterceptor {
|
export default class PhaseInterceptor {
|
||||||
public scene;
|
public scene;
|
||||||
public phases = {};
|
public phases = {};
|
||||||
public log;
|
public log: string[];
|
||||||
private onHold;
|
private onHold;
|
||||||
private interval;
|
private interval;
|
||||||
private promptInterval;
|
private promptInterval;
|
||||||
@ -104,13 +104,20 @@ export default class PhaseInterceptor {
|
|||||||
*/
|
*/
|
||||||
constructor(scene) {
|
constructor(scene) {
|
||||||
this.scene = scene;
|
this.scene = scene;
|
||||||
this.log = [];
|
|
||||||
this.onHold = [];
|
this.onHold = [];
|
||||||
this.prompts = [];
|
this.prompts = [];
|
||||||
|
this.clearLogs();
|
||||||
this.startPromptHandler();
|
this.startPromptHandler();
|
||||||
this.initPhases();
|
this.initPhases();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears phase logs
|
||||||
|
*/
|
||||||
|
clearLogs() {
|
||||||
|
this.log = [];
|
||||||
|
}
|
||||||
|
|
||||||
rejectAll(error) {
|
rejectAll(error) {
|
||||||
if (this.inProgress) {
|
if (this.inProgress) {
|
||||||
clearInterval(this.promptInterval);
|
clearInterval(this.promptInterval);
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
import { CommandPhase, SelectModifierPhase } from "../phases";
|
import { CommandPhase, SelectModifierPhase } from "../phases";
|
||||||
import BattleScene from "../battle-scene";
|
import BattleScene from "../battle-scene";
|
||||||
import { PlayerPokemon, PokemonMove } from "../field/pokemon";
|
import { MoveResult, PlayerPokemon, PokemonMove } from "../field/pokemon";
|
||||||
import { addBBCodeTextObject, addTextObject, getTextColor, TextStyle } from "./text";
|
import { addBBCodeTextObject, addTextObject, getTextColor, TextStyle } from "./text";
|
||||||
import { Command } from "./command-ui-handler";
|
import { Command } from "./command-ui-handler";
|
||||||
import MessageUiHandler from "./message-ui-handler";
|
import MessageUiHandler from "./message-ui-handler";
|
||||||
import { Mode } from "./ui";
|
import { Mode } from "./ui";
|
||||||
import * as Utils from "../utils";
|
import * as Utils from "../utils";
|
||||||
import { PokemonBaseStatModifier, PokemonFormChangeItemModifier, PokemonHeldItemModifier, SwitchEffectTransferModifier } from "../modifier/modifier";
|
import { PokemonBaseStatModifier, PokemonFormChangeItemModifier, PokemonHeldItemModifier, SwitchEffectTransferModifier } from "../modifier/modifier";
|
||||||
import { allMoves } from "../data/move";
|
import { allMoves, ForceSwitchOutAttr } from "../data/move";
|
||||||
import { getGenderColor, getGenderSymbol } from "../data/gender";
|
import { getGenderColor, getGenderSymbol } from "../data/gender";
|
||||||
import { StatusEffect } from "../data/status-effect";
|
import { StatusEffect } from "../data/status-effect";
|
||||||
import PokemonIconAnimHandler, { PokemonIconAnimMode } from "./pokemon-icon-anim-handler";
|
import PokemonIconAnimHandler, { PokemonIconAnimMode } from "./pokemon-icon-anim-handler";
|
||||||
@ -25,18 +25,69 @@ import { getPokemonNameWithAffix } from "#app/messages.js";
|
|||||||
|
|
||||||
const defaultMessage = i18next.t("partyUiHandler:choosePokemon");
|
const defaultMessage = i18next.t("partyUiHandler:choosePokemon");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates the reason why the party UI is being opened.
|
||||||
|
*/
|
||||||
export enum PartyUiMode {
|
export enum PartyUiMode {
|
||||||
|
/**
|
||||||
|
* Indicates that the party UI is open because of a user-opted switch. This
|
||||||
|
* type of switch can be cancelled.
|
||||||
|
*/
|
||||||
SWITCH,
|
SWITCH,
|
||||||
|
/**
|
||||||
|
* Indicates that the party UI is open because of a faint or other forced
|
||||||
|
* switch (eg, move effect). This type of switch cannot be cancelled.
|
||||||
|
*/
|
||||||
FAINT_SWITCH,
|
FAINT_SWITCH,
|
||||||
|
/**
|
||||||
|
* Indicates that the party UI is open because of a start-of-encounter optional
|
||||||
|
* switch. This type of switch can be cancelled.
|
||||||
|
*/
|
||||||
POST_BATTLE_SWITCH,
|
POST_BATTLE_SWITCH,
|
||||||
|
/**
|
||||||
|
* Indicates that the party UI is open because of the move Revival Blessing.
|
||||||
|
* This selection cannot be cancelled.
|
||||||
|
*/
|
||||||
REVIVAL_BLESSING,
|
REVIVAL_BLESSING,
|
||||||
|
/**
|
||||||
|
* Indicates that the party UI is open to select a mon to apply a modifier to.
|
||||||
|
* This type of selection can be cancelled.
|
||||||
|
*/
|
||||||
MODIFIER,
|
MODIFIER,
|
||||||
|
/**
|
||||||
|
* Indicates that the party UI is open to select a mon to apply a move
|
||||||
|
* modifier to (such as an Ether or PP Up). This type of selection can be cancelled.
|
||||||
|
*/
|
||||||
MOVE_MODIFIER,
|
MOVE_MODIFIER,
|
||||||
|
/**
|
||||||
|
* Indicates that the party UI is open to select a mon to teach a TM. This
|
||||||
|
* type of selection can be cancelled.
|
||||||
|
*/
|
||||||
TM_MODIFIER,
|
TM_MODIFIER,
|
||||||
|
/**
|
||||||
|
* Indicates that the party UI is open to select a mon to remember a move.
|
||||||
|
* This type of selection can be cancelled.
|
||||||
|
*/
|
||||||
REMEMBER_MOVE_MODIFIER,
|
REMEMBER_MOVE_MODIFIER,
|
||||||
|
/**
|
||||||
|
* Indicates that the party UI is open to transfer items between mons. This
|
||||||
|
* type of selection can be cancelled.
|
||||||
|
*/
|
||||||
MODIFIER_TRANSFER,
|
MODIFIER_TRANSFER,
|
||||||
|
/**
|
||||||
|
* Indicates that the party UI is open because of a DNA Splicer. This
|
||||||
|
* type of selection can be cancelled.
|
||||||
|
*/
|
||||||
SPLICE,
|
SPLICE,
|
||||||
|
/**
|
||||||
|
* Indicates that the party UI is open to release a party member. This
|
||||||
|
* type of selection can be cancelled.
|
||||||
|
*/
|
||||||
RELEASE,
|
RELEASE,
|
||||||
|
/**
|
||||||
|
* Indicates that the party UI is open to check the team. This
|
||||||
|
* type of selection can be cancelled.
|
||||||
|
*/
|
||||||
CHECK
|
CHECK
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -767,10 +818,21 @@ export default class PartyUiHandler extends MessageUiHandler {
|
|||||||
case PartyUiMode.FAINT_SWITCH:
|
case PartyUiMode.FAINT_SWITCH:
|
||||||
case PartyUiMode.POST_BATTLE_SWITCH:
|
case PartyUiMode.POST_BATTLE_SWITCH:
|
||||||
if (this.cursor >= this.scene.currentBattle.getBattlerCount()) {
|
if (this.cursor >= this.scene.currentBattle.getBattlerCount()) {
|
||||||
this.options.push(PartyOption.SEND_OUT);
|
const allowBatonModifierSwitch =
|
||||||
if (this.partyUiMode !== PartyUiMode.FAINT_SWITCH
|
this.partyUiMode !== PartyUiMode.FAINT_SWITCH
|
||||||
&& this.scene.findModifier(m => m instanceof SwitchEffectTransferModifier
|
&& this.scene.findModifier(m => m instanceof SwitchEffectTransferModifier
|
||||||
&& (m as SwitchEffectTransferModifier).pokemonId === this.scene.getPlayerField()[this.fieldIndex].id)) {
|
&& (m as SwitchEffectTransferModifier).pokemonId === this.scene.getPlayerField()[this.fieldIndex].id);
|
||||||
|
|
||||||
|
const moveHistory = this.scene.getPlayerField()[this.fieldIndex].getMoveHistory();
|
||||||
|
const isBatonPassMove = this.partyUiMode === PartyUiMode.FAINT_SWITCH && moveHistory.length && allMoves[moveHistory[moveHistory.length - 1].move].getAttrs(ForceSwitchOutAttr)[0]?.isBatonPass() && moveHistory[moveHistory.length - 1].result === MoveResult.SUCCESS;
|
||||||
|
|
||||||
|
// isBatonPassMove and allowBatonModifierSwitch shouldn't ever be true
|
||||||
|
// at the same time, because they both explicitly check for a mutually
|
||||||
|
// exclusive partyUiMode. But better safe than sorry.
|
||||||
|
this.options.push(isBatonPassMove && !allowBatonModifierSwitch ? PartyOption.PASS_BATON : PartyOption.SEND_OUT);
|
||||||
|
if (allowBatonModifierSwitch && !isBatonPassMove) {
|
||||||
|
// the BATON modifier gives an extra switch option for
|
||||||
|
// pokemon-command switches, allowing buffs to be optionally passed
|
||||||
this.options.push(PartyOption.PASS_BATON);
|
this.options.push(PartyOption.PASS_BATON);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user