More move scripts
This commit is contained in:
37
Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Sketch.cs
Normal file
37
Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Sketch.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user