Skip to content

Commit

Permalink
Merge pull request #220 from project-fika/fix-med-operation
Browse files Browse the repository at this point in the history
Add custom class for med operations
  • Loading branch information
Lacyway authored Dec 8, 2024
2 parents 68592b2 + a77a8b2 commit 2f7ce5e
Showing 1 changed file with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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)
{
Expand All @@ -16,6 +28,32 @@ public static CoopObservedMedsController Create(CoopPlayer player, Item item, EB
return controller;
}

public override Dictionary<Type, OperationFactoryDelegate> GetOperationFactoryDelegates()
{
return new Dictionary<Type, OperationFactoryDelegate> {
{
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;
Expand All @@ -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();
}
}
}
}
}

0 comments on commit 2f7ce5e

Please sign in to comment.