Implemented a property that will allow a spawnable to be acted on a variable number of times before being consumed.

This commit is contained in:
hz
2025-06-09 23:05:40 -05:00
parent 5a27adf034
commit 43f3e8f0e7
12 changed files with 83 additions and 7 deletions
+11 -2
View File
@@ -12,11 +12,13 @@ public class ItemController : ControllerBase
{
private readonly ItemService _itemService;
private readonly LocationService _locationService;
private readonly SpawnableService _spawnableService;
public ItemController(ItemService itemService, LocationService locationService)
public ItemController(ItemService itemService, LocationService locationService, SpawnableService spawnableService)
{
_itemService = itemService;
_locationService = locationService;
_spawnableService = spawnableService;
}
[HttpPost]
@@ -27,10 +29,16 @@ public class ItemController : ControllerBase
if (location == null)
return BadRequest("Invalid location ID.");
var uses = req.UsesRemaining;
var spawnable = await _spawnableService.GetByNameAsync(req.Name.ToLower());
if (spawnable != null && spawnable.Uses > 0)
uses = spawnable.Uses;
var item = new Item
{
Name = req.Name,
LocationId = req.LocationId
LocationId = req.LocationId,
UsesRemaining = uses
};
await _itemService.CreateAsync(item);
@@ -58,6 +66,7 @@ public class ItemController : ControllerBase
item.Name = req.Name;
item.LocationId = req.LocationId;
item.UsesRemaining = req.UsesRemaining;
await _itemService.UpdateAsync(item);
return Ok(item);
}