Skip to content

Commit

Permalink
Reorganize CoopGame class
Browse files Browse the repository at this point in the history
  • Loading branch information
Lacyway committed May 22, 2024
1 parent 1a01968 commit c1f3c2f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Fika.Core/Coop/Components/CoopExfilManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ protected void Update()
if (!exfiltrationPoint.UnmetRequirements(player).Any())
{
game.MyExitLocation = exfiltrationPoint.Settings.Name;
game.Extract(player, exfiltrationPoint);
game.Extract((CoopPlayer)player, exfiltrationPoint);
}
}

Expand Down
76 changes: 47 additions & 29 deletions Fika.Core/Coop/GameMode/CoopGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,42 +49,45 @@ namespace Fika.Core.Coop.GameMode
/// </summary>
internal sealed class CoopGame : BaseLocalGame<GamePlayerOwner>, IBotGame, IFikaGame
{
public new bool InRaid { get => true; }

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 { get; set; }

public Dictionary<string, Player> Bots { get; set; } = [];
private CoopExfilManager exfilManager;
private GameObject fikaStartButton;
private readonly Dictionary<int, int> botQueue = [];
public FikaDynamicAI DynamicAI { get; private set; }
private Coroutine extractRoutine;
private GClass2928 spawnPoints = null;
private ISpawnPoint spawnPoint = null;
private GClass579 GClass579;
private WavesSpawnScenario wavesSpawnScenario_0;
private NonWavesSpawnScenario nonWavesSpawnScenario_0;
private Func<Player, GamePlayerOwner> func_1;

public FikaDynamicAI DynamicAI { get; private set; }
public RaidSettings RaidSettings { get; private set; }

//WildSpawnType for sptUsec and sptBear
const int sptUsecValue = 47;
const int sptBearValue = 48;

public ISession BackEndSession { get => PatchConstants.BackEndSession; }

BotsController IBotGame.BotsController
{
get
{
return botsController_0;
}
}

public BotsController BotsController
{
get
{
return botsController_0;
}
}

public IWeatherCurve WeatherCurve
{
get
Expand All @@ -93,7 +96,6 @@ public IWeatherCurve WeatherCurve
}
}


private static ManualLogSource Logger;

internal static CoopGame Create(InputTree inputTree, Profile profile, GameDateTime backendDateTime, InsuranceCompanyClass insurance, MenuUI menuUI,
Expand Down Expand Up @@ -214,8 +216,6 @@ public async Task CreateCoopHandler()
}
}

public Dictionary<string, Player> Bots { get; set; } = [];

private List<CoopPlayer> GetPlayers(CoopHandler coopHandler)
{
List<CoopPlayer> humanPlayers = [];
Expand Down Expand Up @@ -687,9 +687,6 @@ private async Task SendOrReceiveSpawnPoint()
}
}

GClass2928 spawnPoints = null;
ISpawnPoint spawnPoint = null;

/// <summary>
/// Creating the EFT.LocalPlayer
/// </summary>
Expand Down Expand Up @@ -1433,7 +1430,7 @@ public void ResetExfilPointsFromServer(ExfiltrationPoint[] points)
/// </summary>
/// <param name="player">The local player to start the Coroutine on</param>
/// <returns></returns>
public void Extract(Player player, ExfiltrationPoint point)
public void Extract(CoopPlayer player, ExfiltrationPoint point)
{
PreloaderUI preloaderUI = Singleton<PreloaderUI>.Instance;

Expand All @@ -1460,7 +1457,7 @@ public void Extract(Player player, ExfiltrationPoint point)

GenericPacket genericPacket = new()
{
NetId = ((CoopPlayer)player).NetId,
NetId = player.NetId,
PacketType = EPackageType.ClientExtract
};

Expand Down Expand Up @@ -1495,6 +1492,8 @@ public void Extract(Player player, ExfiltrationPoint point)
player.ActiveHealthController.DisableMetabolism();
player.ActiveHealthController.PauseAllEffects();

extractRoutine = StartCoroutine(ExtractRoutine(player));

// Prevents players from looting after extracting
GClass3107.Instance.CloseAllScreensForced();

Expand Down Expand Up @@ -1524,6 +1523,30 @@ public void Extract(Player player, ExfiltrationPoint point)
}
}

/// <summary>
/// Used to make sure no stims or mods reset the DamageCoeff
/// </summary>
/// <param name="player">The <see cref="CoopPlayer"/> to run the coroutine on</param>
/// <returns></returns>
private IEnumerator ExtractRoutine(CoopPlayer player)
{
while (true)
{
if (player != null && player.ActiveHealthController != null)
{
if (player.ActiveHealthController.DamageCoeff != 0)
{
player.ActiveHealthController.SetDamageCoeff(0);
}
}
else
{
yield break;
}
yield return new WaitForEndOfFrame();
}
}

public void ClearHostAI(Player player)
{
if (player != null)
Expand All @@ -1550,10 +1573,6 @@ public void ClearHostAI(Player player)
}
}

public ExitStatus MyExitStatus { get; set; } = ExitStatus.Survived;
public string MyExitLocation { get; set; } = null;
public ISpawnSystem SpawnSystem { get; set; }

private void HealthController_DiedEvent(EDamageType obj)
{
gparam_0.Player.HealthController.DiedEvent -= method_15;
Expand Down Expand Up @@ -1836,6 +1855,11 @@ public override void Dispose()
Singleton<GameWorld>.Instance.MineManager.OnExplosion -= OnMineExplode;
}

if (extractRoutine != null)
{
StopCoroutine(extractRoutine);
}

if (MatchmakerAcceptPatches.IsServer)
{
CoopPlayer coopPlayer = (CoopPlayer)Singleton<GameWorld>.Instance.MainPlayer;
Expand Down Expand Up @@ -1884,11 +1908,6 @@ public override void Dispose()
base.Dispose();
}

private GClass579 GClass579;
private WavesSpawnScenario wavesSpawnScenario_0;
private NonWavesSpawnScenario nonWavesSpawnScenario_0;
private Func<Player, GamePlayerOwner> func_1;

private class ErrorExitManager : Class1364
{
public void ExitOverride()
Expand Down Expand Up @@ -1918,10 +1937,9 @@ public void ExitOverride()
}
}


public new void method_6(string backendUrl, string locationId, int variantId)
{
Logger.LogInfo("CoopGame:method_6");
Logger.LogDebug("CoopGame::method_6");
return;
}
}
Expand Down

0 comments on commit c1f3c2f

Please sign in to comment.