namespace PkmnLib.Plugin.Gen7.Scripts.Abilities; /// /// Friend Guard is an ability that reduces the damage taken by allies by 25%. /// This ability is commonly associated with Clefairy and Vivillon. /// /// Bulbapedia - Friend Guard /// [Script(ScriptCategory.Ability, "friend_guard")] public class FriendGuard : Script { private IPokemon? _pokemon; /// public override void OnAddedToParent(IScriptSource source) { if (source is not IPokemon pokemon) throw new InvalidOperationException("Friend Guard can only be added to a Pokemon script source."); _pokemon = pokemon; var effect = _pokemon.BattleData?.BattleSide.VolatileScripts.Add(new Side.FriendGuardEffect()); (effect?.Script as Side.FriendGuardEffect)?.OnAdded(_pokemon); } /// public override void OnRemove() { if (_pokemon is null) return; if (_pokemon.BattleData?.BattleSide.VolatileScripts.TryGet(out var script) == true) { script.OnRemoved(_pokemon); } } }