@@ -61,26 +61,21 @@ public override async Task<TaskRes> Execute(Account acc)
61
61
await MoveIntoBuilding ( acc ) ;
62
62
if ( StopFlag ) return TaskRes . Executed ;
63
63
64
- var contractNode = acc . Wb . Html . GetElementbyId ( $ "contract_building{ ( int ) _buildingTask . Building } ") ;
65
-
66
- result = IsContructPage ( acc , contractNode ) ;
64
+ result = IsContructPage ( acc ) ;
67
65
if ( StopFlag ) return TaskRes . Executed ;
68
66
if ( ! result ) continue ;
69
67
70
- result = await IsEnoughRes ( acc , contractNode ) ;
68
+ result = await IsEnoughRes ( acc ) ;
71
69
if ( StopFlag ) return TaskRes . Executed ;
72
70
if ( ! result ) continue ;
73
71
74
- acc . Wb . UpdateHtml ( ) ;
75
- contractNode = acc . Wb . Html . GetElementbyId ( $ "contract_building{ ( int ) _buildingTask . Building } ") ;
76
-
77
72
if ( construct )
78
73
{
79
- result = await Construct ( acc , contractNode ) ;
74
+ result = await Construct ( acc ) ;
80
75
}
81
76
else
82
77
{
83
- result = await Upgrade ( acc , contractNode ) ;
78
+ result = await Upgrade ( acc ) ;
84
79
}
85
80
if ( StopFlag ) return TaskRes . Executed ;
86
81
if ( ! result ) continue ;
@@ -95,8 +90,10 @@ public override async Task<TaskRes> Execute(Account acc)
95
90
/// </summary>
96
91
/// <param name="acc">Account</param>
97
92
/// <returns>TaskResult</returnss>
98
- private async Task < bool > Construct ( Account acc , HtmlNode node )
93
+ private async Task < bool > Construct ( Account acc )
99
94
{
95
+ acc . Wb . UpdateHtml ( ) ;
96
+ var node = acc . Wb . Html . GetElementbyId ( $ "contract_building{ ( int ) _buildingTask . Building } ") ;
100
97
var button = node . Descendants ( "button" ) . FirstOrDefault ( x => x . HasClass ( "new" ) ) ;
101
98
102
99
// Check for prerequisites
@@ -123,8 +120,20 @@ private async Task<bool> Construct(Account acc, HtmlNode node)
123
120
/// </summary>
124
121
/// <param name="acc">Account</param>
125
122
/// <returns>TaskResult</returns>
126
- private async Task < bool > Upgrade ( Account acc , HtmlNode node )
123
+ private async Task < bool > Upgrade ( Account acc )
127
124
{
125
+ 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
+ }
128
137
( var buildingEnum , var lvl ) = InfrastructureParser . UpgradeBuildingGetInfo ( node ) ;
129
138
130
139
if ( buildingEnum == BuildingEnum . Site || lvl == - 1 )
@@ -442,17 +451,20 @@ private async Task MoveIntoBuilding(Account acc)
442
451
{
443
452
acc . Logger . Information ( $ "Move into building { _buildingTask . Building } ", this ) ;
444
453
await NavigationHelper . EnterBuilding ( acc , Vill , ( int ) _buildingTask . BuildingId ) ;
445
- if ( _buildingTask . ConstructNew )
454
+ var build = Vill . Build . Buildings . FirstOrDefault ( x => x . Id == _buildingTask . BuildingId ) ;
455
+ if ( build . Type == BuildingEnum . Site )
446
456
{
447
457
acc . Logger . Information ( $ "This is contruct task, choose correct tab for building { _buildingTask . Building } ", this ) ;
448
458
await NavigationHelper . ToConstructionTab ( acc , _buildingTask . Building ) ;
449
459
}
450
460
}
451
461
452
- private bool IsContructPage ( Account acc , HtmlNode contractNode )
462
+ private bool IsContructPage ( Account acc )
453
463
{
454
464
acc . Logger . Information ( $ "Finding button to build ...", this ) ;
455
465
466
+ acc . Wb . UpdateHtml ( ) ;
467
+ var contractNode = acc . Wb . Html . GetElementbyId ( $ "contract_building{ ( int ) _buildingTask . Building } ") ;
456
468
if ( contractNode != null )
457
469
{
458
470
construct = true ;
@@ -474,10 +486,23 @@ private bool IsContructPage(Account acc, HtmlNode contractNode)
474
486
return true ;
475
487
}
476
488
477
- private async Task < bool > IsEnoughRes ( Account acc , HtmlNode contractNode )
489
+ private async Task < bool > IsEnoughRes ( Account acc )
478
490
{
479
491
// check enough res
480
492
acc . Logger . Information ( $ "Check resource ...", this ) ;
493
+
494
+ acc . Wb . UpdateHtml ( ) ;
495
+ HtmlNode contractNode = null ;
496
+ switch ( acc . AccInfo . ServerVersion )
497
+ {
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 ;
505
+ }
481
506
var cost = ResourceParser . ParseResourcesNeed ( contractNode ) ;
482
507
acc . Logger . Information ( $ "Need { cost } ") ;
483
508
0 commit comments