2025-05-03 17:52:50 +02:00

37 lines
1.3 KiB
C#

using System.Linq;
using PkmnLib.Static.Utils;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "sketch")]
public class Sketch : Script
{
/// <inheritdoc />
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{
// Defensive programming; If the move we're using is not the same as the one picked, something changed
// our move to sketch. This should never happen, as moves are not allowed to change to sketch, but in the
// case it does, we should fail the move.
if (move.ChosenMove.MoveData != move.UseMove)
{
move.GetHitData(target, hit).Fail();
return;
}
var moveSlot = move.User.Moves.IndexOf(move.ChosenMove);
if (moveSlot == -1)
{
move.GetHitData(target, hit).Fail();
return;
}
var choiceQueue = move.Battle.PreviousTurnChoices;
var lastMove = choiceQueue.SelectMany(x => x).OfType<IMoveChoice>().LastOrDefault(x => x.User == target);
if (lastMove == null || lastMove.ChosenMove.MoveData.HasFlag("not_sketchable"))
{
move.GetHitData(target, hit).Fail();
return;
}
move.User.LearnMove(lastMove.ChosenMove.MoveData.Name, MoveLearnMethod.Sketch, (byte)moveSlot);
}
}