From 2e9c8f22da0e9958bf03981b78fbb8eba700cd60 Mon Sep 17 00:00:00 2001 From: Robert Paciorek Date: Tue, 26 Sep 2023 21:53:52 +0000 Subject: [PATCH] fix intenal error on fuse and reroll --- src/Controllers/Common/ContentController.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Controllers/Common/ContentController.cs b/src/Controllers/Common/ContentController.cs index d21b921..4f497dc 100644 --- a/src/Controllers/Common/ContentController.cs +++ b/src/Controllers/Common/ContentController.cs @@ -979,6 +979,9 @@ public class ContentController : Controller { foreach (string name in req.ItemStatNames) { ItemStat itemStat = itemStatsMap.ItemStats.FirstOrDefault(e => e.Name == name); + if (itemStat is null) + return Ok(new RollUserItemResponse { Status = Status.InvalidStatsMap }); + // draw new stats StatRangeMap rangeMap = itemData.PossibleStatsMap.Stats.FirstOrDefault(e => e.ItemStatsID == itemStat.ItemStatID).ItemStatsRangeMaps.FirstOrDefault(e => e.ItemTierID == (int)(itemStatsMap.ItemTier)); int newVal = random.Next(rangeMap.StartRange, rangeMap.EndRange+1); @@ -1062,12 +1065,21 @@ public class ContentController : Controller { // remove items from DeductibleItemInventoryMaps and BluePrintFuseItemMaps foreach (var item in req.DeductibleItemInventoryMaps) { InventoryItem? invItem = viking.Inventory.InventoryItems.FirstOrDefault(e => e.Id == item.UserInventoryID); + if (invItem is null) { + invItem = viking.Inventory.InventoryItems.FirstOrDefault(e => e.ItemId == item.ItemID); + } + if (invItem is null || invItem.Quantity < item.Quantity) { + return Ok(new FuseItemsResponse { Status = Status.ItemNotFound }); + } invItem.Quantity -= item.Quantity; } foreach (var item in req.BluePrintFuseItemMaps) { InventoryItem? invItem = viking.Inventory.InventoryItems.FirstOrDefault(e => e.Id == item.UserInventoryID); + if (invItem is null) + return Ok(new FuseItemsResponse { Status = Status.ItemNotFound }); viking.Inventory.InventoryItems.Remove(invItem); } + // NOTE: we haven't saved any changes so far ... so we can safely interrupt "fusing" by return in loops above var resItemList = new List(); foreach (BluePrintSpecification output in blueprintItem.BluePrint.Outputs) {