Skip to content

Commit

Permalink
Add MIA manager
Browse files Browse the repository at this point in the history
  • Loading branch information
Lacyway committed May 27, 2024
1 parent adf4854 commit db90674
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 33 deletions.
34 changes: 34 additions & 0 deletions Fika.Core/Coop/Components/CoopTimeManager.cs
Original file line number Diff line number Diff line change
@@ -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<CoopTimeManager>();
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<GameWorld>.Instance.MainPlayer;
CoopGame.Extract(coopPlayer, null);
enabled = false;
}
}
}
}
59 changes: 26 additions & 33 deletions Fika.Core/Coop/GameMode/CoopGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ internal sealed class CoopGame : BaseLocalGame<EftGamePlayerOwner>, IBotGame, IF
public ISpawnSystem SpawnSystem;

public Dictionary<string, Player> Bots = [];
private CoopExfilManager exfilManager;
private GameObject fikaStartButton;
private readonly Dictionary<int, int> botQueue = [];
private Coroutine extractRoutine;
Expand All @@ -74,6 +73,8 @@ internal sealed class CoopGame : BaseLocalGame<EftGamePlayerOwner>, IBotGame, IF
private NonWavesSpawnScenario nonWavesSpawnScenario_0;
private Func<Player, EftGamePlayerOwner> func_1;
private bool hasSaved = false;
private CoopExfilManager exfilManager;
private CoopTimeManager timeManager;

public FikaDynamicAI DynamicAI { get; private set; }
public RaidSettings RaidSettings { get; private set; }
Expand Down Expand Up @@ -143,6 +144,20 @@ internal static CoopGame Create(GInterface170 inputTree, Profile profile, GameDa
Singleton<IFikaGame>.Create(coopGame);
FikaEventDispatcher.DispatchEvent(new FikaGameCreatedEvent(coopGame));

EndByExitTrigerScenario endByExitTrigger = coopGame.GetComponent<EndByExitTrigerScenario>();
EndByTimerScenario endByTimerScenario = coopGame.GetComponent<EndByTimerScenario>();

if (endByExitTrigger != null)
{
Destroy(endByExitTrigger);
}
if (endByTimerScenario != null)
{
Destroy(endByTimerScenario);
}

coopGame.timeManager = CoopTimeManager.Create(coopGame);

coopGame.RaidSettings = raidSettings;

return coopGame;
Expand Down Expand Up @@ -886,10 +901,9 @@ public override async Task<LocalPlayer> vmethod_2(int playerId, Vector3 position

private void MainPlayerDied(EDamageType obj)
{
EndByTimerScenario endByTimerScenario = GetComponent<EndByTimerScenario>();
if (endByTimerScenario != null)
if (timeManager != null)
{
Destroy(endByTimerScenario);
Destroy(timeManager);
}
if (GameUi.TimerPanel.enabled)
{
Expand Down Expand Up @@ -1479,6 +1493,11 @@ public void Extract(CoopPlayer player, ExfiltrationPoint point)
{
PreloaderUI preloaderUI = Singleton<PreloaderUI>.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();
Expand Down Expand Up @@ -1543,10 +1562,9 @@ public void Extract(CoopPlayer player, ExfiltrationPoint point)
GClass3126.Instance.CloseAllScreensForced();

// Detroys session timer
EndByTimerScenario endByTimerScenario = GetComponent<EndByTimerScenario>();
if (endByTimerScenario != null)
if (timeManager != null)
{
Destroy(endByTimerScenario);
Destroy(timeManager);
}
if (GameUi.TimerPanel.enabled)
{
Expand Down Expand Up @@ -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<EndByExitTrigerScenario>();
EndByTimerScenario endByTimerScenario = GetComponent<EndByTimerScenario>();

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();
Expand Down Expand Up @@ -1865,18 +1872,8 @@ private void StopFromError(string profileId, ExitStatus exitStatus)
delay = delay
};

EndByExitTrigerScenario endByExitTrigger = GetComponent<EndByExitTrigerScenario>();
EndByTimerScenario endByTimerScenario = GetComponent<EndByTimerScenario>();
GameUI gameUI = GameUI.Instance;

if (endByTimerScenario != null)
{
if (Status == GameStatus.Starting || Status == GameStatus.Started)
{
endByTimerScenario.GameStatus_0 = GameStatus.SoftStopping;
}
}

if (exfilManager != null)
{
exfilManager.Stop();
Expand All @@ -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();
Expand Down

0 comments on commit db90674

Please sign in to comment.