Skip to content

Commit 034e3c0

Browse files
authored
Release 2.7.0 (#221)
- Change the column's width in debug tab for easy read - Fix pause button not working (it was sleep button before :v ) - Change task flow of all task - Add confirm dialogue to delete account In next release, I will working on auto training troop, please take a look on [this issue](#222) If you like my work, you can donate to me through [ko-fi.com/vinaghost](https://ko-fi.com/vinaghost)
1 parent 2442186 commit 034e3c0

File tree

127 files changed

+4144
-2395
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+4144
-2395
lines changed

MainCore/AppBosstrapper.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
using FluentMigrator.Runner;
2-
using MainCore.Helper.Implementations;
32
using MainCore.Helper.Interface;
43
using MainCore.Migrations;
54
using MainCore.Services.Implementations;
65
using MainCore.Services.Interface;
76
using Microsoft.EntityFrameworkCore;
87
using Microsoft.Extensions.DependencyInjection;
9-
using ModuleCore.Parser;
8+
using MainCore.Parser.Interface;
9+
using MainCore.Services.Implementations.TaskFactories;
1010

1111
#if TRAVIAN_OFFICIAL
1212

13-
using TravianOfficialCore.Parsers;
13+
using MainCore.Parser.Implementations.TravianOfficial;
14+
using MainCore.Helper.Implementations.TravianOfficial;
1415

1516
#elif TTWARS
1617

17-
using TTWarsCore.Parsers;
18+
using MainCore.Parser.Implementations.TTWars;
19+
using MainCore.Helper.Implementations.TTWars;
1820

1921
#else
2022

@@ -40,6 +42,15 @@ public static IServiceCollection ConfigureServices(this IServiceCollection servi
4042
services.AddSingleton<IPlanManager, PlanManager>();
4143
services.AddSingleton<ILogManager, LogManager>();
4244

45+
if (VersionDetector.IsTravianOfficial())
46+
{
47+
services.AddSingleton<ITaskFactory, TravianOfficialTaskFactory>();
48+
}
49+
else if (VersionDetector.IsTTWars())
50+
{
51+
services.AddSingleton<ITaskFactory, TTWarsTaskFactory>();
52+
}
53+
4354
services.AddFluentMigratorCore()
4455
.ConfigureRunner(rb => rb
4556
.AddSQLite()

MainCore/Errors/Cancel.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ namespace MainCore.Errors
44
{
55
public class Cancel : Error
66
{
7-
public Cancel()
7+
public Cancel() : base("Stop command requested")
88
{
9-
109
}
1110
}
1211
}

MainCore/Helper/Implementations/AccessHelper.cs renamed to MainCore/Helper/Implementations/Base/AccessHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using MainCore.Helper.Interface;
22
using RestSharp;
33

4-
namespace MainCore.Helper.Implementations
4+
namespace MainCore.Helper.Implementations.Base
55
{
66
public class AccessHelper : IAccessHelper
77
{

MainCore/Helper/Implementations/BuildingsHelper.cs renamed to MainCore/Helper/Implementations/Base/BuildingsHelper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System.Collections.Generic;
66
using System.Linq;
77

8-
namespace MainCore.Helper.Implementations
8+
namespace MainCore.Helper.Implementations.Base
99
{
1010
public class BuildingsHelper : IBuildingsHelper
1111
{
@@ -118,8 +118,8 @@ public int GetDorf(BuildingEnums building)
118118
{
119119
return building switch
120120
{
121-
BuildingEnums.Woodcutter or BuildingEnums.ClayPit or BuildingEnums.IronMine or BuildingEnums.Cropland => 2,
122-
_ => 1,
121+
BuildingEnums.Woodcutter or BuildingEnums.ClayPit or BuildingEnums.IronMine or BuildingEnums.Cropland => 1,
122+
_ => 2,
123123
};
124124
}
125125
}

MainCore/Helper/Implementations/CheckHelper.cs renamed to MainCore/Helper/Implementations/Base/CheckHelper.cs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
using HtmlAgilityPack;
22
using MainCore.Helper.Interface;
3+
using MainCore.Parser.Interface;
34
using MainCore.Services.Interface;
45
using Microsoft.EntityFrameworkCore;
5-
using ModuleCore.Parser;
66
using System.Linq;
77

8-
namespace MainCore.Helper.Implementations
8+
namespace MainCore.Helper.Implementations.Base
99
{
10-
public class CheckHelper : ICheckHelper
10+
public abstract class CheckHelper : ICheckHelper
1111
{
12-
private readonly IChromeManager _chromeManager;
13-
private readonly IDbContextFactory<AppDbContext> _contextFactory;
14-
private readonly IVillagesTableParser _villagesTableParser;
15-
private readonly IBuildingTabParser _buildingTabParser;
16-
private readonly ISystemPageParser _systemPageParser;
12+
protected readonly IChromeManager _chromeManager;
13+
protected readonly IDbContextFactory<AppDbContext> _contextFactory;
14+
protected readonly IVillagesTableParser _villagesTableParser;
15+
protected readonly IBuildingTabParser _buildingTabParser;
16+
protected readonly ISystemPageParser _systemPageParser;
1717

1818
public CheckHelper(IChromeManager chromeManager, IVillagesTableParser villagesTableParser, IBuildingTabParser buildingTabParser, IDbContextFactory<AppDbContext> contextFactory, ISystemPageParser systemPageParser)
1919
{
@@ -61,16 +61,7 @@ public bool IsCorrectTab(int accountId, int tab)
6161
return _buildingTabParser.IsCurrentTab(tabs[tab]);
6262
}
6363

64-
public bool IsFarmListPage(int accountId)
65-
{
66-
// check building
67-
var chromeBrowser = _chromeManager.Get(accountId);
68-
var url = chromeBrowser.GetCurrentUrl();
69-
70-
if (VersionDetector.IsTravianOfficial() && !url.Contains("id=39")) return false;
71-
if (VersionDetector.IsTTWars() && !url.Contains("tt=99")) return false;
72-
return IsCorrectTab(accountId, 4);
73-
}
64+
public abstract bool IsFarmListPage(int accountId);
7465

7566
public bool IsWWMsg(HtmlDocument doc) => doc.DocumentNode.Descendants("img").FirstOrDefault(x => x.GetAttributeValue("src", "") == "/img/ww100.png") is not null;
7667

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
using FluentResults;
2+
using HtmlAgilityPack;
3+
using MainCore.Errors;
4+
using MainCore.Helper.Interface;
5+
using MainCore.Parser.Interface;
6+
using MainCore.Services.Interface;
7+
using Microsoft.EntityFrameworkCore;
8+
using OpenQA.Selenium;
9+
10+
namespace MainCore.Helper.Implementations.Base
11+
{
12+
public abstract class ClickHelper : IClickHelper
13+
{
14+
protected readonly IChromeManager _chromeManager;
15+
protected readonly IVillageCurrentlyBuildingParser _villageCurrentlyBuildingParser;
16+
protected readonly IHeroSectionParser _heroSectionParser;
17+
protected readonly INavigateHelper _navigateHelper;
18+
protected readonly IDbContextFactory<AppDbContext> _contextFactory;
19+
20+
public ClickHelper(IVillageCurrentlyBuildingParser villageCurrentlyBuildingParser, IChromeManager chromeManager, IHeroSectionParser heroSectionParser, INavigateHelper navigateHelper, IDbContextFactory<AppDbContext> contextFactory)
21+
{
22+
_villageCurrentlyBuildingParser = villageCurrentlyBuildingParser;
23+
_chromeManager = chromeManager;
24+
_heroSectionParser = heroSectionParser;
25+
_navigateHelper = navigateHelper;
26+
_contextFactory = contextFactory;
27+
}
28+
29+
public Result ClickCompleteNow(int accountId)
30+
{
31+
var chromeBrowser = _chromeManager.Get(accountId);
32+
{
33+
var result = ClickCompleteNowButton(accountId, chromeBrowser);
34+
if (result.IsFailed) return result.WithError(new Trace(Trace.TraceMessage()));
35+
}
36+
try
37+
{
38+
WaitDialogCompleteNow(chromeBrowser);
39+
}
40+
catch
41+
{
42+
return Result.Fail(new Retry("Cannot find diaglog complete now"));
43+
}
44+
{
45+
var result = ClickConfirmFinishNowButton(accountId, chromeBrowser);
46+
if (result.IsFailed) return result.WithError(new Trace(Trace.TraceMessage()));
47+
}
48+
return Result.Ok();
49+
}
50+
51+
private Result ClickCompleteNowButton(int accountId, IChromeBrowser chromeBrowser)
52+
{
53+
var html = chromeBrowser.GetHtml();
54+
var finishButton = _villageCurrentlyBuildingParser.GetFinishButton(html);
55+
if (finishButton is null)
56+
{
57+
return Result.Fail(new Retry("Cannot find complete now button"));
58+
}
59+
var chrome = chromeBrowser.GetChrome();
60+
var finishElements = chrome.FindElements(By.XPath(finishButton.XPath));
61+
if (finishElements.Count == 0)
62+
{
63+
return Result.Fail(new Retry("Cannot find complete now button"));
64+
}
65+
{
66+
var result = _navigateHelper.Click(accountId, finishElements[0]);
67+
if (result.IsFailed) return result.WithError(new Trace(Trace.TraceMessage()));
68+
}
69+
return Result.Ok();
70+
}
71+
72+
private void WaitDialogCompleteNow(IChromeBrowser chromeBrowser)
73+
{
74+
var wait = chromeBrowser.GetWait();
75+
wait.Until(driver =>
76+
{
77+
var html = new HtmlDocument();
78+
html.LoadHtml(driver.PageSource);
79+
var confirmButton = _villageCurrentlyBuildingParser.GetConfirmFinishNowButton(html);
80+
return confirmButton is not null;
81+
});
82+
}
83+
84+
private Result ClickConfirmFinishNowButton(int accountId, IChromeBrowser chromeBrowser)
85+
{
86+
var html = chromeBrowser.GetHtml();
87+
var finishButton = _villageCurrentlyBuildingParser.GetConfirmFinishNowButton(html);
88+
if (finishButton is null)
89+
{
90+
return Result.Fail(new Retry("Cannot find confirm button"));
91+
}
92+
var chrome = chromeBrowser.GetChrome();
93+
var finishElements = chrome.FindElements(By.XPath(finishButton.XPath));
94+
if (finishElements.Count == 0)
95+
{
96+
return Result.Fail(new Retry("Cannot find confirm button"));
97+
}
98+
{
99+
var result = _navigateHelper.Click(accountId, finishElements[0]);
100+
if (result.IsFailed) return result.WithError(new Trace(Trace.TraceMessage()));
101+
}
102+
return Result.Ok();
103+
}
104+
105+
public abstract Result ClickStartAdventure(int accountId, int x, int y);
106+
107+
public abstract Result ClickStartFarm(int accountId, int farmId);
108+
}
109+
}

MainCore/Helper/Implementations/GithubHelper.cs renamed to MainCore/Helper/Implementations/Base/GithubHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System;
44
using System.Threading.Tasks;
55

6-
namespace MainCore.Helper.Implementations
6+
namespace MainCore.Helper.Implementations.Base
77
{
88
public class GithubHelper : IGithubHelper
99
{
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using FluentResults;
2+
using MainCore.Enums;
3+
using MainCore.Helper.Interface;
4+
using MainCore.Parser.Interface;
5+
using MainCore.Services.Interface;
6+
using OpenQA.Selenium;
7+
8+
namespace MainCore.Helper.Implementations.Base
9+
{
10+
public abstract class HeroHelper : IHeroHelper
11+
{
12+
protected readonly IChromeManager _chromeManager;
13+
protected readonly IHeroSectionParser _heroSectionParser;
14+
protected readonly INavigateHelper _navigateHelper;
15+
16+
public HeroHelper(IChromeManager chromeManager, IHeroSectionParser heroSectionParser, INavigateHelper navigateHelper)
17+
{
18+
_chromeManager = chromeManager;
19+
_heroSectionParser = heroSectionParser;
20+
_navigateHelper = navigateHelper;
21+
}
22+
23+
public abstract Result ClickItem(int accountId, HeroItemEnums item);
24+
25+
public Result EnterAmount(int accountId, int amount)
26+
{
27+
var chromeBrowser = _chromeManager.Get(accountId);
28+
var doc = chromeBrowser.GetHtml();
29+
var amountBox = _heroSectionParser.GetAmountBox(doc);
30+
if (amountBox is null)
31+
{
32+
return Result.Fail("Cannot find amount box");
33+
}
34+
var chrome = chromeBrowser.GetChrome();
35+
var amountInputs = chrome.FindElements(By.XPath(amountBox.XPath));
36+
if (amountInputs.Count == 0)
37+
{
38+
return Result.Fail("Cannot find amount box");
39+
}
40+
amountInputs[0].SendKeys(Keys.Home);
41+
amountInputs[0].SendKeys(Keys.Shift + Keys.End);
42+
amountInputs[0].SendKeys(amount.ToString());
43+
return Result.Ok();
44+
}
45+
46+
public abstract Result Confirm(int accountId);
47+
}
48+
}

0 commit comments

Comments
 (0)