Deukhoofd 6d71de375e
All checks were successful
Build / Build (push) Successful in 48s
More abilities, refactor custom triggers to be typed.
2025-06-13 11:15:48 +02:00

25 lines
878 B
C#

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
{
/// <inheritdoc />
public override 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;
}
}