using PkmnLib.Plugin.Gen7.Scripts.Pokemon;

namespace PkmnLib.Plugin.Gen7.Scripts.Moves;

[Script(ScriptCategory.Move, "charge_move")]
public class ChargeMove : Script, IScriptPreventMove
{
    public void PreventMove(IExecutingMove move, ref bool prevent)
    {
        var args = new CustomTriggers.BypassChargeMoveArgs(move, false);
        move.RunScriptHook<IScriptCustomTrigger>(script => script.CustomTrigger(CustomTriggers.BypassChargeMove, args));
        if (args.Bypass)
            return;

        var chargeMoveEffect = move.User.Volatile.Get<ChargeMoveEffect>();
        if (chargeMoveEffect != null && chargeMoveEffect.MoveName == move.UseMove.Name)
            return;
        prevent = true;
        move.User.Volatile.Add(new ChargeMoveEffect(move.UseMove.Name, move.User, move.MoveChoice.TargetSide,
            move.MoveChoice.TargetPosition));
    }
}