Skip to content

Commit 51144fe

Browse files
committed
fix adventures update fix update hero everytime when count is zero
1 parent 2cbcb82 commit 51144fe

File tree

5 files changed

+27
-4
lines changed

5 files changed

+27
-4
lines changed

MainCore/Helper/BuildingsHelper.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ public static int GetMaxLevel(this BuildingEnums building)
122122
{
123123
#if TTWARS
124124
BuildingEnums.Brewery => 10,
125+
BuildingEnums.Woodcutter => 25,
126+
BuildingEnums.ClayPit => 25,
127+
BuildingEnums.IronMine => 25,
128+
BuildingEnums.Cropland => 25,
129+
125130
#else
126131
BuildingEnums.Brewery => 20,
127132
#endif

MainCore/Helper/UpdateHelper.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,13 @@ public static void UpdateHeroInventory(AppDbContext context, IChromeBrowser chro
295295
public static void UpdateAdventures(AppDbContext context, IChromeBrowser chromeBrowser, int accountId)
296296
{
297297
var foundAdventures = HeroInfo.GetAdventures(chromeBrowser.GetHtml());
298-
if (foundAdventures.Count == 0) return;
299298
var heroAdventures = context.Adventures.Where(x => x.AccountId == accountId).ToList();
299+
if (foundAdventures.Count == 0)
300+
{
301+
context.Adventures.RemoveRange(heroAdventures);
302+
context.SaveChanges();
303+
return;
304+
}
300305
var addedAdventures = new List<Models.Database.Adventure>();
301306
foreach (var adventure in foundAdventures)
302307
{

MainCore/Tasks/Update/UpdateAdventures.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ public UpdateAdventures(int accountId) : base(accountId)
1313

1414
public override void Execute()
1515
{
16+
using var context = _contextFactory.CreateDbContext();
17+
1618
NavigateHelper.ToAdventure(_chromeBrowser);
1719
if (Cts.IsCancellationRequested) return;
18-
using var context = _contextFactory.CreateDbContext();
1920
UpdateHelper.UpdateAdventures(context, _chromeBrowser, AccountId);
2021

2122
var taskUpdate = new UpdateInfo(AccountId);

MainCore/Tasks/Update/UpdateInfo.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,14 @@ private void UpdateHeroInfo()
159159
context.SaveChanges();
160160

161161
var adventures = context.Adventures.Count(x => x.AccountId == AccountId);
162-
if (adventures != numberAdventure)
162+
if (numberAdventure == 0)
163+
{
164+
var heroAdventures = context.Adventures.Where(x => x.AccountId == AccountId).ToList();
165+
166+
context.Adventures.RemoveRange(heroAdventures);
167+
context.SaveChanges();
168+
}
169+
else if (adventures != numberAdventure)
163170
{
164171
var listTask = _taskManager.GetList(AccountId);
165172
var task = listTask.FirstOrDefault(x => x.GetType() == typeof(UpdateAdventures));

TTWarsCore/Parsers/VillagesTable.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ public static int GetId(HtmlNode node)
3030
var href = System.Net.WebUtility.HtmlDecode(hrefNode.GetAttributeValue("href", ""));
3131
if (string.IsNullOrEmpty(href)) return -1;
3232
if (!href.Contains('=')) return -1;
33-
return int.Parse(href.Split('=')[1]);
33+
var value = href.Split('=')[1];
34+
if (value.Contains('&'))
35+
{
36+
value = value.Split('&')[0];
37+
}
38+
return int.Parse(value);
3439
}
3540

3641
public static string GetName(HtmlNode node)

0 commit comments

Comments
 (0)