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:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -346,6 +346,19 @@ public class PlayerController : ControllerBase
|
||||
await _locationService.RemoveItemFromLocationAsync(location.Id, itemId);
|
||||
await _itemService.DeleteAsync(itemId);
|
||||
}
|
||||
else if (item.UsesRemaining > 0)
|
||||
{
|
||||
item.UsesRemaining--;
|
||||
if (item.UsesRemaining <= 0)
|
||||
{
|
||||
await _locationService.RemoveItemFromLocationAsync(location.Id, itemId);
|
||||
await _itemService.DeleteAsync(itemId);
|
||||
}
|
||||
else
|
||||
{
|
||||
await _itemService.UpdateAsync(item);
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(outcome.Result);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,8 @@ public class SpawnableController : ControllerBase
|
||||
SpawnRate = req.SpawnRate,
|
||||
CollectAction = req.CollectAction,
|
||||
CollectResults = req.CollectResults,
|
||||
ConsumeOnSuccess = req.ConsumeOnSuccess
|
||||
ConsumeOnSuccess = req.ConsumeOnSuccess,
|
||||
Uses = req.Uses
|
||||
};
|
||||
|
||||
await _spawnableService.CreateAsync(spawnable);
|
||||
@@ -47,6 +48,7 @@ public class SpawnableController : ControllerBase
|
||||
spawnable.CollectAction = req.CollectAction;
|
||||
spawnable.CollectResults = req.CollectResults;
|
||||
spawnable.ConsumeOnSuccess = req.ConsumeOnSuccess;
|
||||
spawnable.Uses = req.Uses;
|
||||
|
||||
await _spawnableService.UpdateAsync(spawnable);
|
||||
return Ok(spawnable);
|
||||
|
||||
Reference in New Issue
Block a user