1
- // var r = Math.round(e.building.points * Math.pow(e.building.points_factor, e.next_level)) - Math.round(e.building.points * Math.pow(e.building.points_factor, e.level))
2
-
3
1
class AutoBuild extends ModernUtil {
4
2
constructor ( c , s ) {
5
3
super ( c , s ) ;
@@ -11,10 +9,34 @@ class AutoBuild extends ModernUtil {
11
9
this . shiftHeld = false ;
12
10
13
11
/* Active always, check if the towns are in the active list */
14
- this . enable = setInterval ( this . main , 20000 ) ;
12
+ this . interval = setInterval ( this . main . bind ( this ) , 20000 ) ;
15
13
16
14
/* Add listener that change the Senate look */
17
15
uw . $ . Observer ( GameEvents . window . open ) . subscribe ( "modernSenate" , this . updateSenate ) ;
16
+
17
+ this . simulateCaptcha = false ;
18
+ this . captchaActive = false ;
19
+
20
+ /* Check for captcha conditions every 300ms */
21
+ this . checkCaptchaInterval = setInterval ( ( ) => {
22
+ if ( this . simulateCaptcha || $ ( '.botcheck' ) . length || $ ( '#recaptcha_window' ) . length ) {
23
+ if ( ! this . captchaActive ) {
24
+ this . console . log ( 'Captcha active, autobuild stopped working' ) ;
25
+ clearInterval ( this . interval ) ;
26
+ this . captchaActive = true ;
27
+ }
28
+ } else {
29
+ if ( this . captchaActive ) {
30
+ this . console . log ( 'Captcha resolved, autobuild resumed' ) ;
31
+ this . startInterval ( ) ; // Restart autobuild
32
+ this . captchaActive = false ;
33
+ }
34
+ }
35
+ } , 300 ) ;
36
+ }
37
+
38
+ startInterval ( ) {
39
+ this . interval = setInterval ( this . main . bind ( this ) , 20000 ) ;
18
40
}
19
41
20
42
settings = ( ) => {
@@ -43,7 +65,7 @@ class AutoBuild extends ModernUtil {
43
65
<div class="game_border_corner corner2"></div>
44
66
<div class="game_border_corner corner3"></div>
45
67
<div class="game_border_corner corner4"></div>
46
- <div id="auto_build_title" style="cursor: pointer; filter: ${ this . enable ? 'brightness(100%) saturate(186%) hue-rotate(241deg)' : '' } " class="game_header bold" onclick="window.modernBot.autoBuild.toggle()"> Auto Build <span class="command_count"></span>
68
+ <div id="auto_build_title" style="cursor: pointer; filter: ${ this . interval ? 'brightness(100%) saturate(186%) hue-rotate(241deg)' : '' } " class="game_header bold" onclick="window.modernBot.autoBuild.toggle()"> Auto Build <span class="command_count"></span>
47
69
<div style="position: absolute; right: 10px; top: 4px; font-size: 10px;"> (click to toggle) </div>
48
70
</div>
49
71
<div id="buildings_lvl_buttons"></div>
@@ -56,14 +78,13 @@ class AutoBuild extends ModernUtil {
56
78
if ( handler . context !== "building_senate" ) return ;
57
79
58
80
// Edit the width of the window to fit the new element
59
- handler . wnd . setWidth ( 850 )
81
+ handler . wnd . setWidth ( 850 ) ;
60
82
61
83
// Compute the id of the window
62
- const id = `gpwnd_${ handler . wnd . getID ( ) } `
84
+ const id = `gpwnd_${ handler . wnd . getID ( ) } ` ;
63
85
64
86
// Loop until the element is found
65
87
const updateView = ( ) => {
66
-
67
88
const interval = setInterval ( ( ) => {
68
89
const $window = $ ( '#' + id ) ;
69
90
@@ -100,22 +121,21 @@ class AutoBuild extends ModernUtil {
100
121
setTimeout ( ( ) => {
101
122
clearInterval ( interval ) ;
102
123
} , 100 ) ;
103
- }
124
+ } ;
104
125
105
126
// subscribe to set content event
106
127
const oldSetContent = handler . wnd . setContent2 ;
107
128
handler . wnd . setContent2 = ( ...params ) => {
108
129
updateView ( ) ;
109
130
oldSetContent ( ...params ) ;
110
- }
111
-
112
- }
131
+ } ;
132
+ } ;
113
133
114
134
/* Given the town id, set the polis in the settings menu */
115
135
setPolisInSettings = town_id => {
116
136
let town = uw . ITowns . towns [ town_id ] ;
117
137
118
- /* If the town is in the active list set*/
138
+ /* If the town is in the active list set */
119
139
let town_buildings = this . towns_buildings ?. [ town_id ] ?? { ...town . buildings ( ) ?. attributes } ?? { } ;
120
140
let buildings = { ...town . buildings ( ) . attributes } ;
121
141
@@ -134,7 +154,7 @@ class AutoBuild extends ModernUtil {
134
154
</div>` ;
135
155
} ;
136
156
137
- /* If the town is in a group, the the groups */
157
+ /* If the town is in a group, the groups */
138
158
const groups =
139
159
`(${ Object . values ( uw . ITowns . getTownGroups ( ) )
140
160
. filter ( group => group . id > 0 && group . id !== - 1 && group . towns [ town_id ] )
@@ -273,20 +293,21 @@ class AutoBuild extends ModernUtil {
273
293
town_id : town_id ,
274
294
} ;
275
295
uw . gpAjax . ajaxPost ( 'frontend_bridge' , 'execute' , data ) ;
276
- this . console . log ( `${ town . getName ( ) } : buildUp ${ type } ` ) ;
277
- await this . sleep ( 500 ) ;
296
+ this . console . log ( `${ town . getName ( ) } : Build Up ${ type } ` ) ;
297
+ await this . sleep ( 1234 ) ;
278
298
} ;
279
299
280
300
/* Make post request to tear building down */
281
- postTearDown = async ( type , town_id ) => {
301
+ postTearDown = async ( type , town_id , town ) => {
282
302
let data = {
283
303
model_url : 'BuildingOrder' ,
284
304
action_name : 'tearDown' ,
285
305
arguments : { building_id : type } ,
286
306
town_id : town_id ,
287
307
} ;
288
308
uw . gpAjax . ajaxPost ( 'frontend_bridge' , 'execute' , data ) ;
289
- await this . sleep ( 500 ) ;
309
+ this . console . log ( `${ town . getName ( ) } : Build Down ${ type } ` ) ;
310
+ await this . sleep ( 1234 ) ;
290
311
} ;
291
312
292
313
/* return true if the quee is full */
@@ -358,7 +379,7 @@ class AutoBuild extends ModernUtil {
358
379
return false ;
359
380
}
360
381
if ( target [ build ] < buildings [ build ] ) {
361
- await this . postTearDown ( build , town_id ) ;
382
+ await this . postTearDown ( build , town_id , town ) ;
362
383
return true ;
363
384
}
364
385
return false ;
0 commit comments