warnings fixed in inventoryController

This commit is contained in:
CWX
2025-01-19 12:56:41 +00:00
parent b9b70b8f68
commit 10ca26c022
3 changed files with 10 additions and 9 deletions
+3 -2
View File
@@ -48,6 +48,7 @@ public class GameController(
protected RagfairConfig _ragfairConfig = _configServer.GetConfig<RagfairConfig>();
protected HideoutConfig _hideoutConfig = _configServer.GetConfig<HideoutConfig>();
protected BotConfig _botConfig = _configServer.GetConfig<BotConfig>();
protected double _deviation = 0.0001;
/// <summary>
/// Handle client/game/start
@@ -373,7 +374,7 @@ public class GameController(
.Aggregate(0d, (sum, bonus) => sum + (bonus.Value!.Value));
// Player has energy deficit
if (pmcProfile.Health?.Energy?.Current != pmcProfile.Health?.Energy?.Maximum)
if (Math.Abs((pmcProfile.Health?.Energy?.Current - pmcProfile.Health?.Energy?.Maximum) ?? 1) <= _deviation)
{
// Set new value, whatever is smallest
pmcProfile.Health!.Energy!.Current += Math.Round(energyRegenPerHour * (diffSeconds!.Value / 3600));
@@ -384,7 +385,7 @@ public class GameController(
}
// Player has hydration deficit
if (pmcProfile.Health?.Hydration?.Current != pmcProfile.Health?.Hydration?.Maximum)
if (Math.Abs((pmcProfile.Health?.Hydration?.Current - pmcProfile.Health?.Hydration?.Maximum) ?? 1) <= _deviation)
{
pmcProfile.Health!.Hydration!.Current += Math.Round(hydrationRegenPerHour * (diffSeconds!.Value / 3600));
if (pmcProfile.Health.Hydration.Current > pmcProfile.Health.Hydration.Maximum)
+6 -6
View File
@@ -39,7 +39,7 @@ public class InventoryController(
{
public void MoveItem(PmcData pmcData, InventoryMoveRequestData moveRequest, string sessionID, ItemEventRouterResponse output)
{
if (output.Warnings.Count > 0)
if (output.Warnings?.Count > 0)
{
return;
}
@@ -56,7 +56,7 @@ public class InventoryController(
}
// Check for item in inventory before allowing internal transfer
var originalItemLocation = ownerInventoryItems.From.FirstOrDefault((item) => item.Id == moveRequest.Item);
var originalItemLocation = ownerInventoryItems.From?.FirstOrDefault((item) => item.Id == moveRequest.Item);
if (originalItemLocation is null)
{
// Internal item move but item never existed, possible dupe glitch
@@ -64,9 +64,9 @@ public class InventoryController(
return;
}
var originalLocationSlotId = originalItemLocation?.SlotId;
var originalLocationSlotId = originalItemLocation.SlotId;
var moveResult = _inventoryHelper.MoveItemInternal(pmcData, ownerInventoryItems.From, moveRequest, out var errorMessage);
var moveResult = _inventoryHelper.MoveItemInternal(pmcData, ownerInventoryItems.From ?? [], moveRequest, out var errorMessage);
if (!moveResult)
{
_httpResponseUtil.AppendErrorToOutput(output, errorMessage);
@@ -74,14 +74,14 @@ public class InventoryController(
}
// Item is moving into or out of place of fame dogtag slot
if (moveRequest.To.Container.StartsWith("dogtag") || originalLocationSlotId.StartsWith("dogtag"))
if (moveRequest.To?.Container != null && (moveRequest.To.Container.StartsWith("dogtag") || originalLocationSlotId!.StartsWith("dogtag")))
{
_hideoutHelper.ApplyPlaceOfFameDogtagBonus(pmcData);
}
}
else
{
_inventoryHelper.MoveItemToProfile(ownerInventoryItems.From, ownerInventoryItems.To, moveRequest);
_inventoryHelper.MoveItemToProfile(ownerInventoryItems.From ?? [], ownerInventoryItems.To ?? [], moveRequest);
}
}
+1 -1
View File
@@ -248,7 +248,7 @@ public class InventoryHelper(
/// <returns>OwnerInventoryItems with inventory of player/scav to adjust</returns>
public OwnerInventoryItems GetOwnerInventoryItems(
InventoryBaseActionRequestData request,
string item,
string? item,
string sessionId)
{
var pmcItems = _profileHelper.GetPmcProfile(sessionId).Inventory.Items;