Remove unnecessary RNG roll for targeting

This should make singles battles faster and more accurate
This commit is contained in:
Annika
2022-11-04 17:03:16 -07:00
parent 91b543d2bf
commit 3eda79ccb2
7 changed files with 14 additions and 12 deletions

View File

@@ -2229,13 +2229,15 @@ export class Battle {
// when used without an explicit target.
move = this.dex.moves.get(move);
if (move.target === 'adjacentAlly') {
if (['self', 'all', 'allySide', 'allyTeam', 'adjacentAllyOrSelf'].includes(move.target)) {
return pokemon;
} else if (move.target === 'adjacentAlly') {
if (this.gameType === 'singles') return null;
const adjacentAllies = pokemon.adjacentAllies();
return adjacentAllies.length ? this.sample(adjacentAllies) : null;
}
if (['self', 'all', 'allySide', 'allyTeam', 'adjacentAllyOrSelf'].includes(move.target)) {
return pokemon;
}
if (this.gameType === 'singles') return pokemon.side.foe.active[0];
if (this.activePerHalf > 2) {
if (move.target === 'adjacentFoe' || move.target === 'normal' || move.target === 'randomNormal') {
// even if a move can target an ally, auto-resolution will never make it target an ally

View File

@@ -11,7 +11,7 @@ describe(`Cursed Body`, function () {
});
it(`should be able to disable Z-moves (not the base of Z-moves)`, function () {
battle = common.createBattle({seed: [1, 2, 3, 98]}, [[ // hardcoded seed to force Cursed Body
battle = common.createBattle({seed: [1, 2, 3, 5]}, [[ // hardcoded seed to force Cursed Body
{species: 'gengar', ability: 'cursedbody', item: 'focussash', moves: ['sleeptalk']},
], [
{species: 'kommoo', item: 'kommoniumz', moves: ['clangingscales', 'sleeptalk']},

View File

@@ -239,7 +239,7 @@ describe(`Emergency Exit`, function () {
});
it(`should be suppressed by Sheer Force`, function () {
battle = common.createBattle([
battle = common.createBattle({seed: [1, 2, 3, 4]}, [
[{species: "Golisopod", ability: 'emergencyexit', moves: ['sleeptalk'], ivs: EMPTY_IVS}, {species: "Clefable", ability: 'Unaware', moves: ['metronome']}],
[{species: "Nidoking", ability: 'sheerforce', moves: ['thunder']}],
]);

View File

@@ -28,7 +28,7 @@ describe('Quick Claw', function () {
});
it(`[Gen 3] causes Speed ties with every holder when activated`, function () {
battle = common.gen(3).createBattle([[
battle = common.gen(3).createBattle({seed: [163, 106, 112, 542]}, [[
{species: 'snorlax', item: 'quickclaw', moves: ['spore']},
], [
{species: 'deoxys', item: 'quickclaw', moves: ['seismictoss']},

View File

@@ -27,7 +27,7 @@ describe('Burn', function () {
const target = battle.p2.active[0];
battle.makeChoices('move boneclub', 'move splash');
// hardcoded to RNG
assert.hurtsBy(target, 64, () => battle.makeChoices('move boneclub', 'move willowisp'));
assert.hurtsBy(target, 42, () => battle.makeChoices('move boneclub', 'move willowisp'));
});
it('should reduce atk to 50% of its original value in Stadium', function () {

View File

@@ -74,7 +74,7 @@ describe('Counter', function () {
it(`[Gen 1] Counter Desync Clause`, function () {
// seed chosen so Water Gun succeeds and Pound full paras
battle = common.gen(1).createBattle({seed: [1, 2, 3, 6]}, [[
battle = common.gen(1).createBattle({seed: [1, 2, 3, 3]}, [[
{species: 'Mew', moves: ['pound', 'watergun', 'counter', 'thunderwave']},
], [
{species: 'Persian', moves: ['pound', 'watergun', 'counter', 'thunderwave']},
@@ -84,7 +84,7 @@ describe('Counter', function () {
assert(battle.log.some(line => line.includes('Desync Clause Mod activated')));
// seed chosen so Pound succeeds and Water Gun full paras
battle = common.gen(1).createBattle({seed: [1, 2, 3, 6]}, [[
battle = common.gen(1).createBattle({seed: [1, 2, 3, 3]}, [[
{species: 'Mew', moves: ['pound', 'watergun', 'counter', 'thunderwave']},
], [
{species: 'Persian', moves: ['pound', 'watergun', 'counter', 'thunderwave']},

View File

@@ -49,7 +49,7 @@ describe('Substitute', function () {
});
it('should take specific recoil damage in Gen 1', function () {
battle = common.gen(1).createBattle({seed: [0, 1, 0, 1]});
battle = common.gen(1).createBattle({seed: [1, 10, 1, 10]});
battle.setPlayer('p1', {team: [{species: 'Hitmonlee', moves: ['substitute', 'highjumpkick']}]});
battle.setPlayer('p2', {team: [{species: 'Hitmonchan', moves: ['substitute', 'agility']}]});
battle.makeChoices('move substitute', 'move substitute');
@@ -57,7 +57,7 @@ describe('Substitute', function () {
const subhp = battle.p1.active[0].volatiles['substitute'].hp;
assert.equal(subhp, battle.p2.active[0].volatiles['substitute'].hp);
battle.resetRNG(); // Make Hi Jump Kick miss and cause recoil.
// High Jump Kick will miss and cause recoil
battle.makeChoices('move highjumpkick', 'move agility');
// Both Pokemon had a substitute, so the *target* Substitute takes recoil damage.