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 { 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; const category = allMoves[ar.move].category;
return (category !== MoveCategory.STATUS || areAllies(user.getBattlerIndex(), ar.sourceBattlerIndex)) return (
}) category !== MoveCategory.STATUS
let damage = 0; && !areAllies(user.getBattlerIndex(), ar.sourceBattlerIndex)
const userBattlerIndex = user.getBattlerIndex(); && (this.moveFilter === undefined || category === this.moveFilter)
for (const ar of user.turnData.attacksReceived) { )
// TODO: Adjust this for moves with variable damage categories })?.damage ?? 0;
const category = allMoves[ar.move].category;
if (category === MoveCategory.STATUS
|| areAllies(userBattlerIndex, ar.sourceBattlerIndex)
|| (this.moveFilter && category !== this.moveFilter)) {
continue;
}
damage = ar.damage;
break;
}
(args[0] as NumberHolder).value = toDmgValue(damage * this.multiplier); (args[0] as NumberHolder).value = toDmgValue(damage * this.multiplier);
return true; return true;
} }
} }

View File

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