namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;

/// <summary>
/// Magic Guard is an ability that prevents all damage except from direct attacks.
///
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Magic_Guard_(Ability)">Bulbapedia - Magic Guard</see>
/// </summary>
[Script(ScriptCategory.Ability, "magic_guard")]
public class MagicGuard : Script, IScriptChangeIncomingDamage
{
    /// <inheritdoc />
    public void ChangeIncomingDamage(IPokemon pokemon, DamageSource source, ref uint damage)
    {
        // Magic Guard doesn't work if the Pokémon is not in battle.
        if (pokemon.BattleData is null)
            return;

        if (source is DamageSource.MoveDamage or DamageSource.Struggle or DamageSource.FormChange)
        {
            // If the damage is from a move, struggle, or form change, we don't prevent it.
            return;
        }
        damage = 0;
    }
}