现在版本官方已经有了自动御魂、觉醒和探索的脚本了。
既然是这样那不如就搞一个抽卡的脚本好了,这样大佬(土豪,欧皇)们
几百连抽就不用画符,和点SSR点到手软了XD。
(Ps:过年了,祝大家
SSR抽到手软~
)
作者:Meowcolm024
源自:
https://www.jianshu.com/p/b45416bed86f
1、通过adb截图判断是否在抽卡界面
2、在的话,使用matchTemplate()函数识别开始召唤的按钮
3、点击,画符
4、同样使用matchTemplate()函数和模板对比识别SSR和SR并点击
5、若识别到“十连召唤”(即抽卡结束)点击返回
这里主要通过adb来实现对手机的模拟点按和滑动
(手机记得要开USB侦错啊QWQ)
import os
#模拟点按
def tap(x0, y0):
cmdTap = 'adb shell input tap {x1} {y1}'.format(
x1=x0,
y1=y0
)
print(cmdTap)
os.system(cmdTap)
#模拟滑动(用来画符的)
def swipe(x0, y0, x1, y1, delay0):
cmdSwipe = 'adb shell input swipe {x2} {y2} {x3} {y3} {delay1}'.format(
x2=x0,
y2=y0,
x3=x1,
y3=y1,
delay1=delay0
)
print(cmdSwipe)
os.system(cmdSwipe)
#截图并返回图片
def screenshot():
os.system('adb shell screencap -p /sdcard/sh.png')
os.system('adb pull /sdcard/sh.png .')
return "sh.png"
上面这个基本上是对手机的所有操作OWO。
(我将这个单独保存在了项目目录的/lib/ats.py中,这样主程序就可以直接调用啦XD)
然后来讲一下这里最核心的操作:图像识别orz
#我们要用的其实就只有这一个库
import cv2
#不过我们还是要。。。
import time
import random
import lib.ats #233 这个就是刚才那段代码
import numpy as np
好的我们先来个例子,就从识别开始抽卡的按钮开始。。。
def start(sh):
#一看就知道是导入图片orz
imgSTART = cv2.imread(sh, 0)
templateSTART = cv2.imread('res/START.png', 0) #我的模板保存在了项目目录的/res文件夹里
#和模板对比
resSTART = cv2.matchTemplate(imgSTART, templateSTART, cv2.TM_CCOEFF_NORMED)
thresholdSTART = 0.85
pos = []
#如果result大于threshold才可以执行(不在界面你抽个啥)
if (resSTART >= thresholdSTART).any():
loc = np.where(resSTART >= thresholdSTART)
for pt in zip(*loc[::-1]): #刚学Python没多久,我只知道这个压缩后切片QAQ
pos.append(pt) #更新list
return pos #返回按钮位置
else:
return 0
然后是抽到SSR的时候
(其实这个完全可以不写,因为SSR根本不存在(手动滑稽)XD)