Skip to content

Commit

Permalink
Sim: Fix target resolution from empty ally slots
Browse files Browse the repository at this point in the history
  • Loading branch information
Slayer95 committed Mar 27, 2019
1 parent b65e6f6 commit 628e533
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
15 changes: 6 additions & 9 deletions sim/battle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2185,16 +2185,13 @@ export class Battle extends Dex.ModdedDex {
} else {
target = pokemon.side.active[-targetLoc - 1];
}
if (target) {
if (!target.fainted) {
// target exists and is not fainted
return target;
} else if (target.side === pokemon.side) {
// fainted allied targets don't retarget
return null;
}
if (target && !(target.fainted && target.side !== pokemon.side)) {
// We aren't targetting a fainted foe.
return target;
}
// chosen target not valid, retarget randomly with resolveTarget

// Chosen target not valid,
// retarget randomly with resolveTarget
}
return this.resolveTarget(pokemon, move);
}
Expand Down
3 changes: 3 additions & 0 deletions sim/pokemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,9 @@ export class Pokemon {
target = this.battle.priorityEvent('RedirectTarget', this, this, this.battle.getActiveMove(move), target);
}
}
if (target.fainted) {
return [];
}
if (selectedTarget !== target) {
this.battle.retargetLastMove(target);
}
Expand Down
6 changes: 3 additions & 3 deletions test/simulator/misc/target-resolution.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('Target Resolution', function () {
const newHps = activePokemonList.map(pokemon => pokemon.hp);

assert.deepStrictEqual(prevHps, newHps);
assert(battle.log.includes('|move|p1a: Wailord|Water Pulse|null|[notarget]'));
assert(battle.log.includes('|move|p1a: Wailord|Water Pulse|p1: Latias|[notarget]'));
assert(battle.log.includes('|-fail|p1a: Wailord'));
});

Expand Down Expand Up @@ -136,9 +136,9 @@ describe('Target Resolution', function () {
const newHps = attackers.map(pokemon => pokemon.hp);

assert.deepStrictEqual(prevHps, newHps);
assert(battle.log.includes('|move|p1a: Wailord|Water Pulse|null|[notarget]'));
assert(battle.log.includes('|move|p1a: Wailord|Water Pulse|p1: Shedinja|[notarget]'));
assert(battle.log.includes('|-fail|p1a: Wailord'));
assert(battle.log.includes('|move|p2a: Wailord|Water Pulse|null|[notarget]'));
assert(battle.log.includes('|move|p2a: Wailord|Water Pulse|p2: Shedinja|[notarget]'));
assert(battle.log.includes('|-fail|p2a: Wailord'));
});

Expand Down

0 comments on commit 628e533

Please sign in to comment.