Skip to content

Commit fefc28a

Browse files
authored
Merge pull request #117 from Erol444/fix-29-05-2022
Fix 29 05 2022
2 parents 4c70c98 + 386e036 commit fefc28a

File tree

7 files changed

+58
-340
lines changed

7 files changed

+58
-340
lines changed

TbsCore/Helpers/DefaultConfigurations.cs

Lines changed: 0 additions & 87 deletions
This file was deleted.

TbsCore/Helpers/UpdateAccountObject.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ public static void NewVillageFound(Account acc, VillageChecked newVill)
7777
ImportTasks = true
7878
}, true, vill);
7979

80-
DefaultConfigurations.SetDefaultTransitConfiguration(acc, vill);
81-
8280
// Copy default settings to the new village. TODO: use automapper for this.
8381
//var defaultSettings = acc.NewVillages.DefaultSettings;
8482
//vill.Settings = new VillSettings()

TbsCore/Helpers/UpgradeBuildingHelper.cs

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,23 @@ private static bool FindPlaceToBuild(Village vill, BuildingTask task)
228228

229229
// check building has same type
230230
var existingBuilding = vill.Build.Buildings.FirstOrDefault(x => x.Type == task.Building);
231-
231+
if (existingBuilding == null)
232+
{
233+
var currentBuilding = vill.Build.CurrentlyBuilding.FirstOrDefault(x => x.Building == task.Building);
234+
if (currentBuilding != null)
235+
{
236+
existingBuilding = new Building()
237+
{
238+
Id = (byte)currentBuilding.Location,
239+
Level = currentBuilding.Level,
240+
Type = currentBuilding.Building,
241+
UnderConstruction = true,
242+
};
243+
}
244+
}
232245
// Only special buildings (warehouse, cranny, granary etc.) can have multiple
233246
// buildings of it's type and use ConstructNew option
234-
if (!BuildingsData.CanHaveMultipleBuildings(task.Building)) task.ConstructNew = false;
247+
task.ConstructNew = BuildingsData.CanHaveMultipleBuildings(task.Building);
235248

236249
// change to current building place instead of build new one
237250
if (existingBuilding != null && !task.ConstructNew)
@@ -252,7 +265,7 @@ private static bool FindPlaceToBuild(Village vill, BuildingTask task)
252265

253266
// now find place to build in empty slot
254267
var FreeSites = vill.Build.Buildings
255-
.Where(x => x.Type == BuildingEnum.Site && 19 <= x.Id && x.Id <= 39)
268+
.Where(x => x.Type == BuildingEnum.Site && 18 < x.Id && x.Id < 39)
256269
.OrderBy(a => Guid.NewGuid()) // Shuffle the free sites
257270
.ToList();
258271

@@ -361,45 +374,55 @@ public static bool AddBuildingTask(Account acc, Village vill, BuildingTask task,
361374
}
362375
// other building
363376
else if (task.BuildingId == null ||
364-
vill.Build.Buildings.Any(x => x.Id == task.BuildingId &&
365-
x.Type != task.Building &&
366-
x.Type != BuildingEnum.Site))
377+
vill.Build.Buildings.Any(x => x.Id == task.BuildingId &&
378+
x.Type != task.Building &&
379+
x.Type != BuildingEnum.Site))
367380
{
368381
//Check if bot has any space to build new buildings, otherwise return
369382
if (!FindPlaceToBuild(vill, task)) return false;
370383
}
371384

385+
// double check building's location
386+
372387
// checking multiple building
373388
// you need at least one at level 20 before building other
374-
if (BuildingsData.CanHaveMultipleBuildings(task.Building))
389+
if (BuildingsData.CanHaveMultipleBuildings(task.Building) && !BuildingHelper.IsResourceField(task.Building))
375390
{
376391
if (task.ConstructNew)
377392
{
393+
var maxLevel = BuildingsData.MaxBuildingLevel(acc, task.Building);
378394
// Highest level building
379395
var highestLvl = vill.Build
380396
.Buildings
381-
.Where(x => x.Type == task.Building)
382-
.OrderByDescending(x => x.Level)
383-
.FirstOrDefault();
384-
385-
if (highestLvl != null &&
386-
highestLvl.Level != BuildingsData.MaxBuildingLevel(acc, task.Building))
397+
.FirstOrDefault(x => x.Type == task.Building && x.Level == maxLevel);
398+
if (highestLvl == null)
387399
{
388-
task.BuildingId = highestLvl.Id;
400+
var currentBuilding = vill.Build
401+
.CurrentlyBuilding
402+
.FirstOrDefault(x => x.Building == task.Building && x.Level == maxLevel);
403+
if (currentBuilding == null)
404+
{
405+
var plannedBuilding = vill.Build
406+
.Tasks
407+
.FirstOrDefault(x => x.Building == task.Building && x.Level == maxLevel);
408+
409+
if (plannedBuilding == null)
410+
{
411+
var onlyBuilding = vill.Build
412+
.Buildings
413+
.FirstOrDefault(x => x.Type == task.Building);
414+
if (onlyBuilding != null) task.BuildingId = onlyBuilding.Id;
415+
}
416+
}
389417
}
390418
}
391419
}
392420
else if (!BuildingHelper.IsResourceField(task.Building))
393421
{
394-
var buildings = vill.Build.Buildings.Where(x => x.Type == task.Building);
395-
if (buildings.Count() > 0)
396-
{
397-
var id = buildings.First().Id;
398-
if (id != task.BuildingId)
399-
{
400-
task.BuildingId = id;
401-
}
402-
}
422+
var onlyBuilding = vill.Build
423+
.Buildings
424+
.FirstOrDefault(x => x.Type == task.Building);
425+
if (onlyBuilding != null) task.BuildingId = onlyBuilding.Id;
403426
}
404427

405428
if (bottom) vill.Build.Tasks.Add(task);

0 commit comments

Comments
 (0)