territory claiming modification
This commit is contained in:
@@ -145,8 +145,12 @@ public class LocationService
|
||||
var existing = await GetAsync(q, r);
|
||||
if (existing is not null)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(existing.OwnerUsername) &&
|
||||
!string.Equals(existing.OwnerUsername, username, StringComparison.OrdinalIgnoreCase))
|
||||
if (string.Equals(existing.OwnerUsername, username, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return existing;
|
||||
}
|
||||
|
||||
if (!await CanScoutClaimAsync(username, q, r))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -164,6 +168,26 @@ public class LocationService
|
||||
return await UpsertAsync(new UpsertLocationRequest { Q = q, R = r, Terrain = "Field" }, username);
|
||||
}
|
||||
|
||||
public async Task<bool> CanScoutClaimAsync(string username, int q, int r)
|
||||
{
|
||||
var existing = await GetAsync(q, r);
|
||||
if (existing is not null)
|
||||
{
|
||||
if (string.Equals(existing.OwnerUsername, username, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (string.Equals(existing.Kind, "Home", StringComparison.OrdinalIgnoreCase) ||
|
||||
!string.IsNullOrWhiteSpace(existing.BuildingType))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return !await _units.Find(x => x.Q == q && x.R == r).AnyAsync();
|
||||
}
|
||||
|
||||
public async Task<Location?> BuildAsync(BuildLocationRequest request, string username)
|
||||
{
|
||||
var buildingType = NormalizeBuildingType(request.BuildingType);
|
||||
|
||||
Reference in New Issue
Block a user