Implements Hail

This commit is contained in:
Deukhoofd 2025-01-10 12:16:29 +01:00
parent 42e3273483
commit 6434f9925c
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
7 changed files with 61 additions and 9 deletions

View File

@ -57,15 +57,15 @@ public static class TurnRunner
{ {
scripts.Clear(); scripts.Clear();
pokemon.GetOwnScripts(scripts); pokemon.GetOwnScripts(scripts);
scripts.RunScriptHook(x => x.OnEndTurn()); scripts.RunScriptHook(x => x.OnEndTurn(battle));
} }
scripts.Clear(); scripts.Clear();
side.GetOwnScripts(scripts); side.GetOwnScripts(scripts);
scripts.RunScriptHook(x => x.OnEndTurn()); scripts.RunScriptHook(x => x.OnEndTurn(battle));
} }
scripts.Clear(); scripts.Clear();
battle.GetOwnScripts(scripts); battle.GetOwnScripts(scripts);
scripts.RunScriptHook(x => x.OnEndTurn()); scripts.RunScriptHook(x => x.OnEndTurn(battle));
} }
} }

View File

@ -25,4 +25,9 @@ public enum DamageSource
/// This happens when the form of a Pokemon changes, and it has less max HP than it had before. /// This happens when the form of a Pokemon changes, and it has less max HP than it had before.
/// </summary> /// </summary>
FormChange = 3, FormChange = 3,
/// <summary>
/// The damage is done because of the weather.
/// </summary>
Weather = 4,
} }

View File

@ -428,7 +428,8 @@ public abstract class Script : IDeepCloneable
/// running. Note that choices are not active anymore here, so their scripts do not call this /// running. Note that choices are not active anymore here, so their scripts do not call this
/// function. /// function.
/// </summary> /// </summary>
public virtual void OnEndTurn() /// <param name="battle"></param>
public virtual void OnEndTurn(IBattle battle)
{ {
} }

View File

@ -20,8 +20,9 @@ public class HealEachEndOfTurnEffect : Script
_pokemon = pokemon; _pokemon = pokemon;
} }
/// <param name="battle"></param>
/// <inheritdoc /> /// <inheritdoc />
public override void OnEndTurn() public override void OnEndTurn(IBattle battle)
{ {
if (_pokemon is null) if (_pokemon is null)
return; return;

View File

@ -35,8 +35,9 @@ public class AuroraVeilEffect : Script
NumberOfTurns = numberOfTurns; NumberOfTurns = numberOfTurns;
} }
/// <param name="battle"></param>
/// <inheritdoc /> /// <inheritdoc />
public override void OnEndTurn() public override void OnEndTurn(IBattle battle)
{ {
if (NumberOfTurns > 0) if (NumberOfTurns > 0)
NumberOfTurns--; NumberOfTurns--;

View File

@ -9,9 +9,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Side;
public class DoublePowerIfTargetDamagedInTurnData : Script public class DoublePowerIfTargetDamagedInTurnData : Script
{ {
public HashSet<IPokemon> _hitPokemon = new(); public HashSet<IPokemon> _hitPokemon = new();
/// <param name="battle"></param>
/// <inheritdoc /> /// <inheritdoc />
public override void OnEndTurn() public override void OnEndTurn(IBattle battle)
{ {
RemoveSelf(); RemoveSelf();
} }

View File

@ -1,10 +1,53 @@
using System.Collections.Generic;
using System.Linq;
using PkmnLib.Dynamic.Events;
using PkmnLib.Dynamic.Models;
using PkmnLib.Dynamic.ScriptHandling; using PkmnLib.Dynamic.ScriptHandling;
using PkmnLib.Dynamic.ScriptHandling.Registry; using PkmnLib.Dynamic.ScriptHandling.Registry;
using PkmnLib.Static;
using PkmnLib.Static.Utils;
namespace PkmnLib.Plugin.Gen7.Scripts.Weather; namespace PkmnLib.Plugin.Gen7.Scripts.Weather;
[Script(ScriptCategory.Weather, "hail")] [Script(ScriptCategory.Weather, "hail")]
public class Hail : Script public class Hail : Script
{ {
// TODO: Implement Hail weather effect 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());
}
}
}
} }