-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfinder.js
91 lines (79 loc) · 1.77 KB
/
finder.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// 查找助战
var servants = {
caster: 4
}
var utils = require('./utils')
var swipe1 = utils.swipe
var click1 = utils.click
var sleep1 = utils.sleep
var readImage = utils.readImage
// autojs 这个 node 版本 const 分析的不对,没办法还是用 var 吧
var findButton = utils.findButton
var images = {}
var ListUpdate = [1500, 220]
function initImages () {
for (let key in servants) {
images[key] = []
for (let i = 1; i <= servants[key]; i++) {
images[key].push(readImage(getWholePath(key, i)))
}
}
}
function getWholePath(servant, idx) {
return './assets/friends/' + servant + '/' + idx + '.jpg'
}
function findServant(servant) {
const imageList = images[servant]
let p = null
for (let i = 0; i < imageList.length; i++) {
// 就搜一次就够了
p = findButton(imageList[i], {maxTimes: 1, threshold: 0.9})
if (p) {
return p
}
}
return p
}
function findServantAndSwipe(servant) {
let p = null
for (let i = 0; i < 5; i++) {
p = findServant(servant)
sleep(300)
if (p) {
return p
}
swipe1(1600, 1000, 1600, 500, 600, true)
sleep(200)
}
return p
}
function find(servant) {
p = findServantAndSwipe(servant)
while (!p) {
click1(ListUpdate[0], ListUpdate[1], true)
sleep1(300)
click1(1576,842, true)
sleep1(3000)
p = findServantAndSwipe(servant)
if (p) {
break
}
sleep1(15000)
toast('接着找')
}
click1(p[0],p[1], false)
toast('找到啦 ' + p[0] + ',' + p[1])
sleep1(3000)
}
events.on('exit', function() {
for (let key in images) {
for (let i = 0; i <= images[key].length; i++) {
if (images[key][i]) {
images[key][i].recycle()
}
}
}
})
// 直接初始化一波
initImages()
exports.findServant = find