fixing offline updates
This commit is contained in:
@@ -646,9 +646,14 @@ public class LocationService
|
||||
|
||||
var destinationQ = worker.DestinationQ.Value;
|
||||
var destinationR = worker.DestinationR.Value;
|
||||
if (HexDistance(worker.Q, worker.R, destinationQ, destinationR) > 1)
|
||||
var currentQ = worker.Q;
|
||||
var currentR = worker.R;
|
||||
var elapsedSteps = Math.Max(1, (int)Math.Floor((now - worker.MovementCompletesAtUtc!.Value).TotalMinutes) + 1);
|
||||
var movementBlocked = false;
|
||||
|
||||
while (elapsedSteps > 0 && HexDistance(currentQ, currentR, destinationQ, destinationR) > 1)
|
||||
{
|
||||
var nextStep = await NextPeasantStepTowardAsync(username, worker.Q, worker.R, destinationQ, destinationR);
|
||||
var nextStep = await NextPeasantStepTowardAsync(username, currentQ, currentR, destinationQ, destinationR);
|
||||
if (nextStep is null)
|
||||
{
|
||||
await _units.UpdateOneAsync(
|
||||
@@ -660,14 +665,25 @@ public class LocationService
|
||||
.Unset(x => x.MovementStartedAtUtc)
|
||||
.Unset(x => x.MovementCompletesAtUtc)
|
||||
.Set(x => x.UpdatedAtUtc, now));
|
||||
continue;
|
||||
movementBlocked = true;
|
||||
break;
|
||||
}
|
||||
|
||||
currentQ = nextStep.Value.q;
|
||||
currentR = nextStep.Value.r;
|
||||
elapsedSteps--;
|
||||
}
|
||||
|
||||
if (movementBlocked)
|
||||
continue;
|
||||
|
||||
if (HexDistance(currentQ, currentR, destinationQ, destinationR) > 1)
|
||||
{
|
||||
await _units.UpdateOneAsync(
|
||||
x => x.Id == worker.Id,
|
||||
Builders<UnitInstance>.Update
|
||||
.Set(x => x.Q, nextStep.Value.q)
|
||||
.Set(x => x.R, nextStep.Value.r)
|
||||
.Set(x => x.Q, currentQ)
|
||||
.Set(x => x.R, currentR)
|
||||
.Set(x => x.MovementCompletesAtUtc, now.AddMinutes(1))
|
||||
.Set(x => x.UpdatedAtUtc, now));
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user