territory claiming
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user