allowing territory to be abandoned, units to be dismissed, and buildings to be destroyed
This commit is contained in:
@@ -197,9 +197,9 @@ public class UnitTrainingService
|
||||
}
|
||||
|
||||
var movementDistance = HexDistance(request.FromQ, request.FromR, request.ToQ, request.ToR);
|
||||
if (normalizedUnitType == ArcherUnitType && !await CanMoveToAsync(username, request.ToQ, request.ToR))
|
||||
if ((normalizedUnitType == ArcherUnitType || normalizedUnitType == ScoutUnitType) && !await CanMoveToAsync(username, request.ToQ, request.ToR))
|
||||
{
|
||||
throw new InvalidOperationException("Archers can only move to visible tiles.");
|
||||
throw new InvalidOperationException($"{normalizedUnitType}s can only move to visible tiles.");
|
||||
}
|
||||
|
||||
if (normalizedUnitType == PeasantUnitType && !await CanPeasantMoveToAsync(username, request.ToQ, request.ToR))
|
||||
@@ -257,6 +257,26 @@ public class UnitTrainingService
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<int> DismissSquadAsync(string username, DismissUnitSquadRequest request)
|
||||
{
|
||||
var normalizedUnitType = NormalizeUnitType(request.UnitType);
|
||||
if (normalizedUnitType != ScoutUnitType && normalizedUnitType != ArcherUnitType && normalizedUnitType != PeasantUnitType)
|
||||
{
|
||||
throw new ArgumentException("Only Scouts, Archers, and Peasants can be dismissed right now.", nameof(request.UnitType));
|
||||
}
|
||||
|
||||
await CompletePendingMovementAsync(username);
|
||||
|
||||
var result = await _units.DeleteManyAsync(x =>
|
||||
x.Username == username &&
|
||||
x.UnitType == normalizedUnitType &&
|
||||
x.Status == "Idle" &&
|
||||
x.Q == request.Q &&
|
||||
x.R == request.R);
|
||||
|
||||
return (int)result.DeletedCount;
|
||||
}
|
||||
|
||||
private async Task<Location?> GetBuiltBarracksAsync(string username, int q, int r)
|
||||
{
|
||||
await CompleteFinishedBuildingsAsync(username);
|
||||
|
||||
Reference in New Issue
Block a user