Skip to content

Commit 38c48e2

Browse files
committed
fix bot forget remove finished current building
1 parent 4e9facc commit 38c48e2

File tree

2 files changed

+29
-23
lines changed

2 files changed

+29
-23
lines changed

TbsCore/Helpers/BuildingHelper.cs

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -232,26 +232,26 @@ private static bool BuildingIsOnLevel(BuildingEnum building, int lvl, Village vi
232232
/// </summary>
233233
/// <param name="vill"></param>
234234
/// <returns>Whether there were some tasks removed</returns>
235-
//public static bool RemoveFinishedCB(Village vill)
236-
//{
237-
// var tasksDone = vill.Build
238-
// .CurrentlyBuilding
239-
// .Where(x => x.Duration < DateTime.Now)
240-
// .ToList();
241-
242-
// if (tasksDone.Count == 0) return false;
243-
244-
// foreach (var taskDone in tasksDone)
245-
// {
246-
// var building = vill.Build.Buildings.FirstOrDefault(x => x.Id == taskDone.Location);
247-
// if (building == null) building = vill.Build.Buildings.FirstOrDefault(x => x.Type == taskDone.Building);
248-
// if (building == null || building.Type != taskDone.Building) continue;
249-
250-
// if (building.Level < taskDone.Level) building.Level = taskDone.Level;
251-
// vill.Build.CurrentlyBuilding.Remove(taskDone);
252-
// }
253-
// return true;
254-
//}
235+
public static bool RemoveFinishedCB(Village vill)
236+
{
237+
var tasksDone = vill.Build
238+
.CurrentlyBuilding
239+
.Where(x => x.Duration < DateTime.Now)
240+
.ToList();
241+
242+
if (tasksDone.Count == 0) return false;
243+
244+
foreach (var taskDone in tasksDone)
245+
{
246+
//var building = vill.Build.Buildings.FirstOrDefault(x => x.Id == taskDone.Location);
247+
//if (building == null) building = vill.Build.Buildings.FirstOrDefault(x => x.Type == taskDone.Building);
248+
//if (building == null || building.Type != taskDone.Building) continue;
249+
250+
//if (building.Level < taskDone.Level) building.Level = taskDone.Level;
251+
vill.Build.CurrentlyBuilding.Remove(taskDone);
252+
}
253+
return true;
254+
}
255255

256256
/// <summary>
257257
/// Used by building task to get the url for navigation
@@ -440,10 +440,14 @@ internal static bool UpgradeBuildingForOneLvl(Account acc, Village vill, Buildin
440440
}, bottom);
441441
}
442442

443+
// Current lvl in bot's data
443444
var currentLvl = (int)upgrade.Level;
444445

445-
// RemoveFinishedCB(vill);
446-
currentLvl += vill.Build.CurrentlyBuilding.Count(x => x.Building == building);
446+
RemoveFinishedCB(vill);
447+
448+
// Current lvl in current building list
449+
var currentBuilding = vill.Build.CurrentlyBuilding.FirstOrDefault(x => x.Building == building);
450+
if (currentBuilding != null) currentLvl = currentBuilding.Level;
447451

448452
if (BuildingsData.MaxBuildingLevel(acc, building) == currentLvl)
449453
{
@@ -479,7 +483,7 @@ internal static bool UpgradeBuildingForOneLvl(Account acc, Village vill, Buildin
479483
/// <returns>Whether we have all prerequisite buildings</returns>
480484
public static bool AddBuildingPrerequisites(Account acc, Village vill, BuildingEnum building, bool bottom = true)
481485
{
482-
// RemoveFinishedCB(vill);
486+
RemoveFinishedCB(vill);
483487

484488
(var tribe, var prereqs) = BuildingsData.GetBuildingPrerequisites(building);
485489
if (acc.AccInfo.Tribe != tribe && tribe != TribeEnum.Any) return false;

TbsCore/Tasks/LowLevel/UpgradeBuilding.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,8 @@ public async Task<bool> TTWarsTryFastUpgrade(Account acc, string url)
347347
/// <param name="acc">Account</param>
348348
public void ConfigNextExecute(Account acc, bool restart = true)
349349
{
350+
RemoveFinishedCB(Vill);
351+
350352
if (Vill.Build.AutoBuildResourceBonusBuildings) CheckResourceBonus(acc, Vill, restart);
351353

352354
// Checks if we have enough FreeCrop (above 0)

0 commit comments

Comments
 (0)