using PkmnLib.Plugin.Gen7.Scripts.Pokemon;

namespace PkmnLib.Plugin.Gen7.Scripts.Moves;

[Script(ScriptCategory.Move, "sky_attack")]
public class SkyAttack : Script, IScriptPreventMove, IScriptOnSecondaryEffect
{
    /// <inheritdoc />
    public void PreventMove(IExecutingMove move, ref bool prevent)
    {
        if (move.User.Volatile.Contains<SkyAttackEffect>())
            return;
        move.User.Volatile.Add(new SkyAttackEffect(move.User));
        prevent = true;
    }

    /// <inheritdoc />
    public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
    {
        move.User.Volatile.Remove<SkyAttackEffect>();
        if (move.Battle.Random.EffectChance(30, move, target, hit))
        {
            target.Volatile.Add(new FlinchEffect());
        }
    }
}