-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 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)
- Loading branch information
Showing
127 changed files
with
4,144 additions
and
2,395 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...re/Helper/Implementations/AccessHelper.cs → ...lper/Implementations/Base/AccessHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
using FluentResults; | ||
using HtmlAgilityPack; | ||
using MainCore.Errors; | ||
using MainCore.Helper.Interface; | ||
using MainCore.Parser.Interface; | ||
using MainCore.Services.Interface; | ||
using Microsoft.EntityFrameworkCore; | ||
using OpenQA.Selenium; | ||
|
||
namespace MainCore.Helper.Implementations.Base | ||
{ | ||
public abstract class ClickHelper : IClickHelper | ||
{ | ||
protected readonly IChromeManager _chromeManager; | ||
protected readonly IVillageCurrentlyBuildingParser _villageCurrentlyBuildingParser; | ||
protected readonly IHeroSectionParser _heroSectionParser; | ||
protected readonly INavigateHelper _navigateHelper; | ||
protected readonly IDbContextFactory<AppDbContext> _contextFactory; | ||
|
||
public ClickHelper(IVillageCurrentlyBuildingParser villageCurrentlyBuildingParser, IChromeManager chromeManager, IHeroSectionParser heroSectionParser, INavigateHelper navigateHelper, IDbContextFactory<AppDbContext> contextFactory) | ||
{ | ||
_villageCurrentlyBuildingParser = villageCurrentlyBuildingParser; | ||
_chromeManager = chromeManager; | ||
_heroSectionParser = heroSectionParser; | ||
_navigateHelper = navigateHelper; | ||
_contextFactory = contextFactory; | ||
} | ||
|
||
public Result ClickCompleteNow(int accountId) | ||
{ | ||
var chromeBrowser = _chromeManager.Get(accountId); | ||
{ | ||
var result = ClickCompleteNowButton(accountId, chromeBrowser); | ||
if (result.IsFailed) return result.WithError(new Trace(Trace.TraceMessage())); | ||
} | ||
try | ||
{ | ||
WaitDialogCompleteNow(chromeBrowser); | ||
} | ||
catch | ||
{ | ||
return Result.Fail(new Retry("Cannot find diaglog complete now")); | ||
} | ||
{ | ||
var result = ClickConfirmFinishNowButton(accountId, chromeBrowser); | ||
if (result.IsFailed) return result.WithError(new Trace(Trace.TraceMessage())); | ||
} | ||
return Result.Ok(); | ||
} | ||
|
||
private Result ClickCompleteNowButton(int accountId, IChromeBrowser chromeBrowser) | ||
{ | ||
var html = chromeBrowser.GetHtml(); | ||
var finishButton = _villageCurrentlyBuildingParser.GetFinishButton(html); | ||
if (finishButton is null) | ||
{ | ||
return Result.Fail(new Retry("Cannot find complete now button")); | ||
} | ||
var chrome = chromeBrowser.GetChrome(); | ||
var finishElements = chrome.FindElements(By.XPath(finishButton.XPath)); | ||
if (finishElements.Count == 0) | ||
{ | ||
return Result.Fail(new Retry("Cannot find complete now button")); | ||
} | ||
{ | ||
var result = _navigateHelper.Click(accountId, finishElements[0]); | ||
if (result.IsFailed) return result.WithError(new Trace(Trace.TraceMessage())); | ||
} | ||
return Result.Ok(); | ||
} | ||
|
||
private void WaitDialogCompleteNow(IChromeBrowser chromeBrowser) | ||
{ | ||
var wait = chromeBrowser.GetWait(); | ||
wait.Until(driver => | ||
{ | ||
var html = new HtmlDocument(); | ||
html.LoadHtml(driver.PageSource); | ||
var confirmButton = _villageCurrentlyBuildingParser.GetConfirmFinishNowButton(html); | ||
return confirmButton is not null; | ||
}); | ||
} | ||
|
||
private Result ClickConfirmFinishNowButton(int accountId, IChromeBrowser chromeBrowser) | ||
{ | ||
var html = chromeBrowser.GetHtml(); | ||
var finishButton = _villageCurrentlyBuildingParser.GetConfirmFinishNowButton(html); | ||
if (finishButton is null) | ||
{ | ||
return Result.Fail(new Retry("Cannot find confirm button")); | ||
} | ||
var chrome = chromeBrowser.GetChrome(); | ||
var finishElements = chrome.FindElements(By.XPath(finishButton.XPath)); | ||
if (finishElements.Count == 0) | ||
{ | ||
return Result.Fail(new Retry("Cannot find confirm button")); | ||
} | ||
{ | ||
var result = _navigateHelper.Click(accountId, finishElements[0]); | ||
if (result.IsFailed) return result.WithError(new Trace(Trace.TraceMessage())); | ||
} | ||
return Result.Ok(); | ||
} | ||
|
||
public abstract Result ClickStartAdventure(int accountId, int x, int y); | ||
|
||
public abstract Result ClickStartFarm(int accountId, int farmId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using FluentResults; | ||
using MainCore.Enums; | ||
using MainCore.Helper.Interface; | ||
using MainCore.Parser.Interface; | ||
using MainCore.Services.Interface; | ||
using OpenQA.Selenium; | ||
|
||
namespace MainCore.Helper.Implementations.Base | ||
{ | ||
public abstract class HeroHelper : IHeroHelper | ||
{ | ||
protected readonly IChromeManager _chromeManager; | ||
protected readonly IHeroSectionParser _heroSectionParser; | ||
protected readonly INavigateHelper _navigateHelper; | ||
|
||
public HeroHelper(IChromeManager chromeManager, IHeroSectionParser heroSectionParser, INavigateHelper navigateHelper) | ||
{ | ||
_chromeManager = chromeManager; | ||
_heroSectionParser = heroSectionParser; | ||
_navigateHelper = navigateHelper; | ||
} | ||
|
||
public abstract Result ClickItem(int accountId, HeroItemEnums item); | ||
|
||
public Result EnterAmount(int accountId, int amount) | ||
{ | ||
var chromeBrowser = _chromeManager.Get(accountId); | ||
var doc = chromeBrowser.GetHtml(); | ||
var amountBox = _heroSectionParser.GetAmountBox(doc); | ||
if (amountBox is null) | ||
{ | ||
return Result.Fail("Cannot find amount box"); | ||
} | ||
var chrome = chromeBrowser.GetChrome(); | ||
var amountInputs = chrome.FindElements(By.XPath(amountBox.XPath)); | ||
if (amountInputs.Count == 0) | ||
{ | ||
return Result.Fail("Cannot find amount box"); | ||
} | ||
amountInputs[0].SendKeys(Keys.Home); | ||
amountInputs[0].SendKeys(Keys.Shift + Keys.End); | ||
amountInputs[0].SendKeys(amount.ToString()); | ||
return Result.Ok(); | ||
} | ||
|
||
public abstract Result Confirm(int accountId); | ||
} | ||
} |
Oops, something went wrong.