Skip to content

Commit b7cf81b

Browse files
authored
Merge pull request #100 from Erol444/hotfix-15-04-2022
Hotfix 15 04 2022
2 parents b30e7f3 + eb74045 commit b7cf81b

File tree

10 files changed

+113
-38
lines changed

10 files changed

+113
-38
lines changed

.github/workflows/pre-release.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,16 @@ jobs:
9090
prerelease:
9191
runs-on: ubuntu-latest
9292
needs: [build, version]
93-
steps:
94-
93+
steps:
9594
- name: Download artifact
9695
uses: actions/download-artifact@master
9796
with:
9897
name: TBS-prerelease
99-
path: TravBotSharp/bin/Release
100-
98+
path: TBS-${{needs.version.outputs.version}}
10199
- name: Archive pre release
102100
uses: montudor/action-zip@v1
103101
with:
104-
args: zip -qq -r TBS-${{needs.version.outputs.version}}.zip TravBotSharp/bin/Release
102+
args: zip -r TBS-${{needs.version.outputs.version}}.zip TBS-${{needs.version.outputs.version}}
105103

106104
- name: Create pre release
107105
uses: ncipollo/release-action@v1

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ jobs:
9898
uses: actions/download-artifact@master
9999
with:
100100
name: TBS-release
101-
path: TravBotSharp/bin/Release
101+
path: TBS-${{needs.version.outputs.version}}
102102

103103
- name: Archive Release
104104
uses: montudor/action-zip@v1
105105
with:
106-
args: zip -qq -r TBS-${{needs.version.outputs.version}}.zip TravBotSharp/bin/Release
106+
args: zip -qq -r TBS-${{needs.version.outputs.version}}.zip TBS-${{needs.version.outputs.version}}
107107

108108

109109
- name: Create release

TbsCore/Database/DbRepository.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,12 @@ public static void RemoveAccount(Account acc)
5151
{
5252
using (var context = new TbsContext())
5353
{
54-
context.DbAccount.Remove(FindDbAccount(acc, context));
55-
context.SaveChanges();
54+
var account = FindDbAccount(acc, context);
55+
if (account != null)
56+
{
57+
context.DbAccount.Remove(account);
58+
context.SaveChanges();
59+
}
5660
}
5761
}
5862

TbsCore/Helpers/IoHelperCore.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,16 @@ public static void RemoveCache(Account acc)
135135
var userCacheFolder = UserCachePath(acc.AccInfo.Nickname, acc.AccInfo.ServerUrl);
136136
if (!UserDataExists(acc.AccInfo.Nickname, acc.AccInfo.ServerUrl)) return;
137137

138-
var removeFolders = Directory.GetDirectories(userCacheFolder);
139-
140-
for (int i = 0; i < removeFolders.Count(); i++)
138+
try
141139
{
142-
Directory.Delete(removeFolders[i], true);
140+
var removeFolders = Directory.GetDirectories(userCacheFolder);
141+
142+
for (int i = 0; i < removeFolders.Count(); i++)
143+
{
144+
Directory.Delete(removeFolders[i], true);
145+
}
143146
}
147+
catch { }
144148
}
145149

146150
/// <summary>

