This commit is contained in:
@@ -1,7 +1,43 @@
|
||||
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
|
||||
public class Mimic : Script, IScriptOnSecondaryEffect
|
||||
{
|
||||
// FIXME: support for temporarily copying moves to a move slot.
|
||||
/// <inheritdoc />
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user