From e02b85629f833f4a0c408d1d82c3c22cb478c807 Mon Sep 17 00:00:00 2001 From: Benjamin Odom Date: Fri, 3 May 2024 19:47:28 -0500 Subject: [PATCH] Fix Enemy Counter Moves The AI couldn't decide who to target with CounterDamageAttr moves which don't need a target. This change makes an exception. Now functions the same as when the player selects one of these moves. --- src/field/pokemon.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 909d255ee..27728680c 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -4,7 +4,7 @@ import { Variant, VariantSet, variantColorCache } from '#app/data/variant'; import { variantData } from '#app/data/variant'; import BattleInfo, { PlayerBattleInfo, EnemyBattleInfo } from '../ui/battle-info'; import { Moves } from "../data/enums/moves"; -import Move, { HighCritAttr, HitsTagAttr, applyMoveAttrs, FixedDamageAttr, VariableAtkAttr, VariablePowerAttr, allMoves, MoveCategory, TypelessAttr, CritOnlyAttr, getMoveTargets, OneHitKOAttr, MultiHitAttr, StatusMoveTypeImmunityAttr, MoveTarget, VariableDefAttr, AttackMove, ModifiedDamageAttr, VariableMoveTypeMultiplierAttr, IgnoreOpponentStatChangesAttr, SacrificialAttr, VariableMoveTypeAttr, VariableMoveCategoryAttr } from "../data/move"; +import Move, { HighCritAttr, HitsTagAttr, applyMoveAttrs, FixedDamageAttr, VariableAtkAttr, VariablePowerAttr, allMoves, MoveCategory, TypelessAttr, CritOnlyAttr, getMoveTargets, OneHitKOAttr, MultiHitAttr, StatusMoveTypeImmunityAttr, MoveTarget, VariableDefAttr, AttackMove, ModifiedDamageAttr, VariableMoveTypeMultiplierAttr, IgnoreOpponentStatChangesAttr, SacrificialAttr, VariableMoveTypeAttr, VariableMoveCategoryAttr, CounterDamageAttr } from "../data/move"; import { default as PokemonSpecies, PokemonSpeciesForm, SpeciesFormKey, getFusedSpeciesName, getPokemonSpecies, getPokemonSpeciesForm, getStarterValueFriendshipCap, speciesStarters, starterPassiveAbilities } from '../data/pokemon-species'; import * as Utils from '../utils'; import { Type, TypeDamageMultiplier, getTypeDamageMultiplier, getTypeRgb } from '../data/type'; @@ -2731,6 +2731,10 @@ export class EnemyPokemon extends Pokemon { let targetScores: integer[] = []; for (let mt of moveTargets[move.id]) { + // Prevent a target score from being calculated when there isn't a target + if (mt === -1) + break; + const target = this.scene.getField()[mt]; let targetScore = move.getUserBenefitScore(this, target, move) + move.getTargetBenefitScore(this, target, move) * (mt < BattlerIndex.ENEMY === this.isPlayer() ? 1 : -1); if (move.name.endsWith(' (N)') || !move.applyConditions(this, target, move)) @@ -2801,8 +2805,14 @@ export class EnemyPokemon extends Pokemon { return scoreA < scoreB ? 1 : scoreA > scoreB ? -1 : 0; }); - if (!sortedBenefitScores.length) + if (!sortedBenefitScores.length) { + // Set target to -1 when using a counter move + // This is the same as when the player does so + if (!!move.findAttr(attr => attr instanceof CounterDamageAttr)) + return [-1]; + return []; + } let targetWeights = sortedBenefitScores.map(s => s[1]); const lowestWeight = targetWeights[targetWeights.length - 1];