diff --git a/Fika.Core/Coop/GameMode/CoopGame.cs b/Fika.Core/Coop/GameMode/CoopGame.cs index 71e09d3a..ac63fa67 100644 --- a/Fika.Core/Coop/GameMode/CoopGame.cs +++ b/Fika.Core/Coop/GameMode/CoopGame.cs @@ -62,6 +62,7 @@ public sealed class CoopGame : BaseLocalGame, IBotGame, IFik public string MyExitLocation { get; set; } = null; public ISpawnSystem SpawnSystem; public Dictionary Bots = []; + public List ExtractedPlayers { get; } = []; private readonly Dictionary botQueue = []; private Coroutine extractRoutine; @@ -104,6 +105,26 @@ public IWeatherCurve WeatherCurve private static ManualLogSource Logger; + /// + /// Creates a CoopGame + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// internal static CoopGame Create(IInputTree inputTree, Profile profile, GameDateTime backendDateTime, InsuranceCompanyClass insurance, MenuUI menuUI, GameUI gameUI, LocationSettingsClass.Location location, TimeAndWeatherSettings timeAndWeather, WavesSettings wavesSettings, EDateTime dateTime, @@ -163,6 +184,15 @@ internal static CoopGame Create(IInputTree inputTree, Profile profile, GameDateT return coopGame; } + /// + /// Used to create a + /// + /// + /// + /// + /// + /// + /// private class SetupGamePlayerOwnerHandler(IInputTree inputTree, InsuranceCompanyClass insurance, ISession backEndSession, GameUI gameUI, CoopGame game, LocationSettingsClass.Location location) { private readonly IInputTree inputTree = inputTree; @@ -180,6 +210,10 @@ public EftGamePlayerOwner HandleSetup(Player player) } } + /// + /// Sets up a custom weather curve + /// + /// Struct with custom settings private void SetupCustomWeather(TimeAndWeatherSettings timeAndWeather) { if (WeatherController.Instance == null) @@ -209,6 +243,11 @@ public override void SetMatchmakerStatus(string status, float? progress = null) } } + /// + /// Creates and initializes the + /// + /// + /// If no ServerId was found public Task CreateCoopHandler() { Logger.LogInfo("Creating CoopHandler..."); @@ -241,12 +280,17 @@ public Task CreateCoopHandler() { Destroy(coopHandler); Logger.LogError("No Server Id found, Deleting Coop Handler"); - throw new Exception("No Server Id found"); + throw new MissingReferenceException("No Server Id found"); } return Task.CompletedTask; } + /// + /// Returns all human players + /// + /// used to fetch players + /// private List GetPlayers(CoopHandler coopHandler) { List humanPlayers = []; @@ -262,6 +306,12 @@ private List GetPlayers(CoopHandler coopHandler) return humanPlayers; } + /// + /// Calculates the distance from all players + /// + /// The position + /// of all human s + /// private float GetDistanceFromPlayers(Vector3 position, List humanPlayers) { float distance = float.PositiveInfinity; @@ -278,7 +328,13 @@ private float GetDistanceFromPlayers(Vector3 position, List humanPla return distance; } - private string GetFurthestBot(Dictionary bots, CoopHandler coopHandler, List humanPlayers, out float furthestDistance) + /// + /// Grabs the bot furthest away from all players and returns its distance + /// + /// List of all human s + /// The furthest distance + /// + private string GetFurthestBot(List humanPlayers, out float furthestDistance) { string furthestBot = string.Empty; furthestDistance = 0f; @@ -302,6 +358,11 @@ private string GetFurthestBot(Dictionary bots, CoopHandler coopH return furthestBot; } + /// + /// Checks whether this bot is valid for despawning + /// + /// of profileId and player + /// private bool IsInvalidBotForDespawning(KeyValuePair kvp) { if (kvp.Value == null || kvp.Value == null || kvp.Value.Position == null) @@ -333,6 +394,12 @@ private bool IsInvalidBotForDespawning(KeyValuePair kvp) return false; } + /// + /// Used to spawn a bot for the host + /// + /// to spawn + /// The position to spawn on + /// private async Task CreateBot(Profile profile, Vector3 position) { #if DEBUG @@ -365,7 +432,7 @@ private async Task CreateBot(Profile profile, Vector3 position) if (FikaPlugin.DespawnFurthest.Value) { - despawned = TryDespawnFurthest(profile, position, coopHandler); + despawned = TryDespawnFurthestBot(profile, position, coopHandler); } // If it's not special and we didnt despawn something, we dont spawn a new bot. @@ -472,6 +539,10 @@ private async Task CreateBot(Profile profile, Vector3 position) return localPlayer; } + /// + /// Increments the amount of players that have loaded a bot, used for + /// + /// public void IncreaseLoadedPlayers(int netId) { if (botQueue.ContainsKey(netId)) @@ -484,6 +555,11 @@ public void IncreaseLoadedPlayers(int netId) } } + /// + /// used to ensure that all players loads a bot before it spawns + /// + /// The NetId to spawn + /// private async Task WaitForPlayersToLoadBotProfile(int netId) { botQueue.Add(netId, 0); @@ -505,11 +581,18 @@ private async Task WaitForPlayersToLoadBotProfile(int netId) botQueue.Remove(netId); } - private bool TryDespawnFurthest(Profile profile, Vector3 position, CoopHandler coopHandler) + /// + /// Tries to despawn the furthest bot from all players + /// + /// + /// + /// + /// + private bool TryDespawnFurthestBot(Profile profile, Vector3 position, CoopHandler coopHandler) { List humanPlayers = GetPlayers(coopHandler); - string botKey = GetFurthestBot(Bots, coopHandler, humanPlayers, out float furthestDistance); + string botKey = GetFurthestBot(humanPlayers, out float furthestDistance); if (botKey == string.Empty) { @@ -546,6 +629,11 @@ private bool TryDespawnFurthest(Profile profile, Vector3 position, CoopHandler c return true; } + /// + /// Despawns a bot + /// + /// + /// The bot to despawn private void DespawnBot(CoopHandler coopHandler, Player bot) { IBotGame botGame = Singleton.Instance; @@ -684,6 +772,10 @@ private IEnumerator WaitForOtherPlayers() } } + /// + /// Sends or receives the for the game + /// + /// private async Task SendOrReceiveSpawnPoint() { if (isServer) @@ -790,7 +882,6 @@ public override async Task vmethod_2(int playerId, Vector3 position myPlayer.SpawnPoint = spawnPoint; GameObject customButton = null; - //GameObject customButtonStart = null; await NetManagerUtils.SetupGameVariables(isServer, coopPlayer); @@ -813,7 +904,7 @@ public override async Task vmethod_2(int playerId, Vector3 position message: "Backing out from this stage is currently experimental. It is recommended to ALT+F4 instead. Do you still want to continue?", ErrorScreen.EButtonType.OkButton, 15f, () => { - StopFromError(myPlayer.ProfileId, ExitStatus.Runner); + StopFromCancel(myPlayer.ProfileId, ExitStatus.Runner); PlayerLeftRequest playerLeftRequest = new(coopPlayer.ProfileId); FikaRequestHandler.RaidLeave(playerLeftRequest); }, null); @@ -838,23 +929,16 @@ public override async Task vmethod_2(int playerId, Vector3 position Destroy(customButton); - myPlayer.ActiveHealthController.DiedEvent += MainPlayerDied; - return myPlayer; } - private void MainPlayerDied(EDamageType obj) - { - if (timeManager != null) - { - Destroy(timeManager); - } - if (GameUi.TimerPanel.enabled) - { - GameUi.TimerPanel.Close(); - } - } - + /// + /// Initializes the local player + /// + /// + /// + /// + /// public async Task InitPlayer(BotControllerSettings botsSettings, string backendUrl, Callback runCallback) { Status = GameStatus.Running; @@ -909,6 +993,13 @@ public async Task InitPlayer(BotControllerSettings botsSettings, string backendU await method_11(location, startHandler.FinishLoading); } + /// + /// Handler used to start the game + /// + /// + /// + /// + /// private class StartHandler(BaseLocalGame localGame, BotControllerSettings botSettings, ISpawnSystem spawnSystem, Callback runCallback) { private readonly BaseLocalGame localGame = localGame; @@ -922,6 +1013,10 @@ public void FinishLoading() } } + /// + /// Creates the local player + /// + /// A private async Task CreateLocalPlayer() { int num = method_12(); @@ -966,6 +1061,10 @@ private async Task CreateLocalPlayer() return myPlayer; } + /// + /// used to wait for all other players to join the game + /// + /// private async Task WaitForPlayers() { Logger.LogInfo("Starting task to wait for other players."); @@ -1061,6 +1160,12 @@ private async Task WaitForPlayers() } } + /// + /// Sets the status of the game on the backend + /// + /// + /// + /// private async Task SetStatus(LocalPlayer myPlayer, LobbyEntry.ELobbyStatus status) { SetStatusModel statusBody = new(myPlayer.ProfileId, status); @@ -1262,6 +1367,11 @@ public override IEnumerator vmethod_4(BotControllerSettings controllerSettings, yield break; } + /// + /// Triggers when the setting is changed + /// + /// + /// private void DynamicAIRate_SettingChanged(object sender, EventArgs e) { if (DynamicAI != null) @@ -1270,6 +1380,11 @@ private void DynamicAIRate_SettingChanged(object sender, EventArgs e) } } + /// + /// Triggers when the setting is changed + /// + /// + /// private void DynamicAI_SettingChanged(object sender, EventArgs e) { if (DynamicAI != null) @@ -1278,6 +1393,9 @@ private void DynamicAI_SettingChanged(object sender, EventArgs e) } } + /// + /// Sets up all the s on the map + /// private void SetupBorderzones() { GameWorld gameWorld = Singleton.Instance; @@ -1303,6 +1421,13 @@ private void SetupBorderzones() } } + /// + /// Triggered when a triggers (only runs on host) + /// + /// + /// + /// + /// private void OnBorderZoneShot(GInterface106 player, BorderZone zone, float arg3, bool arg4) { BorderZonePacket packet = new() @@ -1313,6 +1438,10 @@ private void OnBorderZoneShot(GInterface106 player, BorderZone zone, float arg3, Singleton.Instance.SendDataToAll(new NetDataWriter(), ref packet, LiteNetLib.DeliveryMethod.ReliableOrdered); } + /// + /// Triggers when a explodes + /// + /// private void OnMineExplode(MineDirectional directional) { if (!directional.gameObject.active) @@ -1334,6 +1463,9 @@ private void OnMineExplode(MineDirectional directional) } } + /// + /// Sets up events and all s + /// public override void vmethod_5() { GameTimer.Start(null, null); @@ -1402,11 +1534,20 @@ public override void vmethod_5() ConsoleScreen.ApplyStartCommands(); } + /// + /// Updates a from the server + /// + /// + /// public void UpdateExfilPointFromServer(ExfiltrationPoint point, bool enable) { exfilManager.UpdateExfilPointFromServer(point, enable); } + /// + /// Resets all s from the server + /// + /// public void ResetExfilPointsFromServer(ExfiltrationPoint[] points) { Dictionary currentExfils = Traverse.Create(GameUi.TimerPanel).Field>("dictionary_0").Value; @@ -1419,8 +1560,6 @@ public void ResetExfilPointsFromServer(ExfiltrationPoint[] points) GameUi.TimerPanel.SetTime(GClass1304.UtcNow, Profile_0.Info.Side, GameTimer.SessionSeconds(), points); } - public List ExtractedPlayers { get; } = []; - /// /// When the local player successfully extracts, enable freecam, notify other players about the extract /// @@ -1515,8 +1654,6 @@ public void Extract(CoopPlayer player, ExfiltrationPoint point) GameUi.TimerPanel.Close(); } - player.ActiveHealthController.DiedEvent -= MainPlayerDied; - if (FikaPlugin.AutoExtract.Value) { if (!isServer) @@ -1580,8 +1717,21 @@ public void ClearHostAI(Player player) } } + /// + /// Triggers when the main player dies + /// + /// private void HealthController_DiedEvent(EDamageType obj) { + if (timeManager != null) + { + Destroy(timeManager); + } + if (GameUi.TimerPanel != null && GameUi.TimerPanel.enabled) + { + GameUi.TimerPanel.Close(); + } + gparam_0.Player.HealthController.DiedEvent -= method_15; gparam_0.Player.HealthController.DiedEvent -= HealthController_DiedEvent; @@ -1604,6 +1754,13 @@ private IEnumerator SaveOnDeathRoutine() } } + /// + /// Stops the local + /// + /// + /// + /// + /// public override void Stop(string profileId, ExitStatus exitStatus, string exitName, float delay = 0f) { Logger.LogDebug("Stop"); @@ -1719,6 +1876,14 @@ public override void Stop(string profileId, ExitStatus exitStatus, string exitNa BackendConfigAbstractClass.Config.UseSpiritPlayer = false; } + /// + /// Saves your own to the server + /// + /// + /// + /// + /// + /// private Task SavePlayer(CoopPlayer player, ExitStatus exitStatus, string exitName, bool fromDeath) { if (hasSaved) @@ -1754,7 +1919,12 @@ private Task SavePlayer(CoopPlayer player, ExitStatus exitStatus, string exitNam return Task.CompletedTask; } - private void StopFromError(string profileId, ExitStatus exitStatus) + /// + /// Stops the local when waiting for other players + /// + /// + /// + private void StopFromCancel(string profileId, ExitStatus exitStatus) { Logger.LogWarning("Game init was cancelled!"); @@ -1820,7 +1990,7 @@ private void StopFromError(string profileId, ExitStatus exitStatus) wavesSpawnScenario_0.Stop(); } - ErrorExitManager stopManager = new() + CancelExitManager stopManager = new() { baseLocalGame_0 = this, exitStatus = exitStatus, @@ -1853,6 +2023,10 @@ private void StopFromError(string profileId, ExitStatus exitStatus) BackendConfigAbstractClass.Config.UseSpiritPlayer = false; } + /// + /// Toggles the menu + /// + /// public void ToggleDebug(bool enabled) { if (fikaDebug != null) @@ -1861,6 +2035,9 @@ public void ToggleDebug(bool enabled) } } + /// + /// Cleans up after the stops + /// public override void CleanUp() { foreach (Player player in dictionary_0.Values) @@ -1881,6 +2058,9 @@ public override void CleanUp() dictionary_0.Clear(); } + /// + /// Disposes of the + /// public override void Dispose() { Logger.LogDebug("Dispose()"); @@ -1941,6 +2121,14 @@ public override void Dispose() base.Dispose(); } + /// + /// Used to manage the stopping of the gracefully + /// + /// + /// + /// + /// + /// private class ExitManager(CoopGame localGame, ExitStatus exitStatus, string exitName, float delay, CoopPlayer localPlayer) { private readonly CoopGame localGame = localGame; @@ -1980,7 +2168,10 @@ private void FireCallback() } } - private class ErrorExitManager : Class1386 + /// + /// Used to manage the stopping of the gracefully when cancelling + /// + private class CancelExitManager : Class1386 { public void ExitOverride() { diff --git a/Fika.Core/Coop/Players/CoopBot.cs b/Fika.Core/Coop/Players/CoopBot.cs index bc7d9e13..fc2d8e4b 100644 --- a/Fika.Core/Coop/Players/CoopBot.cs +++ b/Fika.Core/Coop/Players/CoopBot.cs @@ -33,7 +33,6 @@ public class CoopBot : CoopPlayer /// The amount of players that have loaded this bot /// public int loadedPlayers = 0; - //private FikaDynamicAI dynamicAi; private bool firstEnabled; public static async Task CreateBot(int playerId, Vector3 position, Quaternion rotation, diff --git a/Fika.Core/Coop/Utils/FikaBackendUtils.cs b/Fika.Core/Coop/Utils/FikaBackendUtils.cs index a05f048d..6813f601 100644 --- a/Fika.Core/Coop/Utils/FikaBackendUtils.cs +++ b/Fika.Core/Coop/Utils/FikaBackendUtils.cs @@ -53,7 +53,7 @@ public static bool JoinMatch(string profileId, string serverId, out CreateMatch return false; } - MatchJoinRequest body = new MatchJoinRequest(serverId, profileId); + MatchJoinRequest body = new(serverId, profileId); result = FikaRequestHandler.RaidJoin(body); if (result.GameVersion != FikaPlugin.EFTVersionMajor)