Skip to content

Commit 7a07d27

Browse files
committed
fix upgrade building fail on find res cost and button to click (thanks Travian devs)
1 parent b30e7f3 commit 7a07d27

File tree

1 file changed

+39
-14
lines changed

1 file changed

+39
-14
lines changed

TbsCore/Tasks/LowLevel/UpgradeBuilding.cs

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,26 +61,21 @@ public override async Task<TaskRes> Execute(Account acc)
6161
await MoveIntoBuilding(acc);
6262
if (StopFlag) return TaskRes.Executed;
6363

64-
var contractNode = acc.Wb.Html.GetElementbyId($"contract_building{(int)_buildingTask.Building}");
65-
66-
result = IsContructPage(acc, contractNode);
64+
result = IsContructPage(acc);
6765
if (StopFlag) return TaskRes.Executed;
6866
if (!result) continue;
6967

70-
result = await IsEnoughRes(acc, contractNode);
68+
result = await IsEnoughRes(acc);
7169
if (StopFlag) return TaskRes.Executed;
7270
if (!result) continue;
7371

74-
acc.Wb.UpdateHtml();
75-
contractNode = acc.Wb.Html.GetElementbyId($"contract_building{(int)_buildingTask.Building}");
76-
7772
if (construct)
7873
{
79-
result = await Construct(acc, contractNode);
74+
result = await Construct(acc);
8075
}
8176
else
8277
{
83-
result = await Upgrade(acc, contractNode);
78+
result = await Upgrade(acc);
8479
}
8580
if (StopFlag) return TaskRes.Executed;
8681
if (!result) continue;
@@ -95,8 +90,10 @@ public override async Task<TaskRes> Execute(Account acc)
9590
/// </summary>
9691
/// <param name="acc">Account</param>
9792
/// <returns>TaskResult</returnss>
98-
private async Task<bool> Construct(Account acc, HtmlNode node)
93+
private async Task<bool> Construct(Account acc)
9994
{
95+
acc.Wb.UpdateHtml();
96+
var node = acc.Wb.Html.GetElementbyId($"contract_building{(int)_buildingTask.Building}");
10097
var button = node.Descendants("button").FirstOrDefault(x => x.HasClass("new"));
10198

10299
// Check for prerequisites
@@ -123,8 +120,20 @@ private async Task<bool> Construct(Account acc, HtmlNode node)
123120
/// </summary>
124121
/// <param name="acc">Account</param>
125122
/// <returns>TaskResult</returns>
126-
private async Task<bool> Upgrade(Account acc, HtmlNode node)
123+
private async Task<bool> Upgrade(Account acc)
127124
{
125+
acc.Wb.UpdateHtml();
126+
HtmlNode node = null;
127+
switch (acc.AccInfo.ServerVersion)
128+
{
129+
case ServerVersionEnum.TTwars:
130+
node = acc.Wb.Html.GetElementbyId($"contract_building{(int)_buildingTask.Building}");
131+
break;
132+
133+
case ServerVersionEnum.T4_5:
134+
node = acc.Wb.Html.GetElementbyId("build");
135+
break;
136+
}
128137
(var buildingEnum, var lvl) = InfrastructureParser.UpgradeBuildingGetInfo(node);
129138

130139
if (buildingEnum == BuildingEnum.Site || lvl == -1)
@@ -442,17 +451,20 @@ private async Task MoveIntoBuilding(Account acc)
442451
{
443452
acc.Logger.Information($"Move into building {_buildingTask.Building}", this);
444453
await NavigationHelper.EnterBuilding(acc, Vill, (int)_buildingTask.BuildingId);
445-
if (_buildingTask.ConstructNew)
454+
var build = Vill.Build.Buildings.FirstOrDefault(x => x.Id == _buildingTask.BuildingId);
455+
if (build.Type == BuildingEnum.Site)
446456
{
447457
acc.Logger.Information($"This is contruct task, choose correct tab for building {_buildingTask.Building}", this);
448458
await NavigationHelper.ToConstructionTab(acc, _buildingTask.Building);
449459
}
450460
}
451461

452-
private bool IsContructPage(Account acc, HtmlNode contractNode)
462+
private bool IsContructPage(Account acc)
453463
{
454464
acc.Logger.Information($"Finding button to build ...", this);
455465

466+
acc.Wb.UpdateHtml();
467+
var contractNode = acc.Wb.Html.GetElementbyId($"contract_building{(int)_buildingTask.Building}");
456468
if (contractNode != null)
457469
{
458470
construct = true;
@@ -474,10 +486,23 @@ private bool IsContructPage(Account acc, HtmlNode contractNode)
474486
return true;
475487
}
476488

477-
private async Task<bool> IsEnoughRes(Account acc, HtmlNode contractNode)
489+
private async Task<bool> IsEnoughRes(Account acc)
478490
{
479491
// check enough res
480492
acc.Logger.Information($"Check resource ...", this);
493+
494+
acc.Wb.UpdateHtml();
495+
HtmlNode contractNode = null;
496+
switch (acc.AccInfo.ServerVersion)
497+
{
498+
case ServerVersionEnum.TTwars:
499+
contractNode = acc.Wb.Html.GetElementbyId($"contract_building{(int)_buildingTask.Building}");
500+
break;
501+
502+
case ServerVersionEnum.T4_5:
503+
contractNode = acc.Wb.Html.GetElementbyId("contract");
504+
break;
505+
}
481506
var cost = ResourceParser.ParseResourcesNeed(contractNode);
482507
acc.Logger.Information($"Need {cost}");
483508

0 commit comments

Comments
 (0)