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, IWeatherScript { private int? _duration; /// public void SetTurns(int turns) { _duration = turns; } /// public override void OnEndTurn(IBattle battle) { if (!battle.Library.StaticLibrary.Types.TryGetTypeIdentifier("ice", out var iceType)) { iceType = new TypeIdentifier(255, "non_existent"); } foreach (var side in battle.Sides) { foreach (var pokemon in side.Pokemon.WhereNotNull()) { if (!pokemon.IsUsable) continue; if (pokemon.Types.Contains(iceType)) continue; var ignoresHail = false; pokemon.RunScriptHook(x => x.CustomTrigger("ignores_hail", new Dictionary() { { "ignoresHail", ignoresHail }, })); if (ignoresHail) continue; var maxHealth = pokemon.BoostedStats.Hp; var damage = maxHealth / 16; pokemon.Damage(damage, DamageSource.Weather, new EventBatchId()); } } _duration--; if (_duration <= 0) RemoveSelf(); } }