29 lines
938 B
C#
29 lines
938 B
C#
using System.Linq;
|
|
using PkmnLib.Dynamic.Models.BattleFlow;
|
|
|
|
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
|
|
|
|
[Script(ScriptCategory.Move, "instruct")]
|
|
public class Instruct : Script
|
|
{
|
|
/// <inheritdoc />
|
|
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
|
|
{
|
|
if (!target.IsUsable)
|
|
return;
|
|
var battleData = move.User.BattleData;
|
|
if (battleData == null)
|
|
return;
|
|
|
|
var lastMoveChoiceByTarget = battleData.Battle.PreviousTurnChoices.SelectMany(x => x).Reverse()
|
|
.SkipWhile(x => x != move.MoveChoice).OfType<MoveChoice>().FirstOrDefault(x => x.User == target);
|
|
|
|
if (lastMoveChoiceByTarget == null || !battleData.Battle.CanUse(lastMoveChoiceByTarget))
|
|
{
|
|
move.GetHitData(target, hit).Fail();
|
|
return;
|
|
}
|
|
|
|
TurnRunner.ExecuteChoice(battleData.Battle, lastMoveChoiceByTarget);
|
|
}
|
|
} |