territory claiming

This commit is contained in:
hz
2026-05-18 15:40:15 -05:00
parent 37a46a7b36
commit 3167558e04
5 changed files with 127 additions and 4 deletions
@@ -11,10 +11,12 @@ namespace LocationsApi.Controllers;
public class LocationsController : ControllerBase
{
private readonly LocationService _locations;
private readonly UnitTrainingService _units;
public LocationsController(LocationService locations)
public LocationsController(LocationService locations, UnitTrainingService units)
{
_locations = locations;
_units = units;
}
[Authorize(Roles = "USER,SUPER")]
@@ -86,6 +88,22 @@ public class LocationsController : ControllerBase
return NotFound();
}
var existingLocation = await _locations.GetAsync(request.Q, request.R);
if (existingLocation is not null && !string.IsNullOrWhiteSpace(existingLocation.OwnerUsername))
{
if (string.Equals(existingLocation.OwnerUsername, username, StringComparison.OrdinalIgnoreCase))
{
return Ok(LocationResponse.FromLocation(existingLocation));
}
return Conflict("Location is already controlled by another player.");
}
if (!User.IsInRole("SUPER") && !await _units.TryConsumeCompletedScoutAsync(username))
{
return BadRequest("A completed scout is required to claim unclaimed territory.");
}
var location = await _locations.ClaimAsync(request.Q, request.R, username);
if (location is null)
{