Skip to content

Commit

Permalink
Sim: Fix targetting of moves with a pressureTarget
Browse files Browse the repository at this point in the history
  • Loading branch information
Slayer95 committed Mar 28, 2019
1 parent 628e533 commit 6a11d55
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions data/mods/gen3/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ let BattleScripts = {
return false;
}

const targets = pokemon.getMoveTargets(move, target);
const {targets, pressureTargets} = pokemon.getMoveTargets(move, target);

if (!sourceEffect || sourceEffect.id === 'pursuit') {
let extraPP = 0;
for (const source of targets) {
for (const source of pressureTargets) {
const ppDrop = this.runEvent('DeductPP', source, pokemon, move);
if (ppDrop !== true) {
extraPP += ppDrop || 0;
Expand Down
4 changes: 2 additions & 2 deletions data/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,11 @@ let BattleScripts = {
return false;
}

let targets = pokemon.getMoveTargets(move, target);
const {targets, pressureTargets} = pokemon.getMoveTargets(move, target);

if (!sourceEffect || sourceEffect.id === 'pursuit') {
let extraPP = 0;
for (const source of targets) {
for (const source of pressureTargets) {
let ppDrop = this.runEvent('DeductPP', source, pokemon, move);
if (ppDrop !== true) {
extraPP += ppDrop || 0;
Expand Down
13 changes: 8 additions & 5 deletions sim/pokemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,10 @@ export class Pokemon {
return this.foes().filter(foe => this.battle.isAdjacent(this, foe));
}

getMoveTargets(move: Move, target: Pokemon): Pokemon[] {
getMoveTargets(move: Move, target: Pokemon): {targets: Pokemon[], pressureTargets: Pokemon[]} {
const targets = [];
let pressureTargets;

switch (move.target) {
case 'all':
case 'foeSide':
Expand Down Expand Up @@ -591,7 +593,7 @@ export class Pokemon {
if (!target || (target.fainted && target.side !== this.side)) {
// If a targeted foe faints, the move is retargeted
const possibleTarget = this.battle.resolveTarget(this, move);
if (!possibleTarget) return [];
if (!possibleTarget) return {targets: [], pressureTargets: []};
target = possibleTarget;
}
if (target.side.active.length > 1) {
Expand All @@ -602,7 +604,7 @@ export class Pokemon {
}
}
if (target.fainted) {
return [];
return {targets: [], pressureTargets: []};
}
if (selectedTarget !== target) {
this.battle.retargetLastMove(target);
Expand All @@ -613,11 +615,12 @@ export class Pokemon {
if (move.pressureTarget) {
// At the moment, this is the only supported target.
if (move.pressureTarget === 'foeSide') {
targets.push(...this.foes());
pressureTargets = this.foes();
}
}
}
return targets;

return {targets, pressureTargets: pressureTargets || targets};
}

ignoringAbility() {
Expand Down

0 comments on commit 6a11d55

Please sign in to comment.