From 10ca26c0221efeed489f92db9bf930849bb68b3f Mon Sep 17 00:00:00 2001 From: CWX Date: Sun, 19 Jan 2025 12:56:41 +0000 Subject: [PATCH] warnings fixed in inventoryController --- Core/Controllers/GameController.cs | 5 +++-- Core/Controllers/InventoryController.cs | 12 ++++++------ Core/Helpers/InventoryHelper.cs | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Core/Controllers/GameController.cs b/Core/Controllers/GameController.cs index e0fe9aeb..1501bd58 100644 --- a/Core/Controllers/GameController.cs +++ b/Core/Controllers/GameController.cs @@ -48,6 +48,7 @@ public class GameController( protected RagfairConfig _ragfairConfig = _configServer.GetConfig(); protected HideoutConfig _hideoutConfig = _configServer.GetConfig(); protected BotConfig _botConfig = _configServer.GetConfig(); + protected double _deviation = 0.0001; /// /// 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) diff --git a/Core/Controllers/InventoryController.cs b/Core/Controllers/InventoryController.cs index 8d69abc2..d4627e15 100644 --- a/Core/Controllers/InventoryController.cs +++ b/Core/Controllers/InventoryController.cs @@ -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); } } diff --git a/Core/Helpers/InventoryHelper.cs b/Core/Helpers/InventoryHelper.cs index c29c1118..a0509791 100644 --- a/Core/Helpers/InventoryHelper.cs +++ b/Core/Helpers/InventoryHelper.cs @@ -248,7 +248,7 @@ public class InventoryHelper( /// OwnerInventoryItems with inventory of player/scav to adjust public OwnerInventoryItems GetOwnerInventoryItems( InventoryBaseActionRequestData request, - string item, + string? item, string sessionId) { var pmcItems = _profileHelper.GetPmcProfile(sessionId).Inventory.Items;