1
1
// 选择可用的车,第一列第一辆编号为1,第一列第二辆为2,第二列第一辆为3,以此类推
2
2
// 在第6行填写车的编号,最多6辆车循环
3
3
// 按填写先后顺序用车
4
- // 请根据自己需求修改
4
+ // 请根据自己实际情况修改第6行后开始运行脚本
5
5
6
- const cars = [ 1 , 2 , 3 , 4 , 5 , 6 ] ;
6
+ const cars = [ 1 , 2 , 3 , 4 , 5 , 6 ] ;
7
7
const width = device . width ;
8
8
const height = device . height ;
9
9
@@ -51,13 +51,11 @@ var profile2160 = {
51
51
y : 974
52
52
} ,
53
53
54
- //生涯,开始,继续
55
54
goldenPoint : {
56
55
x : 1700 ,
57
56
y : 1000
58
57
} ,
59
58
60
- //firstCar
61
59
firstCar : {
62
60
x : 565 ,
63
61
y : 630
@@ -73,10 +71,8 @@ var profile2160 = {
73
71
y : 313
74
72
} ,
75
73
76
- //左边按钮
77
74
left : { x : 961 , y : 730 } ,
78
75
79
- //右边按钮
80
76
right : { x : 1170 , y : 730 }
81
77
}
82
78
@@ -116,16 +112,16 @@ function before() {
116
112
toast ( '请求截图失败,程序结束' ) ;
117
113
exit ( ) ;
118
114
}
119
- //调整屏幕亮度
115
+ // 调整屏幕亮度及媒体音量
120
116
device . setBrightness ( 0 ) ;
121
117
device . setMusicVolume ( 0 ) ;
122
118
}
123
119
124
120
function eventListener ( ) {
125
121
threads . start ( function ( ) {
126
- //启用按键监听
122
+ // 启用按键监听
127
123
events . observeKey ( ) ;
128
- //监听音量上键按下
124
+ // 监听音量上键按下
129
125
events . onKeyDown ( "volume_down" , function ( event ) {
130
126
toastLog ( "程序手动退出" ) ;
131
127
device . setBrightness ( 40 ) ;
@@ -136,41 +132,43 @@ function eventListener() {
136
132
}
137
133
138
134
function main ( ) {
139
- //比赛
135
+ // 比赛
140
136
click ( profile . compete . x , profile . compete . y ) ;
141
137
click ( profile . compete . x , profile . compete . y ) ;
142
138
sleep ( 2000 ) ;
143
139
140
+ // 选车 & 开始比赛
144
141
toast ( "选车" ) ;
145
142
sleep ( 700 ) ;
146
- //选车
147
143
chooseCar ( ) ;
144
+ click ( profile . goldenPoint . x , profile . goldenPoint . y ) ;
145
+ click ( profile . goldenPoint . x , profile . goldenPoint . y ) ;
148
146
149
- //载入动画
147
+ // 载入动画
150
148
sleep ( 10000 ) ;
151
149
152
- //开跑
150
+ // 开跑
153
151
threads . start ( function ( ) {
154
152
run ( )
155
153
} ) ;
156
154
157
- //跑完之后
155
+ // 跑完之后
158
156
afterRun ( ) ;
159
157
}
160
158
161
159
162
160
function run ( ) {
163
- //在新线程执行的代码
164
- //console.log("定时器启动,定时点击氮气");
165
- //预计时间90秒
161
+ // 在新线程执行的代码
162
+ // console.log("定时器启动,定时点击氮气");
163
+ // 预计时间90秒
166
164
var exitTime = new Date ( ) . getTime ( ) + 95000 ;
167
- //定时点击氮气
165
+ // 定时点击氮气
168
166
var id = setInterval ( function ( ) {
169
167
click ( height * 4 / 5 , width / 2 ) ;
170
168
swipe ( 5 * height / 8 , width / 2 , height * 7 / 8 , width / 2 , 500 ) ;
171
169
var now = new Date ( ) . getTime ( ) ;
172
170
if ( now > exitTime ) {
173
- //{ console.log("定时器结束");
171
+ // console.log("定时器结束");
174
172
clearInterval ( id ) ;
175
173
}
176
174
} , 1000 ) ;
@@ -182,22 +180,24 @@ function afterRun() {
182
180
sleep ( 95000 ) ;
183
181
toast ( "跑完了" ) ;
184
182
185
- //本层循环用于点击三次继续.
183
+ // 本层循环用于点击三次继续.
186
184
while ( true ) {
187
185
// 截图
188
186
var img = captureScreen ( ) ;
189
187
190
188
// 倒计时
191
189
var color_countdown = images . pixel ( img , profile . countdown . x , profile . countdown . y ) ;
192
190
193
- // 粉红(在跑完之后会闪现出活动主页 )
191
+ // 粉红(在跑完之后会出现一闪而过的活动主页 )
194
192
if ( colors . equals ( color_countdown , "#ffff0054" ) ) {
195
193
break ;
196
194
}
197
195
click ( profile . goldenPoint . x , profile . goldenPoint . y ) ;
198
196
}
199
197
200
- //本层循环用于控制领代币或者升级
198
+ sleep ( 1000 ) ;
199
+
200
+ // 本层循环用于控制领代币或者升级
201
201
while ( true ) {
202
202
sleep ( 1000 ) ;
203
203
// 截图
@@ -242,8 +242,17 @@ function chooseCar() {
242
242
}
243
243
}
244
244
if ( flag ) {
245
- toastLog ( "都没油了,脚本退出" ) ;
246
- exit ( ) ;
245
+ toastLog ( "都没油了" ) ;
246
+ let n = cars [ 0 ] ;
247
+ var carPoint = {
248
+ x : profile . firstCar . x + profile . distance . x * parseInt ( ( n - 1 ) / 2 ) ,
249
+ y : profile . firstCar . y + profile . distance . y * ( ( n - 1 ) % 2 )
250
+ }
251
+ click ( carPoint . x - profile . distance . x / 2 , carPoint . y - profile . distance . y / 2 ) ;
252
+ sleep ( 2000 ) ;
253
+ //开始
254
+ click ( profile . goldenPoint . x , profile . goldenPoint . y ) ;
255
+ ad ( ) ;
247
256
}
248
257
}
249
258
@@ -260,4 +269,76 @@ function checkForResolution(x, y, img) {
260
269
positionX : x ,
261
270
positionY : y
262
271
} ;
272
+ }
273
+
274
+
275
+ function ad ( ) {
276
+ toastLog ( "开始为车辆补充燃油" ) ;
277
+ while ( true ) {
278
+ // confirm the UI
279
+ var img = captureScreen ( ) ;
280
+ var left = images . pixel ( img , profile . left . x , profile . left . y ) ;
281
+ var right = images . pixel ( img , profile . right . x , profile . right . y ) ;
282
+ // toastLog("left is " + colors.toString(left));
283
+ // toastLog("right is " + colors.toString(right));
284
+ if ( colors . equals ( left , "#c3fb12" ) && colors . equals ( right , "#ffffff" ) ) {
285
+ click ( profile . right . x , profile . right . y ) ;
286
+ toastLog ( "开始看这个广告" ) ;
287
+ break ;
288
+ }
289
+ else {
290
+ sleep ( 1000 ) ;
291
+ }
292
+ }
293
+
294
+ // wait for playing ad
295
+ sleep ( 30000 ) ;
296
+
297
+ var jump_back = 0 ;
298
+
299
+ while ( true ) {
300
+ if ( ! jump_back ) {
301
+ toastLog ( "尝试返回" )
302
+ back ( ) ;
303
+ sleep ( 5000 ) ;
304
+ }
305
+
306
+ var img = captureScreen ( ) ;
307
+ var left = images . pixel ( img , profile . left . x , profile . left . y ) ;
308
+ var right = images . pixel ( img , profile . right . x , profile . right . y ) ;
309
+ var next = images . pixel ( img , profile . goldenPoint . x , profile . goldenPoint . y ) ;
310
+ // toastLog("left is " + colors.toString(left));
311
+ // toastLog("right is " + colors.toString(right));
312
+ // toastLog("next is " + colors.toString(next));
313
+
314
+ // grey blue
315
+ if ( colors . equals ( left , "#bababa" ) && colors . isSimilar ( right , "#2580d8" ) ) {
316
+ toastLog ( "继续广告" ) ;
317
+ click ( profile . right . x , profile . right . y ) ;
318
+ // click(profile.right.x, profile.right.y);
319
+ sleep ( 8000 ) ;
320
+ }
321
+ // green white
322
+ else if ( colors . equals ( left , "#c3fb12" ) && colors . equals ( right , "#ffffff" ) ) {
323
+ toastLog ( "看下一个广告" )
324
+ ad ( ) ;
325
+ }
326
+ // next is green
327
+ else if ( colors . equals ( next , "#c3fb12" ) ) {
328
+ toastLog ( "车辆燃油已恢复,即将开始下一场比赛" ) ;
329
+ break ;
330
+ }
331
+ // next is white
332
+ else if ( colors . equals ( next , "#ffffff" ) ) {
333
+ toastLog ( "偶然多点一次返回,看下一个广告" )
334
+ click ( profile . goldenPoint . x , profile . goldenPoint . y ) ;
335
+ ad ( ) ;
336
+ }
337
+ // In progress
338
+ else {
339
+ toastLog ( "请稍等" ) ;
340
+ sleep ( 3000 ) ;
341
+ jump_back = 1 ;
342
+ }
343
+ }
263
344
}
0 commit comments