Skip to content

Commit 308231f

Browse files
authored
Merge pull request #158 from Erol444/release/2.1.0
- 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)
2 parents 9988879 + 1c171a9 commit 308231f

File tree

90 files changed

+2413
-1016
lines changed

Some content is hidden

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

90 files changed

+2413
-1016
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ name: BuildFlow
22

33
on:
44
pull_request:
5-
branches-ignore: [master]
65
types: [opened, reopened, synchronize]
76
workflow_dispatch:
87

.github/workflows/pre-release.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ name: PreReleaseFlow
22

33
on:
44
pull_request:
5-
branches: [develop]
5+
branches:
6+
- 'releases/**'
67
types: [closed]
78
workflow_dispatch:
89

.github/workflows/release.yml

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,51 @@
11
name: ReleaseFlow
22

33
on:
4-
workflow_dispatch:
5-
inputs:
6-
version:
7-
required: true
8-
4+
pull_request:
5+
branches: [master]
6+
types: [closed]
97
jobs:
8+
version:
9+
if: github.event.pull_request.merged == true
10+
runs-on: ubuntu-latest
11+
outputs:
12+
version: ${{ steps.semvers.outputs.minor }}
13+
changelog: ${{ steps.Changelog.outputs.changelog }}
14+
steps:
15+
- uses: docker://agilepathway/pull-request-label-checker:latest
16+
with:
17+
one_of: release
18+
repo_token: ${{ secrets.GITHUB_TOKEN }}
19+
20+
- name: 'Checkout repo'
21+
uses: actions/checkout@v2
22+
23+
- name: 'Update tag'
24+
run: git fetch --prune --unshallow --tags
25+
26+
- name: 'Get latest tag'
27+
id: latesttag
28+
uses: pozetroninc/github-action-get-latest-release@master
29+
with:
30+
repository: ${{ github.repository }}
31+
32+
- name: 'Get next version'
33+
id: semvers
34+
uses: "WyriHaximus/github-action-next-semvers@v1"
35+
with:
36+
version: ${{ steps.latesttag.outputs.release }}
37+
38+
- name: 'Create changelog'
39+
id: Changelog
40+
run: |
41+
changelog="${{github.event.pull_request.body}}"
42+
changelog="${changelog//'%'/'%25'}"
43+
changelog="${changelog//$'\n'/'%0A'}"
44+
changelog="${changelog//$'\r'/'%0D'}"
45+
echo "::set-output name=changelog::$changelog"
1046
build:
1147
runs-on: windows-2019
48+
needs: version
1249
strategy:
1350
matrix:
1451
server: [TRAVIAN_OFFICIAL, TRAVIAN_OFFICIAL_HEROUI, TTWARS]
@@ -25,7 +62,7 @@ jobs:
2562
run: cd $GITHUB_WORKSPACE
2663

2764
- name: Build Bot
28-
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
65+
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
2966

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

3774
release:
3875
runs-on: ubuntu-latest
39-
needs: build
76+
needs: [build, version]
4077
steps:
4178
- name: Download artifact
4279
uses: actions/download-artifact@v3
@@ -45,21 +82,23 @@ jobs:
4582

