2025-01-10 11:16:29 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using PkmnLib.Dynamic.Events;
|
|
|
|
using PkmnLib.Dynamic.Models;
|
2024-11-02 11:59:55 +00:00
|
|
|
using PkmnLib.Dynamic.ScriptHandling;
|
|
|
|
using PkmnLib.Dynamic.ScriptHandling.Registry;
|
2025-01-10 11:16:29 +00:00
|
|
|
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",
|
|
|
|
"snow_cloak"
|
|
|
|
];
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
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 (_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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-11-02 11:59:55 +00:00
|
|
|
}
|