using PkmnLib.Plugin.Gen7.Scripts.Side;

namespace PkmnLib.Plugin.Gen7.Scripts.Moves;

[Script(ScriptCategory.Move, "rage_powder")]
public class RagePowder : Script, IScriptOnSecondaryEffect
{
    /// <inheritdoc />
    public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
    {
        var battleData = move.User.BattleData;
        if (battleData == null)
            return;

        var effect = battleData.BattleSide.VolatileScripts.Add(new RagePowderEffect(move.User));
        if (effect == null)
        {
            move.GetHitData(target, hit).Fail();
            return;
        }

        ((RagePowderEffect)effect.Script!).User = move.User;
    }
}