Skip to content

Commit 62608e2

Browse files
authored
Merge pull request #92 from Erol444/weekly-26-03-2022
Weekly 26 03 2022
2 parents 7280181 + 396d11c commit 62608e2

File tree

76 files changed

+1864
-2558
lines changed

Some content is hidden

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

76 files changed

+1864
-2558
lines changed

.github/workflows/pre-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
- name: 'Create changelog'
3939
id: Changelog
4040
run: |
41-
changelog=$(git log --no-merges --pretty=format:'- %s' ${{ steps.previoustag.outputs.tag }}..HEAD --reverse)
41+
changelog="$({github.event.pull_request.body})"
4242
changelog="${changelog//'%'/'%25'}"
4343
changelog="${changelog//$'\n'/'%0A'}"
4444
changelog="${changelog//$'\r'/'%0D'}"

.github/workflows/release.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ jobs:
4040
- name: 'Create changelog'
4141
id: Changelog
4242
run: |
43-
last=$(git log --merges --grep='develop' --first-parent master --pretty=format:"%h" | sed -n '2p')
44-
changelog=$(git log --no-merges --pretty=format:'- %s' $last..HEAD --reverse)
43+
changelog="$({github.event.pull_request.body})"
4544
changelog="${changelog//'%'/'%25'}"
4645
changelog="${changelog//$'\n'/'%0A'}"
4746
changelog="${changelog//$'\r'/'%0D'}"
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

TbsCore/Core/PostLoadHelper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public static List<Action> GetPostLoadTasks(Account acc)
228228
// Update adventures
229229
if(homeVill == null)
230230
{
231-
acc.Tasks.Add( new HeroUpdateInfo() { ExecuteAt = DateTime.Now });
231+
acc.Tasks.Add( new HeroUpdateInfo() { ExecuteAt = DateTime.Now }, true);
232232
}
233233
else if (heroReady &&
234234
(homeVill.Build.Buildings.Any(x => x.Type == Classificator.BuildingEnum.RallyPoint && 0 < x.Level)) &&
@@ -289,12 +289,12 @@ private static void AutoExpandStorage(Account acc, Village vill)
289289
warehouse_delta <= vill.Res.Stored.Resources.Clay ||
290290
warehouse_delta <= vill.Res.Stored.Resources.Iron)
291291
{
292-
BuildingHelper.UpgradeBuildingForOneLvl(acc, vill, Classificator.BuildingEnum.Warehouse, false);
292+
UpgradeBuildingHelper.UpgradeBuildingForOneLvl(acc, vill, Classificator.BuildingEnum.Warehouse, false);
293293
return;
294294
}
295295

296296
if (granary_delta <= vill.Res.Stored.Resources.Crop)
297-
BuildingHelper.UpgradeBuildingForOneLvl(acc, vill, Classificator.BuildingEnum.Granary, false);
297+
UpgradeBuildingHelper.UpgradeBuildingForOneLvl(acc, vill, Classificator.BuildingEnum.Granary, false);
298298
}
299299

300300
private static void DonateToAlly(Account acc, Village vill)

TbsCore/Core/TaskExecutor.cs

Lines changed: 56 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
using Newtonsoft.Json;
1+
using OpenQA.Selenium;
22
using System;
3-
using System.Collections.Generic;
43
using System.Linq;
54
using System.Threading.Tasks;
6-
7-
using OpenQA.Selenium;
8-
95
using TbsCore.Extensions;
10-
using TbsCore.Helpers;
116
using TbsCore.Models.AccModels;
12-
using TbsCore.Models.JsObjects;
137
using TbsCore.Models.VillageModels;
148
using TbsCore.Parsers;
159
using TbsCore.Tasks;
@@ -81,50 +75,57 @@ public static async Task Execute(Account acc, BotTask task)
8175
await Task.Delay(AccountHelper.Delay(acc));
8276

8377
if (task.Vill == null) task.Vill = acc.Villages.FirstOrDefault(x => x.Active);
84-
85-
acc.Logger.Information($"Executing task {task.GetName()}" + (task.Vill == null ? "" : $" in village {task.Vill.Name}"));
86-
87-
try
78+
acc.Logger.Information($"Executing task {task.GetName()} in village {task.Vill?.Name}");
79+
TaskRes taskRes = TaskRes.Executed;
80+
do
8881
{
89-
switch (await task.Execute(acc))
82+
try
9083
{
91-
case TaskRes.Retry:
92-
task.RetryCounter++;
93-
if (task.NextExecute == null) task.NextExecute = DateTime.Now.AddMinutes(3);
94-
break;
95-
96-
default:
97-
task.RetryCounter = 0;
98-
if (task.NextTask != null)
99-
{
100-
task.NextTask.ExecuteAt = DateTime.MinValue.AddHours(5);
101-
task.NextTask.Stage = TaskStage.Start;
102-
acc.Tasks.Add(task.NextTask);
103-
task.NextTask = null;
104-
}
105-
break;
84+
taskRes = await task.Execute(acc);
85+
break;
10686
}
107-
}
108-
catch (WebDriverException e) when (e.Message.Contains("chrome not reachable") || e.Message.Contains("no such window:"))
109-
{
110-
acc.Logger.Warning($"Chrome has problem while executing task {task.GetName()}! Vill {task.Vill?.Name}. Try reopen Chrome");
111-
112-
acc.Tasks.Add(new ReopenDriver()
87+
catch (WebDriverException e) when (e.Message.Contains("chrome not reachable") || e.Message.Contains("no such window:"))
11388
{
114-
ExecuteAt = DateTime.MinValue,
115-
Priority = TaskPriority.High,
116-
ReopenAt = DateTime.MinValue
117-
});
118-
119-
//try exccute task after we reopen chrome 1 mintues
89+
acc.Logger.Warning($"Chrome has problem while executing task {task.GetName()}! Vill {task.Vill?.Name}. Try reopen Chrome");
12090

121-
if (task.NextExecute == null) task.NextExecute = DateTime.MinValue.AddMinutes(1); // make sure current task is excuted after reopen driver
91+
acc.Wb.Close();
92+
await acc.Wb.Init(acc);
93+
}
94+
catch (Exception e)
95+
{
96+
acc.Logger.Error(e, $"Error executing task {task.GetName()}! Vill {task.Vill?.Name}");
97+
task.RetryCounter++;
98+
if (task.NextExecute == null)
99+
{
100+
task.NextExecute = DateTime.Now.AddMinutes(3);
101+
acc.Tasks.ReOrder();
102+
}
103+
break;
104+
}
122105
}
123-
catch (Exception e)
106+
while (true);
107+
108+
switch (taskRes)
124109
{
125-
acc.Logger.Error(e, $"Error executing task {task.GetName()}! Vill {task.Vill?.Name}");
126-
task.RetryCounter++;
127-
if (task.NextExecute == null) task.NextExecute = DateTime.Now.AddMinutes(3);
110+
case TaskRes.Retry:
111+
task.RetryCounter++;
112+
if (task.NextExecute == null)
113+
{
114+
task.NextExecute = DateTime.Now.AddMinutes(3);
115+
acc.Tasks.ReOrder();
116+
}
117+
break;
118+
119+
default:
120+
task.RetryCounter = 0;
121+
if (task.NextTask != null)
122+
{
123+
task.NextTask.ExecuteAt = DateTime.MinValue.AddHours(5);
124+
task.NextTask.Stage = TaskStage.Start;
125+
acc.Tasks.Add(task.NextTask);
126+
task.NextTask = null;
127+
}
128+
break;
128129
}
129130

