Skip to content

Commit

Permalink
Merge pull request #68 from Erol444/build_navigation_fix
Browse files Browse the repository at this point in the history
Build navigation fix
  • Loading branch information
Erol444 authored Dec 5, 2021
2 parents c68930f + 2e97337 commit 6cb09ae
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 64 deletions.
5 changes: 3 additions & 2 deletions TbsCore/Helpers/BuildingHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,9 @@ public static bool RemoveFinishedCB(Village vill)

foreach (var taskDone in tasksDone)
{
var building = vill.Build.Buildings.First(x => x.Id == taskDone.Location);
if (building.Type != taskDone.Building) continue;
var building = vill.Build.Buildings.FirstOrDefault(x => x.Id == taskDone.Location);
if (building == null) building = vill.Build.Buildings.FirstOrDefault(x => x.Type == taskDone.Building);
if (building == null || building.Type != taskDone.Building) continue;

if (building.Level < taskDone.Level) building.Level = taskDone.Level;
vill.Build.CurrentlyBuilding.Remove(taskDone);
Expand Down
14 changes: 12 additions & 2 deletions TbsCore/Helpers/NavigationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ private static async Task ToBuildingId(Account acc, int index)
{
if (!acc.Wb.CurrentUrl.Contains("dorf2.php") || acc.Wb.CurrentUrl.Contains("id="))
await MainNavigate(acc, MainNavigationButton.Buildings);
await DriverHelper.ClickByClassName(acc, $"aid{index}", qindex: 1);

await DriverHelper.ExecuteScript(acc, $"document.getElementsByClassName(\"aid{index}\")[0].children[0].click();");
}
await DriverHelper.WaitLoaded(acc);
}
Expand Down Expand Up @@ -93,6 +94,9 @@ private static string TTWarsTabUrl(BuildingEnum building, int tab)
default: return "";
}
}

private static string[] tabMapping = new string[] { "0", "2", "3", "4", "5" };
private static string TTWarsOverviewMapping(OverviewTab tab) => tabMapping[(int)tab];

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

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

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

var currentTab = InfrastructureParser.CurrentlyActiveTab(acc.Wb.Html);
Expand Down
4 changes: 2 additions & 2 deletions TbsCore/Models/Settings/GeneralSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public void Init()
DonateAbove = 95;
DonateExcessOf = 65;
DiscordWebhook = false;
DelayClickingMin = 2500;
DelayClickingMax = 3800;
DelayClickingMin = 1000;
DelayClickingMax = 2000;
}

public bool AutoActivateProductionBoost { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion TbsCore/Tasks/LowLevel/ClaimBeginnerTask2021.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public override async Task<TaskRes> Execute(Account acc)
.Any(x => x.HasClass("newQuestSpeechBubble")) ?? false)
{
// Claim account-wide rewards
await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/tasks?t=2");
await DriverHelper.ClickByClassName(acc, "tabItem", 1);
await ClaimRewards(acc);
}

Expand Down
1 change: 1 addition & 0 deletions TbsCore/Tasks/LowLevel/HeroSetPoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public override async Task<TaskRes> Execute(Account acc)
}

acc.Wb.ExecuteScript("document.getElementById('saveHeroAttributes').click();");
//await Driver
return TaskRes.Executed;
}
}
Expand Down
18 changes: 0 additions & 18 deletions TbsCore/Tasks/LowLevel/NYSUpdateTribesOfVillas.cs

This file was deleted.

1 change: 0 additions & 1 deletion TbsCore/Tasks/LowLevel/UpdateDorf2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public override async Task<TaskRes> Execute(Account acc)

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

Expand Down
39 changes: 2 additions & 37 deletions TbsCore/Tasks/LowLevel/UpgradeBuilding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,50 +51,15 @@ public override async Task<TaskRes> Execute(Account acc)
return TaskRes.Executed;
}

var url = $"{acc.AccInfo.ServerUrl}/build.php?id={urlId}";

// Fast building for TTWars
if (acc.AccInfo.ServerUrl.Contains("ttwars") &&
!constructNew &&
await TTWarsTryFastUpgrade(acc, url))
await TTWarsTryFastUpgrade(acc, $"{acc.AccInfo.ServerUrl}/build.php?id={urlId}"))
{
return TaskRes.Executed;
}

// Navigate to the dorf in which the building is, so bot is less suspicious
string dorfUrl = $"/dorf{((Task.BuildingId ?? default) < 19 ? 1 : 2)}.php"; // "dorf1" / "dorf2"
if (!acc.Wb.CurrentUrl.Contains(dorfUrl))
{
await acc.Wb.Navigate(acc.AccInfo.ServerUrl + dorfUrl);
}
else
{
acc.Wb.UpdateHtml();
}

// Append correct tab
if (!constructNew)
{
switch (this.Task.Building)
{
case BuildingEnum.RallyPoint:
url += "&tt=0";
break;

case BuildingEnum.Marketplace:
url += "&t=0";
break;

case BuildingEnum.Residence:
case BuildingEnum.Palace:
case BuildingEnum.CommandCenter:
case BuildingEnum.Treasury:
url += "&s=0";
break;
}
}

await acc.Wb.Navigate(url);
await NavigationHelper.EnterBuilding(acc, Vill, (int)Task.BuildingId);

var constructContract = acc.Wb.Html.GetElementbyId($"contract_building{(int)Task.Building}");
var upgradeContract = acc.Wb.Html.GetElementbyId("build");
Expand Down
2 changes: 1 addition & 1 deletion TbsCore/Tasks/SecondLevel/AttackOasis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public override async Task<TaskRes> Execute(Account acc)
if (!enoughTroops) return Retry();
}

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

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

0 comments on commit 6cb09ae

Please sign in to comment.