Made use of Math.Clamp to simplify logic across server
Made all fence rep clamping use min/max values from config instead of magic values
This commit is contained in:
@@ -206,16 +206,15 @@ public class BotInventoryGenerator(
|
||||
)
|
||||
{
|
||||
foreach (
|
||||
var equipmentSlotKvP in randomistionDetails.NighttimeChanges.EquipmentModsModifiers
|
||||
var (equipment, weight) in randomistionDetails
|
||||
.NighttimeChanges
|
||||
.EquipmentModsModifiers
|
||||
)
|
||||
// Never let mod chance go outside 0 - 100
|
||||
{
|
||||
randomistionDetails.EquipmentMods[equipmentSlotKvP.Key] = Math.Min(
|
||||
Math.Max(
|
||||
randomistionDetails.EquipmentMods[equipmentSlotKvP.Key]
|
||||
+ equipmentSlotKvP.Value,
|
||||
0
|
||||
),
|
||||
randomistionDetails.EquipmentMods[equipment] = Math.Clamp(
|
||||
randomistionDetails.EquipmentMods[equipment] + weight,
|
||||
0,
|
||||
100
|
||||
);
|
||||
}
|
||||
|
||||
@@ -86,13 +86,13 @@ public class BotLevelGenerator(
|
||||
var minPossibleLevel = levelOverride is not null
|
||||
? Math.Min(
|
||||
Math.Max(levelDetails.Min, levelOverride.Min), // Biggest between json min and the botgen min
|
||||
maxAvailableLevel // Fallback if value above is crazy (default is 79)
|
||||
maxAvailableLevel // Fallback if value above is crazy
|
||||
)
|
||||
: Math.Min(levelDetails.Min, maxAvailableLevel); // Not pmc with override or non-pmc
|
||||
: Math.Clamp(levelDetails.Min, 1, maxAvailableLevel); // Not pmc with override or non-pmc
|
||||
|
||||
// Create a max limit PMCs level cannot go above
|
||||
var maxPossibleLevel = levelOverride is not null
|
||||
? Math.Min(levelOverride.Max, maxAvailableLevel) // Was a PMC and they have a level override
|
||||
? Math.Min(levelOverride.Max, maxAvailableLevel) // Is PMC and have a level override
|
||||
: Math.Min(levelDetails.Max, maxAvailableLevel); // Not pmc with override or non-pmc
|
||||
|
||||
// Get min level relative to player if value exists
|
||||
@@ -108,8 +108,8 @@ public class BotLevelGenerator(
|
||||
: 1 + botGenerationDetails.BotRelativeLevelDeltaMin.Value;
|
||||
|
||||
// Bound the level to the min/max possible
|
||||
maxLevel = Math.Min(Math.Max(maxLevel, minPossibleLevel), maxPossibleLevel);
|
||||
minLevel = Math.Min(Math.Max(minLevel, minPossibleLevel), maxPossibleLevel);
|
||||
maxLevel = Math.Clamp(maxLevel, minPossibleLevel, maxPossibleLevel);
|
||||
minLevel = Math.Clamp(minLevel, minPossibleLevel, maxPossibleLevel);
|
||||
|
||||
return new MinMax<int>(minLevel, maxLevel);
|
||||
}
|
||||
|
||||
+1
-1
@@ -485,7 +485,7 @@ public class RepeatableQuestRewardGenerator(
|
||||
var stackMaxCount = Math.Min(itemSelected.Properties.StackMaxSize.Value, 100);
|
||||
|
||||
// Ensure stack size is at least 1 + is no larger than the max possible stack size
|
||||
return (int)Math.Max(1, Math.Min(stackSizeThatFitsBudget, stackMaxCount));
|
||||
return (int)Math.Clamp(stackSizeThatFitsBudget, 1, stackMaxCount);
|
||||
}
|
||||
|
||||
protected bool CanIncreaseRewardItemStackSize(
|
||||
|
||||
@@ -588,7 +588,9 @@ public class LocationLifecycleService(
|
||||
fenceStanding += Math.Max(baseGain / extractCount, 0.01);
|
||||
|
||||
// Ensure fence loyalty level is not above/below the range -7 to 15
|
||||
var newFenceStanding = Math.Min(Math.Max((double)fenceStanding, -7), 15);
|
||||
var fenceMax = _traderConfig.Fence.PlayerRepMax;
|
||||
var fenceMin = _traderConfig.Fence.PlayerRepMin;
|
||||
var newFenceStanding = Math.Clamp(fenceStanding.GetValueOrDefault(0), fenceMin, fenceMax);
|
||||
logger.Debug(
|
||||
$"Old vs new fence standing: {pmcData.TradersInfo[fenceId].Standing}, {newFenceStanding}"
|
||||
);
|
||||
@@ -678,8 +680,9 @@ public class LocationLifecycleService(
|
||||
logger.Error($"post raid fence data not found for: {sessionId}");
|
||||
}
|
||||
|
||||
scavProfile.TradersInfo[Traders.FENCE].Standing = Math.Min(
|
||||
Math.Max(postRaidFenceData.Standing.Value, fenceMin),
|
||||
scavProfile.TradersInfo[Traders.FENCE].Standing = Math.Clamp(
|
||||
postRaidFenceData.Standing.Value,
|
||||
fenceMin,
|
||||
fenceMax
|
||||
);
|
||||
|
||||
@@ -882,11 +885,14 @@ public class LocationLifecycleService(
|
||||
var fenceId = Traders.FENCE;
|
||||
|
||||
// Clamp fence standing
|
||||
var currentFenceStanding = postRaidProfile.TradersInfo[fenceId].Standing ?? 0d;
|
||||
serverPmcProfile.TradersInfo[fenceId].Standing = Math.Min(
|
||||
Math.Max(currentFenceStanding, -7),
|
||||
15
|
||||
); // Ensure it stays between -7 and 15
|
||||
var fenceMax = _traderConfig.Fence.PlayerRepMax; // 15
|
||||
var fenceMin = _traderConfig.Fence.PlayerRepMin; //-7
|
||||
|
||||
serverPmcProfile.TradersInfo[fenceId].Standing = Math.Clamp(
|
||||
postRaidProfile.TradersInfo[fenceId].Standing ?? 0d,
|
||||
fenceMin,
|
||||
fenceMax
|
||||
);
|
||||
|
||||
// Copy fence values to Scav
|
||||
scavProfile.TradersInfo[fenceId] = serverPmcProfile.TradersInfo[fenceId];
|
||||
|
||||
@@ -748,8 +748,9 @@ public class RepairService(
|
||||
{
|
||||
// Ensure the max percent is at least 0.01
|
||||
var validMaxPercent = Math.Max(0.01, receiveDurabilityMaxPercent);
|
||||
|
||||
// Calculate the ratio and constrain it between 0.01 and 1
|
||||
return Math.Min(1, Math.Max(0.01, receiveDurabilityPercent / validMaxPercent));
|
||||
return Math.Clamp(receiveDurabilityPercent / validMaxPercent, 0.01, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,8 @@ public class MathUtil
|
||||
var deltaOut = maxOut - minOut;
|
||||
|
||||
var xScale = (x - minIn) / deltaIn;
|
||||
return Math.Max(minOut, Math.Min(maxOut, minOut + xScale * deltaOut));
|
||||
|
||||
return Math.Clamp(minOut + xScale * deltaOut, minOut, maxOut);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user