@@ -53,6 +53,7 @@ public override async Task<TaskRes> Execute(Account acc)
53
53
if ( acc . AccInfo . ServerVersion == ServerVersionEnum . TTwars && ! _buildingTask . ConstructNew )
54
54
{
55
55
acc . Logger . Information ( "Try using TTWars fast build method" , this ) ;
56
+ await Task . Delay ( AccountHelper . Delay ( acc ) ) ;
56
57
var fastUpgrade = await TTWarsTryFastUpgrade ( acc , $ "{ acc . AccInfo . ServerUrl } /build.php?id={ _buildingTask . BuildingId } ") ;
57
58
if ( fastUpgrade ) continue ;
58
59
acc . Logger . Information ( "Using TTWars fast build method failed. Continue normal method" , this ) ;
@@ -99,11 +100,19 @@ private async Task<bool> Construct(Account acc)
99
100
// Check for prerequisites
100
101
if ( button == null )
101
102
{
103
+ Retry ( acc , "Button disappear." ) ;
102
104
return false ;
103
105
}
104
106
105
- await DriverHelper . ClickById ( acc , button . Id ) ;
106
-
107
+ await AccountHelper . DelayWait ( acc ) ;
108
+ acc . Logger . Information ( $ "Starting contruct { _buildingTask . Building } in { Vill . Name } ") ;
109
+ var element = acc . Wb . Driver . FindElement ( By . XPath ( button . XPath ) ) ;
110
+ if ( element == null )
111
+ {
112
+ Retry ( acc , "Button disappear." ) ;
113
+ return false ;
114
+ }
115
+ element . Click ( ) ;
107
116
_buildingTask . ConstructNew = false ;
108
117
109
118
acc . Logger . Warning ( $ "Started construction of { _buildingTask . Building } in { Vill . Name } ") ;
@@ -123,17 +132,7 @@ private async Task<bool> Construct(Account acc)
123
132
private async Task < bool > Upgrade ( Account acc )
124
133
{
125
134
acc . Wb . UpdateHtml ( ) ;
126
- HtmlNode node = null ;
127
- switch ( acc . AccInfo . ServerVersion )
128
- {
129
- case ServerVersionEnum . TTwars :
130
- node = acc . Wb . Html . GetElementbyId ( $ "contract_building{ ( int ) _buildingTask . Building } ") ;
131
- break ;
132
-
133
- case ServerVersionEnum . T4_5 :
134
- node = acc . Wb . Html . GetElementbyId ( "build" ) ;
135
- break ;
136
- }
135
+ HtmlNode node = acc . Wb . Html . GetElementbyId ( "build" ) ;
137
136
( var buildingEnum , var lvl ) = InfrastructureParser . UpgradeBuildingGetInfo ( node ) ;
138
137
139
138
if ( buildingEnum == BuildingEnum . Site || lvl == - 1 )
@@ -156,7 +155,7 @@ private async Task<bool> Upgrade(Account acc)
156
155
157
156
if ( lvl >= _buildingTask . Level )
158
157
{
159
- acc . Logger . Information ( $ "{ _buildingTask . Building } is already level { lvl } in village { Vill . Name } . Will be removed from the queue.") ;
158
+ acc . Logger . Information ( $ "{ _buildingTask . Building } is already level { lvl } in village { Vill . Name } . Will be removed from the queue.", this ) ;
160
159
RemoveCurrentTask ( ) ;
161
160
return false ;
162
161
}
@@ -165,7 +164,7 @@ private async Task<bool> Upgrade(Account acc)
165
164
var buttons = container ? . Descendants ( "button" ) ;
166
165
if ( buttons == null )
167
166
{
168
- acc . Logger . Warning ( $ "We wanted to upgrade { _buildingTask . Building } , but no 'upgrade' button was found! Url={ acc . Wb . CurrentUrl } ") ;
167
+ acc . Logger . Information ( $ "We wanted to upgrade { _buildingTask . Building } , but no 'upgrade' button was found! Url={ acc . Wb . CurrentUrl } ", this ) ;
169
168
return false ;
170
169
}
171
170
@@ -178,34 +177,47 @@ private async Task<bool> Upgrade(Account acc)
178
177
179
178
if ( upgradeButton == null )
180
179
{
181
- acc . Logger . Warning ( $ "We wanted to upgrade { _buildingTask . Building } , but no 'upgrade' button was found!") ;
180
+ Retry ( acc , $ "We wanted to upgrade { _buildingTask . Building } , but no 'upgrade' button was found!") ;
182
181
return false ;
183
182
}
184
183
185
184
// Not enough resources?
186
185
if ( acc . AccInfo . ServerVersion == ServerVersionEnum . T4_5 && errorMessage != null )
187
186
{
188
- acc . Logger . Warning ( $ "We wanted to upgrade { _buildingTask . Building } , but there was an error message:\n { errorMessage . InnerText } ") ;
187
+ Retry ( acc , $ "We wanted to upgrade { _buildingTask . Building } , but there was an error message:\n { errorMessage . InnerText } ") ;
189
188
return false ;
190
189
}
191
190
192
191
var buildDuration = InfrastructureParser . GetBuildDuration ( container , acc . AccInfo . ServerVersion ) ;
193
192
194
- acc . Logger . Information ( $ "Started upgrading { _buildingTask . Building } to level { lvl + 1 } in { Vill . Name } ") ;
193
+ acc . Logger . Information ( "Complete checking" , this ) ;
194
+ acc . Logger . Information ( $ "Upgrading { _buildingTask . Building } to level { lvl + 1 } in { Vill . Name } ", this ) ;
195
195
196
196
var watchAd = false ;
197
197
if ( acc . AccInfo . ServerVersion == ServerVersionEnum . T4_5 && buildDuration . TotalMinutes > acc . Settings . WatchAdAbove )
198
198
{
199
199
// watchAd = await TryFastUpgrade(acc);
200
+ acc . Logger . Information ( "Try using watch ads upgrade button" , this ) ;
201
+ acc . Logger . Information ( "Watch ads function is disable because of bugs from Chrome. We cannot do anything about this" , this ) ;
200
202
}
201
203
202
204
if ( ! watchAd )
203
205
{
206
+ await AccountHelper . DelayWait ( acc ) ;
207
+ acc . Logger . Information ( "Using normal upgrade button" ) ;
208
+
204
209
upgradeButton = buttons . FirstOrDefault ( x => x . HasClass ( "build" ) ) ;
205
- await DriverHelper . ClickById ( acc , upgradeButton . Id ) ; // Normal upgrade
210
+
211
+ var element = acc . Wb . Driver . FindElement ( By . XPath ( upgradeButton . XPath ) ) ;
212
+ if ( element == null )
213
+ {
214
+ Retry ( acc , "Button disappear." ) ;
215
+ return false ;
216
+ }
217
+ element . Click ( ) ;
206
218
}
207
219
208
- acc . Logger . Information ( $ "Upgraded { _buildingTask . Building } to level { lvl + 1 } in { Vill . Name } ") ;
220
+ acc . Logger . Information ( $ "Upgraded { _buildingTask . Building } to level { lvl + 1 } in { Vill . Name } ", this ) ;
209
221
if ( _buildingTask . Level == lvl + 1 )
210
222
{
211
223
RemoveCurrentTask ( ) ;
@@ -449,11 +461,13 @@ private async Task<bool> FreeCropCondition(Account acc)
449
461
450
462
private async Task MoveIntoBuilding ( Account acc )
451
463
{
464
+ await AccountHelper . DelayWait ( acc ) ;
452
465
acc . Logger . Information ( $ "Move into building { _buildingTask . Building } ", this ) ;
453
466
await NavigationHelper . EnterBuilding ( acc , Vill , ( int ) _buildingTask . BuildingId ) ;
454
467
var build = Vill . Build . Buildings . FirstOrDefault ( x => x . Id == _buildingTask . BuildingId ) ;
455
468
if ( build . Type == BuildingEnum . Site )
456
469
{
470
+ await AccountHelper . DelayWait ( acc ) ;
457
471
acc . Logger . Information ( $ "This is contruct task, choose correct tab for building { _buildingTask . Building } ", this ) ;
458
472
await NavigationHelper . ToConstructionTab ( acc , _buildingTask . Building ) ;
459
473
}
@@ -493,31 +507,30 @@ private async Task<bool> IsEnoughRes(Account acc)
493
507
494
508
acc . Wb . UpdateHtml ( ) ;
495
509
HtmlNode contractNode = null ;
496
- switch ( acc . AccInfo . ServerVersion )
510
+ if ( construct )
497
511
{
498
- case ServerVersionEnum . TTwars :
499
- contractNode = acc . Wb . Html . GetElementbyId ( $ "contract_building{ ( int ) _buildingTask . Building } ") ;
500
- break ;
501
-
502
- case ServerVersionEnum . T4_5 :
503
- contractNode = acc . Wb . Html . GetElementbyId ( "contract" ) ;
504
- break ;
512
+ contractNode = acc . Wb . Html . GetElementbyId ( $ "contract_building{ ( int ) _buildingTask . Building } ") ;
513
+ }
514
+ else
515
+ {
516
+ contractNode = acc . Wb . Html . GetElementbyId ( "contract" ) ;
505
517
}
506
- var cost = ResourceParser . ParseResourcesNeed ( contractNode ) ;
507
- acc . Logger . Information ( $ "Need { cost } ") ;
518
+
519
+ var resWrapper = contractNode . Descendants ( ) . FirstOrDefault ( x => x . HasClass ( "resourceWrapper" ) ) ;
520
+ var cost = ResourceParser . GetResourceCost ( resWrapper ) ;
521
+
522
+ acc . Logger . Information ( $ "Need { cost } ", this ) ;
508
523
509
524
if ( ! ResourcesHelper . IsEnoughRes ( Vill , cost . ToArray ( ) ) )
510
525
{
511
526
if ( ResourcesHelper . IsStorageTooLow ( acc , Vill , cost ) )
512
527
{
513
- acc . Logger . Warning ( $ "Storage is too low to build { _buildingTask . Building } - Level { _buildingTask . Level } ! Needed { cost } . Need upgrade storage first", this ) ;
514
- acc . Logger . Information ( "Now bot CANNOT add upgrade storage task, please do it manually." , this ) ;
515
- StopFlag = true ;
528
+ acc . Logger . Warning ( $ "Storage is too low. Added storage upgrade.", this ) ;
516
529
return false ;
517
530
}
518
531
519
532
var stillNeededRes = ResourcesHelper . SubtractResources ( cost . ToArray ( ) , Vill . Res . Stored . Resources . ToArray ( ) , true ) ;
520
- acc . Logger . Information ( "Not enough resources to build." ) ;
533
+ acc . Logger . Information ( "Not enough resources to build." , this ) ;
521
534
if ( Vill . Settings . UseHeroRes && acc . AccInfo . ServerVersion == ServerVersionEnum . T4_5 ) // Only T4.5 has resources in hero inv
522
535
{
523
536
var heroRes = HeroHelper . GetHeroResources ( acc ) ;
0 commit comments