Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom class for med operations #220

Merged
merged 1 commit into from
Dec 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
}
}
}
Loading