Skip to content

Commit

Permalink
Merge pull request #158 from Erol444/release/2.1.0
Browse files Browse the repository at this point in the history
- Add auto NPC when crop is full
- Add NPC tab for manually NPC (enter ratio and bot will calculate for you correct value)
- Update adventures now only run if user turn on auto start adventures
- Optimize user experience (aka UX)
- Fix a lot of bug 

That is all for this release, see you again in next two weeks 
If you like my work, you can donate to me through [ko-fi.com/vinaghost](ko-fi.com/vinaghost)
  • Loading branch information
vinaghost authored Oct 14, 2022
2 parents 9988879 + 1c171a9 commit 308231f
Show file tree
Hide file tree
Showing 90 changed files with 2,413 additions and 1,016 deletions.
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: BuildFlow

on:
pull_request:
branches-ignore: [master]
types: [opened, reopened, synchronize]
workflow_dispatch:

Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ name: PreReleaseFlow

on:
pull_request:
branches: [develop]
branches:
- 'releases/**'
types: [closed]
workflow_dispatch:

Expand Down
74 changes: 58 additions & 16 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,51 @@
name: ReleaseFlow

on:
workflow_dispatch:
inputs:
version:
required: true

pull_request:
branches: [master]
types: [closed]
jobs:
version:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
outputs:
version: ${{ steps.semvers.outputs.minor }}
changelog: ${{ steps.Changelog.outputs.changelog }}
steps:
- uses: docker://agilepathway/pull-request-label-checker:latest
with:
one_of: release
repo_token: ${{ secrets.GITHUB_TOKEN }}

- name: 'Checkout repo'
uses: actions/checkout@v2

- name: 'Update tag'
run: git fetch --prune --unshallow --tags

- name: 'Get latest tag'
id: latesttag
uses: pozetroninc/github-action-get-latest-release@master
with:
repository: ${{ github.repository }}

- name: 'Get next version'
id: semvers
uses: "WyriHaximus/github-action-next-semvers@v1"
with:
version: ${{ steps.latesttag.outputs.release }}

- name: 'Create changelog'
id: Changelog
run: |
changelog="${{github.event.pull_request.body}}"
changelog="${changelog//'%'/'%25'}"
changelog="${changelog//$'\n'/'%0A'}"
changelog="${changelog//$'\r'/'%0D'}"
echo "::set-output name=changelog::$changelog"
build:
runs-on: windows-2019
needs: version
strategy:
matrix:
server: [TRAVIAN_OFFICIAL, TRAVIAN_OFFICIAL_HEROUI, TTWARS]
Expand All @@ -25,7 +62,7 @@ jobs:
run: cd $GITHUB_WORKSPACE

- name: Build Bot
run: dotnet publish WPFUI -c Release --self-contained true -p:PublishSingleFile=true -r win-x86 -p:Server=${{ matrix.server }} -p:AssemblyVersion=${{github.event.inputs.version}}.0
run: dotnet publish WPFUI -c Release --self-contained true -p:PublishSingleFile=true -r win-x86 -p:Server=${{ matrix.server }} -p:AssemblyVersion=${{needs.version.outputs.version}}.0

- name: Upload a Build Artifact
uses: actions/upload-artifact@v2
Expand All @@ -36,7 +73,7 @@ jobs:

release:
runs-on: ubuntu-latest
needs: build
needs: [build, version]
steps:
- name: Download artifact
uses: actions/download-artifact@v3
Expand All @@ -45,21 +82,23 @@ jobs:

