Skip to content

Commit db27c70

Browse files
authored
Merge pull request #80 from Erol444/fix-currently-building
Fix currently building update
2 parents ae3d8d9 + 38c48e2 commit db27c70

File tree

5 files changed

+30
-33
lines changed

5 files changed

+30
-33
lines changed

TbsCore/Core/TaskExecutor.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -232,19 +232,8 @@ private static void UpdateCurrentlyBuilding(Account acc, Village vill)
232232
var cb = InfrastructureParser.CurrentlyBuilding(acc.Wb.Html, acc);
233233
if (cb == null) return; // Nothing is currently building
234234

235-
var bldJson = DriverHelper.GetJsObj<string>(acc, "JSON.stringify(bld);");
236-
if (string.IsNullOrEmpty(bldJson)) return;
237-
var bldJs = JsonConvert.DeserializeObject<List<Bld>>(bldJson);
238-
239-
// Combine data from two sources about currently building (JS object and HTML table)
240-
// We get time duration and level from HTML
241-
// and build location, level and building (type) from JSON
242235
for (int i = 0; i < cb.Count; i++)
243236
{
244-
cb[i].Building = bldJs[i].Building;
245-
cb[i].Location = bldJs[i].Location;
246-
cb[i].Level = (byte)bldJs[i].Level;
247-
248237
vill.Build.CurrentlyBuilding.Add(cb[i]);
249238
}
250239
}

TbsCore/Helpers/BuildingHelper.cs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,11 @@ public static bool RemoveFinishedCB(Village vill)
243243

244244
foreach (var taskDone in tasksDone)
245245
{
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;
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;
249249

250-
if (building.Level < taskDone.Level) building.Level = taskDone.Level;
250+
//if (building.Level < taskDone.Level) building.Level = taskDone.Level;
251251
vill.Build.CurrentlyBuilding.Remove(taskDone);
252252
}
253253
return true;
@@ -294,11 +294,11 @@ public static bool IsTaskCompleted(Village vill, Account acc, BuildingTask task)
294294
if (task.Level <= building.Level) return true;
295295

296296
// If the building is being upgraded to the desired level, task is complete
297-
var cb = vill.Build
298-
.CurrentlyBuilding
299-
.OrderByDescending(x => x.Level)
300-
.FirstOrDefault(x => x.Location == task.BuildingId);
301-
if (cb != null && task.Level <= cb.Level) return true;
297+
//var cb = vill.Build
298+
// .CurrentlyBuilding
299+
// .OrderByDescending(x => x.Level)
300+
// .FirstOrDefault(x => x.Location == task.BuildingId);
301+
//if (cb != null && task.Level <= cb.Level) return true;
302302
break;
303303

304304
case BuildingType.AutoUpgradeResFields:
@@ -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

445446
RemoveFinishedCB(vill);
446-
currentLvl += vill.Build.CurrentlyBuilding.Count(x => x.Building == building);
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
{

TbsCore/Models/VillageModels/BuildingCurrently.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ public class BuildingCurrently
88
public DateTime Duration { get; set; }
99
public byte Level { get; set; }
1010
public BuildingEnum Building { get; set; }
11-
public int Location { get; set; }
11+
//public int Location { get; set; }
1212
}
1313
}

TbsCore/Parsers/InfrastructureParser.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,13 @@ public static List<BuildingCurrently> CurrentlyBuilding(HtmlDocument htmlDoc, Ac
7373
{
7474
var duration = TimeParser.ParseTimer(row);
7575
var level = row.Descendants("span").FirstOrDefault(x => x.HasClass("lvl")).InnerText;
76+
var strName = row.Descendants("div").FirstOrDefault(x => x.HasClass("name")).ChildNodes[0].InnerText.Trim(new[] { '\t', '\n', '\r', ' ' });
77+
strName = string.Join("", strName.Split(default(string[]), StringSplitOptions.RemoveEmptyEntries));
78+
Enum.TryParse(strName, out Classificator.BuildingEnum name);
7679

7780
ret.Add(new BuildingCurrently()
7881
{
82+
Building = name,
7983
Duration = DateTime.Now.Add(duration),
8084
Level = (byte)Parser.RemoveNonNumeric(level),
8185
});

TbsCore/Tasks/LowLevel/UpgradeBuilding.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,12 @@ private async Task<TaskRes> Upgrade(Account acc, HtmlNode node)
150150
var building = Vill.Build.Buildings.FirstOrDefault(x => x.Id == this.Task.BuildingId);
151151
lvl = building.Level;
152152
// Check if building is under construction
153-
if (building.UnderConstruction)
154-
{
155-
// Check currently building
156-
var cb = Vill.Build.CurrentlyBuilding.OrderByDescending(x => x.Level).FirstOrDefault(x => x.Location == building.Id);
157-
if (cb != null && lvl < cb.Level) lvl = cb.Level;
158-
}
153+
//if (building.UnderConstruction)
154+
//{
155+
// // Check currently building
156+
// var cb = Vill.Build.CurrentlyBuilding.OrderByDescending(x => x.Level).FirstOrDefault(x => x.Location == building.Id);
157+
// if (cb != null && lvl < cb.Level) lvl = cb.Level;
158+
//}
159159

160160
if (Task.Level <= lvl)
161161
{
@@ -248,11 +248,11 @@ private async Task PostTaskCheckDorf(Account acc)
248248
}
249249

250250
// Check if the task is completed
251-
var taskCb = Vill.Build
252-
.CurrentlyBuilding
253-
.OrderByDescending(x => x.Level)
254-
.FirstOrDefault(x => x.Location == this.Task.BuildingId);
255-
if (taskCb != null && this.Task.TaskType == BuildingType.General && this.Task.Level <= taskCb.Level) RemoveCurrentTask();
251+
//var taskCb = Vill.Build
252+
// .CurrentlyBuilding
253+
// .OrderByDescending(x => x.Level)
254+
// .FirstOrDefault(x => x.Location == this.Task.BuildingId);
255+
//if (taskCb != null && this.Task.TaskType == BuildingType.General && this.Task.Level <= taskCb.Level) RemoveCurrentTask();
256256
}
257257

258258
/// <summary>

0 commit comments

Comments
 (0)