Skip to content

Commit 2b9ff8f

Browse files
committed
fix train settlers in ttwars
1 parent 388c858 commit 2b9ff8f

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

TbsCore/Tasks/LowLevel/TrainSettlers.cs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,33 @@ private bool EnoughSettlers(Account acc)
180180

181181
private bool UpdateSettlersAmount(Account acc)
182182
{
183-
var troopBox = acc.Wb.Html.DocumentNode.Descendants("div").FirstOrDefault(x => x.HasClass($"troop{(int)settlerId}") && x.HasClass("innerTroopWrapper"));
184-
if (troopBox == null)
183+
HtmlAgilityPack.HtmlNode nodeSettler = null;
184+
switch (acc.AccInfo.ServerVersion)
185185
{
186-
Retry(acc, "Cannot find settler box");
187-
return false;
186+
case ServerVersionEnum.TTwars:
187+
{
188+
var troopNode = acc.Wb.Html.DocumentNode.Descendants("img").FirstOrDefault(x => x.HasClass("u" + (int)settlerId));
189+
while (!troopNode.HasClass("details")) troopNode = troopNode.ParentNode;
190+
nodeSettler = troopNode;
191+
}
192+
break;
193+
194+
case ServerVersionEnum.T4_5:
195+
{
196+
var troopBox = acc.Wb.Html.DocumentNode.Descendants("div").FirstOrDefault(x => x.HasClass($"troop{(int)settlerId}") && x.HasClass("innerTroopWrapper"));
197+
if (troopBox == null)
198+
{
199+
Retry(acc, "Cannot find settler box");
200+
return false;
201+
}
202+
nodeSettler = troopBox;
203+
}
204+
break;
205+
206+
default:
207+
break;
188208
}
189-
var divTit = troopBox.Descendants("div").FirstOrDefault(x => x.HasClass("tit"));
209+
var divTit = nodeSettler.Descendants("div").FirstOrDefault(x => x.HasClass("tit"));
190210
if (divTit == null)
191211
{
192212
Retry(acc, "Cannot find Settler title");
@@ -198,6 +218,7 @@ private bool UpdateSettlersAmount(Account acc)
198218
Retry(acc, "Cannot find Settler present number");
199219
return false;
200220
}
221+
201222
Vill.Troops.Settlers = (int)Parser.RemoveNonNumeric(spanPresent.InnerText);
202223
acc.Logger.Information($"Update Settler present number: {Vill.Troops.Settlers}");
203224

0 commit comments

Comments
 (0)