Skip to content

Commit

Permalink
feat: resize points
Browse files Browse the repository at this point in the history
  • Loading branch information
csvwolf committed Aug 14, 2021
1 parent 82ec391 commit 786a59f
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 45 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
主要功能使用指南:https://github.com/csvwolf/fgo-auto-scripts/wiki

## 说明
安卓 App FGO 自动刷图(使用前请开启技能确认功能)。
安卓 App FGO 自动刷图(使用前请**开启技能确认**功能)。

**不保证都能用,坐标偏移不修(可能是不同设备分辨率之类的奇怪的问题)**

确定可以的测试设备:
- MI 10(MiUI 12.5)
- MI 10(MIUI 12.5)
- MI 8(MIUI Global 12.0.1)

### Features
#### 刷图
Expand Down
18 changes: 8 additions & 10 deletions attack.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,17 @@ const Card1= [475,764]
const Card2 = [855,764]

const NextImage = readImage('./assets/next.jpg')
const HelpImage = readImage('./assets/caster-1.jpg')
const GoldAppleImage = readImage('./assets/gold_apple.jpg')
const Attack = readImage('./assets/attack.jpg')

function fight() {
click1(Battle[0],Battle[1])
click1(Battle[0],Battle[1], true)
sleep1(1500)
click1(CardSP[0],CardSP[1])
click1(CardSP[0],CardSP[1], true)
sleep1(500)
click1(Card1[0],Card1[1])
click1(Card1[0],Card1[1], true)
sleep1(500)
click1(Card2[0],Card2[1])
click1(Card2[0],Card2[1], true)
sleep1(20000)
}

