diff --git a/Libraries/SPTarkov.Server.Core/Helpers/InventoryHelper.cs b/Libraries/SPTarkov.Server.Core/Helpers/InventoryHelper.cs index bf187523..2c5e6ee3 100644 --- a/Libraries/SPTarkov.Server.Core/Helpers/InventoryHelper.cs +++ b/Libraries/SPTarkov.Server.Core/Helpers/InventoryHelper.cs @@ -843,7 +843,7 @@ public class InventoryHelper( foreach (var item in containerItemHash) { - var (itemLocation, _) = ItemHelper.TryParseItemLocation(item); + var itemLocation = ItemHelper.TryParseItemLocation(item); if (itemLocation is null) { diff --git a/Libraries/SPTarkov.Server.Core/Helpers/ItemHelper.cs b/Libraries/SPTarkov.Server.Core/Helpers/ItemHelper.cs index e92233da..7527b6d4 100644 --- a/Libraries/SPTarkov.Server.Core/Helpers/ItemHelper.cs +++ b/Libraries/SPTarkov.Server.Core/Helpers/ItemHelper.cs @@ -859,65 +859,6 @@ public class ItemHelper( return _dogTagTpls.Contains(tpl); } - /// - /// Given that the R field of item location can be string enum or int, provide a method to get the exact type - /// - /// - /// - - public static (ItemLocation? itemLocation, LocationInGrid? locationInGrid) TryParseItemLocation(Item item) - { - if (item.Location is not JsonElement jsonLocation) - { - return ((ItemLocation?) item.Location, null); - } - - var itemLocation = TryParseItemLocation(jsonLocation); - if (itemLocation != null) - { - return (itemLocation, null); - } - - var locationInGrid = TryParseLocationInGrid(jsonLocation); - if (locationInGrid == null) - { - return (null, null); - } - - itemLocation = new ItemLocation - { - X = locationInGrid.X, - Y = locationInGrid.Y, - IsSearched = locationInGrid.IsSearched, - R = locationInGrid.R == ItemRotation.Vertical ? 1 : 0 - }; - return (itemLocation, locationInGrid); - - ItemLocation? TryParseItemLocation(JsonElement element) - { - try - { - return element.ToObject(); - } - catch - { - return null; - } - } - - LocationInGrid? TryParseLocationInGrid(JsonElement element) - { - try - { - return element.ToObject(); - } - catch - { - return null; - } - } - } - /// /// Gets the identifier for a child using slotId, locationX and locationY. /// @@ -2241,6 +2182,64 @@ public class ItemHelper( } } } + + /// + /// Given that the R field of item location can be string enum or int, provide a method to get the exact type + /// + /// + /// ItemLocation possible null + public static ItemLocation? TryParseItemLocation(Item item) + { + if (item.Location is not JsonElement jsonLocation) + { + return (ItemLocation?) item.Location; + } + + var itemLocation = TryParseItemLocation(jsonLocation); + if (itemLocation != null) + { + return itemLocation; + } + + var locationInGrid = TryParseLocationInGrid(jsonLocation); + if (locationInGrid == null) + { + return null; + } + + itemLocation = new ItemLocation + { + X = locationInGrid.X, + Y = locationInGrid.Y, + IsSearched = locationInGrid.IsSearched, + R = locationInGrid.R == ItemRotation.Vertical ? 1 : 0 + }; + return itemLocation; + } + + private static ItemLocation? TryParseItemLocation(JsonElement element) + { + try + { + return element.ToObject(); + } + catch + { + return null; + } + } + + private static LocationInGrid? TryParseLocationInGrid(JsonElement element) + { + try + { + return element.ToObject(); + } + catch + { + return null; + } + } } public class ItemSize