Fix issues with logic related to AI targeting and types

pull/2/head
Flashfyre 2023-07-04 15:25:11 -04:00
parent 05fe3b899c
commit 64da443fa6
2 changed files with 37 additions and 7 deletions

View File

@ -2182,7 +2182,7 @@ export function getMoveTargets(user: Pokemon, move: Moves): MoveTargetSet {
return { targets: set.filter(t => t !== undefined), multiple }; return { targets: set.filter(t => t !== undefined), multiple };
} }
export const allMoves = [ export const allMoves: Move[] = [
new StatusMove(Moves.NONE, "-", Type.NORMAL, MoveCategory.STATUS, -1, -1, "", -1, 0, 1), new StatusMove(Moves.NONE, "-", Type.NORMAL, MoveCategory.STATUS, -1, -1, "", -1, 0, 1),
]; ];

View File

@ -411,7 +411,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
types.push(speciesForm.type1); types.push(speciesForm.type1);
if (speciesForm.type2 !== null) if (speciesForm.type2 !== null)
types.push(speciesForm.type1); types.push(speciesForm.type2);
} }
if (this.getTag(BattlerTagType.IGNORE_FLYING) || this.scene.arena.getTag(ArenaTagType.GRAVITY)) { if (this.getTag(BattlerTagType.IGNORE_FLYING) || this.scene.arena.getTag(ArenaTagType.GRAVITY)) {
@ -440,7 +440,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
getAttackMoveEffectiveness(moveType: Type): TypeDamageMultiplier { getAttackMoveEffectiveness(moveType: Type): TypeDamageMultiplier {
const types = this.getTypes(); const types = this.getTypes();
return getTypeDamageMultiplier(moveType, types[0]) * (types.length ? getTypeDamageMultiplier(moveType, types[1]) : 1) as TypeDamageMultiplier; return getTypeDamageMultiplier(moveType, types[0]) * (types.length > 1 ? getTypeDamageMultiplier(moveType, types[1]) : 1) as TypeDamageMultiplier;
} }
getEvolution(): SpeciesEvolution { getEvolution(): SpeciesEvolution {
@ -1206,7 +1206,7 @@ export class EnemyPokemon extends Pokemon {
const move = allMoves[moveId]; const move = allMoves[moveId];
let benefitScores = targets const benefitScores = targets
.map(p => [ p.getBattlerIndex(), move.getTargetBenefitScore(this, p, move) * (p.isPlayer() === this.isPlayer() ? 1 : -1) ]); .map(p => [ p.getBattlerIndex(), move.getTargetBenefitScore(this, p, move) * (p.isPlayer() === this.isPlayer() ? 1 : -1) ]);
const sortedBenefitScores = benefitScores.slice(0); const sortedBenefitScores = benefitScores.slice(0);
@ -1216,12 +1216,42 @@ export class EnemyPokemon extends Pokemon {
return scoreA < scoreB ? 1 : scoreA > scoreB ? -1 : 0; return scoreA < scoreB ? 1 : scoreA > scoreB ? -1 : 0;
}); });
// TODO: Add some randomness
if (!sortedBenefitScores.length) if (!sortedBenefitScores.length)
return []; return [];
return [ sortedBenefitScores[0][0] ]; let targetWeights = sortedBenefitScores.map(s => s[1]);
const lowestWeight = targetWeights[targetWeights.length - 1];
if (lowestWeight < 1) {
for (let w = 0; w < targetWeights.length; w++)
targetWeights[w] += Math.abs(lowestWeight - 1);
}
const benefitCutoffIndex = targetWeights.findIndex(s => s < targetWeights[0] / 2);
if (benefitCutoffIndex > -1)
targetWeights = targetWeights.slice(0, benefitCutoffIndex);
const thresholds: integer[] = [];
let totalWeight: integer;
targetWeights.reduce((total: integer, w: integer) => {
total += w;
thresholds.push(total);
totalWeight = total;
return total;
}, 0);
const randValue = Utils.randInt(totalWeight);
let targetIndex: integer;
thresholds.every((t, i) => {
if (randValue >= t)
return true;
targetIndex = i;
return false;
});
return [ sortedBenefitScores[targetIndex][0] ];
} }
isPlayer() { isPlayer() {