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.pull/443/head
parent
ed24e03a6f
commit
e02b85629f
|
@ -4,7 +4,7 @@ import { Variant, VariantSet, variantColorCache } from '#app/data/variant';
|
||||||
import { variantData } from '#app/data/variant';
|
import { variantData } from '#app/data/variant';
|
||||||
import BattleInfo, { PlayerBattleInfo, EnemyBattleInfo } from '../ui/battle-info';
|
import BattleInfo, { PlayerBattleInfo, EnemyBattleInfo } from '../ui/battle-info';
|
||||||
import { Moves } from "../data/enums/moves";
|
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 { default as PokemonSpecies, PokemonSpeciesForm, SpeciesFormKey, getFusedSpeciesName, getPokemonSpecies, getPokemonSpeciesForm, getStarterValueFriendshipCap, speciesStarters, starterPassiveAbilities } from '../data/pokemon-species';
|
||||||
import * as Utils from '../utils';
|
import * as Utils from '../utils';
|
||||||
import { Type, TypeDamageMultiplier, getTypeDamageMultiplier, getTypeRgb } from '../data/type';
|
import { Type, TypeDamageMultiplier, getTypeDamageMultiplier, getTypeRgb } from '../data/type';
|
||||||
|
@ -2731,6 +2731,10 @@ export class EnemyPokemon extends Pokemon {
|
||||||
let targetScores: integer[] = [];
|
let targetScores: integer[] = [];
|
||||||
|
|
||||||
for (let mt of moveTargets[move.id]) {
|
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];
|
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);
|
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))
|
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;
|
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 [];
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
let targetWeights = sortedBenefitScores.map(s => s[1]);
|
let targetWeights = sortedBenefitScores.map(s => s[1]);
|
||||||
const lowestWeight = targetWeights[targetWeights.length - 1];
|
const lowestWeight = targetWeights[targetWeights.length - 1];
|
||||||
|
|
Loading…
Reference in New Issue