diff --git a/data/mods/gen1/moves.ts b/data/mods/gen1/moves.ts index ba21a2506c..a219633070 100644 --- a/data/mods/gen1/moves.ts +++ b/data/mods/gen1/moves.ts @@ -458,6 +458,22 @@ export const Moves: import('../../../sim/dex-moves').ModdedMoveDataTable = { target: "self", type: "Psychic", }, + metronome: { + inherit: true, + onHit(pokemon) { + const moves = this.dex.moves.all().filter(move => ( + (!move.isNonstandard || move.isNonstandard === 'Unobtainable') && move.flags['metronome'] + )); + let randomMove = ''; + if (moves.length) { + moves.sort((a, b) => a.num - b.num); + randomMove = this.sample(moves).id; + } + if (!randomMove) return false; + pokemon.side.lastSelectedMove = this.toID(randomMove); + this.actions.useMove(randomMove, pokemon); + }, + }, mimic: { inherit: true, flags: { protect: 1, bypasssub: 1, metronome: 1 }, diff --git a/data/mods/gen1/scripts.ts b/data/mods/gen1/scripts.ts index 118b5ac213..7aa7786f21 100644 --- a/data/mods/gen1/scripts.ts +++ b/data/mods/gen1/scripts.ts @@ -25,6 +25,25 @@ export const Scripts: ModdedBattleScriptsData = { // BattlePokemon scripts. pokemon: { inherit: true, + // In gen 1, a Pokémon can have two instances of the same move using Mimic + // we need to make sure to deduct PP from a move that has PP left + deductPP(move, amount, target) { + move = this.battle.dex.moves.get(move); + // first loop: get the first instance with PP left + // second loop: get the first instance, even if it has no PP left + for (let i = 0; i < 2; i++) { + for (const ppData of this.moveSlots) { + if (ppData.id !== move.id) continue; + ppData.used = true; + if (!ppData.pp && i === 0) continue; + + if (!amount) amount = 1; + ppData.pp -= amount; + return amount; + } + } + return 0; + }, getStat(statName, unmodified) { // @ts-expect-error type checking prevents 'hp' from being passed, but we're paranoid if (statName === 'hp') throw new Error("Please read `maxhp` directly"); diff --git a/data/mods/gen4/moves.ts b/data/mods/gen4/moves.ts index 1acc40facf..848090153c 100644 --- a/data/mods/gen4/moves.ts +++ b/data/mods/gen4/moves.ts @@ -1087,9 +1087,8 @@ export const Moves: import('../../../sim/dex-moves').ModdedMoveDataTable = { flags: { noassist: 1, failcopycat: 1, nosleeptalk: 1, failmimic: 1 }, onHit(pokemon) { const moves = this.dex.moves.all().filter(move => ( - (![2, 4].includes(this.gen) || !pokemon.moves.includes(move.id)) && + move.flags['metronome'] && !pokemon.moves.includes(move.id) && (!move.isNonstandard || move.isNonstandard === 'Unobtainable') && - move.flags['metronome'] && !(this.field.pseudoWeather['gravity'] && move.flags['gravity']) && !(pokemon.volatiles['healblock'] && move.flags['heal']) )); diff --git a/data/mods/gen7letsgo/moves.ts b/data/mods/gen7letsgo/moves.ts index 552a0df8c8..31f669b0e1 100644 --- a/data/mods/gen7letsgo/moves.ts +++ b/data/mods/gen7letsgo/moves.ts @@ -41,8 +41,11 @@ export const Moves: import('../../../sim/dex-moves').ModdedMoveDataTable = { inherit: true, desc: "A random move that was introduced in gen 1 is selected for use, other than Counter, Mimic, Mirror Move, Struggle, or Transform.", shortDesc: "Picks a random move from gen 1.", - onHit(target, source, effect) { - const moves = this.dex.moves.all().filter(move => move.gen === 1 && move.flags['metronome']); + onHit(target) { + const moves = this.dex.moves.all().filter(move => ( + (!move.isNonstandard || move.isNonstandard === 'Unobtainable') && + move.flags['metronome'] && move.gen === 1 + )); let randomMove = ''; if (moves.length) { moves.sort((a, b) => a.num - b.num); diff --git a/sim/pokemon.ts b/sim/pokemon.ts index 418bdc3bd2..6ff69ec153 100644 --- a/sim/pokemon.ts +++ b/sim/pokemon.ts @@ -876,16 +876,15 @@ export class Pokemon { } deductPP(move: string | Move, amount?: number | null, target?: Pokemon | null | false) { - const gen = this.battle.gen; move = this.battle.dex.moves.get(move); const ppData = this.getMoveData(move); if (!ppData) return 0; ppData.used = true; - if (!ppData.pp && gen > 1) return 0; + if (!ppData.pp) return 0; if (!amount) amount = 1; ppData.pp -= amount; - if (ppData.pp < 0 && gen > 1) { + if (ppData.pp < 0) { amount += ppData.pp; ppData.pp = 0; }