diff --git a/Fika.Core/Coop/Components/CoopHandler.cs b/Fika.Core/Coop/Components/CoopHandler.cs index 2b701d1e..1aa4c614 100644 --- a/Fika.Core/Coop/Components/CoopHandler.cs +++ b/Fika.Core/Coop/Components/CoopHandler.cs @@ -26,13 +26,13 @@ public class CoopHandler : MonoBehaviour { #region Fields/Properties public Dictionary ListOfInteractiveObjects { get; private set; } = []; + public CoopGame LocalGameInstance { get; internal set; } public string ServerId { get; set; } = null; - public Dictionary Players { get; } = new(); + public Dictionary Players = []; public int HumanPlayers = 1; - public List ExtractedPlayers { get; set; } = []; + public List ExtractedPlayers = []; ManualLogSource Logger; public CoopPlayer MyPlayer => (CoopPlayer)Singleton.Instance.MainPlayer; - public List queuedProfileIds = []; private Queue spawnQueue = new(50); @@ -340,7 +340,7 @@ await Singleton.Instance.LoadBundlesAndCreatePools(PoolManager.Pool { if (LocalGameInstance != null) { - CoopGame coopGame = (CoopGame)LocalGameInstance; + CoopGame coopGame = LocalGameInstance; BotsController botController = coopGame.BotsController; if (botController != null) { @@ -507,7 +507,7 @@ private ObservedCoopPlayer SpawnObservedPlayer(Profile profile, Vector3 position private IEnumerator AddClientToBotEnemies(BotsController botController, LocalPlayer playerToAdd) { - CoopGame coopGame = (CoopGame)LocalGameInstance; + CoopGame coopGame = LocalGameInstance; Logger.LogInfo($"AddClientToBotEnemies: " + playerToAdd.Profile.Nickname); @@ -601,8 +601,6 @@ public void SetWeaponInHandsOfNewPlayer(Player person, Action successCallback) } }); } - - public BaseLocalGame LocalGameInstance { get; internal set; } } public enum ESpawnState diff --git a/Fika.Core/Coop/FreeCamera/FreeCameraController.cs b/Fika.Core/Coop/FreeCamera/FreeCameraController.cs index 323ec8e9..ac45bc5f 100644 --- a/Fika.Core/Coop/FreeCamera/FreeCameraController.cs +++ b/Fika.Core/Coop/FreeCamera/FreeCameraController.cs @@ -145,7 +145,7 @@ protected void Update() if (quitState == CoopHandler.EQuitState.YouHaveExtracted && !extracted) { - CoopGame coopGame = (CoopGame)coopHandler.LocalGameInstance; + CoopGame coopGame = coopHandler.LocalGameInstance; if (coopGame.ExtractedPlayers.Contains((_player).NetId)) { extracted = true; diff --git a/Fika.Core/Coop/GameMode/CoopGame.cs b/Fika.Core/Coop/GameMode/CoopGame.cs index b8b9701c..9ebd64d2 100644 --- a/Fika.Core/Coop/GameMode/CoopGame.cs +++ b/Fika.Core/Coop/GameMode/CoopGame.cs @@ -52,13 +52,12 @@ namespace Fika.Core.Coop.GameMode { /// - /// A custom Game Type + /// Coop game used in Fika /// - internal sealed class CoopGame : BaseLocalGame, IBotGame, IFikaGame + public sealed class CoopGame : BaseLocalGame, IBotGame, IFikaGame { public string InfiltrationPoint; public bool HasAddedFenceRep = false; - //public bool forceStart = false; public ExitStatus MyExitStatus { get; set; } = ExitStatus.Survived; public string MyExitLocation { get; set; } = null; public ISpawnSystem SpawnSystem; @@ -752,7 +751,6 @@ public override async Task vmethod_2(int playerId, Vector3 position { Logger.LogInfo("Creating CoopHandler"); await CreateCoopHandler(); - CoopHandler.GetCoopHandler().LocalGameInstance = this; profile.SetSpawnedInSession(profile.Side == EPlayerSide.Savage); diff --git a/Fika.Core/Coop/Players/CoopBot.cs b/Fika.Core/Coop/Players/CoopBot.cs index 6d94594a..eeb27130 100644 --- a/Fika.Core/Coop/Players/CoopBot.cs +++ b/Fika.Core/Coop/Players/CoopBot.cs @@ -226,7 +226,7 @@ public override void OnDead(EDamageType damageType) } } - CoopGame coopGame = (CoopGame)Singleton.Instance; + CoopGame coopGame = (CoopGame)Singleton.Instance; if (coopGame.Bots.ContainsKey(ProfileId)) { coopGame.Bots.Remove(ProfileId); diff --git a/Fika.Core/Networking/FikaClient.cs b/Fika.Core/Networking/FikaClient.cs index fd321609..e90e0f26 100644 --- a/Fika.Core/Networking/FikaClient.cs +++ b/Fika.Core/Networking/FikaClient.cs @@ -50,8 +50,6 @@ public NetManager NetClient } } public NetPeer ServerConnection { get; private set; } - /*public string IP { get; private set; } - public int Port { get; private set; }*/ public bool SpawnPointsReceived { get; private set; } = false; private readonly ManualLogSource logger = BepInEx.Logging.Logger.CreateLogSource("Fika.Client"); public bool Started @@ -106,12 +104,6 @@ public void Init() _netClient.Start(); - /*GetHostRequest body = new(MatchmakerAcceptPatches.GetGroupId()); - GetHostResponse result = FikaRequestHandler.GetHost(body); - - IP = result.Ip; - Port = result.Port;*/ - string ip = MatchmakerAcceptPatches.RemoteIp; int port = MatchmakerAcceptPatches.RemotePort; @@ -299,7 +291,7 @@ private void OnExfiltrationPacketReceived(ExfiltrationPacket packet) if (exfilController.ExfiltrationPoints == null) return; - CoopGame coopGame = (CoopGame)Singleton.Instance; + CoopGame coopGame = coopHandler.LocalGameInstance; CarExtraction carExtraction = FindObjectOfType(); @@ -387,7 +379,7 @@ private void OnGenericPacketReceived(GenericPacket packet) if (!coopHandler.ExtractedPlayers.Contains(packet.NetId)) { coopHandler.ExtractedPlayers.Add(packet.NetId); - CoopGame coopGame = (CoopGame)coopHandler.LocalGameInstance; + CoopGame coopGame = coopHandler.LocalGameInstance; coopGame.ExtractedPlayers.Add(packet.NetId); coopGame.ClearHostAI(playerToApply); @@ -435,7 +427,7 @@ private void OnGenericPacketReceived(GenericPacket packet) ExfiltrationPoint exfilPoint = exfilController.ExfiltrationPoints.FirstOrDefault(x => x.Settings.Name == packet.ExfilName); if (exfilPoint != null) { - CoopGame game = (CoopGame)Singleton.Instance; + CoopGame game = coopHandler.LocalGameInstance; exfilPoint.ExfiltrationStartTime = game != null ? game.PastTime : packet.ExfilStartTime; if (exfilPoint.Status != EExfiltrationStatus.Countdown) @@ -647,30 +639,23 @@ private void OnFirearmPacketReceived(WeaponPacket packet) private void OnGameTimerPacketReceived(GameTimerPacket packet) { - CoopHandler coopHandler = CoopHandler.GetCoopHandler(); - if (coopHandler == null) - { - return; - } - TimeSpan sessionTime = new(packet.Tick); - if (coopHandler.LocalGameInstance is CoopGame coopGame) + CoopGame coopGame = coopHandler.LocalGameInstance; + + GameTimerClass gameTimer = coopGame.GameTimer; + if (gameTimer.StartDateTime.HasValue && gameTimer.SessionTime.HasValue) { - GameTimerClass gameTimer = coopGame.GameTimer; - if (gameTimer.StartDateTime.HasValue && gameTimer.SessionTime.HasValue) + if (gameTimer.PastTime.TotalSeconds < 3) { - if (gameTimer.PastTime.TotalSeconds < 3) - { - return; - } + return; + } - TimeSpan timeRemain = gameTimer.PastTime + sessionTime; + TimeSpan timeRemain = gameTimer.PastTime + sessionTime; - gameTimer.ChangeSessionTime(timeRemain); + gameTimer.ChangeSessionTime(timeRemain); - Traverse.Create(coopGame.GameUi.TimerPanel).Field("dateTime_0").SetValue(gameTimer.StartDateTime.Value); - } + Traverse.Create(coopGame.GameUi.TimerPanel).Field("dateTime_0").SetValue(gameTimer.StartDateTime.Value); } } diff --git a/Fika.Core/Networking/FikaServer.cs b/Fika.Core/Networking/FikaServer.cs index a901c444..c5b718c7 100644 --- a/Fika.Core/Networking/FikaServer.cs +++ b/Fika.Core/Networking/FikaServer.cs @@ -367,7 +367,7 @@ private void OnGenericPacketReceived(GenericPacket packet, NetPeer peer) if (!coopHandler.ExtractedPlayers.Contains(packet.NetId)) { coopHandler.ExtractedPlayers.Add(packet.NetId); - CoopGame coopGame = (CoopGame)coopHandler.LocalGameInstance; + CoopGame coopGame = coopHandler.LocalGameInstance; coopGame.ExtractedPlayers.Add(packet.NetId); coopGame.ClearHostAI(playerToApply); @@ -392,7 +392,7 @@ private void OnGenericPacketReceived(GenericPacket packet, NetPeer peer) } else if (packet.PacketType == EPackageType.LoadBot) { - CoopGame coopGame = (CoopGame)Singleton.Instance; + CoopGame coopGame = coopHandler.LocalGameInstance; coopGame.IncreaseLoadedPlayers(packet.BotNetId); return; @@ -406,7 +406,7 @@ private void OnGenericPacketReceived(GenericPacket packet, NetPeer peer) ExfiltrationPoint exfilPoint = exfilController.ExfiltrationPoints.FirstOrDefault(x => x.Settings.Name == packet.ExfilName); if (exfilPoint != null) { - CoopGame game = (CoopGame)Singleton.Instance; + CoopGame game = coopHandler.LocalGameInstance; exfilPoint.ExfiltrationStartTime = game != null ? game.PastTime : packet.ExfilStartTime; if (exfilPoint.Status != EExfiltrationStatus.Countdown) @@ -625,7 +625,7 @@ private void OnGameTimerPacketReceived(GameTimerPacket packet, NetPeer peer) if (!packet.IsRequest) return; - CoopGame game = (CoopGame)Singleton.Instance; + CoopGame game = coopHandler.LocalGameInstance; if (game != null) { GameTimerPacket gameTimerPacket = new(false, (game.GameTimer.SessionTime - game.GameTimer.PastTime).Value.Ticks);