- name: Archive release
run: |
cd TBS; zip -r "TBS-${{github.event.inputs.version}}-TravianOfficial-OldHeroUI.zip" TBS-TRAVIAN_OFFICIAL; cp -R "TBS-${{github.event.inputs.version}}-TravianOfficial-OldHeroUI.zip" ../; cd ..
cd TBS; zip -r "TBS-${{github.event.inputs.version}}-TravianOfficial-NewHeroUI.zip" TBS-TRAVIAN_OFFICIAL_HEROUI; cp -R "TBS-${{github.event.inputs.version}}-TravianOfficial-NewHeroUI.zip" ../; cd ..
cd TBS; zip -r "TBS-${{github.event.inputs.version}}-TTWars.zip" TBS-TTWARS; cp -R "TBS-${{github.event.inputs.version}}-TTWars.zip" ../; cd ..
cd TBS; zip -r "TBS-${{needs.version.outputs.version}}-TravianOfficial-OldHeroUI.zip" TBS-TRAVIAN_OFFICIAL; cp -R "TBS-${{needs.version.outputs.version}}-TravianOfficial-OldHeroUI.zip" ../; cd ..
cd TBS; zip -r "TBS-${{needs.version.outputs.version}}-TravianOfficial-NewHeroUI.zip" TBS-TRAVIAN_OFFICIAL_HEROUI; cp -R "TBS-${{needs.version.outputs.version}}-TravianOfficial-NewHeroUI.zip" ../; cd ..
cd TBS; zip -r "TBS-${{needs.version.outputs.version}}-TTWars.zip" TBS-TTWARS; cp -R "TBS-${{needs.version.outputs.version}}-TTWars.zip" ../; cd ..
- name: Create release
uses: ncipollo/release-action@v1
with:
name: TBS-${{github.event.inputs.version}}
tag: ${{github.event.inputs.version}}
name: TBS-${{needs.version.outputs.version}}
tag: ${{needs.version.outputs.version}}
commit: master
artifacts: "TBS-${{github.event.inputs.version}}-TravianOfficial-OldHeroUI.zip, TBS-${{github.event.inputs.version}}-TravianOfficial-NewHeroUI.zip, TBS-${{github.event.inputs.version}}-TTWars.zip"
artifacts: "TBS-${{needs.version.outputs.version}}-TravianOfficial-OldHeroUI.zip, TBS-${{needs.version.outputs.version}}-TravianOfficial-NewHeroUI.zip, TBS-${{needs.version.outputs.version}}-TTWars.zip"
token: ${{ secrets.GITHUB_TOKEN }}
body: |
Please join our Discord server for more information: [https://discord.gg/mBa4f2K](https://discord.gg/mBa4f2K)
**Changelog**:
${{needs.version.outputs.changelog}}
Discord:
runs-on: ubuntu-latest
needs: release
Expand All @@ -74,8 +113,11 @@ jobs:
title: New release
nodetail: true
description: |
Version `TBS-${{github.event.inputs.version}}`
Click [here](https://github.com/Erol444/TravianBotSharp/releases/tag/${{github.event.inputs.version}}) to download!
Version `TBS-${{needs.version.outputs.version}}`
Click [here](https://github.com/Erol444/TravianBotSharp/releases/tag/${{needs.version.outputs.version}}) to download!
**Changelog**:
${{needs.version.outputs.changelog}}
Clear:
runs-on: ubuntu-latest
needs: release
Expand Down
15 changes: 14 additions & 1 deletion MainCore/AppDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,22 @@ public void AddVillage(int villageId)
VillageId = villageId,
IsAdsUpgrade = false,
AdsUpgradeTime = 5,

IsUseHeroRes = false,

IsInstantComplete = false,
InstantCompleteTime = 30
InstantCompleteTime = 30,

IsAutoRefresh = false,
AutoRefreshTimeMin = 25,
AutoRefreshTimeMax = 35,

IsAutoNPC = false,
AutoNPCPercent = 90,
AutoNPCWood = 1,
AutoNPCClay = 1,
AutoNPCIron = 1,
AutoNPCCrop = 0,
});

//VillagesQueueBuildings
Expand Down
58 changes: 49 additions & 9 deletions MainCore/Helper/BuildingsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public static class BuildingsHelper

public static List<BuildingEnums> GetCanBuild(AppDbContext context, IPlanManager planManager, int accountId, int villageId)
{
var result = new List<BuildingEnums>(); var tribe = context.AccountsInfo.Find(accountId).Tribe;
var result = new List<BuildingEnums>();
var tribe = context.AccountsInfo.Find(accountId).Tribe;
for (var i = BuildingEnums.Sawmill; i <= BuildingEnums.Hospital; i++)
{
if (CanBuild(context, planManager, villageId, tribe, i))
Expand All @@ -27,8 +28,7 @@ public static List<BuildingEnums> GetCanBuild(AppDbContext context, IPlanManager

public static bool CanBuild(AppDbContext context, IPlanManager planManager, int villageId, TribeEnums tribe, BuildingEnums building)
{
bool exists = (context.VillagesBuildings.Where(x => x.VillageId == villageId).FirstOrDefault(x => x.Type == building) is not null); //there is already a building of this type in the vill
if (exists)
if (IsExists(context, planManager, villageId, building))
{
//check cranny/warehouse/grannary/trapper/GG/GW
return building switch
Expand All @@ -47,15 +47,52 @@ public static bool CanBuild(AppDbContext context, IPlanManager planManager, int
if (reqTribe != TribeEnums.Any && reqTribe != tribe) return false;
foreach (var prerequisite in prerequisites)
{
if (prerequisite.Building.IsResourceField())
{
if (prerequisite.Building == BuildingEnums.Cropland)
{
if (IsAutoCropFieldAboveLevel(planManager, villageId, prerequisite.Level)) return true;
}
else
{
if (IsAutoResourceFieldAboveLevel(planManager, villageId, prerequisite.Level)) return true;
}
}
if (!IsBuildingAboveLevel(context, planManager, villageId, prerequisite.Building, prerequisite.Level)) return false;
}
return true;
}

public static bool IsBuildingAboveLevel(AppDbContext context, IPlanManager planManager, int villageId, BuildingEnums building, int lvl)
private static bool IsExists(AppDbContext context, IPlanManager planManager, int villageId, BuildingEnums building)
{
var b = context.VillagesBuildings.Where(x => x.VillageId == villageId).FirstOrDefault(x => x.Type == building);
if (b is not null) return true;
var c = context.VillagesCurrentlyBuildings.Where(x => x.VillageId == villageId).FirstOrDefault(x => x.Type == building);
if (c is not null) return true;
var q = planManager.GetList(villageId).FirstOrDefault(x => x.Building == building);
if (q is not null) return true;
return false;
}

private static bool IsBuildingAboveLevel(AppDbContext context, IPlanManager planManager, int villageId, BuildingEnums building, int lvl)
{
var b = context.VillagesBuildings.Where(x => x.VillageId == villageId).Any(x => x.Type == building && lvl <= x.Level);
if (b) return true;
var c = context.VillagesCurrentlyBuildings.Where(x => x.VillageId == villageId).Any(x => x.Type == building && lvl <= x.Level);
if (c) return true;
var q = planManager.GetList(villageId).Any(x => x.Building == building && lvl <= x.Level);
if (q) return true;
return false;
}

private static bool IsAutoResourceFieldAboveLevel(IPlanManager planManager, int villageId, int lvl)
{
return (context.VillagesBuildings.Where(x => x.VillageId == villageId).Any(x => x.Type == building && lvl <= x.Level) ||
planManager.GetList(villageId).Any(x => x.Building == building && lvl <= x.Level));
return planManager.GetList(villageId).Any(x => (x.ResourceType == ResTypeEnums.AllResources || x.ResourceType == ResTypeEnums.ExcludeCrop) && lvl <= x.Level);
}

private static bool IsAutoCropFieldAboveLevel(IPlanManager planManager, int villageId, int lvl)
{
return planManager.GetList(villageId).Any(x => (x.ResourceType == ResTypeEnums.AllResources || x.ResourceType == ResTypeEnums.OnlyCrop) && lvl <= x.Level);
}

public static bool IsResourceField(this BuildingEnums building)
Expand Down Expand Up @@ -120,15 +157,18 @@ public static int GetMaxLevel(this BuildingEnums building)
{
return building switch
{
#if TTWARS
#if TRAVIAN_OFFICIAL || TRAVIAN_OFFICIAL_HEROUI
BuildingEnums.Brewery => 20,
#elif TTWARS
BuildingEnums.Brewery => 10,
BuildingEnums.Woodcutter => 25,
BuildingEnums.ClayPit => 25,
BuildingEnums.IronMine => 25,
BuildingEnums.Cropland => 25,

#else
BuildingEnums.Brewery => 20,

#error You forgot to define Travian version here

#endif
BuildingEnums.Bakery => 5,
BuildingEnums.Brickyard => 5,
Expand Down
32 changes: 26 additions & 6 deletions MainCore/Helper/CheckHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
using MainCore.Enums;
using MainCore.Services;
using System.Linq;
using System;
using MainCore.Models.Runtime;

#if TRAVIAN_OFFICIAL

using System;
using MainCore.Models.Runtime;
using TravianOfficialCore.Parsers;
using TravianOfficialCore.FindElements;

#elif TRAVIAN_OFFICIAL_HEROUI

using System;
using MainCore.Models.Runtime;
using TravianOfficialNewHeroUICore.Parsers;
using TravianOfficialNewHeroUICore.FindElements;

Expand All @@ -20,6 +22,10 @@
using TTWarsCore.Parsers;
using TTWarsCore.FindElements;

#else

#error You forgot to define Travian version here

#endif

namespace MainCore.Helper
Expand Down Expand Up @@ -71,10 +77,14 @@ public static int[] GetResourceNeed(IChromeBrowser chromeBrowser, BuildingEnums
}
else
{
#if TTWARS
#if TRAVIAN_OFFICIAL || TRAVIAN_OFFICIAL_HEROUI
contractNode = html.GetElementbyId("contract");
#elif TTWARS
contractNode = html.DocumentNode.Descendants("div").FirstOrDefault(x => x.Id.Equals("contract"));
#else
contractNode = html.GetElementbyId("contract");

#error You forgot to define Travian version here

#endif
}
var resWrapper = contractNode.Descendants("div").FirstOrDefault(x => x.HasClass("resourceWrapper"));
Expand Down Expand Up @@ -120,16 +130,26 @@ public static bool IsNeedAdsUpgrade(IChromeBrowser chromeBrowser, AppDbContext c
return true;
}

#elif TTWARS

#else

#error You forgot to define Travian version here

#endif

public static bool IsFarmListPage(IChromeBrowser chromeBrowser)
{
// check building
var url = chromeBrowser.GetCurrentUrl();
#if TTWARS
#if TRAVIAN_OFFICIAL || TRAVIAN_OFFICIAL_HEROUI
if (!url.Contains("id=39")) return false;
#elif TTWARS
if (!url.Contains("tt=99")) return false;
#else
if (!url.Contains("id=39")) return false;

#error You forgot to define Travian version here

#endif
//check tab
return IsCorrectTab(chromeBrowser, 4);
Expand Down
30 changes: 30 additions & 0 deletions MainCore/Helper/ClickHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@

using TTWarsCore.FindElements;

#else

#error You forgot to define Travian version here

#endif

namespace MainCore.Helper
Expand Down Expand Up @@ -82,6 +86,32 @@ public static void ClickStartAdventure(IChromeBrowser chromeBrowser, int x, int
throw new Exception("Cannot find start adventure button");
}
finishElements[0].Click();

#if TRAVIAN_OFFICIAL || TRAVIAN_OFFICIAL_HEROUI
#elif TTWARS
var wait = chromeBrowser.GetWait();
wait.Until(driver =>
{
var elements = driver.FindElements(By.Id("start"));
if (elements.Count == 0) return false;
return elements[0].Enabled && elements[0].Displayed;
});


var elements = chrome.FindElements(By.Id("start"));
elements[0].Click();

wait.Until(driver =>
{
var elements = driver.FindElements(By.Id("ok"));
if (elements.Count == 0) return false;
return elements[0].Enabled && elements[0].Displayed;
});
#else

#error You forgot to define Travian version here

#endif
}
}
}
Loading

0 comments on commit 308231f

Please sign in to comment.