From 6c6821b47d96df23a6b71f508e1a810a70d4b1ec Mon Sep 17 00:00:00 2001 From: Sirz Benjie <142067137+SirzBenjie@users.noreply.github.com> Date: Sun, 11 May 2025 20:10:19 -0500 Subject: [PATCH] [Bug] [Move] Fix KO causing effects to occur twice (#5811) * Fix firstTarget calculation when a target was fainted * Update type annotation in applyMoveEffects Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> --------- Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> --- src/phases/move-effect-phase.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/phases/move-effect-phase.ts b/src/phases/move-effect-phase.ts index 462e4ba47b8..d067807486d 100644 --- a/src/phases/move-effect-phase.ts +++ b/src/phases/move-effect-phase.ts @@ -206,11 +206,13 @@ export class MoveEffectPhase extends PokemonPhase { * @throws Error if there was an unexpected hit check result */ private applyToTargets(user: Pokemon, targets: Pokemon[]): void { + let firstHit = true; for (const [i, target] of targets.entries()) { const [hitCheckResult, effectiveness] = this.hitChecks[i]; switch (hitCheckResult) { case HitCheckResult.HIT: - this.applyMoveEffects(target, effectiveness); + this.applyMoveEffects(target, effectiveness, firstHit); + firstHit = false; if (isFieldTargeted(this.move)) { // Stop processing other targets if the move is a field move return; @@ -763,15 +765,12 @@ export class MoveEffectPhase extends PokemonPhase { * - Invoking {@linkcode applyOnTargetEffects} if the move does not hit a substitute * - Triggering form changes and emergency exit / wimp out if this is the last hit * - * @param target the {@linkcode Pokemon} hit by this phase's move. - * @param effectiveness the effectiveness of the move (as previously evaluated in {@linkcode hitCheck}) + * @param target - the {@linkcode Pokemon} hit by this phase's move. + * @param effectiveness - The effectiveness of the move (as previously evaluated in {@linkcode hitCheck}) + * @param firstTarget - Whether this is the first target successfully struck by the move */ - protected applyMoveEffects(target: Pokemon, effectiveness: TypeDamageMultiplier): void { + protected applyMoveEffects(target: Pokemon, effectiveness: TypeDamageMultiplier, firstTarget: boolean): void { const user = this.getUserPokemon(); - - /** The first target hit by the move */ - const firstTarget = target === this.getTargets().find((_, i) => this.hitChecks[i][1] > 0); - if (isNullOrUndefined(user)) { return; }