Expand Down Expand Up @@ -83,9 +82,9 @@ function eatApple() {
console.log('别吃啊!!!')
return false
}
click1(1365, 471)
click1(1365, 471, true)
sleep1(300)
click1(1603,835)
click1(1603,835, true)
console.log('吃屎啦你')
} else {
toast('不用吃苹果')
Expand All @@ -111,11 +110,11 @@ function nextTurn() {
toast('完成')
let p = null
while (!p) {
click1(1920,993)
click1(1920,993, true)
sleep1(300)
p = findButton(NextImage, {maxTimes:1})
}
click(1564, 852)
click1(1564, 852, true)

}

Expand Down Expand Up @@ -146,7 +145,6 @@ var i = 0
events.on('exit', function() {
toast('共刷 ' + i + ' 轮')
NextImage.recycle()
HelpImage.recycle()
GoldAppleImage.recycle()
Attack.recycle()
})
Expand Down
20 changes: 10 additions & 10 deletions commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,36 +47,36 @@ const ChangeS6 = [2008, ChangeY]
const ChangeConfirm = [1353, 958]

function useMasterSkill(i) {
click2(MasterSkillStart[0], MasterSkillStart[1])
click2(MasterSkillStart[0], MasterSkillStart[1], true)
sleep2(150)
use(i)
}

function use(t) {
var i = t[0]
var avatar = t[1]
click2(i[0],i[1])
click2(i[0],i[1], true)
sleep2(200)
click2(Confirm[0],Confirm[1])
click2(Confirm[0],Confirm[1], true)
sleep2(100)
click2(avatar[0],avatar[1])
click2(avatar[0],avatar[1], true)
sleep2(3000)
}

// t: [from, to]
function changeServant(t) {
click2(MasterSkillStart[0], MasterSkillStart[1])
click2(MasterSkillStart[0], MasterSkillStart[1], true)
sleep2(150)
// 换人服是三技能
click2(MasterSkill3[0], MasterSkill3[1])
click2(MasterSkill3[0], MasterSkill3[1], true)
sleep2(200)
click2(Confirm[0],Confirm[1])
click2(Confirm[0],Confirm[1], true)
sleep2(100)
click2(t[0][0], t[0][1])
click2(t[0][0], t[0][1], true)
sleep2(100)
click2(t[1][0], t[1][1])
click2(t[1][0], t[1][1], true)
sleep2(100)
click2(ChangeConfirm[0], ChangeConfirm[1])
click2(ChangeConfirm[0], ChangeConfirm[1], true)
sleep2(3000)
}

Expand Down
13 changes: 7 additions & 6 deletions finder.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function findServantAndSwipe(servant) {
if (p) {
return p
}
swipe1(1600, 1000, 1600, 500, 600)
swipe1(1600, 1000, 1600, 500, 600, true)
sleep(200)
}
return p
Expand All @@ -57,9 +57,9 @@ function find(servant) {
p = findServantAndSwipe(servant)

while (!p) {
click1(1566,183)
click1(1566,183, true)
sleep1(300)
click1(1576,842)
click1(1576,842, true)
sleep1(3000)

p = findServantAndSwipe(servant)
Expand All @@ -69,16 +69,17 @@ function find(servant) {
sleep1(15000)
toast('接着找')
}
click1(p[0],p[1])
click1(p[0],p[1], false)
toast('找到啦 ' + p[0] + ',' + p[1])
sleep1(3000)
}

events.on('exit', function() {
for (let key in images) {
images[key]
for (let i = 0; i <= images[key].length; i++) {
images[key][i].recycle()
if (images[key][i]) {
images[key][i].recycle()
}
}
}
})
Expand Down
8 changes: 4 additions & 4 deletions friend_pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var readImage = utils.readImage
var click1 = utils.click
var sleep1 = utils.sleep

setScreenMetrics(1080, 2340)
// setScreenMetrics(1080, 2340)

const Blank = [2016, 821]
const Confirm = [1564, 855]
Expand All @@ -32,13 +32,13 @@ toast('开抽')

while (true) {
while (!findButton(Continue10Image, { maxTimes: 1 })) {
click1(Blank[0], Blank[1])
click1(Blank[0], Blank[1], true)
}
toast('抽完了一次!')

click1(Continue[0], Continue[1])
click1(Continue[0], Continue[1], true)
sleep1(300)
click1(Confirm[0], Confirm[1])
click1(Confirm[0], Confirm[1], true)

// 在这里才开始
i++
Expand Down
2 changes: 1 addition & 1 deletion project.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@
},
"scripts": {},
"versionCode": 1,
"versionName": "0.0.9.alpha.1"
"versionName": "0.0.9"
}
57 changes: 45 additions & 12 deletions utils.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,51 @@
var click1 = function(x, y) {
const _x = x+random(-10,10)
const _y = y+random(-10,10)
console.log(_x, _y)
// 自动缩放不好使
// setScreenMetrics(1080, 2340)

// 人工缩放坐标系
var resize = function(x, y) {
return [Math.floor(x / 2340 * device.height), Math.floor(y / 1080 * device.width)]
}

/**
*
* @param {*} x
* @param {*} y
* @param {*} r resize or not
*/
var click1 = function(x, y, r) {
let p = [x, y]
if (r) {
p = resize(x, y)
}
const _x = p[0] + random(-10,10)
const _y = p[1] + random(-10,10)
click(_x, _y)
}

var sleep1 = function(t) {
sleep(t + random(0, 80))
}

var swipe1 = function(x1, y1, x2, y2, duration) {
const _x1 = x1 + random(-10, 10)
const _x2 = x2 + random(-10, 10)
const _y1 = y1 + random(-10, 10)
const _y2 = y2 + random(-10, 10)
/**
*
* @param {*} x1
* @param {*} y1
* @param {*} x2
* @param {*} y2
* @param {*} duration
* @param {*} r resize or not
*/
var swipe1 = function(x1, y1, x2, y2, duration, r) {
var p1 = [x1, y1]
var p2 = [x2, y2]
if (resize) {
p1 = resize(x1, y1)
p2 = resize(x2, y2)
}
const _x1 = p1[0] + random(-10, 10)
const _x2 = p2[0] + random(-10, 10)
const _y1 = p1[1] + random(-10, 10)
const _y2 = p2[1] + random(-10, 10)
const _duration = duration + random(-100, 100)
swipe(_x1, _y1, _x2, _y2, _duration)
}
Expand All @@ -29,12 +61,13 @@ var findButton = function (b, options) {
const threshold = options ? options.threshold || 0.7 : 0.7

for (let i = 0; i < maxTimes; i++) {
const h = captureScreen().getHeight()
const w = captureScreen().getWidth()
const point = findImage(captureScreen(), b, { threshold: threshold })

if (point) {
return [Math.floor(point.x / h * 1080), Math.floor(point.y / w * 2340)]
return [
Math.floor(point.x + b.getWidth() / 2),
Math.floor(point.y + b.getHeight() / 2)
]
}
sleep1(interval)
}
Expand Down

0 comments on commit 786a59f

Please sign in to comment.