Skip to content

Commit

Permalink
Merge pull request #2 from csvwolf/alpha
Browse files Browse the repository at this point in the history
feat: swipe to find servant caster
  • Loading branch information
csvwolf authored Aug 14, 2021
2 parents 9540748 + 786a59f commit 14d93f2
Show file tree
Hide file tree
Showing 12 changed files with 177 additions and 55 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,4 @@ dist

# TernJS port file
.tern-port
.DS_Store
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
Binary file added assets/friends/caster/1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/friends/caster/2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/friends/caster/3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/friends/caster/4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 11 additions & 26 deletions attack.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ if (!requestScreenCapture(true)) {
sleep(300)

var utils = require('./utils')
var finder = require('./finder')
var defaults = require('./default')
var getCommands = require('./commands')

Expand All @@ -16,6 +17,7 @@ setScreenMetrics(1080, 2340)
var click1 = utils.click
var sleep1 = utils.sleep
var readImage = utils.readImage
var findServant = finder.findServant
// autojs 这个 node 版本 const 分析的不对,没办法还是用 var 吧
var findButton = utils.findButton

Expand All @@ -32,18 +34,17 @@ const Card1= [475,764]
const Card2 = [855,764]

const NextImage = readImage('./assets/next.jpg')
const HelpImage = readImage('./assets/help-v2.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 @@ -81,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 @@ -92,22 +93,7 @@ function eatApple() {
}

function clickRefresh() {
let p = findButton(HelpImage, {maxTimes:10, threshold: 0.7})
while (!p) {
click1(1566,183)
sleep1(300)
click1(1576,842)
sleep1(3000)
p = findButton(HelpImage, {maxTimes:100, threshold: 0.7})
if (p) {
break
}
sleep1(15000)
toast('接着找')
}
click1(p[0],p[1])
toast('找到啦')
sleep1(3000)
findServant('caster')
}


Expand All @@ -124,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 @@ -159,7 +145,6 @@ var i = 0
events.on('exit', function() {
toast('共刷 ' + i + ' 轮')
NextImage.recycle()
HelpImage.recycle()
GoldAppleImage.recycle()
Attack.recycle()
})
Expand Down
25 changes: 12 additions & 13 deletions commands.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@

var utils = require('./utils')

setScreenMetrics(1080, 2340)

const click2 = utils.click
const sleep2 = utils.sleep
var click2 = utils.click
var sleep2 = utils.sleep

const SkillY = 880
const MasterSkillY = 479
Expand Down Expand Up @@ -48,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
90 changes: 90 additions & 0 deletions finder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// 查找助战

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 = {}

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(1566,183, 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
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.8"
"versionName": "0.0.9"
}
64 changes: 55 additions & 9 deletions utils.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,55 @@
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))
}

/**
*
* @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)
}

var readImage = function(img) {
const b = images.read(img)
return b
Expand All @@ -20,11 +61,15 @@ var findButton = function (b, options) {
const threshold = options ? options.threshold || 0.7 : 0.7

for (let i = 0; i < maxTimes; i++) {
const point = findImage(captureScreen(), b, { threshold: threshold })
if (point) {
return [point.x, point.y]
}
sleep1(interval)
const point = findImage(captureScreen(), b, { threshold: threshold })

if (point) {
return [
Math.floor(point.x + b.getWidth() / 2),
Math.floor(point.y + b.getHeight() / 2)
]
}
sleep1(interval)
}
return false
}
Expand All @@ -41,3 +86,4 @@ exports.sleep = sleep1
exports.readImage = readImage
exports.findButton = findButton
exports.stopExecution = stopExecution
exports.swipe = swipe1

0 comments on commit 14d93f2

Please sign in to comment.