PkmnLib.NET/Plugins/PkmnLib.Plugin.Gen7/Scripts/Weather/Hail.cs

49 lines
1.5 KiB
C#
Raw Normal View History

2025-01-10 11:16:29 +00:00
using System.Collections.Generic;
using System.Linq;
using PkmnLib.Static;
using PkmnLib.Static.Utils;
2024-11-02 11:59:55 +00:00
namespace PkmnLib.Plugin.Gen7.Scripts.Weather;
[Script(ScriptCategory.Weather, "hail")]
public class Hail : Script
{
2025-01-10 11:16:29 +00:00
public static void RegisterHailIgnoreAbility(StringKey abilityName)
{
_hailIgnoreAbilities.Add(abilityName);
}
private static readonly HashSet<StringKey> _hailIgnoreAbilities =
[
"ice_body",
"magic_guard",
"overcoat",
2025-03-02 16:19:57 +00:00
"snow_cloak",
2025-01-10 11:16:29 +00:00
];
/// <inheritdoc />
public override void OnEndTurn(IBattle battle)
{
if (!battle.Library.StaticLibrary.Types.TryGetTypeIdentifier("ice", out var iceType))
{
iceType = new TypeIdentifier(255, "non_existent");
2025-01-10 11:16:29 +00:00
}
foreach (var side in battle.Sides)
{
foreach (var pokemon in side.Pokemon.WhereNotNull())
{
if (!pokemon.IsUsable)
continue;
if (pokemon.Types.Contains(iceType))
continue;
2025-01-27 11:18:48 +00:00
if (pokemon.ActiveAbility != null && _hailIgnoreAbilities.Contains(pokemon.ActiveAbility.Name))
2025-01-10 11:16:29 +00:00
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());
}
}
}
2024-11-02 11:59:55 +00:00
}