From 85ea31f7cd7e05f9cb6cdbd87076a251a3c3ad8d Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Fri, 10 Jan 2025 10:34:11 +0100 Subject: [PATCH] More move scripts --- PkmnLib.Dynamic/Models/Pokemon.cs | 2 +- .../Scripts/Moves/HealEachEndOfTurn.cs | 42 +++++++++++++++++++ .../Scripts/Moves/IncreasedCriticalStage.cs | 21 ++++++++++ .../Scripts/Moves/MultiHitMove.cs | 28 +++++++++++++ .../Scripts/Moves/PreventFoesExit.cs | 16 +++++++ .../Pokemon/HealEachEndOfTurnEffect.cs | 36 ++++++++++++++++ .../Scripts/Pokemon/PreventFoesExitEffect.cs | 21 ++++++++++ 7 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/HealEachEndOfTurn.cs create mode 100644 Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/IncreasedCriticalStage.cs create mode 100644 Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/MultiHitMove.cs create mode 100644 Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/PreventFoesExit.cs create mode 100644 Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/HealEachEndOfTurnEffect.cs create mode 100644 Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/PreventFoesExitEffect.cs diff --git a/PkmnLib.Dynamic/Models/Pokemon.cs b/PkmnLib.Dynamic/Models/Pokemon.cs index 4aa0bd6..8d642b4 100644 --- a/PkmnLib.Dynamic/Models/Pokemon.cs +++ b/PkmnLib.Dynamic/Models/Pokemon.cs @@ -299,7 +299,7 @@ public interface IPokemon : IScriptSource, IDeepCloneable /// Heals the Pokemon by a specific amount. Unless allow_revive is set to true, this will not /// heal if the Pokemon has 0 health. If the amount healed is 0, this will return false. /// - bool Heal(uint heal, bool allowRevive); + bool Heal(uint heal, bool allowRevive = false); /// /// Restores all PP of the Pokemon. diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/HealEachEndOfTurn.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/HealEachEndOfTurn.cs new file mode 100644 index 0000000..2c1b718 --- /dev/null +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/HealEachEndOfTurn.cs @@ -0,0 +1,42 @@ +using System.Collections.Generic; +using PkmnLib.Dynamic.Libraries; +using PkmnLib.Dynamic.Models; +using PkmnLib.Dynamic.ScriptHandling; +using PkmnLib.Dynamic.ScriptHandling.Registry; +using PkmnLib.Plugin.Gen7.Scripts.Pokemon; +using PkmnLib.Static.Utils; + +namespace PkmnLib.Plugin.Gen7.Scripts.Moves; + +[Script(ScriptCategory.Move, "heal_each_end_of_turn")] +public class HealEachEndOfTurn : Script +{ + private float _healPercentage; + + /// + public override void OnInitialize(IDynamicLibrary library, IReadOnlyDictionary? parameters) + { + base.OnInitialize(library, parameters); + if (parameters == null || !parameters.TryGetValue("percent", out var healPercentageObj) || + healPercentageObj is not float healPercentage) + { + _healPercentage = 6.25f; + } + else + { + _healPercentage = healPercentage!; + } + } + + /// + public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit) + { + var effectName = ScriptUtils.ResolveName(); + if (target.Volatile.Contains(effectName)) + { + move.GetHitData(target, hit).Fail(); + return; + } + target.Volatile.Add(new HealEachEndOfTurnEffect(_healPercentage, target)); + } +} \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/IncreasedCriticalStage.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/IncreasedCriticalStage.cs new file mode 100644 index 0000000..cc0e5d6 --- /dev/null +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/IncreasedCriticalStage.cs @@ -0,0 +1,21 @@ +using PkmnLib.Dynamic.Models; +using PkmnLib.Dynamic.ScriptHandling; +using PkmnLib.Dynamic.ScriptHandling.Registry; + +namespace PkmnLib.Plugin.Gen7.Scripts.Moves; + +[Script(ScriptCategory.Move, "increased_critical_stage")] +public class IncreasedCriticalStage : Script +{ + /// + public override void ChangeCriticalStage(IExecutingMove move, IPokemon target, byte hit, ref byte stage) + { + // Extreme edge case, should never happen + if (stage == byte.MaxValue) + { + move.GetHitData(target, hit).Fail(); + return; + } + stage += 1; + } +} \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/MultiHitMove.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/MultiHitMove.cs new file mode 100644 index 0000000..0784f6c --- /dev/null +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/MultiHitMove.cs @@ -0,0 +1,28 @@ +using PkmnLib.Dynamic.Models.Choices; +using PkmnLib.Dynamic.ScriptHandling; +using PkmnLib.Dynamic.ScriptHandling.Registry; + +namespace PkmnLib.Plugin.Gen7.Scripts.Moves; + +[Script(ScriptCategory.Move, "2_5_hit_move")] +public class MultiHitMove : Script +{ + /// + public override void ChangeNumberOfHits(IMoveChoice choice, ref byte numberOfHits) + { + var random = choice.User.BattleData?.Battle.Random; + if (random == null) + return; + var roll = random.GetInt(100); + // 35% chance that it will hit 2 times, a 35% chance it will hit 3 times, a 15% chance it + // will hit 4 times, and a 15% chance it will hit 5 times. + var newHits = roll switch + { + < 35 => 2, + < 70 => 3, + < 85 => 4, + _ => 5 + }; + numberOfHits = (byte)newHits; + } +} \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/PreventFoesExit.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/PreventFoesExit.cs new file mode 100644 index 0000000..4b471d1 --- /dev/null +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/PreventFoesExit.cs @@ -0,0 +1,16 @@ +using PkmnLib.Dynamic.Models; +using PkmnLib.Dynamic.ScriptHandling; +using PkmnLib.Dynamic.ScriptHandling.Registry; +using PkmnLib.Plugin.Gen7.Scripts.Pokemon; + +namespace PkmnLib.Plugin.Gen7.Scripts.Moves; + +[Script(ScriptCategory.Move, "prevent_foes_exit")] +public class PreventFoesExit : Script +{ + /// + public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit) + { + move.User.Volatile.Add(new PreventFoesExitEffect()); + } +} \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/HealEachEndOfTurnEffect.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/HealEachEndOfTurnEffect.cs new file mode 100644 index 0000000..191c7eb --- /dev/null +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/HealEachEndOfTurnEffect.cs @@ -0,0 +1,36 @@ +using PkmnLib.Dynamic.Models; +using PkmnLib.Dynamic.ScriptHandling; +using PkmnLib.Dynamic.ScriptHandling.Registry; + +namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon; + +[Script(ScriptCategory.Pokemon, "heal_each_end_of_turn_effect")] +public class HealEachEndOfTurnEffect : Script +{ + private readonly float _healPercentage; + private readonly IPokemon? _pokemon; + + private HealEachEndOfTurnEffect() + { + } + + public HealEachEndOfTurnEffect(float healPercentage, IPokemon pokemon) + { + _healPercentage = healPercentage; + _pokemon = pokemon; + } + + /// + public override void OnEndTurn() + { + if (_pokemon is null) + return; + if (_pokemon.BattleData?.IsOnBattlefield != true) + return; + + var amount = _pokemon.BoostedStats.Hp * _healPercentage; + if (_pokemon.HasHeldItem("big_root")) + amount *= 1.3f; + _pokemon.Heal((uint)amount); + } +} \ No newline at end of file diff --git a/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/PreventFoesExitEffect.cs b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/PreventFoesExitEffect.cs new file mode 100644 index 0000000..336f51c --- /dev/null +++ b/Plugins/PkmnLib.Plugin.Gen7/Scripts/Pokemon/PreventFoesExitEffect.cs @@ -0,0 +1,21 @@ +using PkmnLib.Dynamic.Models.Choices; +using PkmnLib.Dynamic.ScriptHandling; +using PkmnLib.Dynamic.ScriptHandling.Registry; + +namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon; + +[Script(ScriptCategory.Pokemon, "prevent_foes_exit_effect")] +public class PreventFoesExitEffect : Script +{ + /// + public override void PreventOpponentSwitch(ISwitchChoice choice, ref bool prevent) + { + prevent = true; + } + + /// + public override void PreventOpponentRunAway(IFleeChoice choice, ref bool prevent) + { + prevent = true; + } +} \ No newline at end of file