mirror of
https://github.com/SoDOff-Project/sodoff.git
synced 2025-10-11 08:18:49 -07:00
ContentController.cs: Handle CommonInventoryRequests in CreatePet (#20)
This commit is contained in:
parent
17303d9256
commit
c3bb769934
@ -388,7 +388,20 @@ public class ContentController : Controller {
|
||||
ctx.Images.Add(image);
|
||||
ctx.SaveChanges();
|
||||
|
||||
// TODO: handle CommonInventoryRequests here too
|
||||
if (raisedPetRequest.CommonInventoryRequests is not null) {
|
||||
foreach (var req in raisedPetRequest.CommonInventoryRequests) {
|
||||
InventoryItem? item = viking.Inventory.InventoryItems.FirstOrDefault(e => e.ItemId == req.ItemID);
|
||||
|
||||
//Does the item exist in the user's inventory?
|
||||
if (item is null) continue; //If not, skip it.
|
||||
|
||||
if (item.Quantity + req.Quantity >= 0 ) { //If so, can we update it appropriately?
|
||||
//We can. Do so.
|
||||
item.Quantity += req.Quantity; //Note that we use += here because req.Quantity is negative.
|
||||
ctx.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(new CreatePetResponse {
|
||||
RaisedPetData = GetRaisedPetDataFromDragon(dragon)
|
||||
|
Loading…
x
Reference in New Issue
Block a user