43 lines
1.5 KiB
C#
43 lines
1.5 KiB
C#
using PkmnLib.Plugin.Gen7.Scripts.Utils;
|
|
|
|
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
|
|
|
|
/// <summary>
|
|
/// 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.
|
|
///
|
|
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Mimic_(move)">Bulbapedia - Mimic</see>
|
|
/// </summary>
|
|
[Script(ScriptCategory.Move, "mimic")]
|
|
public class Mimic : Script, IScriptOnSecondaryEffect
|
|
{
|
|
/// <inheritdoc />
|
|
public void OnSecondaryEffect(IExecutingMove move, IBattlePokemon target, byte hit)
|
|
{
|
|
var moveSlot = move.User.Moves.IndexOf(move.ChosenMove);
|
|
if (moveSlot == -1)
|
|
{
|
|
move.GetHitData(target, hit).Fail();
|
|
return;
|
|
}
|
|
|
|
var lastMove = target.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);
|
|
}
|
|
} |