Skip to content

Commit

Permalink
Further cleanup/refactor in CoopGame
Browse files Browse the repository at this point in the history
  • Loading branch information
Lacyway committed Jun 14, 2024
1 parent e09b217 commit 807ee9f
Showing 1 changed file with 33 additions and 11 deletions.
44 changes: 33 additions & 11 deletions Fika.Core/Coop/GameMode/CoopGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ internal static CoopGame Create(IInputTree inputTree, Profile profile, GameDateT
coopGame.SetupCustomWeather(timeAndWeather);
}

coopGame.func_1 = (Player player) => EftGamePlayerOwner.Create<EftGamePlayerOwner>(player, inputTree, insurance, backEndSession, gameUI, coopGame.GameDateTime, location);
SetupGamePlayerOwnerHandler setupGamePlayerOwnerHandler = new(inputTree, insurance, backEndSession, gameUI, coopGame, location);
coopGame.func_1 = new Func<Player, EftGamePlayerOwner>(setupGamePlayerOwnerHandler.HandleSetup);

Singleton<IFikaGame>.Create(coopGame);
FikaEventDispatcher.DispatchEvent(new FikaGameCreatedEvent(coopGame));
Expand All @@ -162,6 +163,23 @@ internal static CoopGame Create(IInputTree inputTree, Profile profile, GameDateT
return coopGame;
}

private class SetupGamePlayerOwnerHandler(IInputTree inputTree, InsuranceCompanyClass insurance, ISession backEndSession, GameUI gameUI, CoopGame game, LocationSettingsClass.Location location)
{
private readonly IInputTree inputTree = inputTree;
private readonly InsuranceCompanyClass insurance = insurance;
private readonly ISession backEndSession = backEndSession;
private readonly GameUI gameUI = gameUI;
private readonly CoopGame game = game;
private readonly LocationSettingsClass.Location location = location;

public EftGamePlayerOwner HandleSetup(Player player)
{
EftGamePlayerOwner gamePlayerOwner = EftGamePlayerOwner.Create(player, inputTree, insurance, backEndSession, gameUI, game.GameDateTime, location);
gamePlayerOwner.OnLeave += game.vmethod_3;
return gamePlayerOwner;
}
}

