Reduced memory allocations relating to debug logging
Improved debug log text consistency Removed duplicate survival time calculation Improved survival time calculation safety improved `exitAdjustments` contents check Improved use of values to be explicitly doubles
This commit is contained in:
@@ -7,6 +7,7 @@ using SPTarkov.Server.Core.Models.Eft.Game;
|
|||||||
using SPTarkov.Server.Core.Models.Enums;
|
using SPTarkov.Server.Core.Models.Enums;
|
||||||
using SPTarkov.Server.Core.Models.Spt.Config;
|
using SPTarkov.Server.Core.Models.Spt.Config;
|
||||||
using SPTarkov.Server.Core.Models.Spt.Location;
|
using SPTarkov.Server.Core.Models.Spt.Location;
|
||||||
|
using SPTarkov.Server.Core.Models.Spt.Logging;
|
||||||
using SPTarkov.Server.Core.Models.Utils;
|
using SPTarkov.Server.Core.Models.Utils;
|
||||||
using SPTarkov.Server.Core.Servers;
|
using SPTarkov.Server.Core.Servers;
|
||||||
using SPTarkov.Server.Core.Utils;
|
using SPTarkov.Server.Core.Utils;
|
||||||
@@ -35,9 +36,12 @@ public class RaidTimeAdjustmentService(
|
|||||||
{
|
{
|
||||||
if (raidAdjustments.DynamicLootPercent < 100 || raidAdjustments.StaticLootPercent < 100)
|
if (raidAdjustments.DynamicLootPercent < 100 || raidAdjustments.StaticLootPercent < 100)
|
||||||
{
|
{
|
||||||
logger.Debug(
|
if (logger.IsLogEnabled(LogLevel.Debug))
|
||||||
$"Adjusting dynamic loot multipliers to {raidAdjustments.DynamicLootPercent}% and static loot multipliers to {raidAdjustments.StaticLootPercent}% of original"
|
{
|
||||||
|
logger.Debug(
|
||||||
|
$"Adjusting dynamic loot multipliers to: {raidAdjustments.DynamicLootPercent}% and static loot multipliers to: {raidAdjustments.StaticLootPercent}% of original"
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change loot multiplier values before they're used below
|
// Change loot multiplier values before they're used below
|
||||||
@@ -60,7 +64,10 @@ public class RaidTimeAdjustmentService(
|
|||||||
var exitToChange = mapBase.Exits.FirstOrDefault(exit => exit.Name == exitChange.Name);
|
var exitToChange = mapBase.Exits.FirstOrDefault(exit => exit.Name == exitChange.Name);
|
||||||
if (exitToChange is null)
|
if (exitToChange is null)
|
||||||
{
|
{
|
||||||
logger.Debug($"Exit with Id: {exitChange.Name} not found, skipping");
|
if (logger.IsLogEnabled(LogLevel.Debug))
|
||||||
|
{
|
||||||
|
logger.Debug($"Exit with Id: {exitChange.Name} not found, skipping");
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -123,10 +130,11 @@ public class RaidTimeAdjustmentService(
|
|||||||
wave.TimeMin -= (int)Math.Max(startSeconds, 0);
|
wave.TimeMin -= (int)Math.Max(startSeconds, 0);
|
||||||
wave.TimeMax -= (int)Math.Max(startSeconds, 0);
|
wave.TimeMax -= (int)Math.Max(startSeconds, 0);
|
||||||
}
|
}
|
||||||
|
if (logger.IsLogEnabled(LogLevel.Debug)) {
|
||||||
logger.Debug(
|
logger.Debug(
|
||||||
$"Removed: {originalWaveCount - mapBase.Waves.Count} wave from map due to simulated raid start time of {raidAdjustments.SimulatedRaidStartSeconds / 60} minutes"
|
$"Removed: {originalWaveCount - mapBase.Waves.Count} wave from map due to simulated raid start time of: {raidAdjustments.SimulatedRaidStartSeconds / 60} minutes"
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -170,12 +178,16 @@ public class RaidTimeAdjustmentService(
|
|||||||
spawn.Time = (double)Math.Max(spawn.Time.GetValueOrDefault(1) - pmcStartSeconds, 1);
|
spawn.Time = (double)Math.Max(spawn.Time.GetValueOrDefault(1) - pmcStartSeconds, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Debug($"Offset PMC spawns by {pmcStartSeconds} seconds");
|
if (logger.IsLogEnabled(LogLevel.Debug))
|
||||||
|
{
|
||||||
|
logger.Debug($"Offset PMC spawns by: {pmcStartSeconds} seconds");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (logger.IsLogEnabled(LogLevel.Debug)) {
|
||||||
logger.Debug(
|
logger.Debug(
|
||||||
$"Removed: {originalPmcWaveCount - mapBase.BossLocationSpawn.Count} boss waves from map due to simulated raid start time of {raidAdjustments.SimulatedRaidStartSeconds / 60} minutes"
|
$"Removed: {originalPmcWaveCount - mapBase.BossLocationSpawn.Count} boss waves from map due to simulated raid start time of: {raidAdjustments.SimulatedRaidStartSeconds / 60} minutes"
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -223,17 +235,17 @@ public class RaidTimeAdjustmentService(
|
|||||||
var raidTimeRemainingPercent = 100 - chosenRaidReductionPercent;
|
var raidTimeRemainingPercent = 100 - chosenRaidReductionPercent;
|
||||||
|
|
||||||
// How many minutes raid will last
|
// How many minutes raid will last
|
||||||
var newRaidTimeMinutes = Math.Floor(randomUtil.ReduceValueByPercent(baseEscapeTimeMinutes ?? 1, chosenRaidReductionPercent));
|
var newRaidTimeMinutes = Math.Floor(randomUtil.ReduceValueByPercent(baseEscapeTimeMinutes ?? 1d, chosenRaidReductionPercent));
|
||||||
|
|
||||||
// Time player spawns into the raid if it was online
|
// Time player spawns into the raid if it was online
|
||||||
var simulatedRaidStartTimeMinutes = baseEscapeTimeMinutes - newRaidTimeMinutes;
|
var simulatedRaidStartTimeMinutes = baseEscapeTimeMinutes - newRaidTimeMinutes;
|
||||||
result.SimulatedRaidStartSeconds = simulatedRaidStartTimeMinutes * 60;
|
result.SimulatedRaidStartSeconds = simulatedRaidStartTimeMinutes * 60d;
|
||||||
result.RaidTimeMinutes = newRaidTimeMinutes;
|
result.RaidTimeMinutes = newRaidTimeMinutes;
|
||||||
|
|
||||||
// Calculate how long player needs to be in raid to get a `survived` extract status
|
// Calculate how long player needs to be in raid to get a `survived` extract status, never falls below 0
|
||||||
result.NewSurviveTimeSeconds = Math.Max(
|
result.NewSurviveTimeSeconds = Math.Max(
|
||||||
result.OriginalSurvivalTimeSeconds.Value - (baseEscapeTimeMinutes.Value - newRaidTimeMinutes) * 60,
|
(result.OriginalSurvivalTimeSeconds - ((baseEscapeTimeMinutes - newRaidTimeMinutes) * 60)) ?? 0d,
|
||||||
0
|
0d
|
||||||
);
|
);
|
||||||
|
|
||||||
if (mapSettings.ReduceLootByPercent)
|
if (mapSettings.ReduceLootByPercent)
|
||||||
@@ -242,16 +254,13 @@ public class RaidTimeAdjustmentService(
|
|||||||
result.StaticLootPercent = Math.Max(raidTimeRemainingPercent, mapSettings.MinStaticLootPercent);
|
result.StaticLootPercent = Math.Max(raidTimeRemainingPercent, mapSettings.MinStaticLootPercent);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Debug($"Reduced: {request.Location} raid time by: {chosenRaidReductionPercent}% to {newRaidTimeMinutes} minutes");
|
if (logger.IsLogEnabled(LogLevel.Debug))
|
||||||
|
{
|
||||||
// Calculate how long player needs to be in raid to get a `survived` extract status
|
logger.Debug($"Reduced: {request.Location} raid time by: {chosenRaidReductionPercent}% to {newRaidTimeMinutes} minutes");
|
||||||
result.NewSurviveTimeSeconds = Math.Max(
|
}
|
||||||
result.OriginalSurvivalTimeSeconds - (baseEscapeTimeMinutes - newRaidTimeMinutes) * 60 ?? 0,
|
|
||||||
0D
|
|
||||||
);
|
|
||||||
|
|
||||||
var exitAdjustments = GetExitAdjustments(mapBase, newRaidTimeMinutes);
|
var exitAdjustments = GetExitAdjustments(mapBase, newRaidTimeMinutes);
|
||||||
if (exitAdjustments.Any())
|
if (exitAdjustments.Count != 0)
|
||||||
{
|
{
|
||||||
result.ExitChanges.AddRange(exitAdjustments);
|
result.ExitChanges.AddRange(exitAdjustments);
|
||||||
}
|
}
|
||||||
@@ -336,9 +345,12 @@ public class RaidTimeAdjustmentService(
|
|||||||
{
|
{
|
||||||
exitChange.Chance = 0;
|
exitChange.Chance = 0;
|
||||||
|
|
||||||
logger.Debug(
|
if (logger.IsLogEnabled(LogLevel.Debug))
|
||||||
$"Train Exit: {exit.Name} disabled as new raid time {newRaidTimeMinutes} minutes is below {mostPossibleTimeRemainingAfterDeparture} minutes"
|
{
|
||||||
|
logger.Debug(
|
||||||
|
$"Train Exit: {exit.Name} disabled as new raid time: {newRaidTimeMinutes} minutes is below: {mostPossibleTimeRemainingAfterDeparture} minutes"
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
result.Add(exitChange);
|
result.Add(exitChange);
|
||||||
|
|
||||||
@@ -349,7 +361,10 @@ public class RaidTimeAdjustmentService(
|
|||||||
exitChange.MinTime = Math.Max(exit.MinTime - reductionSeconds ?? 0, 0);
|
exitChange.MinTime = Math.Max(exit.MinTime - reductionSeconds ?? 0, 0);
|
||||||
exitChange.MaxTime = Math.Max(exit.MaxTime - reductionSeconds ?? 0, 0);
|
exitChange.MaxTime = Math.Max(exit.MaxTime - reductionSeconds ?? 0, 0);
|
||||||
|
|
||||||
logger.Debug($"Train appears between: {exitChange.MinTime} and {exitChange.MaxTime} seconds raid time");
|
if (logger.IsLogEnabled(LogLevel.Debug))
|
||||||
|
{
|
||||||
|
logger.Debug($"Train appears between: {exitChange.MinTime} and: {exitChange.MaxTime} seconds raid time");
|
||||||
|
}
|
||||||
|
|
||||||
result.Add(exitChange);
|
result.Add(exitChange);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user