4683
- name: Archive release
4784
run: |
48-
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 ..
49-
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 ..
50-
cd TBS; zip -r "TBS-${{github.event.inputs.version}}-TTWars.zip" TBS-TTWARS; cp -R "TBS-${{github.event.inputs.version}}-TTWars.zip" ../; cd ..
85+
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 ..
86+
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 ..
87+
cd TBS; zip -r "TBS-${{needs.version.outputs.version}}-TTWars.zip" TBS-TTWARS; cp -R "TBS-${{needs.version.outputs.version}}-TTWars.zip" ../; cd ..
5188
5289
- name: Create release
5390
uses: ncipollo/release-action@v1
5491
with:
55-
name: TBS-${{github.event.inputs.version}}
56-
tag: ${{github.event.inputs.version}}
92+
name: TBS-${{needs.version.outputs.version}}
93+
tag: ${{needs.version.outputs.version}}
5794
commit: master
58-
artifacts: "TBS-${{github.event.inputs.version}}-TravianOfficial-OldHeroUI.zip, TBS-${{github.event.inputs.version}}-TravianOfficial-NewHeroUI.zip, TBS-${{github.event.inputs.version}}-TTWars.zip"
95+
artifacts: "TBS-${{needs.version.outputs.version}}-TravianOfficial-OldHeroUI.zip, TBS-${{needs.version.outputs.version}}-TravianOfficial-NewHeroUI.zip, TBS-${{needs.version.outputs.version}}-TTWars.zip"
5996
token: ${{ secrets.GITHUB_TOKEN }}
6097
body: |
6198
Please join our Discord server for more information: [https://discord.gg/mBa4f2K](https://discord.gg/mBa4f2K)
62-
99+
100+
**Changelog**:
101+
${{needs.version.outputs.changelog}}
63102
Discord:
64103
runs-on: ubuntu-latest
65104
needs: release
@@ -74,8 +113,11 @@ jobs:
74113
title: New release
75114
nodetail: true
76115
description: |
77-
Version `TBS-${{github.event.inputs.version}}`
78-
Click [here](https://github.com/Erol444/TravianBotSharp/releases/tag/${{github.event.inputs.version}}) to download!
116+
Version `TBS-${{needs.version.outputs.version}}`
117+
Click [here](https://github.com/Erol444/TravianBotSharp/releases/tag/${{needs.version.outputs.version}}) to download!
118+
119+
**Changelog**:
120+
${{needs.version.outputs.changelog}}
79121
Clear:
80122
runs-on: ubuntu-latest
81123
needs: release

MainCore/AppDbContext.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,22 @@ public void AddVillage(int villageId)
243243
VillageId = villageId,
244244
IsAdsUpgrade = false,
245245
AdsUpgradeTime = 5,
246+
246247
IsUseHeroRes = false,
248+
247249
IsInstantComplete = false,
248-
InstantCompleteTime = 30
250+
InstantCompleteTime = 30,
251+
252+
IsAutoRefresh = false,
253+
AutoRefreshTimeMin = 25,
254+
AutoRefreshTimeMax = 35,
255+
256+
IsAutoNPC = false,
257+
AutoNPCPercent = 90,
258+
AutoNPCWood = 1,
259+
AutoNPCClay = 1,
260+
AutoNPCIron = 1,
261+
AutoNPCCrop = 0,
249262
});
250263

251264
//VillagesQueueBuildings

MainCore/Helper/BuildingsHelper.cs

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ public static class BuildingsHelper
1414

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

2829
public static bool CanBuild(AppDbContext context, IPlanManager planManager, int villageId, TribeEnums tribe, BuildingEnums building)
2930
{
30-
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
31-
if (exists)
31+
if (IsExists(context, planManager, villageId, building))
3232
{
3333
//check cranny/warehouse/grannary/trapper/GG/GW
3434
return building switch
@@ -47,15 +47,52 @@ public static bool CanBuild(AppDbContext context, IPlanManager planManager, int
4747
if (reqTribe != TribeEnums.Any && reqTribe != tribe) return false;
4848
foreach (var prerequisite in prerequisites)
4949
{
50+
if (prerequisite.Building.IsResourceField())
51+
{
52+
if (prerequisite.Building == BuildingEnums.Cropland)
53+
{
54+
if (IsAutoCropFieldAboveLevel(planManager, villageId, prerequisite.Level)) return true;
55+
}
56+
else
57+
{
58+
if (IsAutoResourceFieldAboveLevel(planManager, villageId, prerequisite.Level)) return true;
59+
}
60+
}
5061
if (!IsBuildingAboveLevel(context, planManager, villageId, prerequisite.Building, prerequisite.Level)) return false;
5162
}
5263
return true;
5364
}
5465

55-
public static bool IsBuildingAboveLevel(AppDbContext context, IPlanManager planManager, int villageId, BuildingEnums building, int lvl)
66+
private static bool IsExists(AppDbContext context, IPlanManager planManager, int villageId, BuildingEnums building)
67+
{
68+
var b = context.VillagesBuildings.Where(x => x.VillageId == villageId).FirstOrDefault(x => x.Type == building);
69+
if (b is not null) return true;
70+
var c = context.VillagesCurrentlyBuildings.Where(x => x.VillageId == villageId).FirstOrDefault(x => x.Type == building);
71+
if (c is not null) return true;
72+
var q = planManager.GetList(villageId).FirstOrDefault(x => x.Building == building);
73+
if (q is not null) return true;
74+
return false;
75+
}
76+
77+
private static bool IsBuildingAboveLevel(AppDbContext context, IPlanManager planManager, int villageId, BuildingEnums building, int lvl)
78+
{
79+
var b = context.VillagesBuildings.Where(x => x.VillageId == villageId).Any(x => x.Type == building && lvl <= x.Level);
80+
if (b) return true;
81+
var c = context.VillagesCurrentlyBuildings.Where(x => x.VillageId == villageId).Any(x => x.Type == building && lvl <= x.Level);
82+
if (c) return true;
83+
var q = planManager.GetList(villageId).Any(x => x.Building == building && lvl <= x.Level);
84+
if (q) return true;
85+
return false;
86+
}
87+
88+
private static bool IsAutoResourceFieldAboveLevel(IPlanManager planManager, int villageId, int lvl)
5689
{
57-
return (context.VillagesBuildings.Where(x => x.VillageId == villageId).Any(x => x.Type == building && lvl <= x.Level) ||
58-
planManager.GetList(villageId).Any(x => x.Building == building && lvl <= x.Level));
90+
return planManager.GetList(villageId).Any(x => (x.ResourceType == ResTypeEnums.AllResources || x.ResourceType == ResTypeEnums.ExcludeCrop) && lvl <= x.Level);
91+
}
92+
93+
private static bool IsAutoCropFieldAboveLevel(IPlanManager planManager, int villageId, int lvl)
94+
{
95+
return planManager.GetList(villageId).Any(x => (x.ResourceType == ResTypeEnums.AllResources || x.ResourceType == ResTypeEnums.OnlyCrop) && lvl <= x.Level);
5996
}
6097

6198
public static bool IsResourceField(this BuildingEnums building)
@@ -120,15 +157,18 @@ public static int GetMaxLevel(this BuildingEnums building)
120157
{
121158
return building switch
122159
{
123-
#if TTWARS
160+
#if TRAVIAN_OFFICIAL || TRAVIAN_OFFICIAL_HEROUI
161+
BuildingEnums.Brewery => 20,
162+
#elif TTWARS
124163
BuildingEnums.Brewery => 10,
125164
BuildingEnums.Woodcutter => 25,
126165
BuildingEnums.ClayPit => 25,
127166
BuildingEnums.IronMine => 25,
128167
BuildingEnums.Cropland => 25,
129-
130168
#else
131-
BuildingEnums.Brewery => 20,
169+
170+
#error You forgot to define Travian version here
171+
132172
#endif
133173
BuildingEnums.Bakery => 5,
134174
BuildingEnums.Brickyard => 5,

MainCore/Helper/CheckHelper.cs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
using MainCore.Enums;
33
using MainCore.Services;
44
using System.Linq;
5-
using System;
6-
using MainCore.Models.Runtime;
75

86
#if TRAVIAN_OFFICIAL
97

8+
using System;
9+
using MainCore.Models.Runtime;
1010
using TravianOfficialCore.Parsers;
1111
using TravianOfficialCore.FindElements;
1212

1313
#elif TRAVIAN_OFFICIAL_HEROUI
1414

15+
using System;
16+
using MainCore.Models.Runtime;
1517
using TravianOfficialNewHeroUICore.Parsers;
1618
using TravianOfficialNewHeroUICore.FindElements;
1719

@@ -20,6 +22,10 @@
2022
using TTWarsCore.Parsers;
2123
using TTWarsCore.FindElements;
2224

25+
#else
26+
27+
#error You forgot to define Travian version here
28+
2329
#endif
2430

2531
namespace MainCore.Helper
@@ -71,10 +77,14 @@ public static int[] GetResourceNeed(IChromeBrowser chromeBrowser, BuildingEnums
7177
}
7278
else
7379
{
74-
#if TTWARS
80+
#if TRAVIAN_OFFICIAL || TRAVIAN_OFFICIAL_HEROUI
81+
contractNode = html.GetElementbyId("contract");
82+
#elif TTWARS
7583
contractNode = html.DocumentNode.Descendants("div").FirstOrDefault(x => x.Id.Equals("contract"));
7684
#else
77-
contractNode = html.GetElementbyId("contract");
85+
86+
#error You forgot to define Travian version here
87+
7888
#endif
7989
}
8090
var resWrapper = contractNode.Descendants("div").FirstOrDefault(x => x.HasClass("resourceWrapper"));
@@ -120,16 +130,26 @@ public static bool IsNeedAdsUpgrade(IChromeBrowser chromeBrowser, AppDbContext c
120130
return true;
121131
}
122132

133+
#elif TTWARS
134+
135+
#else
136+
137+
#error You forgot to define Travian version here
138+
123139
#endif
124140

125141
public static bool IsFarmListPage(IChromeBrowser chromeBrowser)
126142
{
127143
// check building
128144
var url = chromeBrowser.GetCurrentUrl();
129-
#if TTWARS
145+
#if TRAVIAN_OFFICIAL || TRAVIAN_OFFICIAL_HEROUI
146+
if (!url.Contains("id=39")) return false;
147+
#elif TTWARS
130148
if (!url.Contains("tt=99")) return false;
131149
#else
132-
if (!url.Contains("id=39")) return false;
150+
151+
#error You forgot to define Travian version here
152+
133153
#endif
134154
//check tab
135155
return IsCorrectTab(chromeBrowser, 4);

MainCore/Helper/ClickHelper.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515

1616
using TTWarsCore.FindElements;
1717

18+
#else
19+
20+
#error You forgot to define Travian version here
21+
1822
#endif
1923

2024
namespace MainCore.Helper
@@ -82,6 +86,32 @@ public static void ClickStartAdventure(IChromeBrowser chromeBrowser, int x, int
8286
throw new Exception("Cannot find start adventure button");
8387
}
8488
finishElements[0].Click();
89+
90+
#if TRAVIAN_OFFICIAL || TRAVIAN_OFFICIAL_HEROUI
91+
#elif TTWARS
92+
var wait = chromeBrowser.GetWait();
93+
wait.Until(driver =>
94+
{
95+
var elements = driver.FindElements(By.Id("start"));
96+
if (elements.Count == 0) return false;
97+
return elements[0].Enabled && elements[0].Displayed;
98+
});
99+
100+
101+
var elements = chrome.FindElements(By.Id("start"));
102+
elements[0].Click();
103+
104+
wait.Until(driver =>
105+
{
106+
var elements = driver.FindElements(By.Id("ok"));
107+
if (elements.Count == 0) return false;
108+
return elements[0].Enabled && elements[0].Displayed;
109+
});
110+
#else
111+
112+
#error You forgot to define Travian version here
113+
114+
#endif
85115
}
86116
}
87117
}

0 commit comments

Comments
 (0)