namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;

/// <summary>
/// Sand Veil is an ability that raises the Pokémon's evasion during a sandstorm.
///
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Sand_Veil_(Ability)">Bulbapedia - Sand Veil</see>
/// </summary>
[Script(ScriptCategory.Ability, "sand_veil")]
public class SandVeil : Script, IScriptCustomTrigger, IScriptChangeIncomingAccuracy
{
    /// <inheritdoc />
    public void ChangeIncomingAccuracy(IExecutingMove executingMove, IPokemon target, byte hitIndex,
        ref int modifiedAccuracy)
    {
        if (executingMove.Battle.WeatherName != ScriptUtils.ResolveName<Weather.Sandstorm>())
            return;

        modifiedAccuracy = (int)(modifiedAccuracy * (3277f / 4096f));
    }

    /// <inheritdoc />
    public void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
    {
        if (eventName == CustomTriggers.BypassSandstormDamage &&
            args is CustomTriggers.BypassSandstormDamageArgs bypassArgs)
        {
            bypassArgs.Bypass = true;
        }
    }
}