From 405a21e8872e1acb84fbbfe67378d5ae540c6305 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Mon, 19 May 2025 15:56:27 +0200 Subject: [PATCH] Implements freeze, poisoned, badly poisoned --- .../Scripts/Status/BadlyPoisoned.cs | 13 +++++- .../Scripts/Status/Frozen.cs | 45 ++++++++++++++++++- .../Scripts/Status/Poisoned.cs | 37 ++++++++++++++- .../Scripts/Status/Sleep.cs | 18 +++++--- .../Scripts/Weather/Hail.cs | 4 +- 5 files changed, 107 insertions(+), 10 deletions(-) diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Status/BadlyPoisoned.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Status/BadlyPoisoned.cs index c05ebea..1b0c25d 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Status/BadlyPoisoned.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Status/BadlyPoisoned.cs @@ -1,6 +1,17 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Status; [Script(ScriptCategory.Status, "badly_poisoned")] -public class BadlyPoisoned : Script +public class BadlyPoisoned : Poisoned { + private int _turns = 1; + + /// + public override float GetPoisonMultiplier() => 1f / (16f * _turns); + + /// + public override void OnEndTurn(IBattle battle) + { + base.OnEndTurn(battle); + _turns = Math.Min(_turns + 1, 15); + } } \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Status/Frozen.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Status/Frozen.cs index 360e9cc..dd68181 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Status/Frozen.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Status/Frozen.cs @@ -3,5 +3,48 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Status; [Script(ScriptCategory.Status, "frozen")] public class Frozen : Script { - // TODO: Implement the Frozen status effect. + private IPokemon? _pokemon; + + /// + 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."); + } + } + + /// + public override void PreventMove(IExecutingMove move, ref bool prevent) + { + if (move.UseMove.MoveType.Name == "fire" || move.UseMove.HasFlag("defrost")) + { + _pokemon?.ClearStatus(); + return; + } + + prevent = true; + } + + /// + public override void OnEndTurn(IBattle battle) + { + if (_pokemon == null) + return; + if (battle.Random.GetInt(0, 100) >= 20) + return; + + _pokemon.ClearStatus(); + } + + /// + public override void OnRemove() + { + _pokemon?.BattleData?.Battle.EventHook.Invoke(new DialogEvent("pokemon_thawed_out", + new Dictionary + { + { "pokemon", _pokemon }, + })); + } } \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Status/Poisoned.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Status/Poisoned.cs index b992c26..3d5129c 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Status/Poisoned.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Status/Poisoned.cs @@ -3,5 +3,40 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Status; [Script(ScriptCategory.Status, "poisoned")] public class Poisoned : Script { - // TODO: Implement the Poisoned status effect. + private IPokemon? _pokemon; + + /// + public override void OnAddedToParent(IScriptSource source) + { + if (source is not IPokemon pokemon) + throw new InvalidOperationException("Poisoned script can only be added to a Pokemon."); + _pokemon = pokemon; + } + + public virtual float GetPoisonMultiplier() => 1f / 8f; + + /// + public override void OnEndTurn(IBattle battle) + { + if (_pokemon == null) + return; + if (_pokemon.IsFainted) + return; + + var damage = (uint)(_pokemon.MaxHealth * GetPoisonMultiplier()); + if (damage == 0) + damage = 1; + + var battleData = _pokemon.BattleData; + var eventBatchId = new EventBatchId(); + battleData?.Battle.EventHook.Invoke(new DialogEvent("poisoned_damage", new Dictionary + { + { "pokemon", _pokemon }, + { "damage", damage }, + }) + { + BatchId = eventBatchId, + }); + _pokemon.Damage(damage, DamageSource.Status, eventBatchId); + } } \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Status/Sleep.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Status/Sleep.cs index 7da3837..05251cc 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Status/Sleep.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Status/Sleep.cs @@ -5,6 +5,7 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Status; [Script(ScriptCategory.Status, "sleep")] public class Sleep : Script { + private IPokemon? _pokemon; public int Turns { get; set; } /// @@ -15,6 +16,7 @@ public class Sleep : Script return; if (source is not IPokemon pokemon) throw new InvalidOperationException("Sleep script can only be added to a Pokemon."); + _pokemon = pokemon; var battleData = pokemon.BattleData; if (battleData != null) { @@ -29,12 +31,7 @@ public class Sleep : Script Turns--; if (Turns <= 0) { - RemoveSelf(); - move.User.BattleData?.Battle.EventHook.Invoke(new DialogEvent("pokemon_woke_up", - new Dictionary - { - { "pokemon", move.User }, - })); + move.User.ClearStatus(); return; } @@ -52,4 +49,13 @@ public class Sleep : Script return; prevent = true; } + + /// + public override void OnRemove() + { + _pokemon?.BattleData?.Battle.EventHook.Invoke(new DialogEvent("pokemon_woke_up", new Dictionary + { + { "pokemon", _pokemon }, + })); + } } \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Weather/Hail.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Weather/Hail.cs index 338c6b8..25d86a8 100644 --- a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Weather/Hail.cs +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Weather/Hail.cs @@ -44,6 +44,8 @@ public class Hail : Script, ILimitedTurnsScript _duration--; if (_duration <= 0) - RemoveSelf(); + { + battle.SetWeather(null, 0); + } } } \ No newline at end of file