Adjust counter attr to use array.find

This commit is contained in:
Sirz Benjie 2025-08-19 00:00:03 -05:00
parent 8feaa8c86b
commit 5c7c87e075
No known key found for this signature in database
GPG Key ID: 4A524B4D196C759E
2 changed files with 7 additions and 18 deletions

View File

@ -1818,25 +1818,15 @@ export class CounterDamageAttr extends FixedDamageAttr {
}
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
user.turnData.attacksReceived.find(ar => {
const damage = user.turnData.attacksReceived.find(ar => {
const category = allMoves[ar.move].category;
return (category !== MoveCategory.STATUS || areAllies(user.getBattlerIndex(), ar.sourceBattlerIndex))
})
let damage = 0;
const userBattlerIndex = user.getBattlerIndex();
for (const ar of user.turnData.attacksReceived) {
// TODO: Adjust this for moves with variable damage categories
const category = allMoves[ar.move].category;
if (category === MoveCategory.STATUS
|| areAllies(userBattlerIndex, ar.sourceBattlerIndex)
|| (this.moveFilter && category !== this.moveFilter)) {
continue;
}
damage = ar.damage;
break;
}
return (
category !== MoveCategory.STATUS
&& !areAllies(user.getBattlerIndex(), ar.sourceBattlerIndex)
&& (this.moveFilter === undefined || category === this.moveFilter)
)
})?.damage ?? 0;
(args[0] as NumberHolder).value = toDmgValue(damage * this.multiplier);
return true;
}
}

View File

@ -909,7 +909,6 @@ export class MovePhase extends PokemonPhase {
*/
protected resolveCounterAttackTarget(): void {
if (this.targets.length !== 1 || this.targets[0] !== BattlerIndex.ATTACKER) {
console.log("%cSkipping counter attack target resolution", "color: blue");
return;
}