From ed8cba8159e08bccb6be9c75d426584e050207e7 Mon Sep 17 00:00:00 2001 From: Robert Paciorek Date: Mon, 4 Sep 2023 21:05:57 +0000 Subject: [PATCH] bugfixes: removing item in SetCommonInventory, ... - fix removing item from inventtory in SetCommonInventory (regresion after switch to InventoryService) - fix null exception in SellItem on invalid UserInventoryCommonIDs - remove unused fields in AchievementService (are in AchievementStoreSingleton) --- src/Controllers/Common/ContentController.cs | 11 +++++++---- src/Services/AchievementService.cs | 7 ------- src/Services/InventoryService.cs | 2 ++ 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/Controllers/Common/ContentController.cs b/src/Controllers/Common/ContentController.cs index 8992c2d..f3a48b1 100644 --- a/src/Controllers/Common/ContentController.cs +++ b/src/Controllers/Common/ContentController.cs @@ -176,7 +176,7 @@ public class ContentController : Controller { // Now that we know the request is valid, update the inventory foreach (var req in request) { if (req.ItemID == 0) continue; // Do not save a null item - + if (inventoryService.ItemNeedUniqueInventorySlot((int)req.ItemID)) { // if req.Quantity < 0 remove unique items for (int i=req.Quantity; i<0; ++i) { @@ -190,10 +190,9 @@ public class ContentController : Controller { ); } } else { + var responseItem = inventoryService.AddItemToInventoryAndGetResponse(viking, (int)req.ItemID!, req.Quantity); if (req.Quantity > 0) { - responseItems.Add( - inventoryService.AddItemToInventoryAndGetResponse(viking, (int)req.ItemID!, req.Quantity) - ); + responseItems.Add(responseItem); } } } @@ -1016,6 +1015,10 @@ public class ContentController : Controller { inventoryService.SellInventoryItem(viking, invItemID, ref gold, ref shard); } + if (gold == 0 && shard == 0) { // NOTE: client sometimes call SellItems with invalid UserInventoryCommonIDs for unknown reasons + return Ok(new CommonInventoryResponse { Success = false }); + } + // apply shards reward CommonInventoryResponseItem resShardsItem = inventoryService.AddItemToInventoryAndGetResponse(viking, InventoryService.Shards, shard); diff --git a/src/Services/AchievementService.cs b/src/Services/AchievementService.cs index 5e92179..d4f4449 100644 --- a/src/Services/AchievementService.cs +++ b/src/Services/AchievementService.cs @@ -10,13 +10,6 @@ namespace sodoff.Services { private AchievementStoreSingleton achievementStore; private InventoryService inventoryService; - Dictionary ranks = new(); - Dictionary achivmentsRewardByID = new(); - Dictionary achivmentsRewardByTask = new(); - - int dragonAdultMinXP; - int dragonTitanMinXP; - public AchievementService(AchievementStoreSingleton achievementStore, InventoryService inventoryService) { this.achievementStore = achievementStore; this.inventoryService = inventoryService; diff --git a/src/Services/InventoryService.cs b/src/Services/InventoryService.cs index d48915f..a27c203 100644 --- a/src/Services/InventoryService.cs +++ b/src/Services/InventoryService.cs @@ -74,6 +74,8 @@ namespace sodoff.Services { public void SellInventoryItem(Viking viking, int invItemID, ref int gold, ref int shard) { // get item from inventory InventoryItem? item = viking.Inventory.InventoryItems.FirstOrDefault(e => e.Id == invItemID); + if (item is null) + return; // get item data ItemData? itemData = itemService.GetItem(item.ItemId);