Skip to content

Commit

Permalink
Release 2.7.0 (#221)
Browse files Browse the repository at this point in the history
- 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
vinaghost authored Apr 4, 2023
1 parent 2442186 commit 034e3c0
Show file tree
Hide file tree
Showing 127 changed files with 4,144 additions and 2,395 deletions.
19 changes: 15 additions & 4 deletions MainCore/AppBosstrapper.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
using FluentMigrator.Runner;
using MainCore.Helper.Implementations;
using MainCore.Helper.Interface;
using MainCore.Migrations;
using MainCore.Services.Implementations;
using MainCore.Services.Interface;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using ModuleCore.Parser;
using MainCore.Parser.Interface;
using MainCore.Services.Implementations.TaskFactories;

#if TRAVIAN_OFFICIAL

using TravianOfficialCore.Parsers;
using MainCore.Parser.Implementations.TravianOfficial;
using MainCore.Helper.Implementations.TravianOfficial;

#elif TTWARS

using TTWarsCore.Parsers;
using MainCore.Parser.Implementations.TTWars;
using MainCore.Helper.Implementations.TTWars;

#else

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

if (VersionDetector.IsTravianOfficial())
{
services.AddSingleton<ITaskFactory, TravianOfficialTaskFactory>();
}
else if (VersionDetector.IsTTWars())
{
services.AddSingleton<ITaskFactory, TTWarsTaskFactory>();
}

services.AddFluentMigratorCore()
.ConfigureRunner(rb => rb
.AddSQLite()
Expand Down
3 changes: 1 addition & 2 deletions MainCore/Errors/Cancel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ namespace MainCore.Errors
{
public class Cancel : Error
{
public Cancel()
public Cancel() : base("Stop command requested")
{

}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using MainCore.Helper.Interface;
using RestSharp;

namespace MainCore.Helper.Implementations
namespace MainCore.Helper.Implementations.Base
{
public class AccessHelper : IAccessHelper
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Collections.Generic;
using System.Linq;

namespace MainCore.Helper.Implementations
namespace MainCore.Helper.Implementations.Base
{
public class BuildingsHelper : IBuildingsHelper
{
Expand Down Expand Up @@ -118,8 +118,8 @@ public int GetDorf(BuildingEnums building)
{
return building switch
{
BuildingEnums.Woodcutter or BuildingEnums.ClayPit or BuildingEnums.IronMine or BuildingEnums.Cropland => 2,
_ => 1,
BuildingEnums.Woodcutter or BuildingEnums.ClayPit or BuildingEnums.IronMine or BuildingEnums.Cropland => 1,
_ => 2,
};
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
using HtmlAgilityPack;
using MainCore.Helper.Interface;
using MainCore.Parser.Interface;
using MainCore.Services.Interface;
using Microsoft.EntityFrameworkCore;
using ModuleCore.Parser;
using System.Linq;

namespace MainCore.Helper.Implementations
namespace MainCore.Helper.Implementations.Base
{
public class CheckHelper : ICheckHelper
public abstract class CheckHelper : ICheckHelper
{
private readonly IChromeManager _chromeManager;
private readonly IDbContextFactory<AppDbContext> _contextFactory;
private readonly IVillagesTableParser _villagesTableParser;
private readonly IBuildingTabParser _buildingTabParser;
private readonly ISystemPageParser _systemPageParser;
protected readonly IChromeManager _chromeManager;
protected readonly IDbContextFactory<AppDbContext> _contextFactory;
protected readonly IVillagesTableParser _villagesTableParser;
protected readonly IBuildingTabParser _buildingTabParser;
protected readonly ISystemPageParser _systemPageParser;

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

public bool IsFarmListPage(int accountId)
{
// check building
var chromeBrowser = _chromeManager.Get(accountId);
var url = chromeBrowser.GetCurrentUrl();

if (VersionDetector.IsTravianOfficial() && !url.Contains("id=39")) return false;
if (VersionDetector.IsTTWars() && !url.Contains("tt=99")) return false;
return IsCorrectTab(accountId, 4);
}
public abstract bool IsFarmListPage(int accountId);

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

Expand Down
109 changes: 109 additions & 0 deletions MainCore/Helper/Implementations/Base/ClickHelper.cs
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System;
using System.Threading.Tasks;

namespace MainCore.Helper.Implementations
namespace MainCore.Helper.Implementations.Base
{
public class GithubHelper : IGithubHelper
{
Expand Down
48 changes: 48 additions & 0 deletions MainCore/Helper/Implementations/Base/HeroHelper.cs
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);
}
}
Loading

0 comments on commit 034e3c0

Please sign in to comment.