territory claiming modification

This commit is contained in:
hz
2026-05-20 21:10:19 -05:00
parent f142440aca
commit c89c3a0947
4 changed files with 35 additions and 69 deletions
@@ -375,10 +375,6 @@ public class UnitTrainingService
.Unset(x => x.MovementCompletesAtUtc)
.Set(x => x.UpdatedAtUtc, now));
if (unit.UnitType == ArcherUnitType)
{
await ClaimTargetIfEmptyAsync(username, destinationQ, destinationR, now);
}
}
}
@@ -503,64 +499,6 @@ public class UnitTrainingService
return step == start ? target : step;
}
private async Task ClaimTargetIfEmptyAsync(string username, int q, int r, DateTime now)
{
var hasOtherUnits = await _units.Find(x => x.Username != username && x.Q == q && x.R == r).AnyAsync();
var target = await _locations.Find(x => x.Q == q && x.R == r).FirstOrDefaultAsync();
var hasBuilding = target is not null &&
(!string.IsNullOrWhiteSpace(target.BuildingType) ||
string.Equals(target.Kind, "Home", StringComparison.OrdinalIgnoreCase));
if (hasOtherUnits || hasBuilding)
{
return;
}
if (target is null)
{
var location = new Location
{
Q = q,
R = r,
Terrain = "Field",
Kind = "Claimed",
OwnerUsername = username,
Level = 1,
CreatedAtUtc = now,
UpdatedAtUtc = now
};
try
{
await _locations.InsertOneAsync(location);
}
catch (MongoWriteException)
{
}
return;
}
if (string.Equals(target.OwnerUsername, username, StringComparison.OrdinalIgnoreCase))
{
return;
}
var capturableFilter = Builders<Location>.Filter.And(
Builders<Location>.Filter.Eq(x => x.Id, target.Id),
Builders<Location>.Filter.Ne(x => x.Kind, "Home"),
Builders<Location>.Filter.Or(
Builders<Location>.Filter.Eq(x => x.BuildingType, null),
Builders<Location>.Filter.Eq(x => x.BuildingType, "")));
await _locations.UpdateOneAsync(
capturableFilter,
Builders<Location>.Update
.Set(x => x.OwnerUsername, username)
.Set(x => x.Kind, "Claimed")
.Set(x => x.UpdatedAtUtc, now));
}
private static int HexDistance(int q1, int r1, int q2, int r2)
{
var s1 = -q1 - r1;