Skip to content

Commit

Permalink
Merge branch 'project-fika:dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
nexus4880 authored May 23, 2024
2 parents 73a6829 + e841bd0 commit 9de7136
Show file tree
Hide file tree
Showing 14 changed files with 186 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public override void Execute(GClass2837 operation, [CanBeNull] Callback callback
HostInventoryOperationManager operationManager = new(this, operation, callback);
if (vmethod_0(operationManager.operation))
{
operationManager.operation.vmethod_0(operationManager.HandleResult);
operationManager.operation.vmethod_0(operationManager.HandleResult);

InventoryPacket packet = new()
{
Expand Down
3 changes: 1 addition & 2 deletions Fika.Core/Coop/Custom/FikaDynamicAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using EFT;
using Fika.Core.Coop.Components;
using Fika.Core.Coop.Players;
using System;
using System.Collections.Generic;
using UnityEngine;

Expand Down Expand Up @@ -123,7 +122,7 @@ private void DeactivateBot(CoopBot bot)

if (!disabledBots.Contains(bot))
{
disabledBots.Add(bot);
disabledBots.Add(bot);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion Fika.Core/Coop/Custom/FikaHealthBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private void UpdateScreenSpacePosition(bool throttleUpdate)

float processedDistance = Mathf.Clamp(sqrDistance / 625, 0.6f, 1f);
Vector3 position = new(currentPlayer.PlayerBones.Neck.position.x, currentPlayer.PlayerBones.Neck.position.y + (1f * processedDistance), currentPlayer.PlayerBones.Neck.position.z);

if (!WorldToScreen.GetScreenPoint(position, mainPlayer, out Vector3 screenPoint))
{
UpdateColorTextMeshProUGUI(playerPlate.playerNameScreen, 0);
Expand Down
152 changes: 98 additions & 54 deletions Fika.Core/Coop/FreeCamera/FreeCameraController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
using Fika.Core.Coop.GameMode;
using Fika.Core.Coop.Players;
using Fika.Core.UI;
using HarmonyLib;
using Koenigz.PerfectCulling;
using Koenigz.PerfectCulling.EFT;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using TMPro;
using UnityEngine;

Expand All @@ -31,7 +34,8 @@ public class FreeCameraController : MonoBehaviour
private bool _effectsCleared = false;

private GamePlayerOwner _gamePlayerOwner;
private Player _player => Singleton<GameWorld>.Instance.MainPlayer;
private CoopPlayer _player => (CoopPlayer)Singleton<GameWorld>.Instance.MainPlayer;
private CoopHandler coopHandler;

public GameObject CameraParent;
public Camera CameraFreeCamera { get; private set; }
Expand All @@ -41,7 +45,6 @@ public class FreeCameraController : MonoBehaviour
private bool extracted = false;
private DeathFade deathFade;
private bool deathFadeEnabled;
private float DeadTime = 0f;
private DisablerCullingObjectBase[] allCullingObjects;
private List<PerfectCullingBakeGroup> previouslyActiveBakeGroups;

Expand Down Expand Up @@ -80,6 +83,26 @@ protected void Start()

allCullingObjects = FindObjectsOfType<DisablerCullingObjectBase>();
previouslyActiveBakeGroups = [];

_player.ActiveHealthController.DiedEvent += MainPlayer_DiedEvent;

if (CoopHandler.TryGetCoopHandler(out CoopHandler cHandler))
{
coopHandler = cHandler;
}
}

private void MainPlayer_DiedEvent(EDamageType obj)
{
_player.ActiveHealthController.DiedEvent -= MainPlayer_DiedEvent;

if (!deathFadeEnabled)
{
deathFade.EnableEffect();
deathFadeEnabled = true;
}

StartCoroutine(DeathRoutine());
}

protected void Update()
Expand All @@ -97,18 +120,7 @@ protected void Update()
if (_player.PlayerHealthController == null)
{
return;
}

if (!CoopHandler.TryGetCoopHandler(out CoopHandler coopHandler))
{
return;
}

CoopGame coopGame = (CoopGame)coopHandler.LocalGameInstance;
if (coopGame == null)
{
return;
}
}

CoopHandler.EQuitState quitState = coopHandler.GetQuitState();

Expand All @@ -134,7 +146,8 @@ protected void Update()

if (quitState == CoopHandler.EQuitState.YouHaveExtracted && !extracted)
{
if (coopGame.ExtractedPlayers.Contains(((CoopPlayer)_player).NetId))
CoopGame coopGame = (CoopGame)coopHandler.LocalGameInstance;
if (coopGame.ExtractedPlayers.Contains((_player).NetId))
{
extracted = true;
ShowExtractMessage();
Expand All @@ -161,64 +174,95 @@ protected void Update()
_effectsCleared = true;
}
}
}

if (!_player.HealthController.IsAlive)
private IEnumerator DeathRoutine()
{
yield return new WaitForSeconds(5);

CameraClass cameraClassInstance = CameraClass.Instance;
if (cameraClassInstance == null)
{
DeadTime += Time.deltaTime;
if (!deathFadeEnabled)
{
deathFade.EnableEffect();
deathFadeEnabled = true;
}
yield break;
}

// Player is dead. Remove all effects!
if (!_player.HealthController.IsAlive && !_freeCamScript.IsActive && DeadTime > 5f)
if (cameraClassInstance.EffectsController == null)
{
CameraClass cameraClassInstance = CameraClass.Instance;
if (cameraClassInstance == null)
{
return;
}
yield break;
}

if (cameraClassInstance.Camera != null)
{
cameraClassInstance.Camera.fieldOfView = Singleton<SharedGameSettingsClass>.Instance.Game.Settings.FieldOfView;
}

// Disable the DeathFade effect & Toggle the Camera
deathFade.DisableEffect();
if (!_freeCamScript.IsActive)
{
ToggleCamera();
ToggleUi();
}
ShowExtractMessage();

if (cameraClassInstance.EffectsController == null)
if (!_effectsCleared)
{
if (_player != null)
{
return;
_player.Muffled = false;
_player.HeavyBreath = false;
}

if (cameraClassInstance.Camera != null)
if (CameraClass.Exist)
{
cameraClassInstance.Camera.fieldOfView = Singleton<SharedGameSettingsClass>.Instance.Game.Settings.FieldOfView;
ClearEffects();
}
_effectsCleared = true;
}
}

// Disable the DeathFade effect & Toggle the Camera
deathFade.DisableEffect();
ToggleCamera();
ToggleUi();
ShowExtractMessage();
private void ClearEffects()
{
CameraClass cameraClass = CameraClass.Instance;
cameraClass.EffectsController.method_4(false);

if (!_effectsCleared)
Traverse effectsController = Traverse.Create(cameraClass.EffectsController);

BloodOnScreen bloodOnScreen = effectsController.Field("bloodOnScreen_0").GetValue<BloodOnScreen>();
if (bloodOnScreen != null)
{
Destroy(bloodOnScreen);
}

List<EffectsController.Class566> effectsManagerList = effectsController.Field("list_0").GetValue<List<EffectsController.Class566>>();
if (effectsManagerList != null)
{
foreach (EffectsController.Class566 effectsManager in effectsManagerList)
{
if (_player != null)
while (effectsManager.ActiveEffects.Count > 0)
{
_player.Muffled = false;
_player.HeavyBreath = false;
IEffect effect = effectsManager.ActiveEffects[0];
effectsManager.DeleteEffect(effect);
}
}
effectsManagerList.Clear();
}

if (CameraClass.Exist)
{
ClearEffects();
}
_effectsCleared = true;
CC_Wiggle wiggleEffect = cameraClass.Camera.gameObject.GetComponent<CC_Wiggle>();
if (wiggleEffect != null)
{
wiggleEffect.enabled = false;
}

CC_Blend[] blendEffects = cameraClass.Camera.gameObject.GetComponents<CC_Blend>();
if (blendEffects.Length > 0)
{
foreach (CC_Blend blendEffect in blendEffects)
{
blendEffect.enabled = false;
}
}
}

private void ClearEffects()
{
CameraClass cameraClass = CameraClass.Instance;
cameraClass.EffectsController.method_4(false);
cameraClass.EffectsController.enabled = false;
Destroy(cameraClass.EffectsController);
cameraClass.VisorEffect.Clear();
Destroy(cameraClass.VisorEffect);
Expand Down Expand Up @@ -432,11 +476,11 @@ public void OnDestroy()

// Destroy FreeCamScript before FreeCamController if exists
Destroy(_freeCamScript);
Destroy(this);
if (extractText != null)
{
Destroy(extractText);
}
Destroy(this);
}
}
}
12 changes: 6 additions & 6 deletions Fika.Core/Coop/GameMode/AFikaGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ BotsController IBotGame.BotsController
if (BotsController == null)
{
BotsController = (BotsController)GetType().GetFields().Where(x => x.FieldType == typeof(BotsController)).FirstOrDefault().GetValue(this);
}
}
return BotsController;
}
}
Expand All @@ -37,11 +37,11 @@ public BotsController PBotsController
{
get
{
if (BotsController == null)
{
BotsController = (BotsController)GetType().GetFields().Where(x => x.FieldType == typeof(BotsController)).FirstOrDefault().GetValue(this);
}
return BotsController;
if (BotsController == null)
{
BotsController = (BotsController)GetType().GetFields().Where(x => x.FieldType == typeof(BotsController)).FirstOrDefault().GetValue(this);
}
return BotsController;
}
}

Expand Down
Loading

0 comments on commit 9de7136

Please sign in to comment.