Skip to content

Commit

Permalink
CameraController improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Lacyway committed May 23, 2024
1 parent 634f1b7 commit e841bd0
Showing 1 changed file with 98 additions and 54 deletions.
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);
}
}
}

0 comments on commit e841bd0

Please sign in to comment.