130131
//We want to re-execute the same task later
@@ -135,18 +136,18 @@ public static async Task Execute(Account acc, BotTask task)
135136
acc.Tasks.ReOrder();
136137

137138
task.Stage = TaskStage.Start;
138-
acc.Logger.Warning($"Task {task.GetName()}" + (task.Vill == null ? "" : $" in village {task.Vill.Name} will be re-executed at {task.ExecuteAt}"));
139+
acc.Logger.Warning($"Task {task.GetName()} in village {task.Vill?.Name} will be re-executed at {task.ExecuteAt}");
139140
return;
140141
}
141142
// Remove the task from the task list
142143
acc.Tasks.Remove(task);
143144
if (task.RetryCounter >= 3)
144145
{
145-
acc.Logger.Warning($"Task {task.GetName()}" + (task.Vill == null ? "" : $" in village {task.Vill.Name} is already re-executed 3 times. Ignore it"));
146+
acc.Logger.Warning($"Task {task.GetName()} in village {task.Vill?.Name} is already re-executed 3 times. Ignore it");
146147
}
147148
else
148149
{
149-
acc.Logger.Information($"Task {task.GetName()}" + (task.Vill == null ? "" : $" in village {task.Vill.Name} is done."));
150+
acc.Logger.Information($"Task {task.GetName()} in village {task.Vill?.Name} is done.");
150151
}
151152
}
152153

@@ -180,8 +181,6 @@ public static void UpdateDorf2Info(Account acc)
180181
//remove any further UpdateDorf2 BotTasks for this village (if below 5min)
181182
acc.Tasks.Remove(typeof(UpdateDorf2), vill, 5);
182183

183-
UpdateCurrentlyBuilding(acc, vill);
184-
185184
var buildings = InfrastructureParser.GetBuildings(acc, acc.Wb.Html);
186185
foreach (var field in buildings)
187186
{
@@ -190,6 +189,8 @@ public static void UpdateDorf2Info(Account acc)
190189
building.Type = field.Type;
191190
building.UnderConstruction = field.UnderConstruction;
192191
}
192+
193+
UpdateCurrentlyBuilding(acc, vill);
193194
}
194195

195196
public static void UpdateDorf1Info(Account acc)
@@ -200,8 +201,6 @@ public static void UpdateDorf1Info(Account acc)
200201
//remove any further UpdateDorf1 BotTasks for this village (if below 5min)
201202
acc.Tasks.Remove(typeof(UpdateDorf1), vill, 5);
202203

203-
UpdateCurrentlyBuilding(acc, vill);
204-
205204
var dorf1Movements = TroopsMovementParser.ParseDorf1Movements(acc.Wb.Html);
206205

207206
// Check attacks if there are incoming attacks and alerts aren't disabled and task isn't already on task list
@@ -224,16 +223,21 @@ public static void UpdateDorf1Info(Account acc)
224223
building.Type = field.Type;
225224
building.UnderConstruction = field.UnderConstruction;
226225
}
226+
227+
UpdateCurrentlyBuilding(acc, vill);
227228
}
228229

229230
private static void UpdateCurrentlyBuilding(Account acc, Village vill)
230231
{
231232
vill.Build.CurrentlyBuilding.Clear();
232-
var cb = InfrastructureParser.CurrentlyBuilding(acc.Wb.Html, acc);
233+
var cb = InfrastructureParser.CurrentlyBuilding(acc.Wb.Html);
233234
if (cb == null) return; // Nothing is currently building
234235

235236
for (int i = 0; i < cb.Count; i++)
236237
{
238+
var build = vill.Build.Buildings.FirstOrDefault(x => x.Type == cb[i].Building && x.Level - cb[i].Level < 3);
239+
if (build == null) continue;
240+
cb[i].Location = build.Id;
237241
vill.Build.CurrentlyBuilding.Add(cb[i]);
238242
}
239243
}

0 commit comments

Comments
 (0)