adding farms
This commit is contained in:
@@ -107,8 +107,12 @@ public class UnitTrainingService
|
||||
}
|
||||
}
|
||||
|
||||
var goldCost = normalizedUnitType == ArcherUnitType ? _archerGoldCost : _scoutGoldCost;
|
||||
var woodCost = normalizedUnitType == ArcherUnitType ? _archerWoodCost : 0;
|
||||
var goldCost = normalizedUnitType == ArcherUnitType
|
||||
? await _settings.GetNonNegativeIntAsync(GameSettingsService.ArcherGoldCost, _archerGoldCost)
|
||||
: await _settings.GetNonNegativeIntAsync(GameSettingsService.ScoutGoldCost, _scoutGoldCost);
|
||||
var woodCost = normalizedUnitType == ArcherUnitType
|
||||
? await _settings.GetNonNegativeIntAsync(GameSettingsService.ArcherWoodCost, _archerWoodCost)
|
||||
: 0;
|
||||
var spent = normalizedUnitType == ArcherUnitType
|
||||
? await _resources.TrySpendResourcesAsync(username, goldCost, woodCost, 0)
|
||||
: await _resources.TrySpendGoldAsync(username, goldCost);
|
||||
@@ -241,7 +245,9 @@ public class UnitTrainingService
|
||||
{
|
||||
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);
|
||||
var hasBuilding = target is not null &&
|
||||
(!string.IsNullOrWhiteSpace(target.BuildingType) ||
|
||||
string.Equals(target.Kind, "Home", StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
if (hasOtherUnits || hasBuilding)
|
||||
{
|
||||
@@ -278,14 +284,15 @@ public class UnitTrainingService
|
||||
return;
|
||||
}
|
||||
|
||||
var emptyBuildingFilter = Builders<Location>.Filter.And(
|
||||
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(
|
||||
emptyBuildingFilter,
|
||||
capturableFilter,
|
||||
Builders<Location>.Update
|
||||
.Set(x => x.OwnerUsername, username)
|
||||
.Set(x => x.Kind, "Claimed")
|
||||
|
||||
Reference in New Issue
Block a user