using System.Collections.Generic; using System.Linq; using PkmnLib.Static; using PkmnLib.Static.Utils; namespace PkmnLib.Plugin.Gen7.Scripts.Weather; [Script(ScriptCategory.Weather, "hail")] public class Hail : Script { public static void RegisterHailIgnoreAbility(StringKey abilityName) { _hailIgnoreAbilities.Add(abilityName); } private static readonly HashSet _hailIgnoreAbilities = [ "ice_body", "magic_guard", "overcoat", "snow_cloak" ]; /// public override void OnEndTurn(IBattle battle) { if (!battle.Library.StaticLibrary.Types.TryGetTypeIdentifier("ice", out var iceType)) { iceType = new TypeIdentifier(255); } foreach (var side in battle.Sides) { foreach (var pokemon in side.Pokemon.WhereNotNull()) { if (!pokemon.IsUsable) continue; if (pokemon.Types.Contains(iceType)) continue; if (pokemon.ActiveAbility != null && _hailIgnoreAbilities.Contains(pokemon.ActiveAbility.Name)) continue; var maxHealth = pokemon.BoostedStats.Hp; var damage = maxHealth / 16; // TODO: Consider Safety Goggles. Handle it inside the Damage method? pokemon.Damage(damage, DamageSource.Weather, new EventBatchId()); } } } }