Adding interactable object spawning

This commit is contained in:
2026-03-19 16:35:07 -05:00
parent 932f7be66b
commit 1aefd5ba88
12 changed files with 768 additions and 68 deletions
@@ -94,40 +94,42 @@ public class LocationsController : ControllerBase
return Ok("Updated");
}
[HttpPost("{id}/gather")]
[HttpPost("{id}/interact")]
[Authorize(Roles = "USER,SUPER")]
public async Task<IActionResult> Gather(string id, [FromBody] GatherResourceRequest req)
public async Task<IActionResult> Interact(string id, [FromBody] InteractLocationObjectRequest req)
{
if (string.IsNullOrWhiteSpace(req.CharacterId))
return BadRequest("characterId required");
if (string.IsNullOrWhiteSpace(req.ResourceKey))
return BadRequest("resourceKey required");
if (string.IsNullOrWhiteSpace(req.ObjectId))
return BadRequest("objectId required");
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
if (string.IsNullOrWhiteSpace(userId))
return Unauthorized();
var allowAnyOwner = User.IsInRole("SUPER");
var gather = await _locations.GatherResourceAsync(id, req.CharacterId, req.ResourceKey, userId, allowAnyOwner);
if (gather.Status == GatherStatus.LocationNotFound)
var interact = await _locations.InteractWithObjectAsync(id, req.CharacterId, req.ObjectId, userId, allowAnyOwner);
if (interact.Status == InteractStatus.LocationNotFound)
return NotFound("Location not found");
if (gather.Status == GatherStatus.CharacterNotFound)
if (interact.Status == InteractStatus.CharacterNotFound)
return NotFound("Character not found");
if (gather.Status == GatherStatus.Forbidden)
if (interact.Status == InteractStatus.Forbidden)
return Forbid();
if (gather.Status == GatherStatus.Invalid)
if (interact.Status == InteractStatus.Invalid)
return BadRequest("Character is not at the target location");
if (gather.Status == GatherStatus.ResourceNotFound)
return NotFound("Resource not found at location");
if (gather.Status == GatherStatus.ResourceDepleted)
return Conflict("Resource is depleted");
if (interact.Status == InteractStatus.ObjectNotFound)
return NotFound("Location object not found");
if (interact.Status == InteractStatus.UnsupportedObjectType)
return BadRequest("Location object type is not supported");
if (interact.Status == InteractStatus.ObjectConsumed)
return Conflict("Location object is consumed");
var inventoryBaseUrl = (_configuration["Services:InventoryApiBaseUrl"] ?? "http://localhost:5003").TrimEnd('/');
var token = Request.Headers.Authorization.ToString();
var grantBody = JsonSerializer.Serialize(new
{
itemKey = gather.ResourceKey,
quantity = gather.QuantityGranted
itemKey = interact.ItemKey,
quantity = interact.QuantityGranted
});
var client = _httpClientFactory.CreateClient();
@@ -142,17 +144,21 @@ public class LocationsController : ControllerBase
var responseBody = await response.Content.ReadAsStringAsync();
if (!response.IsSuccessStatusCode)
{
await _locations.RestoreGatheredResourceAsync(id, gather.ResourceKey, gather.QuantityGranted);
if (interact.PreviousObject is not null)
await _locations.RestoreObjectInteractionAsync(id, interact.PreviousObject);
return StatusCode((int)response.StatusCode, responseBody);
}
return Ok(new GatherResourceResponse
return Ok(new InteractLocationObjectResponse
{
LocationId = id,
CharacterId = req.CharacterId,
ResourceKey = gather.ResourceKey,
QuantityGranted = gather.QuantityGranted,
RemainingQuantity = gather.RemainingQuantity,
ObjectId = interact.ObjectId,
ObjectType = interact.ObjectType,
ItemKey = interact.ItemKey,
QuantityGranted = interact.QuantityGranted,
RemainingQuantity = interact.RemainingQuantity,
Consumed = interact.Consumed,
InventoryResponseJson = responseBody
});
}