From 2ba7dbf6a38c8d40945a89b511885700d0050a5e Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Tue, 1 Sep 2020 12:20:54 +0200 Subject: [PATCH] Fix wrapper for MiscLibrary ReplacementMove --- PkmnLibSharp/Battling/ChoiceTurn/MoveTurnChoice.cs | 3 +++ PkmnLibSharp/Battling/MiscLibrary.cs | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/PkmnLibSharp/Battling/ChoiceTurn/MoveTurnChoice.cs b/PkmnLibSharp/Battling/ChoiceTurn/MoveTurnChoice.cs index 12161d8..19edfa7 100644 --- a/PkmnLibSharp/Battling/ChoiceTurn/MoveTurnChoice.cs +++ b/PkmnLibSharp/Battling/ChoiceTurn/MoveTurnChoice.cs @@ -1,3 +1,4 @@ +using System; using PkmnLibSharp.Utilities; namespace PkmnLibSharp.Battling.ChoiceTurn @@ -8,6 +9,8 @@ namespace PkmnLibSharp.Battling.ChoiceTurn : base(Creaturelib.Generated.AttackTurnChoice.Construct(user.Ptr, move.Ptr, targetSide, targetIndex)) { } + + internal MoveTurnChoice(IntPtr ptr) : base(ptr){} public LearnedMove Move { diff --git a/PkmnLibSharp/Battling/MiscLibrary.cs b/PkmnLibSharp/Battling/MiscLibrary.cs index e6a81f4..b658c1f 100644 --- a/PkmnLibSharp/Battling/MiscLibrary.cs +++ b/PkmnLibSharp/Battling/MiscLibrary.cs @@ -1,5 +1,8 @@ using System; +using Creaturelib.Generated; +using PkmnLibSharp.Battling.ChoiceTurn; using PkmnLibSharp.Utilities; +using BaseTurnChoice = PkmnLibSharp.Battling.ChoiceTurn.BaseTurnChoice; namespace PkmnLibSharp.Battling { @@ -26,12 +29,16 @@ namespace PkmnLibSharp.Battling return b == MarshalHelper.True; } - public IntPtr ReplacementAttack(Pokemon user, byte sideTarget, byte creatureTarget) + public BaseTurnChoice ReplacementMove(Pokemon user, byte sideTarget, byte creatureTarget) { var b = IntPtr.Zero; Creaturelib.Generated.MiscLibrary.ReplacementAttack(ref b, Ptr, user.Ptr, sideTarget, creatureTarget) .Assert(); - return b; + if (TryResolvePointer(b, out BaseTurnChoice? choice)) + { + return choice!; + } + return new MoveTurnChoice(b); }