TbsCore/Helpers/NavigationHelper.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,22 +110,38 @@ internal static async Task<bool> ToConstructionTab(Account acc, BuildingEnum bui
110110
var tab = BuildingsData.GetBuildingsCategory(building);
111111
if (tab == BuildingCategoryEnum.Infrastructure) return true;
112112
acc.Logger.Information($"{building} is in {tab} section, switch tab");
113-
string classNode;
113+
string classCategoryNode;
114114
switch (tab)
115115
{
116116
case BuildingCategoryEnum.Military:
117-
classNode = "military";
117+
classCategoryNode = "military";
118118
break;
119119

120120
case BuildingCategoryEnum.Resources:
121-
classNode = "resources";
121+
classCategoryNode = "resources";
122122
break;
123123

124124
default:
125-
classNode = "";
125+
classCategoryNode = "";
126126
break;
127127
}
128-
var node = acc.Wb.Html.DocumentNode.Descendants("a").FirstOrDefault(x => x.HasClass("tabItem") && x.HasClass(classNode));
128+
string classFirstNode;
129+
switch (acc.AccInfo.ServerVersion)
130+
{
131+
case ServerVersionEnum.TTwars:
132+
classFirstNode = "container";
133+
break;
134+
135+
case ServerVersionEnum.T4_5:
136+
classFirstNode = "tabItem";
137+
138+
break;
139+
140+
default:
141+
classFirstNode = "";
142+
break;
143+
}
144+
var node = acc.Wb.Html.DocumentNode.Descendants("a").FirstOrDefault(x => x.HasClass(classFirstNode) && x.HasClass(classCategoryNode));
129145
if (node == null) return false;
130146

131147
var element = acc.Wb.Driver.FindElement(By.XPath(node.XPath));

TbsCore/Tasks/LowLevel/ReviveHero.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,46 @@
22
using System.Threading.Tasks;
33
using TbsCore.Models.AccModels;
44
using TbsCore.Helpers;
5+
using OpenQA.Selenium;
56

67
namespace TbsCore.Tasks.LowLevel
78
{
89
public class ReviveHero : BotTask
910
{
1011
public override async Task<TaskRes> Execute(Account acc)
1112
{
13+
StopFlag = false;
14+
acc.Logger.Information("Navigate to revive page", this);
1215
await NavigationHelper.ToHero(acc, NavigationHelper.HeroTab.Attributes);
16+
if (StopFlag) return TaskRes.Executed;
1317

18+
acc.Logger.Information("Find revive button to click", this);
1419
//heroRegeneration
1520
var reviveButton = acc.Wb.Html.GetElementbyId("heroRegeneration");
1621
if (reviveButton == null)
1722
{
18-
acc.Logger.Warning("No revive button found!");
23+
acc.Logger.Information("No revive button found!");
1924
return TaskRes.Executed;
2025
}
26+
2127
if (reviveButton.HasClass("green"))
2228
{
23-
acc.Wb.ExecuteScript("document.getElementById('heroRegeneration').click()"); //revive hero
29+
var element = acc.Wb.Driver.FindElement(By.XPath(reviveButton.XPath));
30+
31+
if (element == null)
32+
{
33+
acc.Logger.Information("Cannot click revive button!");
34+
return TaskRes.Executed;
35+
}
36+
37+
element.Click();
2438
return TaskRes.Executed;
2539
}
2640
else
2741
{
2842
//no resources?
29-
this.NextExecute = DateTime.Now.AddMinutes(10);
43+
acc.Logger.Information("Don't have enough resource. Retry after 10 minutes!");
44+
NextExecute = DateTime.Now.AddMinutes(10);
3045
return TaskRes.Executed;
3146
}
3247
}

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

TravBotSharp/Forms/AddAccounts.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ private void richTextBox1_TextChanged(object sender, EventArgs e)
3131
var strArr = richTextBox1.Text.Split('\n');
3232
richTextBox2.Text = "";
3333

34+
accounts.Clear();
3435
foreach (var str in strArr)
3536
{
3637
var account = ParserAccout(str);
@@ -41,17 +42,17 @@ private void richTextBox1_TextChanged(object sender, EventArgs e)
4142
{
4243
if (!string.IsNullOrEmpty(account.Proxy.ProxyUsername))
4344
{
44-
richTextBox2.AppendText($"{account.Server} {account.Username} {account.Proxy.Password} {account.Proxy.Proxy} {account.Proxy.ProxyPort} {account.Proxy.ProxyUsername} {account.Proxy.ProxyPassword}\n");
45+
richTextBox2.AppendText($"[{account.Server}] [{account.Username}] [{account.Proxy.Password}] [{account.Proxy.Proxy}] [{account.Proxy.ProxyPort}] [{account.Proxy.ProxyUsername}] [{account.Proxy.ProxyPassword}]\n");
4546

4647
}
4748
else
4849
{
49-
richTextBox2.AppendText($"{account.Server} {account.Username} {account.Proxy.Password} {account.Proxy.Proxy} {account.Proxy.ProxyPort}\n");
50+
richTextBox2.AppendText($"[{account.Server}] [{account.Username}] [{account.Proxy.Password}] [{account.Proxy.Proxy}] [{account.Proxy.ProxyPort}]\n");
5051
}
5152
}
5253
else
5354
{
54-
richTextBox2.AppendText($"{account.Server} {account.Username} {account.Proxy.Password} \n");
55+
richTextBox2.AppendText($"[{account.Server}] [{account.Username}] [{account.Proxy.Password}]\n");
5556
}
5657
}
5758
}

TravBotSharp/Forms/Hero/UpdateSettings.Designer.cs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

TravBotSharp/Forms/Hero/UpdateSettings.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,15 @@ private void button2_Click(object sender, EventArgs e)
2929
{
3030
Close();
3131
}
32+
33+
private void minInterval_ValueChanged(object sender, EventArgs e)
34+
{
35+
if (minInterval.Value > maxInterval.Value) minInterval.Value = maxInterval.Value;
36+
}
37+
38+
private void maxInterval_ValueChanged(object sender, EventArgs e)
39+
{
40+
if (minInterval.Value > maxInterval.Value) maxInterval.Value = minInterval.Value;
41+
}
3242
}
3343
}

0 commit comments

Comments
 (0)