From a77a8b253994ff06e74b8ed74a1d42a8b2d61ff5 Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Sun, 8 Dec 2024 18:13:25 +0100 Subject: [PATCH] Add custom class for med operations - Should fix random swallowed nullrefs --- .../CoopObservedMedsController.cs | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/Fika.Core/Coop/ObservedClasses/HandsControllers/CoopObservedMedsController.cs b/Fika.Core/Coop/ObservedClasses/HandsControllers/CoopObservedMedsController.cs index 2397f191..b45c92d4 100644 --- a/Fika.Core/Coop/ObservedClasses/HandsControllers/CoopObservedMedsController.cs +++ b/Fika.Core/Coop/ObservedClasses/HandsControllers/CoopObservedMedsController.cs @@ -1,13 +1,25 @@ // © 2024 Lacyway All Rights Reserved +using EFT; +using EFT.HealthSystem; using EFT.InventoryLogic; using Fika.Core.Coop.Players; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; namespace Fika.Core.Coop.ObservedClasses { internal class CoopObservedMedsController : EFT.Player.MedsController { private CoopPlayer coopPlayer; + private ObservedMedsOperation observedObsOperation + { + get + { + return CurrentHandsOperation as ObservedMedsOperation; + } + } public static CoopObservedMedsController Create(CoopPlayer player, Item item, EBodyPart bodyPart, float amount, int animationVariant) { @@ -16,6 +28,32 @@ public static CoopObservedMedsController Create(CoopPlayer player, Item item, EB return controller; } + public override Dictionary GetOperationFactoryDelegates() + { + return new Dictionary { + { + typeof(Class1158), + new OperationFactoryDelegate(GetObservedMedsOperation) + }}; + } + + public override void Drop(float animationSpeed, Action callback, bool fastDrop = false, Item nextControllerItem = null) + { + DropController(callback).HandleExceptions(); + } + + private async Task DropController(Action callback) + { + await Task.Delay(600); + Destroyed = true; + observedObsOperation.HideObservedWeapon(callback); + } + + private Player.BaseAnimationOperation GetObservedMedsOperation() + { + return new ObservedMedsOperation(this); + } + public override bool CanChangeCompassState(bool newState) { return false; @@ -30,5 +68,30 @@ public override void SetCompassState(bool active) { // Do nothing } + + private class ObservedMedsOperation(Player.MedsController controller) : Class1158(controller) + { + private readonly CoopObservedMedsController observedMedsController = (CoopObservedMedsController)controller; + private Action hiddenCallback; + + public void HideObservedWeapon(Action onHiddenCallback) + { + ActiveHealthController activeHealthController = observedMedsController._player.ActiveHealthController; + if (activeHealthController != null) + { + activeHealthController.RemoveMedEffect(); + } + observedMedsController._player.HealthController.EffectRemovedEvent -= method_2; + hiddenCallback = onHiddenCallback; + if (observedMedsController.FirearmsAnimator != null) + { + observedMedsController.FirearmsAnimator.SetActiveParam(false, false); + } + if (State == Player.EOperationState.Finished) + { + hiddenCallback(); + } + } + } } }