Skip to content

Commit 6cb09ae

Browse files
authored
Merge pull request #68 from Erol444/build_navigation_fix
Build navigation fix
2 parents c68930f + 2e97337 commit 6cb09ae

File tree

9 files changed

+22
-64
lines changed

9 files changed

+22
-64
lines changed

TbsCore/Helpers/BuildingHelper.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,9 @@ public static bool RemoveFinishedCB(Village vill)
243243

244244
foreach (var taskDone in tasksDone)
245245
{
246-
var building = vill.Build.Buildings.First(x => x.Id == taskDone.Location);
247-
if (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;
248249

249250
if (building.Level < taskDone.Level) building.Level = taskDone.Level;
250251
vill.Build.CurrentlyBuilding.Remove(taskDone);

TbsCore/Helpers/NavigationHelper.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ private static async Task ToBuildingId(Account acc, int index)
5151
{
5252
if (!acc.Wb.CurrentUrl.Contains("dorf2.php") || acc.Wb.CurrentUrl.Contains("id="))
5353
await MainNavigate(acc, MainNavigationButton.Buildings);
54-
await DriverHelper.ClickByClassName(acc, $"aid{index}", qindex: 1);
54+
55+
await DriverHelper.ExecuteScript(acc, $"document.getElementsByClassName(\"aid{index}\")[0].children[0].click();");
5556
}
5657
await DriverHelper.WaitLoaded(acc);
5758
}
@@ -93,6 +94,9 @@ private static string TTWarsTabUrl(BuildingEnum building, int tab)
9394
default: return "";
9495
}
9596
}
97+
98+
private static string[] tabMapping = new string[] { "0", "2", "3", "4", "5" };
99+
private static string TTWarsOverviewMapping(OverviewTab tab) => tabMapping[(int)tab];
96100

97101
/// <summary>
98102
/// Enters a specific building.
@@ -126,6 +130,8 @@ public static async Task<bool> EnterBuilding(Account acc, Building building, int
126130
}
127131
return true;
128132
}
133+
public static async Task<bool> EnterBuilding(Account acc, Village vill, int buildingId, int? tab = null, Coordinates coords = null) =>
134+
await EnterBuilding(acc, vill.Build.Buildings.First(x => x.Id == buildingId), tab, coords);
129135

130136
public static async Task<bool> EnterBuilding(Account acc, Village vill, BuildingEnum buildingEnum, int? tab = null, Coordinates coords = null)
131137
{
@@ -189,8 +195,12 @@ public static async Task<bool> ToHero(Account acc, HeroTab tab)
189195

190196
public static async Task<bool> ToOverview(Account acc, OverviewTab tab, TroopOverview subTab = TroopOverview.OwnTroops)
191197
{
198+
if (acc.AccInfo.ServerVersion == ServerVersionEnum.TTwars)
199+
{
200+
await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/dorf3.php?s={TTWarsOverviewMapping(tab)}&su={(int)subTab}");
201+
return true;
202+
}
192203
string query = "overview";
193-
if (acc.AccInfo.ServerVersion == ServerVersionEnum.TTwars) query += "White";
194204
await DriverHelper.ClickByClassName(acc, query);
195205

196206
var currentTab = InfrastructureParser.CurrentlyActiveTab(acc.Wb.Html);

TbsCore/Models/Settings/GeneralSettings.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public void Init()
2626
DonateAbove = 95;
2727
DonateExcessOf = 65;
2828
DiscordWebhook = false;
29-
DelayClickingMin = 2500;
30-
DelayClickingMax = 3800;
29+
DelayClickingMin = 1000;
30+
DelayClickingMax = 2000;
3131
}
3232

3333
public bool AutoActivateProductionBoost { get; set; }

TbsCore/Tasks/LowLevel/ClaimBeginnerTask2021.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public override async Task<TaskRes> Execute(Account acc)
2020
.Any(x => x.HasClass("newQuestSpeechBubble")) ?? false)
2121
{
2222
// Claim account-wide rewards
23-
await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/tasks?t=2");
23+
await DriverHelper.ClickByClassName(acc, "tabItem", 1);
2424
await ClaimRewards(acc);
2525
}
2626

TbsCore/Tasks/LowLevel/HeroSetPoints.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public override async Task<TaskRes> Execute(Account acc)
4949
}
5050

5151
acc.Wb.ExecuteScript("document.getElementById('saveHeroAttributes').click();");
52+
//await Driver
5253
return TaskRes.Executed;
5354
}
5455
}

TbsCore/Tasks/LowLevel/NYSUpdateTribesOfVillas.cs

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

TbsCore/Tasks/LowLevel/UpdateDorf2.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ public override async Task<TaskRes> Execute(Account acc)
1212

1313
if (!acc.Wb.CurrentUrl.Contains("/dorf2.php")) // Don't re-navigate
1414
{
15-
//await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/dorf2.php");
1615
await NavigationHelper.ToDorf2(acc);
1716
}
1817

TbsCore/Tasks/LowLevel/UpgradeBuilding.cs

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -51,50 +51,15 @@ public override async Task<TaskRes> Execute(Account acc)
5151
return TaskRes.Executed;
5252
}
5353

54-
var url = $"{acc.AccInfo.ServerUrl}/build.php?id={urlId}";
55-
5654
// Fast building for TTWars
5755
if (acc.AccInfo.ServerUrl.Contains("ttwars") &&
5856
!constructNew &&
59-
await TTWarsTryFastUpgrade(acc, url))
57+
await TTWarsTryFastUpgrade(acc, $"{acc.AccInfo.ServerUrl}/build.php?id={urlId}"))
6058
{
6159
return TaskRes.Executed;
6260
}
6361

64-
// Navigate to the dorf in which the building is, so bot is less suspicious
65-
string dorfUrl = $"/dorf{((Task.BuildingId ?? default) < 19 ? 1 : 2)}.php"; // "dorf1" / "dorf2"
66-
if (!acc.Wb.CurrentUrl.Contains(dorfUrl))
67-
{
68-
await acc.Wb.Navigate(acc.AccInfo.ServerUrl + dorfUrl);
69-
}
70-
else
71-
{
72-
acc.Wb.UpdateHtml();
73-
}
74-
75-
// Append correct tab
76-
if (!constructNew)
77-
{
78-
switch (this.Task.Building)
79-
{
80-
case BuildingEnum.RallyPoint:
81-
url += "&tt=0";
82-
break;
83-
84-
case BuildingEnum.Marketplace:
85-
url += "&t=0";
86-
break;
87-
88-
case BuildingEnum.Residence:
89-
case BuildingEnum.Palace:
90-
case BuildingEnum.CommandCenter:
91-
case BuildingEnum.Treasury:
92-
url += "&s=0";
93-
break;
94-
}
95-
}
96-
97-
await acc.Wb.Navigate(url);
62+
await NavigationHelper.EnterBuilding(acc, Vill, (int)Task.BuildingId);
9863

9964
var constructContract = acc.Wb.Html.GetElementbyId($"contract_building{(int)Task.Building}");
10065
var upgradeContract = acc.Wb.Html.GetElementbyId("build");

TbsCore/Tasks/SecondLevel/AttackOasis.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public override async Task<TaskRes> Execute(Account acc)
4444
if (!enoughTroops) return Retry();
4545
}
4646

47-
await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/karte.php");
47+
await NavigationHelper.ToMap(acc);
4848

4949
// Get map tiles around the current village
5050
var mapTiles = MapHelper.GetMapTiles(acc, Vill.Coordinates);

0 commit comments

Comments
 (0)