namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;

/// <summary>
/// Snow Cloak is an ability that raises the Pokémon's evasion during hail.
///
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Snow_Cloak_(Ability)">Bulbapedia - Snow Cloak</see>
/// </summary>
[Script(ScriptCategory.Ability, "snow_cloak")]
public class SnowCloak : Script, IScriptCustomTrigger, IScriptChangeIncomingAccuracy
{
    /// <inheritdoc />
    public void ChangeIncomingAccuracy(IExecutingMove executingMove, IPokemon target, byte hitIndex,
        ref int modifiedAccuracy)
    {
        // If the weather is hail, increase evasion by 20%
        if (executingMove.Battle.WeatherName == ScriptUtils.ResolveName<Weather.Hail>())
        {
            modifiedAccuracy = (int)(modifiedAccuracy * 0.8f);
        }
    }

    public void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
    {
        if (eventName == CustomTriggers.IgnoreHail && args is CustomTriggers.IgnoreHailArgs hailArgs)
            hailArgs.Ignore = true;
    }
}