mirror of
https://github.com/SoDOff-Project/sodoff.git
synced 2025-11-27 01:56:53 -08:00
add AddItemsToInventoryBulkAndGetResponse function
This commit is contained in:
parent
693a73a71e
commit
f12fcda9d6
@ -1201,24 +1201,12 @@ public class ContentController : Controller {
|
||||
inventoryItemsToAdd[reward.ItemId] += quantity;
|
||||
}
|
||||
|
||||
var addedItems = inventoryService.AddItemsToInventoryBulk(viking, inventoryItemsToAdd);
|
||||
|
||||
// build response
|
||||
List<CommonInventoryResponseItem> items = new List<CommonInventoryResponseItem>();
|
||||
foreach (var i in inventoryItemsToAdd) {
|
||||
items.AddRange(Enumerable.Repeat(
|
||||
new CommonInventoryResponseItem {
|
||||
CommonInventoryID = addedItems.ContainsKey(i.Key) ? addedItems[i.Key] : 0, // return inventory id if this item was added to the DB
|
||||
ItemID = i.Key,
|
||||
Quantity = 0
|
||||
}, i.Value));
|
||||
}
|
||||
|
||||
return Ok(new CommonInventoryResponse{
|
||||
Success = true,
|
||||
CommonInventoryIDs = items.ToArray(),
|
||||
UserGameCurrency = achievementService.GetUserCurrency(viking)
|
||||
});
|
||||
// add items to the inventory (database) and build response
|
||||
return Ok(
|
||||
inventoryService.AddItemsToInventoryBulkAndGetResponse(
|
||||
viking, inventoryItemsToAdd, inventoryItemsToAdd, achievementService.GetUserCurrency(viking)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
@ -2484,26 +2472,9 @@ public class ContentController : Controller {
|
||||
achievementService.AddAchievementPoints(viking, AchievementPointTypes.GameCurrency, -totalCoinCost + coinsToAdd);
|
||||
achievementService.AddAchievementPoints(viking, AchievementPointTypes.CashCurrency, -totalGemCost + gemsToAdd);
|
||||
|
||||
// add items to the inventory (database)
|
||||
var addedItems = inventoryService.AddItemsToInventoryBulk(viking, inventoryItemsToAdd);
|
||||
|
||||
// build response
|
||||
List<CommonInventoryResponseItem> items = new List<CommonInventoryResponseItem>();
|
||||
foreach (var i in itemsToSendBack) {
|
||||
items.AddRange(Enumerable.Repeat(
|
||||
new CommonInventoryResponseItem {
|
||||
CommonInventoryID = addedItems.ContainsKey(i.Key) ? addedItems[i.Key] : 0, // return inventory id if this item was added to the DB
|
||||
ItemID = i.Key,
|
||||
Quantity = 0
|
||||
}, i.Value));
|
||||
}
|
||||
// NOTE: The quantity of purchased items can always be 0 and the items are instead duplicated in both the request and the response.
|
||||
// Item quantities are used for non-store related requests/responses.
|
||||
|
||||
return new CommonInventoryResponse {
|
||||
Success = true,
|
||||
CommonInventoryIDs = items.ToArray(),
|
||||
UserGameCurrency = achievementService.GetUserCurrency(viking)
|
||||
};
|
||||
// add items to the inventory (database) and build response
|
||||
return inventoryService.AddItemsToInventoryBulkAndGetResponse(
|
||||
viking, inventoryItemsToAdd, itemsToSendBack, achievementService.GetUserCurrency(viking)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,6 +74,30 @@ namespace sodoff.Services {
|
||||
return itemsWithInventoryId;
|
||||
}
|
||||
|
||||
public CommonInventoryResponse AddItemsToInventoryBulkAndGetResponse(Viking viking, Dictionary<int,int> inventoryItemsToAdd, Dictionary<int,int> itemsToSendBack, UserGameCurrency gameCurrency) {
|
||||
// add items to the inventory (database)
|
||||
var addedItems = AddItemsToInventoryBulk(viking, inventoryItemsToAdd);
|
||||
|
||||
// build response
|
||||
List<CommonInventoryResponseItem> items = new List<CommonInventoryResponseItem>();
|
||||
foreach (var i in itemsToSendBack) {
|
||||
items.AddRange(Enumerable.Repeat(
|
||||
new CommonInventoryResponseItem {
|
||||
CommonInventoryID = addedItems.ContainsKey(i.Key) ? addedItems[i.Key] : 0, // return inventory id if this item was added to the DB
|
||||
ItemID = i.Key,
|
||||
Quantity = 0
|
||||
}, i.Value));
|
||||
}
|
||||
// NOTE: The quantity of purchased items can always be 0 and the items are instead duplicated in both the request and the response.
|
||||
// Item quantities are used for non-store related requests/responses.
|
||||
|
||||
return new CommonInventoryResponse {
|
||||
Success = true,
|
||||
CommonInventoryIDs = items.ToArray(),
|
||||
UserGameCurrency = gameCurrency
|
||||
};
|
||||
}
|
||||
|
||||
public InventoryItemStatsMap AddBattleItemToInventory(Viking viking, int itemId, int itemTier, ItemStat[] itemStat = null) {
|
||||
// get item data
|
||||
ItemData itemData = itemService.GetItem(itemId);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user