mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-07-06 08:22:16 +02:00
Added tests for Last Resort regarding moveHistory
This commit is contained in:
parent
c34fd10ccb
commit
25446f3d1e
@ -7781,17 +7781,27 @@ export class StatusIfBoostedAttr extends MoveEffectAttr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attribute to fail move usage unless all of the user's other moves have been used at least once.
|
||||||
|
* Used by {@linkcode Moves.LAST_RESORT}.
|
||||||
|
*/
|
||||||
export class LastResortAttr extends MoveAttr {
|
export class LastResortAttr extends MoveAttr {
|
||||||
|
// TODO: Verify behavior as Bulbapedia page is _extremely_ poorly documented
|
||||||
getCondition(): MoveConditionFunc {
|
getCondition(): MoveConditionFunc {
|
||||||
return (user: Pokemon, target: Pokemon, move: Move) => {
|
return (user: Pokemon, _target: Pokemon, move: Move) => {
|
||||||
const uniqueUsedMoveIds = new Set<Moves>();
|
const movesInMoveset = new Set<Moves>(user.getMoveset().map(m => m.moveId));
|
||||||
const movesetMoveIds = user.getMoveset().map(m => m.moveId);
|
if (!movesInMoveset.delete(move.id) || !movesInMoveset.size) {
|
||||||
user.getMoveHistory().map(m => {
|
return false; // Last resort fails if used when not in user's moveset or no other moves exist
|
||||||
if (m.move !== move.id && movesetMoveIds.find(mm => mm === m.move)) {
|
}
|
||||||
uniqueUsedMoveIds.add(m.move);
|
|
||||||
}
|
const movesInHistory = new Set(
|
||||||
});
|
user.getMoveHistory()
|
||||||
return uniqueUsedMoveIds.size >= movesetMoveIds.length - 1;
|
.filter(m => !m.virtual) // TODO: Change to (m) => m < MoveUseType.INDIRECT after Dancer PR refactors virtual into enum
|
||||||
|
.map(m => m.move)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Since `Set.intersection()` is only present in ESNext, we have to coerce it to an array to check inclusion
|
||||||
|
return [...movesInMoveset].every(m => movesInHistory.has(m))
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -9009,6 +9019,7 @@ export function initMoves() {
|
|||||||
.soundBased()
|
.soundBased()
|
||||||
.target(MoveTarget.RANDOM_NEAR_ENEMY)
|
.target(MoveTarget.RANDOM_NEAR_ENEMY)
|
||||||
.partial(), // Does not lock the user, does not stop Pokemon from sleeping
|
.partial(), // Does not lock the user, does not stop Pokemon from sleeping
|
||||||
|
// Likely can make use of FrenzyAttr and an ArenaTag (just without the FrenzyMissFunc)
|
||||||
new SelfStatusMove(Moves.STOCKPILE, PokemonType.NORMAL, -1, 20, -1, 0, 3)
|
new SelfStatusMove(Moves.STOCKPILE, PokemonType.NORMAL, -1, 20, -1, 0, 3)
|
||||||
.condition(user => (user.getTag(StockpilingTag)?.stockpiledCount ?? 0) < 3)
|
.condition(user => (user.getTag(StockpilingTag)?.stockpiledCount ?? 0) < 3)
|
||||||
.attr(AddBattlerTagAttr, BattlerTagType.STOCKPILING, true),
|
.attr(AddBattlerTagAttr, BattlerTagType.STOCKPILING, true),
|
||||||
@ -9444,7 +9455,8 @@ export function initMoves() {
|
|||||||
.makesContact(true)
|
.makesContact(true)
|
||||||
.attr(PunishmentPowerAttr),
|
.attr(PunishmentPowerAttr),
|
||||||
new AttackMove(Moves.LAST_RESORT, PokemonType.NORMAL, MoveCategory.PHYSICAL, 140, 100, 5, -1, 0, 4)
|
new AttackMove(Moves.LAST_RESORT, PokemonType.NORMAL, MoveCategory.PHYSICAL, 140, 100, 5, -1, 0, 4)
|
||||||
.attr(LastResortAttr),
|
.attr(LastResortAttr)
|
||||||
|
.edgeCase(), // May or may not need to ignore remotely called moves depending on how it works
|
||||||
new StatusMove(Moves.WORRY_SEED, PokemonType.GRASS, 100, 10, -1, 0, 4)
|
new StatusMove(Moves.WORRY_SEED, PokemonType.GRASS, 100, 10, -1, 0, 4)
|
||||||
.attr(AbilityChangeAttr, Abilities.INSOMNIA)
|
.attr(AbilityChangeAttr, Abilities.INSOMNIA)
|
||||||
.reflectable(),
|
.reflectable(),
|
||||||
|
@ -7768,16 +7768,26 @@ export class PokemonSummonData {
|
|||||||
/** Array containing all berries eaten in the last turn; used by {@linkcode Abilities.CUD_CHEW} */
|
/** Array containing all berries eaten in the last turn; used by {@linkcode Abilities.CUD_CHEW} */
|
||||||
public berriesEatenLast: BerryType[] = [];
|
public berriesEatenLast: BerryType[] = [];
|
||||||
|
|
||||||
/** The number of turns the pokemon has passed since entering the battle */
|
/**
|
||||||
|
* The number of turns this pokemon has spent in the active position since entering the battle.
|
||||||
|
* Currently exclusively used for positioning the battle cursor.
|
||||||
|
*/
|
||||||
public turnCount = 1;
|
public turnCount = 1;
|
||||||
/** The number of turns the pokemon has passed since the start of the wave */
|
/**
|
||||||
|
* The number of turns this pokemon has spent in the active position since starting a new wave.
|
||||||
|
* Used for most "first turn only" conditions ({@linkcode Moves.FAKE_OUT | Fake Out}, {@linkcode Moves.FIRST_IMPRESSION | First Impression}, etc.)
|
||||||
|
*/
|
||||||
public waveTurnCount = 1;
|
public waveTurnCount = 1;
|
||||||
/** The list of moves the pokemon has used since entering the battle */
|
/**
|
||||||
|
* An array of all moves this pokemon has used since entering the battle.
|
||||||
|
* Used for most moves and abilities that check prior move usage or copy already-used moves.
|
||||||
|
*/
|
||||||
public moveHistory: TurnMove[] = [];
|
public moveHistory: TurnMove[] = [];
|
||||||
|
|
||||||
constructor(source?: PokemonSummonData | Partial<PokemonSummonData>) {
|
constructor(source?: PokemonSummonData | Partial<PokemonSummonData>) {
|
||||||
if (!isNullOrUndefined(source)) {
|
if (!isNullOrUndefined(source)) {
|
||||||
Object.assign(this, source)
|
Object.assign(this, source)
|
||||||
|
// TODO: Do we need these mapping statements?
|
||||||
this.moveset &&= this.moveset.map(m => PokemonMove.loadMove(m))
|
this.moveset &&= this.moveset.map(m => PokemonMove.loadMove(m))
|
||||||
this.tags &&= this.tags.map(t => loadBattlerTag(t))
|
this.tags &&= this.tags.map(t => loadBattlerTag(t))
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,8 @@ export class SwitchSummonPhase extends SummonPhase {
|
|||||||
!(this.player ? globalScene.getPlayerParty() : globalScene.getEnemyParty())[this.slotIndex])
|
!(this.player ? globalScene.getPlayerParty() : globalScene.getEnemyParty())[this.slotIndex])
|
||||||
) {
|
) {
|
||||||
if (this.player) {
|
if (this.player) {
|
||||||
return this.switchAndSummon();
|
this.switchAndSummon();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
globalScene.time.delayedCall(750, () => this.switchAndSummon());
|
globalScene.time.delayedCall(750, () => this.switchAndSummon());
|
||||||
return;
|
return;
|
||||||
|
@ -26,64 +26,71 @@ describe("Moves - Fake Out", () => {
|
|||||||
.moveset([Moves.FAKE_OUT, Moves.SPLASH])
|
.moveset([Moves.FAKE_OUT, Moves.SPLASH])
|
||||||
.enemyMoveset(Moves.SPLASH)
|
.enemyMoveset(Moves.SPLASH)
|
||||||
.enemyLevel(10)
|
.enemyLevel(10)
|
||||||
.startingLevel(10) // prevent LevelUpPhase from happening
|
.startingLevel(1) // prevent LevelUpPhase from happening
|
||||||
.disableCrits();
|
.disableCrits();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("can only be used on the first turn a pokemon is sent out in a battle", async () => {
|
it("should only work the first turn a pokemon is sent out in a battle", async () => {
|
||||||
await game.classicMode.startBattle([Species.FEEBAS]);
|
await game.classicMode.startBattle([Species.FEEBAS]);
|
||||||
|
|
||||||
const enemy = game.scene.getEnemyPokemon()!;
|
const corv = game.scene.getEnemyPokemon()!;
|
||||||
|
|
||||||
game.move.select(Moves.FAKE_OUT);
|
game.move.select(Moves.FAKE_OUT);
|
||||||
await game.toNextTurn();
|
await game.toNextTurn();
|
||||||
|
|
||||||
expect(enemy.hp).toBeLessThan(enemy.getMaxHp());
|
expect(corv.hp).toBeLessThan(corv.getMaxHp());
|
||||||
const postTurnOneHp = enemy.hp;
|
const postTurnOneHp = corv.hp;
|
||||||
|
|
||||||
game.move.select(Moves.FAKE_OUT);
|
game.move.select(Moves.FAKE_OUT);
|
||||||
await game.toNextTurn();
|
await game.toNextTurn();
|
||||||
|
|
||||||
expect(enemy.hp).toBe(postTurnOneHp);
|
expect(corv.hp).toBe(postTurnOneHp);
|
||||||
}, 20000);
|
});
|
||||||
|
|
||||||
// This is a PokeRogue buff to Fake Out
|
// This is a PokeRogue buff to Fake Out
|
||||||
it("can be used at the start of every wave even if the pokemon wasn't recalled", async () => {
|
it("should succeed at the start of each new wave, even if user wasn't recalled", async () => {
|
||||||
await game.classicMode.startBattle([Species.FEEBAS]);
|
await game.classicMode.startBattle([Species.FEEBAS]);
|
||||||
|
|
||||||
const enemy = game.scene.getEnemyPokemon()!;
|
// set hp to 1 for easy knockout
|
||||||
enemy.damageAndUpdate(enemy.getMaxHp() - 1);
|
game.scene.getEnemyPokemon()!.hp = 1;
|
||||||
|
|
||||||
game.move.select(Moves.FAKE_OUT);
|
game.move.select(Moves.FAKE_OUT);
|
||||||
await game.toNextWave();
|
await game.toNextWave();
|
||||||
|
|
||||||
game.move.select(Moves.FAKE_OUT);
|
game.move.select(Moves.FAKE_OUT);
|
||||||
await game.toNextTurn();
|
await game.toNextTurn();
|
||||||
|
|
||||||
expect(game.scene.getEnemyPokemon()!.isFullHp()).toBe(false);
|
const corv = game.scene.getEnemyPokemon()!;
|
||||||
}, 20000);
|
expect(corv).toBeDefined();
|
||||||
|
expect(corv?.hp).toBeLessThan(corv?.getMaxHp());
|
||||||
|
});
|
||||||
|
|
||||||
it("can be used again if recalled and sent back out", async () => {
|
// This is a PokeRogue buff to Fake Out
|
||||||
game.override.startingWave(4);
|
it("should succeed at the start of each new wave, even if user wasn't recalled", async () => {
|
||||||
|
await game.classicMode.startBattle([Species.FEEBAS]);
|
||||||
|
|
||||||
|
// set hp to 1 for easy knockout
|
||||||
|
game.scene.getEnemyPokemon()!.hp = 1;
|
||||||
|
game.move.select(Moves.FAKE_OUT);
|
||||||
|
await game.toNextWave();
|
||||||
|
|
||||||
|
game.move.select(Moves.FAKE_OUT);
|
||||||
|
await game.toNextTurn();
|
||||||
|
|
||||||
|
const corv = game.scene.getEnemyPokemon()!;
|
||||||
|
expect(corv).toBeDefined();
|
||||||
|
expect(corv.hp).toBeLessThan(corv.getMaxHp());
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should succeed if recalled and sent back out", async () => {
|
||||||
await game.classicMode.startBattle([Species.FEEBAS, Species.MAGIKARP]);
|
await game.classicMode.startBattle([Species.FEEBAS, Species.MAGIKARP]);
|
||||||
|
|
||||||
const enemy1 = game.scene.getEnemyPokemon()!;
|
|
||||||
|
|
||||||
game.move.select(Moves.FAKE_OUT);
|
|
||||||
await game.phaseInterceptor.to("MoveEndPhase");
|
|
||||||
|
|
||||||
expect(enemy1.hp).toBeLessThan(enemy1.getMaxHp());
|
|
||||||
|
|
||||||
await game.doKillOpponents();
|
|
||||||
await game.toNextWave();
|
|
||||||
|
|
||||||
game.move.select(Moves.FAKE_OUT);
|
game.move.select(Moves.FAKE_OUT);
|
||||||
await game.toNextTurn();
|
await game.toNextTurn();
|
||||||
|
|
||||||
const enemy2 = game.scene.getEnemyPokemon()!;
|
const corv = game.scene.getEnemyPokemon()!;
|
||||||
|
|
||||||
expect(enemy2.hp).toBeLessThan(enemy2.getMaxHp());
|
expect(corv.hp).toBeLessThan(corv.getMaxHp());
|
||||||
enemy2.hp = enemy2.getMaxHp();
|
corv.hp = corv.getMaxHp();
|
||||||
|
|
||||||
game.doSwitchPokemon(1);
|
game.doSwitchPokemon(1);
|
||||||
await game.toNextTurn();
|
await game.toNextTurn();
|
||||||
@ -94,6 +101,6 @@ describe("Moves - Fake Out", () => {
|
|||||||
game.move.select(Moves.FAKE_OUT);
|
game.move.select(Moves.FAKE_OUT);
|
||||||
await game.toNextTurn();
|
await game.toNextTurn();
|
||||||
|
|
||||||
expect(enemy2.hp).toBeLessThan(enemy2.getMaxHp());
|
expect(corv.hp).toBeLessThan(corv.getMaxHp());
|
||||||
}, 20000);
|
});
|
||||||
});
|
});
|
||||||
|
166
test/moves/last-resort.test.ts
Normal file
166
test/moves/last-resort.test.ts
Normal file
@ -0,0 +1,166 @@
|
|||||||
|
import { BattlerIndex } from "#app/battle";
|
||||||
|
import { MoveResult } from "#app/field/pokemon";
|
||||||
|
import { Abilities } from "#enums/abilities";
|
||||||
|
import { Moves } from "#enums/moves";
|
||||||
|
import { Species } from "#enums/species";
|
||||||
|
import GameManager from "#test/testUtils/gameManager";
|
||||||
|
import Phaser from "phaser";
|
||||||
|
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
|
||||||
|
|
||||||
|
describe("Moves - Last Resort", () => {
|
||||||
|
let phaserGame: Phaser.Game;
|
||||||
|
let game: GameManager;
|
||||||
|
|
||||||
|
function expectLastResortFail() {
|
||||||
|
expect(game.scene.getPlayerPokemon()?.getLastXMoves()[0]).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
move: Moves.LAST_RESORT,
|
||||||
|
result: MoveResult.FAIL,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
beforeAll(() => {
|
||||||
|
phaserGame = new Phaser.Game({
|
||||||
|
type: Phaser.HEADLESS,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
game.phaseInterceptor.restoreOg();
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
game = new GameManager(phaserGame);
|
||||||
|
game.override
|
||||||
|
.ability(Abilities.BALL_FETCH)
|
||||||
|
.battleStyle("single")
|
||||||
|
.disableCrits()
|
||||||
|
.enemySpecies(Species.MAGIKARP)
|
||||||
|
.enemyAbility(Abilities.BALL_FETCH)
|
||||||
|
.enemyMoveset(Moves.SPLASH);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should fail unless all other moves (excluding itself) has been used at least once", async () => {
|
||||||
|
game.override.moveset([Moves.LAST_RESORT, Moves.SPLASH, Moves.GROWL, Moves.GROWTH]);
|
||||||
|
await game.classicMode.startBattle([Species.BLISSEY]);
|
||||||
|
|
||||||
|
const blissey = game.scene.getPlayerPokemon()!;
|
||||||
|
expect(blissey).toBeDefined();
|
||||||
|
|
||||||
|
// Last resort by itself
|
||||||
|
game.move.select(Moves.LAST_RESORT);
|
||||||
|
await game.phaseInterceptor.to("TurnEndPhase");
|
||||||
|
expectLastResortFail();
|
||||||
|
|
||||||
|
// Splash (1/3)
|
||||||
|
blissey.pushMoveHistory({ move: Moves.SPLASH, targets: [BattlerIndex.PLAYER] });
|
||||||
|
game.move.select(Moves.LAST_RESORT);
|
||||||
|
await game.phaseInterceptor.to("TurnEndPhase");
|
||||||
|
expectLastResortFail();
|
||||||
|
|
||||||
|
// Growl (2/3)
|
||||||
|
blissey.pushMoveHistory({ move: Moves.GROWL, targets: [BattlerIndex.ENEMY] });
|
||||||
|
game.move.select(Moves.LAST_RESORT);
|
||||||
|
await game.phaseInterceptor.to("TurnEndPhase");
|
||||||
|
expectLastResortFail(); // Were last resort itself counted, it would error here
|
||||||
|
|
||||||
|
// Growth (3/3)
|
||||||
|
blissey.pushMoveHistory({ move: Moves.GROWTH, targets: [BattlerIndex.PLAYER] });
|
||||||
|
game.move.select(Moves.LAST_RESORT);
|
||||||
|
await game.phaseInterceptor.to("TurnEndPhase");
|
||||||
|
expect(game.scene.getPlayerPokemon()?.getLastXMoves()[0]).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
move: Moves.LAST_RESORT,
|
||||||
|
result: MoveResult.SUCCESS,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should disregard virtually invoked moves", async () => {
|
||||||
|
game.override
|
||||||
|
.moveset([Moves.LAST_RESORT, Moves.SWORDS_DANCE, Moves.ABSORB, Moves.MIRROR_MOVE])
|
||||||
|
.enemyMoveset([Moves.SWORDS_DANCE, Moves.ABSORB])
|
||||||
|
.ability(Abilities.DANCER)
|
||||||
|
.enemySpecies(Species.ABOMASNOW); // magikarp has 50% chance to be okho'd on absorb crit
|
||||||
|
await game.classicMode.startBattle([Species.BLISSEY]);
|
||||||
|
|
||||||
|
// use mirror move normally to trigger absorb virtually
|
||||||
|
game.move.select(Moves.MIRROR_MOVE);
|
||||||
|
await game.forceEnemyMove(Moves.ABSORB);
|
||||||
|
await game.toNextTurn();
|
||||||
|
|
||||||
|
game.move.select(Moves.LAST_RESORT);
|
||||||
|
await game.forceEnemyMove(Moves.SWORDS_DANCE); // goes first to proc dancer ahead of time
|
||||||
|
await game.setTurnOrder([BattlerIndex.ENEMY, BattlerIndex.PLAYER]);
|
||||||
|
await game.phaseInterceptor.to("TurnEndPhase");
|
||||||
|
expectLastResortFail();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should fail if no other moves in moveset", async () => {
|
||||||
|
game.override.moveset(Moves.LAST_RESORT);
|
||||||
|
await game.classicMode.startBattle([Species.BLISSEY]);
|
||||||
|
|
||||||
|
game.move.select(Moves.LAST_RESORT);
|
||||||
|
await game.phaseInterceptor.to("TurnEndPhase");
|
||||||
|
|
||||||
|
expectLastResortFail();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should work if invoked virtually when all other moves have been used", async () => {
|
||||||
|
game.override.moveset([Moves.LAST_RESORT, Moves.SLEEP_TALK]).ability(Abilities.COMATOSE);
|
||||||
|
await game.classicMode.startBattle([Species.KOMALA]);
|
||||||
|
|
||||||
|
game.move.select(Moves.SLEEP_TALK);
|
||||||
|
await game.phaseInterceptor.to("TurnEndPhase");
|
||||||
|
|
||||||
|
expect(game.scene.getPlayerPokemon()?.getLastXMoves(-1)).toEqual([
|
||||||
|
expect.objectContaining({
|
||||||
|
move: Moves.LAST_RESORT,
|
||||||
|
result: MoveResult.SUCCESS,
|
||||||
|
virtual: true,
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
move: Moves.SLEEP_TALK,
|
||||||
|
result: MoveResult.SUCCESS,
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should preserve usability status on reload", async () => {
|
||||||
|
game.override.moveset([Moves.LAST_RESORT, Moves.SPLASH]).ability(Abilities.COMATOSE);
|
||||||
|
await game.classicMode.startBattle([Species.BLISSEY]);
|
||||||
|
|
||||||
|
game.move.select(Moves.SPLASH);
|
||||||
|
await game.doKillOpponents();
|
||||||
|
await game.toNextWave();
|
||||||
|
|
||||||
|
const oldMoveHistory = game.scene.getPlayerPokemon()?.summonData.moveHistory;
|
||||||
|
await game.reload.reloadSession();
|
||||||
|
|
||||||
|
const newMoveHistory = game.scene.getPlayerPokemon()?.summonData.moveHistory;
|
||||||
|
expect(oldMoveHistory).toEqual(newMoveHistory);
|
||||||
|
|
||||||
|
// use last resort and it should kill the karp just fine
|
||||||
|
game.move.select(Moves.LAST_RESORT);
|
||||||
|
game.scene.getEnemyPokemon()!.hp = 1;
|
||||||
|
await game.phaseInterceptor.to("TurnEndPhase");
|
||||||
|
|
||||||
|
expect(game.isVictory()).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should fail if used while not in moveset", async () => {
|
||||||
|
game.override.moveset(Moves.MIRROR_MOVE).enemyMoveset([Moves.ABSORB, Moves.LAST_RESORT]);
|
||||||
|
await game.classicMode.startBattle([Species.BLISSEY]);
|
||||||
|
|
||||||
|
// ensure enemy last resort succeeds
|
||||||
|
game.move.select(Moves.MIRROR_MOVE);
|
||||||
|
await game.forceEnemyMove(Moves.ABSORB);
|
||||||
|
await game.phaseInterceptor.to("TurnEndPhase");
|
||||||
|
game.move.select(Moves.MIRROR_MOVE);
|
||||||
|
await game.forceEnemyMove(Moves.LAST_RESORT);
|
||||||
|
await game.setTurnOrder([BattlerIndex.ENEMY, BattlerIndex.PLAYER]);
|
||||||
|
await game.phaseInterceptor.to("TurnEndPhase");
|
||||||
|
|
||||||
|
expectLastResortFail();
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user