adding delivery
Deploy Territory Autobattler Auth API / deploy (push) Canceled after 0s
Deploy Territory Autobattler Locations API / deploy (push) Canceled after 0s
k8s smoke test / test (push) Canceled after 0s

This commit is contained in:
hz
2026-05-22 03:11:32 -05:00
parent a2fd9a84e3
commit c0e60d622c
6 changed files with 199 additions and 25 deletions
@@ -337,6 +337,8 @@ public class LocationService
.Set(x => x.MovementRemaining, 0)
.Set(x => x.DestinationQ, request.Q)
.Set(x => x.DestinationR, request.R)
.Set(x => x.WorksiteQ, request.Q)
.Set(x => x.WorksiteR, request.R)
.Set(x => x.MovementStartedAtUtc, now)
.Set(x => x.MovementCompletesAtUtc, now.AddMinutes(1))
.Set(x => x.UpdatedAtUtc, now));
@@ -360,11 +362,19 @@ public class LocationService
}
await _units.UpdateOneAsync(
x => x.Id == location.WorkerUnitId && x.Username == username && x.Status == "Working",
x => x.Id == location.WorkerUnitId && x.Username == username,
Builders<UnitInstance>.Update
.Set(x => x.Q, request.Q)
.Set(x => x.R, request.R)
.Set(x => x.Status, "Idle")
.Unset(x => x.WorksiteQ)
.Unset(x => x.WorksiteR)
.Unset(x => x.DestinationQ)
.Unset(x => x.DestinationR)
.Unset(x => x.CarryingResourceType)
.Set(x => x.CarryingResourceAmount, 0)
.Unset(x => x.MovementStartedAtUtc)
.Unset(x => x.MovementCompletesAtUtc)
.Set(x => x.UpdatedAtUtc, now));
var updated = await _locations.FindOneAndUpdateAsync(
@@ -372,6 +382,7 @@ public class LocationService
Builders<Location>.Update
.Unset(x => x.WorkerUnitId)
.Unset(x => x.WorkerUnitType)
.Unset(x => x.DeliveryCycleStartedAtUtc)
.Set(x => x.UpdatedAtUtc, now),
new FindOneAndUpdateOptions<Location> { ReturnDocument = ReturnDocument.After });
@@ -404,6 +415,14 @@ public class LocationService
.Set(x => x.R, r)
.Set(x => x.Status, "Idle")
.Set(x => x.MovementRemaining, 1)
.Unset(x => x.WorksiteQ)
.Unset(x => x.WorksiteR)
.Unset(x => x.DestinationQ)
.Unset(x => x.DestinationR)
.Unset(x => x.CarryingResourceType)
.Set(x => x.CarryingResourceAmount, 0)
.Unset(x => x.MovementStartedAtUtc)
.Unset(x => x.MovementCompletesAtUtc)
.Set(x => x.UpdatedAtUtc, now));
}
@@ -420,6 +439,7 @@ public class LocationService
.Set(x => x.StoredResourceAmount, 0)
.Set(x => x.StoredResourceCapacity, 10)
.Unset(x => x.LastResourceGeneratedAtUtc)
.Unset(x => x.DeliveryCycleStartedAtUtc)
.Set(x => x.UpdatedAtUtc, now),
new FindOneAndUpdateOptions<Location> { ReturnDocument = ReturnDocument.After });
@@ -649,6 +669,7 @@ public class LocationService
var currentQ = worker.Q;
var currentR = worker.R;
var elapsedSteps = Math.Max(1, (int)Math.Floor((now - worker.MovementCompletesAtUtc!.Value).TotalMinutes) + 1);
var usedSteps = 0;
var movementBlocked = false;
while (elapsedSteps > 0 && HexDistance(currentQ, currentR, destinationQ, destinationR) > 1)
@@ -672,6 +693,7 @@ public class LocationService
currentQ = nextStep.Value.q;
currentR = nextStep.Value.r;
elapsedSteps--;
usedSteps++;
}
if (movementBlocked)
@@ -689,6 +711,7 @@ public class LocationService
continue;
}
var assignedAt = worker.MovementCompletesAtUtc.Value.AddMinutes(Math.Max(0, usedSteps - 1));
var location = await _locations.FindOneAndUpdateAsync(
x => x.OwnerUsername == username &&
x.Q == destinationQ &&
@@ -699,7 +722,8 @@ public class LocationService
Builders<Location>.Update
.Set(x => x.WorkerUnitId, worker.Id)
.Set(x => x.WorkerUnitType, "Peasant")
.Set(x => x.LastResourceGeneratedAtUtc, now)
.Set(x => x.LastResourceGeneratedAtUtc, assignedAt)
.Set(x => x.DeliveryCycleStartedAtUtc, assignedAt)
.Set(x => x.UpdatedAtUtc, now),
new FindOneAndUpdateOptions<Location> { ReturnDocument = ReturnDocument.After });