Skip to content

Commit

Permalink
refactor(client): CustomExfilServiceFika + better logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Trap committed Dec 25, 2024
1 parent 32f2b35 commit 4923686
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 31 deletions.
16 changes: 8 additions & 8 deletions PTT-Plugin/Services/CustomExfilService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ public static void ExtractTo(ExfiltrationPoint exfil, ExfilTarget exfilTarget)
Player player = Singleton<GameWorld>.Instance.MainPlayer;
string customExtractName = exfilTarget.GetCustomExitName(exfil);

// TODO: log -> started extraction on customExtractName
Logger.Info($"started extraction on '{customExtractName}'");

if (localGame == null)
{
// TODO: log error
Logger.Error($"cannot extract because no LocalGame found");
return;
}

if (player == null)
{
// TODO: log error
Logger.Error($"cannot extract because no Player found");
return;
}

float delay = 0f;
localGame.Stop(player.ProfileId, ExitStatus.Survived, customExtractName, delay);
// TODO: log -> local game stopped
Logger.Info($"local game stopped for profile '${player.ProfileId}'");
}

public static void TransitTo(ExfiltrationPoint exfil, ExfilTarget exfilTarget)
Expand All @@ -52,18 +52,18 @@ public static void TransitTo(ExfiltrationPoint exfil, ExfilTarget exfilTarget)

TransitPoint transit = Transit.Create(exfil, exfilTarget);
string customTransitName = transit.parameters.name;
// TODO: log -> started transit on customTransitName
Logger.Info($"started transit on '{customTransitName}'");

if (!TransitControllerAbstractClass.Exist(out GClass1642 vanillaTransitController))
{
// TODO: log error
Logger.Error($"cannot transit because no TransitControllerAbstractClass found");
return;
}

Player player = Singleton<GameWorld>.Instance.MainPlayer;
if (player == null)
{
// TODO: log error
Logger.Error($"cannot transit because no player found");
return;
}

Expand All @@ -79,6 +79,6 @@ public static void TransitTo(ExfiltrationPoint exfil, ExfilTarget exfilTarget)
int playersCount = 1;

vanillaTransitController.Transit(transit, playersCount, transitHash, profiles, player);
// TODO: log -> transit done
Logger.Info($"transit done for profile '${player.ProfileId}'");
}
}
59 changes: 36 additions & 23 deletions PTT-Plugin/Services/CustomExfilServiceFika.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,55 +18,61 @@ public static void ExtractTo(ExfiltrationPoint exfil, ExfilTarget exfilTarget)
CoopPlayer coopPlayer = (CoopPlayer)Singleton<GameWorld>.Instance.MainPlayer;

string customExtractName = exfilTarget.GetCustomExitName(exfil);
// TODO: log -> started fika extraction on customExtractName
Logger.Info($"(FIKA) started extraction on '{customExtractName}'");

if (coopGame == null)
{
// TODO: log error
Logger.Error($"(FIKA) cannot extract because no CoopGame found");
return;
}

if (coopPlayer == null)
{
// TODO: log error
Logger.Error($"(FIKA) cannot extract because no CoopPlayer found");
return;
}

coopGame.ExitLocation = customExtractName; // not sure if it's needed
coopGame.Extract(coopPlayer, exfil, null);
Logger.Info($"(FIKA) extraction done for profile {coopPlayer.ProfileId}");

// TODO: log -> fika extraction done
}

public static void TransitTo(ExfiltrationPoint exfil, ExfilTarget exfilTarget)
{
CoopGame coopGame = (CoopGame)Singleton<IFikaGame>.Instance;
CoopPlayer coopPlayer = (CoopPlayer)Singleton<GameWorld>.Instance.MainPlayer;

string customExtractName = exfilTarget.GetCustomExitName(exfil);
// TODO: log -> started fika transit on customExtractName
string customTransitName = exfilTarget.GetCustomExitName(exfil);
Logger.Info($"started transit on '{customTransitName}'");

if (coopGame == null)
{
// TODO: log error
Logger.Error($"(FIKA) cannot transit because no CoopGame found");
return;
}

if (coopPlayer == null)
{
// TODO: log error
Logger.Error($"(FIKA) cannot transit because no CoopPlayer found");
return;
}

if (!TransitControllerAbstractClass.Exist(out GClass1642 vanillaTransitController))
if (!TransitControllerAbstractClass.Exist(out GClass1642 transitController))
{
// TODO: log errors
Logger.Error($"(FIKA) cannot transit because no TransitControllerAbstractClass found");
return;
}

TransitPoint transit = Transit.Create(exfil, exfilTarget);
var localRaidSettings = LocalRaidSettingsRetriever.Settings;

if (localRaidSettings == null)
{
Logger.Error($"(FIKA) cannot transit because no LocalRaidSettings found");
return;
}

// 1. set the transition status
string location = transit.parameters.location;
ERaidMode eraidMode = ERaidMode.Local;
Expand All @@ -76,12 +82,24 @@ public static void TransitTo(ExfiltrationPoint exfil, ExfilTarget exfilTarget)
}
else
{
// TODO: log errors
Logger.Error($"(FIKA) cannot transit because no TarkovApplication found");
return;
}


// 2. prepare profiles
// 2. add the transitPayload
var transitPayload = CreateTransitPayload(location, transitController, coopPlayer);
transitController.alreadyTransits.Add(coopPlayer.ProfileId, transitPayload);

// 3. trigger extract
coopGame.ExitLocation = customTransitName; // not sure if it's needed
coopGame.Extract(coopPlayer, null, transit);
Logger.Info($"(FIKA) transit done for profile '${coopPlayer.ProfileId}'");
}

private static GClass1926 CreateTransitPayload(string locationName, GClass1642 transitController, CoopPlayer coopPlayer)
{
// 1. create player profiles
Dictionary<string, ProfileKey> profiles = new() {
{coopPlayer.ProfileId, new()
{
Expand All @@ -92,25 +110,20 @@ public static void TransitTo(ExfiltrationPoint exfil, ExfilTarget exfilTarget)
}
};

// 3. prepare transitPayload (TODO: refactor)
// 2. create the transit payload
GClass1926 transitPayload = new()
{
hash = Guid.NewGuid().ToString(),
playersCount = 1,
ip = "",
location = location,
location = locationName,
profiles = profiles,
transitionRaidId = vanillaTransitController.summonedTransits[coopPlayer.ProfileId].raidId,
raidMode = eraidMode,
transitionRaidId = transitController?.summonedTransits?[coopPlayer.ProfileId]?.raidId,
raidMode = ERaidMode.Local,
side = coopPlayer.Side is EPlayerSide.Savage ? ESideType.Savage : ESideType.Pmc,
dayTime = localRaidSettings.timeVariant
dayTime = LocalRaidSettingsRetriever.Settings.timeVariant
};

// 4. add transitPayload
vanillaTransitController.alreadyTransits.Add(coopPlayer.ProfileId, transitPayload);

// 5. trigger extract
coopGame.ExitLocation = customExtractName; // not sure if it's needed
coopGame.Extract(coopPlayer, null, transit);
return transitPayload;
}
}

0 comments on commit 4923686

Please sign in to comment.