34 lines
1.3 KiB
C#
34 lines
1.3 KiB
C#
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
|
|
|
|
[Script(ScriptCategory.Move, "sketch")]
|
|
public class Sketch : Script, IScriptOnSecondaryEffect
|
|
{
|
|
/// <inheritdoc />
|
|
public 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);
|
|
}
|
|
} |