diff --git a/Fika.Core/Coop/Components/CoopTimeManager.cs b/Fika.Core/Coop/Components/CoopTimeManager.cs new file mode 100644 index 00000000..eef05cfe --- /dev/null +++ b/Fika.Core/Coop/Components/CoopTimeManager.cs @@ -0,0 +1,34 @@ +using Comfort.Common; +using EFT; +using EFT.UI; +using Fika.Core.Coop.GameMode; +using Fika.Core.Coop.Players; +using UnityEngine; + +namespace Fika.Core.Coop.Components +{ + internal class CoopTimeManager : MonoBehaviour + { + public CoopGame CoopGame; + public GameTimerClass GameTimer; + + public static CoopTimeManager Create(CoopGame game) + { + CoopTimeManager timeManager = game.gameObject.AddComponent(); + timeManager.CoopGame = game; + timeManager.GameTimer = game.GameTimer; + return timeManager; + } + + protected void Update() + { + if (CoopGame.Status == GameStatus.Started && GameTimer != null && GameTimer.SessionTime != null && GameTimer.PastTime >= GameTimer.SessionTime) + { + CoopGame.MyExitStatus = ExitStatus.MissingInAction; + CoopPlayer coopPlayer = (CoopPlayer)Singleton.Instance.MainPlayer; + CoopGame.Extract(coopPlayer, null); + enabled = false; + } + } + } +} diff --git a/Fika.Core/Coop/GameMode/CoopGame.cs b/Fika.Core/Coop/GameMode/CoopGame.cs index 52433f28..16fa6530 100644 --- a/Fika.Core/Coop/GameMode/CoopGame.cs +++ b/Fika.Core/Coop/GameMode/CoopGame.cs @@ -63,7 +63,6 @@ internal sealed class CoopGame : BaseLocalGame, IBotGame, IF public ISpawnSystem SpawnSystem; public Dictionary Bots = []; - private CoopExfilManager exfilManager; private GameObject fikaStartButton; private readonly Dictionary botQueue = []; private Coroutine extractRoutine; @@ -74,6 +73,8 @@ internal sealed class CoopGame : BaseLocalGame, IBotGame, IF private NonWavesSpawnScenario nonWavesSpawnScenario_0; private Func func_1; private bool hasSaved = false; + private CoopExfilManager exfilManager; + private CoopTimeManager timeManager; public FikaDynamicAI DynamicAI { get; private set; } public RaidSettings RaidSettings { get; private set; } @@ -143,6 +144,20 @@ internal static CoopGame Create(GInterface170 inputTree, Profile profile, GameDa Singleton.Create(coopGame); FikaEventDispatcher.DispatchEvent(new FikaGameCreatedEvent(coopGame)); + EndByExitTrigerScenario endByExitTrigger = coopGame.GetComponent(); + EndByTimerScenario endByTimerScenario = coopGame.GetComponent(); + + if (endByExitTrigger != null) + { + Destroy(endByExitTrigger); + } + if (endByTimerScenario != null) + { + Destroy(endByTimerScenario); + } + + coopGame.timeManager = CoopTimeManager.Create(coopGame); + coopGame.RaidSettings = raidSettings; return coopGame; @@ -886,10 +901,9 @@ public override async Task vmethod_2(int playerId, Vector3 position private void MainPlayerDied(EDamageType obj) { - EndByTimerScenario endByTimerScenario = GetComponent(); - if (endByTimerScenario != null) + if (timeManager != null) { - Destroy(endByTimerScenario); + Destroy(timeManager); } if (GameUi.TimerPanel.enabled) { @@ -1479,6 +1493,11 @@ public void Extract(CoopPlayer player, ExfiltrationPoint point) { PreloaderUI preloaderUI = Singleton.Instance; + if (MyExitStatus == ExitStatus.MissingInAction) + { + NotificationManagerClass.DisplayMessageNotification("You have gone missing in action...", iconType: EFT.Communications.ENotificationIconType.Alert, textColor: Color.red); + } + if (point != null) { point.Disable(); @@ -1543,10 +1562,9 @@ public void Extract(CoopPlayer player, ExfiltrationPoint point) GClass3126.Instance.CloseAllScreensForced(); // Detroys session timer - EndByTimerScenario endByTimerScenario = GetComponent(); - if (endByTimerScenario != null) + if (timeManager != null) { - Destroy(endByTimerScenario); + Destroy(timeManager); } if (GameUi.TimerPanel.enabled) { @@ -1728,24 +1746,13 @@ public override void Stop(string profileId, ExitStatus exitStatus, string exitNa } ExitManager stopManager = new(this, exitStatus, exitName, delay, myPlayer); - - EndByExitTrigerScenario endByExitTrigger = GetComponent(); - EndByTimerScenario endByTimerScenario = GetComponent(); + GameUI gameUI = GameUI.Instance; - if (endByTimerScenario != null) - { - if (Status == GameStatus.Starting || Status == GameStatus.Started) - { - endByTimerScenario.GameStatus_0 = GameStatus.SoftStopping; - } - } - exfilManager.Stop(); Status = GameStatus.Stopping; GameTimer.TryStop(); - endByExitTrigger.Stop(); if (gameUI.TimerPanel.enabled) { gameUI.TimerPanel.Close(); @@ -1865,18 +1872,8 @@ private void StopFromError(string profileId, ExitStatus exitStatus) delay = delay }; - EndByExitTrigerScenario endByExitTrigger = GetComponent(); - EndByTimerScenario endByTimerScenario = GetComponent(); GameUI gameUI = GameUI.Instance; - if (endByTimerScenario != null) - { - if (Status == GameStatus.Starting || Status == GameStatus.Started) - { - endByTimerScenario.GameStatus_0 = GameStatus.SoftStopping; - } - } - if (exfilManager != null) { exfilManager.Stop(); @@ -1887,10 +1884,6 @@ private void StopFromError(string profileId, ExitStatus exitStatus) { GameTimer.TryStop(); } - if (endByExitTrigger != null) - { - endByExitTrigger.Stop(); - } if (gameUI.TimerPanel.enabled) { gameUI.TimerPanel.Close();