From 1f418c9d902c1e1eff28bc7973e426cc74512808 Mon Sep 17 00:00:00 2001 From: Bertie690 Date: Tue, 31 Dec 2024 16:04:48 -0500 Subject: [PATCH] Fixed things --- src/battle-scene.ts | 2 +- src/field/pokemon.ts | 2 +- src/test/phases/learn-move-phase.test.ts | 66 ++++++++++++++---------- src/test/utils/helpers/moveHelper.ts | 17 +++--- 4 files changed, 49 insertions(+), 38 deletions(-) diff --git a/src/battle-scene.ts b/src/battle-scene.ts index 70e27467ab0..38179696128 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -1823,7 +1823,7 @@ export default class BattleScene extends SceneBase { this.currentBattle.battleScore += Math.ceil(scoreIncrease); } - getMaxExpLevel(ignoreLevelCap?: boolean): integer { + getMaxExpLevel(ignoreLevelCap: boolean = false): integer { if (Overrides.LEVEL_CAP_OVERRIDE > 0) { return Overrides.LEVEL_CAP_OVERRIDE; } else if (ignoreLevelCap || Overrides.LEVEL_CAP_OVERRIDE < 0) { diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 5344a7eb802..2f94cb0c51c 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -2383,7 +2383,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { * @param exp The amount of experience to add * @param ignoreLevelCap Whether to ignore level caps when adding experience (defaults to false) */ - addExp(exp: integer, ignoreLevelCap?: boolean) { + addExp(exp: integer, ignoreLevelCap: boolean = false) { const maxExpLevel = this.scene.getMaxExpLevel(ignoreLevelCap); const initialExp = this.exp; this.exp += exp; diff --git a/src/test/phases/learn-move-phase.test.ts b/src/test/phases/learn-move-phase.test.ts index 49a8839fe24..3a3d111f551 100644 --- a/src/test/phases/learn-move-phase.test.ts +++ b/src/test/phases/learn-move-phase.test.ts @@ -42,12 +42,12 @@ describe("Learn Move Phase", () => { }); it("If a pokemon has 4 move slots filled, the chosen move will be deleted and replaced", async () => { - await game.classicMode.startBattle([ Species.GALAR_MR_MIME ]); // many level up moves - const mrMime = game.scene.getPlayerPokemon()!; + await game.classicMode.startBattle([ Species.BULBASAUR ]); + const bulbasaur = game.scene.getPlayerPokemon()!; const prevMoveset = [ Moves.SPLASH, Moves.ABSORB, Moves.ACID, Moves.VINE_WHIP ]; const moveSlotNum = 3; - game.move.changeMoveset(mrMime, prevMoveset); + game.move.changeMoveset(bulbasaur, prevMoveset); game.move.select(Moves.SPLASH); await game.doKillOpponents(); @@ -63,23 +63,23 @@ describe("Learn Move Phase", () => { }); await game.phaseInterceptor.to(LearnMovePhase); - const levelMove = mrMime.getLevelMoves(5)[0]; + const levelMove = bulbasaur.getLevelMoves(5)[0]; const levelReq = levelMove[0]; const levelMoveId = levelMove[1]; - expect(mrMime.level).toBeGreaterThanOrEqual(levelReq); + expect(bulbasaur.level).toBeGreaterThanOrEqual(levelReq); // Check each of mr mime's moveslots to make sure the changed move (and ONLY the changed move) is different - mrMime.getMoveset().forEach((move, index) => { + bulbasaur.getMoveset().forEach((move, index) => { const expectedMove: Moves = (index === moveSlotNum ? levelMoveId : prevMoveset[index]); expect(move?.moveId).toBe(expectedMove); }); }); it("selecting the newly deleted move will reject it and keep old moveset", async () => { - await game.classicMode.startBattle([ Species.GALAR_MR_MIME ]); // many level up moves - const mrMime = game.scene.getPlayerPokemon()!; + await game.classicMode.startBattle([ Species.BULBASAUR ]); + const bulbasaur = game.scene.getPlayerPokemon()!; const prevMoveset = [ Moves.SPLASH, Moves.ABSORB, Moves.ACID, Moves.VINE_WHIP ]; - game.move.changeMoveset(mrMime, [ Moves.SPLASH, Moves.ABSORB, Moves.ACID, Moves.VINE_WHIP ]); + game.move.changeMoveset(bulbasaur, [ Moves.SPLASH, Moves.ABSORB, Moves.ACID, Moves.VINE_WHIP ]); game.move.select(Moves.SPLASH); await game.doKillOpponents(); @@ -98,38 +98,52 @@ describe("Learn Move Phase", () => { }); await game.phaseInterceptor.to(LearnMovePhase); - const levelReq = mrMime.getLevelMoves(5)[0][0]; - expect(mrMime.level).toBeGreaterThanOrEqual(levelReq); - expect(mrMime.getMoveset()).toEqual(prevMoveset); + const levelReq = bulbasaur.getLevelMoves(5)[0][0]; + expect(bulbasaur.level).toBeGreaterThanOrEqual(levelReq); + expect(bulbasaur.getMoveset().map(m => m?.moveId)).toEqual(prevMoveset); }); it("macro should add moves in free slots normally", async () => { - await game.classicMode.startBattle([ Species.GALAR_MR_MIME ]); - const mrMime = game.scene.getPlayerPokemon()!; + await game.classicMode.startBattle([ Species.BULBASAUR ]); + const bulbasaur = game.scene.getPlayerPokemon()!; - game.move.changeMoveset(mrMime, [ Moves.SPLASH, Moves.ABSORB, Moves.ACID ]); + game.move.changeMoveset(bulbasaur, [ Moves.SPLASH, Moves.ABSORB, Moves.ACID ]); + game.move.select(Moves.SPLASH); await game.move.learnMove(Moves.SACRED_FIRE, 0, 1); - expect(mrMime.getMoveset()).toEqual([ Moves.SPLASH, Moves.ABSORB, Moves.ACID, Moves.SACRED_FIRE ]); + expect(bulbasaur.getMoveset().map(m => m?.moveId)).toEqual([ Moves.SPLASH, Moves.ABSORB, Moves.ACID, Moves.SACRED_FIRE ]); }); it("macro should replace moves", async () => { - await game.classicMode.startBattle([ Species.GALAR_MR_MIME ]); - const mrMime = game.scene.getPlayerPokemon()!; + await game.classicMode.startBattle([ Species.BULBASAUR ]); + const bulbasaur = game.scene.getPlayerPokemon()!; - game.move.changeMoveset(mrMime, [ Moves.SPLASH, Moves.ABSORB, Moves.ACID, Moves.VINE_WHIP ]); - await game.move.learnMove(Moves.SACRED_FIRE, 0, 3); - expect(mrMime.getMoveset()).toEqual([ Moves.SPLASH, Moves.ABSORB, Moves.SACRED_FIRE, Moves.VINE_WHIP ]); + game.move.changeMoveset(bulbasaur, [ Moves.SPLASH, Moves.ABSORB, Moves.ACID, Moves.VINE_WHIP ]); + game.move.select(Moves.SPLASH); + await game.move.learnMove(Moves.SACRED_FIRE, 0, 1); + expect(bulbasaur.getMoveset().map(m => m?.moveId)).toEqual([ Moves.SPLASH, Moves.SACRED_FIRE, Moves.ACID, Moves.VINE_WHIP ]); }); - it("macro should cancel move learning", async () => { - await game.classicMode.startBattle([ Species.GALAR_MR_MIME ]); - const mrMime = game.scene.getPlayerPokemon()!; + it("macro should allow for cancelling move learning", async () => { + await game.classicMode.startBattle([ Species.BULBASAUR ]); + const bulbasaur = game.scene.getPlayerPokemon()!; - game.move.changeMoveset(mrMime, [ Moves.SPLASH, Moves.ABSORB, Moves.ACID, Moves.VINE_WHIP ]); + game.move.changeMoveset(bulbasaur, [ Moves.SPLASH, Moves.ABSORB, Moves.ACID, Moves.VINE_WHIP ]); + game.move.select(Moves.SPLASH); await game.move.learnMove(Moves.SACRED_FIRE, 0, 4); - expect(mrMime.getMoveset()).toEqual([ Moves.SPLASH, Moves.ABSORB, Moves.ACID, Moves.VINE_WHIP ]); + expect(bulbasaur.getMoveset().map(m => m?.moveId)).toEqual([ Moves.SPLASH, Moves.ABSORB, Moves.ACID, Moves.VINE_WHIP ]); + + }); + + it("macro works on off-field party members", async () => { + await game.classicMode.startBattle([ Species.BULBASAUR, Species.SQUIRTLE ]); + const squirtle = game.scene.getPlayerParty()[1]!; + + game.move.changeMoveset(squirtle, [ Moves.SPLASH, Moves.WATER_GUN, Moves.FREEZE_DRY, Moves.GROWL ]); + game.move.select(Moves.TACKLE); + await game.move.learnMove(Moves.SHELL_SMASH, 1, 0); + expect(squirtle.getMoveset().map(m => m?.moveId)).toEqual([ Moves.SHELL_SMASH, Moves.WATER_GUN, Moves.FREEZE_DRY, Moves.GROWL ]); }); diff --git a/src/test/utils/helpers/moveHelper.ts b/src/test/utils/helpers/moveHelper.ts index 2f10011f04f..3271f5d8cd8 100644 --- a/src/test/utils/helpers/moveHelper.ts +++ b/src/test/utils/helpers/moveHelper.ts @@ -98,30 +98,27 @@ export class MoveHelper extends GameManagerHelper { * Simulates learning a move for a player pokemon. * @param move The {@linkcode Moves} being learnt * @param partyIndex The party position of the {@linkcode PlayerPokemon} learning the move (defaults to 0) - * @param slot The move slot index (0-4) to replace if existent move slots are full; + * @param moveSlotIndex The INDEX (0-4) of the move slot to replace if existent move slots are full; * defaults to 0 (first slot) and 4 aborts the procedure * @returns a promise that resolves once the move has been successfully learnt */ - public async learnMove(move: Moves, partyIndex?: number, slot?: integer) { + public async learnMove(move: Moves | integer, partyIndex: integer = 0, moveSlotIndex: integer = 0) { return new Promise(async (resolve, reject) => { - if (partyIndex === undefined || partyIndex >= this.game.scene.getPlayerParty().length) { - partyIndex = 0; - } this.game.scene.pushPhase(new LearnMovePhase(this.game.scene, partyIndex, move)); // if slots are full, queue up inputs to replace existing moves if (this.game.scene.getPlayerParty()[partyIndex].moveset.filter(m => m).length === 4) { this.game.onNextPrompt("LearnMovePhase", Mode.CONFIRM, () => { - this.game.scene.ui.processInput(Button.ACTION); + this.game.scene.ui.processInput(Button.ACTION); // "Should a move be forgotten and replaced with XXX?" }); this.game.onNextPrompt("LearnMovePhase", Mode.SUMMARY, () => { - for (let x = 0; x < (slot ?? 0); x++) { - this.game.scene.ui.processInput(Button.DOWN); + for (let x = 0; x < (moveSlotIndex ?? 0); x++) { + this.game.scene.ui.processInput(Button.DOWN); // Scrolling in summary pane to move position } this.game.scene.ui.processInput(Button.ACTION); - if (slot === 4) { // hit confirm 1 last time to give up on learning move + if (moveSlotIndex === 4) { this.game.onNextPrompt("LearnMovePhase", Mode.CONFIRM, () => { - this.game.scene.ui.processInput(Button.ACTION); + this.game.scene.ui.processInput(Button.ACTION); // "Give up on learning XXX?" }); } });