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)
This commit is contained in:
Robert Paciorek 2023-09-04 21:05:57 +00:00 committed by Spirtix
parent 883fbd2181
commit ed8cba8159
3 changed files with 9 additions and 11 deletions

View File

@ -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);

View File

@ -10,13 +10,6 @@ namespace sodoff.Services {
private AchievementStoreSingleton achievementStore;
private InventoryService inventoryService;
Dictionary<AchievementPointTypes, UserRank[]> ranks = new();
Dictionary<int, AchievementReward[]> achivmentsRewardByID = new();
Dictionary<int, AchievementReward[]> achivmentsRewardByTask = new();
int dragonAdultMinXP;
int dragonTitanMinXP;
public AchievementService(AchievementStoreSingleton achievementStore, InventoryService inventoryService) {
this.achievementStore = achievementStore;
this.inventoryService = inventoryService;

View File

@ -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);