2025-06-28 12:02:24 +02:00

50 lines
1.3 KiB
C#

namespace PkmnLib.Plugin.Gen7.Scripts.Status;
[Script(ScriptCategory.Status, "frozen")]
public class Frozen : Script, IScriptPreventMove
{
private IPokemon? _pokemon;
/// <inheritdoc />
public override void OnAddedToParent(IScriptSource source)
{
_pokemon = source as IPokemon;
if (_pokemon == null)
{
throw new InvalidOperationException("Frozen script can only be added to a Pokemon.");
}
}
/// <inheritdoc />
public void PreventMove(IExecutingMove move, ref bool prevent)
{
if (move.UseMove.MoveType.Name == "fire" || move.UseMove.HasFlag("defrost"))
{
_pokemon?.ClearStatus();
return;
}
prevent = true;
}
/// <inheritdoc />
public override void OnEndTurn(IScriptSource owner, IBattle battle)
{
if (_pokemon == null)
return;
if (battle.Random.GetInt(0, 100) >= 20)
return;
_pokemon.ClearStatus();
}
/// <inheritdoc />
public override void OnRemove()
{
_pokemon?.BattleData?.Battle.EventHook.Invoke(new DialogEvent("pokemon_thawed_out",
new Dictionary<string, object>
{
{ "pokemon", _pokemon },
}));
}
}