using PkmnLib.Dynamic.BattleFlow; namespace PkmnLib.Plugin.Gen7.Scripts.Moves; [Script(ScriptCategory.Move, "instruct")] public class Instruct : Script, IScriptOnSecondaryEffect { /// public 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().FirstOrDefault(x => x.User == target); if (lastMoveChoiceByTarget == null || !battleData.Battle.CanUse(lastMoveChoiceByTarget)) { move.GetHitData(target, hit).Fail(); return; } TurnRunner.ExecuteChoice(battleData.Battle, lastMoveChoiceByTarget); } }