private void SetupCustomWeather(TimeAndWeatherSettings timeAndWeather)
{
if (WeatherController.Instance == null)
Expand Down Expand Up @@ -193,6 +211,7 @@ public override void SetMatchmakerStatus(string status, float? progress = null)

public Task CreateCoopHandler()
{
Logger.LogInfo("Creating CoopHandler...");
CoopHandler coopHandler = CoopHandler.GetCoopHandler();
if (coopHandler != null)
{
Expand Down Expand Up @@ -707,7 +726,7 @@ private async Task SendOrReceiveSpawnPoint()
}

/// <summary>
/// Creating the EFT.LocalPlayer
///
/// </summary>
/// <param name="playerId"></param>
/// <param name="position"></param>
Expand All @@ -725,28 +744,29 @@ private async Task SendOrReceiveSpawnPoint()
/// <param name="getAimingSensitivity"></param>
/// <param name="statisticsManager"></param>
/// <param name="questController"></param>
/// <param name="achievementsController"></param>
/// <returns></returns>
/// <exception cref="MissingComponentException"></exception>
public override async Task<LocalPlayer> vmethod_2(int playerId, Vector3 position, Quaternion rotation,
string layerName, string prefix, EPointOfView pointOfView, Profile profile, bool aiControl,
EUpdateQueue updateQueue, Player.EUpdateMode armsUpdateMode, Player.EUpdateMode bodyUpdateMode,
CharacterControllerSpawner.Mode characterControllerMode, Func<float> getSensitivity, Func<float> getAimingSensitivity,
IStatisticsManager statisticsManager, AbstractQuestControllerClass questController, AbstractAchievementControllerClass achievementsController)
{
Logger.LogInfo("Creating CoopHandler");
await CreateCoopHandler();

profile.SetSpawnedInSession(profile.Side == EPlayerSide.Savage);

LocalPlayer myPlayer = await CoopPlayer.Create(playerId, spawnPoint.Position, spawnPoint.Rotation, "Player", "Main_", EPointOfView.FirstPerson, profile,
false, UpdateQueue, armsUpdateMode, bodyUpdateMode,
LocalPlayer myPlayer = await CoopPlayer.Create(playerId, spawnPoint.Position, spawnPoint.Rotation, "Player",
"Main_", EPointOfView.FirstPerson, profile, false, UpdateQueue, armsUpdateMode, bodyUpdateMode,
BackendConfigAbstractClass.Config.CharacterController.ClientPlayerMode, getSensitivity,
getAimingSensitivity, new GClass1456(), isServer ? 0 : 1000, statisticsManager);

await NetManagerUtils.InitNetManager(isServer);

if (!CoopHandler.TryGetCoopHandler(out CoopHandler coopHandler))
{
Logger.LogDebug($"{nameof(vmethod_2)}:Unable to find {nameof(CoopHandler)}");
Logger.LogError($"{nameof(vmethod_2)}:Unable to find {nameof(CoopHandler)}");
throw new MissingComponentException("CoopHandler was missing during CoopGame init");
}

Expand Down Expand Up @@ -785,7 +805,8 @@ public override async Task<LocalPlayer> vmethod_2(int playerId, Vector3 position
UnityEngine.Events.UnityEvent newEvent = new();
newEvent.AddListener(() =>
{
Singleton<PreloaderUI>.Instance.ShowCriticalErrorScreen("WARNING", message: "Backing out from this stage is currently experimental. It is recommended to ALT+F4 instead. Do you still want to continue?",
Singleton<PreloaderUI>.Instance.ShowCriticalErrorScreen("WARNING",
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);
Expand Down Expand Up @@ -860,7 +881,7 @@ public async Task InitPlayer(BotControllerSettings botsSettings, string backendU
}
else
{
Logger.LogError("Can't find event prefab in resources. Path : Prefabs/HALLOWEEN_CONTROLLER");
Logger.LogError("Can't find event prefab in resources. Path: 'Prefabs/HALLOWEEN_CONTROLLER'");
}
}
ApplicationConfigClass config = BackendConfigAbstractClass.Config;
Expand Down Expand Up @@ -910,7 +931,7 @@ private async Task<Player> CreateLocalPlayer()
spawnPoints = GClass2949.CreateFromScene(new DateTime?(GClass1304.LocalDateTimeFromUnixTime(Location_0.UnixDateTime)), Location_0.SpawnPointParams);
int spawnSafeDistance = (Location_0.SpawnSafeDistanceMeters > 0) ? Location_0.SpawnSafeDistanceMeters : 100;
GStruct379 settings = new(Location_0.MinDistToFreePoint, Location_0.MaxDistToFreePoint, Location_0.MaxBotPerZone, spawnSafeDistance);
SpawnSystem = GClass2950.CreateSpawnSystem(settings, () => Time.time, Singleton<GameWorld>.Instance, zones: botsController_0, spawnPoints);
SpawnSystem = GClass2950.CreateSpawnSystem(settings, new Func<float>(Class1384.class1384_0.method_0), Singleton<GameWorld>.Instance, zones: botsController_0, spawnPoints);

if (isServer)
{
Expand Down Expand Up @@ -996,7 +1017,8 @@ private async Task WaitForPlayers()

if (client.ServerConnection == null && connectionAttempts == 5)
{
Singleton<PreloaderUI>.Instance.ShowErrorScreen("Network Error", "Unable to connect to the raid server. Make sure ports are forwarded and/or UPnP is enabled and supported.");
Singleton<PreloaderUI>.Instance.ShowErrorScreen("Network Error",
"Unable to connect to the raid server. Make sure ports are forwarded and/or UPnP is enabled and supported.");
}
}

Expand Down Expand Up @@ -1322,7 +1344,7 @@ public override void vmethod_5()

InfiltrationPoint = spawnPoint.Infiltration;
Profile_0.Info.EntryPoint = InfiltrationPoint;
Logger.LogDebug("SpawnPoint: " + spawnPoint.Id + ", InfiltrationPoint: " + InfiltrationPoint);
Logger.LogInfo("SpawnPoint: " + spawnPoint.Id + ", InfiltrationPoint: " + InfiltrationPoint);

if (!isServer)
{
Expand Down

0 comments on commit 807ee9f

Please sign in to comment.