From bb09fdacdf301599c9c98f0cc4a7c4987bd0033c Mon Sep 17 00:00:00 2001 From: NightKev <34855794+DayKev@users.noreply.github.com> Date: Sun, 17 Nov 2024 15:20:17 -0800 Subject: [PATCH 1/2] Honey Gather and Pickup will only activate if the battle was won --- src/data/ability.ts | 20 +++++++++++-------- src/data/move.ts | 2 +- .../utils/encounter-phase-utils.ts | 2 +- src/phases/attempt-run-phase.ts | 2 +- src/phases/battle-end-phase.ts | 4 ++-- src/phases/victory-phase.ts | 2 +- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/data/ability.ts b/src/data/ability.ts index 1697c816902a..6849ec41601b 100644 --- a/src/data/ability.ts +++ b/src/data/ability.ts @@ -4112,9 +4112,13 @@ export class PostBattleAbAttr extends AbAttr { } export class PostBattleLootAbAttr extends PostBattleAbAttr { + /** + * @param args - `[0]`: boolean for if the battle ended in a victory + * @returns `true` if successful + */ applyPostBattle(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean { const postBattleLoot = pokemon.scene.currentBattle.postBattleLoot; - if (!simulated && postBattleLoot.length) { + if (!simulated && postBattleLoot.length && args[0]) { const randItem = Utils.randSeedItem(postBattleLoot); //@ts-ignore - TODO see below if (pokemon.scene.tryTransferHeldItemModifier(randItem, pokemon, true, 1, true, undefined, false)) { // TODO: fix. This is a promise!? @@ -4575,14 +4579,15 @@ export class MoneyAbAttr extends PostBattleAbAttr { /** * @param pokemon {@linkcode Pokemon} that is the user of this ability. * @param passive N/A - * @param args N/A - * @returns true + * @param args - `[0]`: boolean for if the battle ended in a victory + * @returns `true` if successful */ applyPostBattle(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean { - if (!simulated) { + if (!simulated && args[0]) { pokemon.scene.currentBattle.moneyScattered += pokemon.scene.getWaveMoneyAmount(0.2); + return true; } - return true; + return false; } } @@ -4590,13 +4595,12 @@ export class MoneyAbAttr extends PostBattleAbAttr { * Applies a stat change after a Pokémon is summoned, * conditioned on the presence of a specific arena tag. * - * @extends {PostSummonStatStageChangeAbAttr} + * @extends PostSummonStatStageChangeAbAttr */ export class PostSummonStatStageChangeOnArenaAbAttr extends PostSummonStatStageChangeAbAttr { /** * The type of arena tag that conditions the stat change. * @private - * @type {ArenaTagType} */ private tagType: ArenaTagType; @@ -4972,7 +4976,7 @@ class ForceSwitchOutHelper { pokemon.scene.clearEnemyHeldItemModifiers(); if (switchOutTarget.hp) { - pokemon.scene.pushPhase(new BattleEndPhase(pokemon.scene)); + pokemon.scene.pushPhase(new BattleEndPhase(pokemon.scene, false)); pokemon.scene.pushPhase(new NewBattlePhase(pokemon.scene)); } } diff --git a/src/data/move.ts b/src/data/move.ts index 2ac4d74b712f..30477bbe46f6 100644 --- a/src/data/move.ts +++ b/src/data/move.ts @@ -6035,7 +6035,7 @@ export class ForceSwitchOutAttr extends MoveEffectAttr { user.scene.clearEnemyHeldItemModifiers(); if (switchOutTarget.hp) { - user.scene.pushPhase(new BattleEndPhase(user.scene)); + user.scene.pushPhase(new BattleEndPhase(user.scene, false)); user.scene.pushPhase(new NewBattlePhase(user.scene)); } } diff --git a/src/data/mystery-encounters/utils/encounter-phase-utils.ts b/src/data/mystery-encounters/utils/encounter-phase-utils.ts index c6dda1343461..b5dd43a9221a 100644 --- a/src/data/mystery-encounters/utils/encounter-phase-utils.ts +++ b/src/data/mystery-encounters/utils/encounter-phase-utils.ts @@ -731,7 +731,7 @@ export function handleMysteryEncounterVictory(scene: BattleScene, addHealPhase: scene.pushPhase(new MysteryEncounterRewardsPhase(scene, addHealPhase)); scene.pushPhase(new EggLapsePhase(scene)); } else if (!scene.getEnemyParty().find(p => encounter.encounterMode !== MysteryEncounterMode.TRAINER_BATTLE ? p.isOnField() : !p?.isFainted(true))) { - scene.pushPhase(new BattleEndPhase(scene)); + scene.pushPhase(new BattleEndPhase(scene, true)); if (encounter.encounterMode === MysteryEncounterMode.TRAINER_BATTLE) { scene.pushPhase(new TrainerVictoryPhase(scene)); } diff --git a/src/phases/attempt-run-phase.ts b/src/phases/attempt-run-phase.ts index b4768dc9a26f..109fc5b582d5 100644 --- a/src/phases/attempt-run-phase.ts +++ b/src/phases/attempt-run-phase.ts @@ -52,7 +52,7 @@ export class AttemptRunPhase extends PokemonPhase { enemyPokemon.trySetStatus(StatusEffect.FAINT); }); - this.scene.pushPhase(new BattleEndPhase(this.scene)); + this.scene.pushPhase(new BattleEndPhase(this.scene, false)); this.scene.pushPhase(new NewBattlePhase(this.scene)); } else { playerPokemon.turnData.failedRunAway = true; diff --git a/src/phases/battle-end-phase.ts b/src/phases/battle-end-phase.ts index 3b9ca012ef79..eb6a112960ea 100644 --- a/src/phases/battle-end-phase.ts +++ b/src/phases/battle-end-phase.ts @@ -8,7 +8,7 @@ export class BattleEndPhase extends BattlePhase { /** If true, will increment battles won */ isVictory: boolean; - constructor(scene: BattleScene, isVictory: boolean = true) { + constructor(scene: BattleScene, isVictory: boolean) { super(scene); this.isVictory = isVictory; @@ -42,7 +42,7 @@ export class BattleEndPhase extends BattlePhase { } for (const pokemon of this.scene.getPokemonAllowedInBattle()) { - applyPostBattleAbAttrs(PostBattleAbAttr, pokemon); + applyPostBattleAbAttrs(PostBattleAbAttr, pokemon, false, this.isVictory); } if (this.scene.currentBattle.moneyScattered) { diff --git a/src/phases/victory-phase.ts b/src/phases/victory-phase.ts index 1faa31655dfe..62479241a6ce 100644 --- a/src/phases/victory-phase.ts +++ b/src/phases/victory-phase.ts @@ -41,7 +41,7 @@ export class VictoryPhase extends PokemonPhase { } if (!this.scene.getEnemyParty().find(p => this.scene.currentBattle.battleType === BattleType.WILD ? p.isOnField() : !p?.isFainted(true))) { - this.scene.pushPhase(new BattleEndPhase(this.scene)); + this.scene.pushPhase(new BattleEndPhase(this.scene, true)); if (this.scene.currentBattle.battleType === BattleType.TRAINER) { this.scene.pushPhase(new TrainerVictoryPhase(this.scene)); } From f7a3c0ea008d5ca552b0247835bcd34484dff74e Mon Sep 17 00:00:00 2001 From: NightKev <34855794+DayKev@users.noreply.github.com> Date: Mon, 18 Nov 2024 21:42:27 -0800 Subject: [PATCH 2/2] Add tests for Honey Gather --- src/test/abilities/honey_gather.test.ts | 74 +++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/test/abilities/honey_gather.test.ts diff --git a/src/test/abilities/honey_gather.test.ts b/src/test/abilities/honey_gather.test.ts new file mode 100644 index 000000000000..fc9d6cdd1500 --- /dev/null +++ b/src/test/abilities/honey_gather.test.ts @@ -0,0 +1,74 @@ +import type { CommandPhase } from "#app/phases/command-phase"; +import { Command } from "#app/ui/command-ui-handler"; +import { Abilities } from "#enums/abilities"; +import { Moves } from "#enums/moves"; +import { Species } from "#enums/species"; +import GameManager from "#test/utils/gameManager"; +import Phaser from "phaser"; +import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; + +describe("Abilities - Honey Gather", () => { + 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 + .moveset([ Moves.SPLASH, Moves.ROAR, Moves.THUNDERBOLT ]) + .startingLevel(100) + .ability(Abilities.HONEY_GATHER) + .passiveAbility(Abilities.RUN_AWAY) + .battleType("single") + .disableCrits() + .enemySpecies(Species.MAGIKARP) + .enemyAbility(Abilities.BALL_FETCH) + .enemyMoveset(Moves.SPLASH); + }); + + it("should give money when winning a battle", async () => { + await game.classicMode.startBattle([ Species.MILOTIC ]); + game.scene.money = 1000; + + game.move.select(Moves.THUNDERBOLT); + await game.toNextWave(); + + expect(game.scene.money).toBeGreaterThan(1000); + }); + + it("should not give money when the enemy pokemon flees", async () => { + await game.classicMode.startBattle([ Species.MILOTIC ]); + game.scene.money = 1000; + + game.move.select(Moves.ROAR); + await game.toNextTurn(); + + expect(game.scene.money).toBe(1000); + expect(game.scene.currentBattle.waveIndex).toBe(2); + }); + + it("should not give money when the player flees", async () => { + await game.classicMode.startBattle([ Species.MILOTIC ]); + game.scene.money = 1000; + + // something weird is going on with the test framework, so this is required to prevent a crash + const enemy = game.scene.getEnemyPokemon()!; + vi.spyOn(enemy, "scene", "get").mockReturnValue(game.scene); + + const commandPhase = game.scene.getCurrentPhase() as CommandPhase; + commandPhase.handleCommand(Command.RUN, 0); + await game.toNextTurn(); + + expect(game.scene.money).toBe(1000); + expect(game.scene.currentBattle.waveIndex).toBe(2); + }); +});