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")]
|
2025-03-08 09:26:45 +00:00
|
|
|
public class Hail : Script, IWeatherScript
|
2024-11-02 11:59:55 +00:00
|
|
|
{
|
2025-03-08 09:26:45 +00:00
|
|
|
private int? _duration;
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
public void SetTurns(int turns)
|
2025-01-10 11:16:29 +00:00
|
|
|
{
|
2025-03-08 09:26:45 +00:00
|
|
|
_duration = turns;
|
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))
|
|
|
|
{
|
2025-03-07 11:57:06 +00:00
|
|
|
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-03-08 09:26:45 +00:00
|
|
|
var ignoresHail = false;
|
|
|
|
pokemon.RunScriptHook(x => x.CustomTrigger("ignores_hail", new Dictionary<StringKey, object?>()
|
|
|
|
{
|
|
|
|
{ "ignoresHail", ignoresHail },
|
|
|
|
}));
|
|
|
|
if (ignoresHail)
|
2025-01-10 11:16:29 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
var maxHealth = pokemon.BoostedStats.Hp;
|
|
|
|
var damage = maxHealth / 16;
|
|
|
|
pokemon.Damage(damage, DamageSource.Weather, new EventBatchId());
|
|
|
|
}
|
|
|
|
}
|
2025-03-08 09:26:45 +00:00
|
|
|
|
|
|
|
_duration--;
|
|
|
|
if (_duration <= 0)
|
|
|
|
RemoveSelf();
|
2025-01-10 11:16:29 +00:00
|
|
|
}
|
2024-11-02 11:59:55 +00:00
|
|
|
}
|