Fix firstTarget calculation when a target was fainted

This commit is contained in:
Sirz Benjie 2025-05-10 16:42:57 -05:00
parent 0712f86462
commit a1fce52133
No known key found for this signature in database
GPG Key ID: 4A524B4D196C759E

View File

@ -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): 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;
}