using PkmnLib.Plugin.Gen7.Scripts.Utils; namespace PkmnLib.Plugin.Gen7.Scripts.Moves; /// /// Mimic copies the target's last used move into the move slot Mimic occupies, with 5 PP, until the user /// leaves the field. It fails if the target has not used a move, if that move is Sketch, Transform, Struggle, /// Metronome, or Chatter, or if the user already knows it. /// /// Bulbapedia - Mimic /// [Script(ScriptCategory.Move, "mimic")] public class Mimic : Script, IScriptOnSecondaryEffect { /// public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit) { var moveSlot = move.User.Moves.IndexOf(move.ChosenMove); if (moveSlot == -1) { move.GetHitData(target, hit).Fail(); return; } var lastMove = target.BattleData?.LastMoveChoice; if (lastMove == null || !lastMove.ChosenMove.MoveData.CanCopyMove()) { move.GetHitData(target, hit).Fail(); return; } var copiedMoveName = lastMove.ChosenMove.MoveData.Name; if (move.User.Moves.Any(m => m?.MoveData.Name == copiedMoveName)) { move.GetHitData(target, hit).Fail(); return; } move.User.LearnTemporaryMove(copiedMoveName, MoveLearnMethod.Mimic, (byte)moveSlot); // The copied move only has 5 PP, or its own maximum PP if that is lower. move.User.Moves[moveSlot]?.SetCurrentPP(5); } }