讨论QQ群:801582968

<>

目录

* 引入: <https://www.cnblogs.com/Java-Starter/p/9588829.html#_label0>
* 前期准备: <https://www.cnblogs.com/Java-Starter/p/9588829.html#_label1>
* 利用PIL的ImageGrab截图
<https://www.cnblogs.com/Java-Starter/p/9588829.html#_label1_0>
* 利用baidu-aip进行文字识别
<https://www.cnblogs.com/Java-Starter/p/9588829.html#_label1_1>
* 开始制作外挂: <https://www.cnblogs.com/Java-Starter/p/9588829.html#_label2>
 

正文

接着上篇的博文 <https://www.cnblogs.com/Java-Starter/p/9571919.html>,今天我们讲如何实现自动组队刷道

 

回到顶部 <https://www.cnblogs.com/Java-Starter/p/9588829.html#_labelTop> <>

引入:

自动组队刷道的流程是先点击刷道按钮、再点击前往按钮、再点击便捷组队······

这些操作上篇博文已经告诉我们怎么做了,利用picpick丈量坐标,再用autopy模拟鼠标点击

但是点击过便捷组队后如何实现自动创建队伍并匹配队友呢?

这里要用到文字识别

玩过问道的都知道,没有队友或者队友数量没到4的时候,队伍会存在守护,如下



并且守护的位置是固定的,守护的优先级是从左到右,例如,匹配到一个队友,斗阙长老就会消失(不会参战);再匹配一个队友,白骨长老就会消失(不会参战)

我的思路是,隔一段时间对夜神模拟器截图,再对这张截图文字识别,判断“斗阙长老”和“白骨长老”是否存在于识别出的字符串中。当然,也可以判断长老数量是否小于等于2

因为玩过回合制的知道,队伍达到三个人就可以发车了,做任务的过程中系统会自动匹配队友,直到匹配满为止

 

回到顶部 <https://www.cnblogs.com/Java-Starter/p/9588829.html#_labelTop> <>

前期准备:

<>

利用PIL的ImageGrab截图

安装PIL
pip install pillow
(pillow包里包含了pil,pil目前已经停止维护了)

我这里是用PyCharm直接安装的依赖包

 

复制代码,直接运行

<>
#coding=utf-8 import time import win32api import win32con from PIL import
ImageGrab time.sleep(3) # 参数说明 # 第一个参数 开始截图的x坐标 # 第二个参数 开始截图的y坐标 # 第三个参数
结束截图的x坐标 # 第四个参数 结束截图的y坐标 bbox = (391, 156, 1582, 853) im =
ImageGrab.grab(bbox) # 参数 保存截图文件的路径 im.save('as.png')
<>

 

直接运行,会发现在当前目录下有一个as.png的截图文件

官方文档对grab方法给出的解释

这里bbox = (x1,y1,x2,y2),意思是从屏幕坐标(x1,y1)到(x2,y2)的一段区域
ImageGrab.grab(bbox) ⇒ image (New in 1.1.3) Take a snapshot of the screen,
and return an “RGB” image. The bounding box argument can be used to copy only a
part of the screen.
 

 

<>

利用baidu-aip进行文字识别

我尝试过pytesseract和pytesser的文字识别,经常会出现识别失败,对中文的支持也不够友好

所以我这里选用baidu-aip进行文字识别

PyCharm打开File->Settings->加号



 

搜索baidu-aip,再点击左下角Install Package



 

我们需要APPP_ID、API_KEY、SECRET_KEY,我们去百度云申请

登录百度云 <https://cloud.baidu.com/>,百度云盘和百度贴吧账号可以直接使用,没有的话申请一个百度账号

找到文字识别



 

 点击创建应用



 

完成创建,个人用户一天可以免费识别600次



 

需要识别文字的图片用下图



 

复制代码,运行

<>
#coding=utf-8 from aip import AipOcr import re #百度文字识别 APPP_ID = 'APP_ID'
API_KEY = 'APP_KEY' SECRET_KEY = 'SECRET_KEY' client =
AipOcr(APPP_ID,API_KEY,SECRET_KEY) i =
open(r'E:\python_project\test\imageIdentification\helpedName1.png','rb') img =
i.read() message = client.basicGeneral(img);for i in
message.get('words_result'): print(i.get('words'))
<>

 可以看到结果



 

回到顶部 <https://www.cnblogs.com/Java-Starter/p/9588829.html#_labelTop> <>

开始制作外挂:

和上篇博客一样,先丈量坐标,坐标根据分辨率不同而不同,我这里是1920*1080

 刷道按钮的坐标是(809,222)



 

 前往按钮的坐标是(1101,646)



 

便捷组队的坐标是(1449,730)



 

 创建队伍按钮(998,799)



 

 开始匹配(1232,794)



 

丈量坐标完毕后,调用文字识别,判断“斗阙长老”和“白骨长老”是否存在于识别的字符串中

如果两位长老都不存在,说明队伍里已经有三人。此时关闭刷道窗口,点击陆压真人,对话,开始刷道

设置十轮刷道时间,十轮刷道任务结束后开始新的一轮刷道

 

详细代码如下:

imageGrabUtil.py(截图工具)

<>
#coding=utf-8 from PIL import ImageGrab # 参数说明 # 第一个参数 开始截图的x坐标 # 第二个参数
开始截图的y坐标 # 第三个参数 结束截图的x坐标 # 第四个参数 结束截图的y坐标 def
screenshot(x1,y1,x2,y2,filename): bbox = (x1, y1, x2, y2) im =
ImageGrab.grab(bbox) # 参数 保存截图文件的路径
im.save('E:\\python_project\\Asktao_Automation\\resource\\'+filename+'.png')
<>

 

baiduAipUtil.py(文字识别工具)

我这里百度云的APPP_ID、API_KEY、SECRET_KEY保存在config.ini

<>
#coding=utf-8 from aip import AipOcr import re #百度文字识别 # !/usr/bin/env python
# -*- coding:utf-8 -*- import ConfigParser import os
os.chdir("E:\python_project\Asktao_Automation\util") cf =
ConfigParser.ConfigParser() cf.read("config.ini") secs = cf.sections() APPP_ID
= cf.get("baiduAip","APPP_ID") API_KEY = cf.get("baiduAip","API_KEY")
SECRET_KEY = cf.get("baiduAip","SECRET_KEY") client =
AipOcr(APPP_ID,API_KEY,SECRET_KEY) def characterRecognition(filePath): i =
open(filePath,'rb') img = i.read() message = client.basicGeneral(img);
#print(message.get('words_result')) string = ''; for i in
message.get('words_result'): print(i.get('words')) string += i.get('words')
return string
<>

 

config.ini
[baiduAip] APPP_ID = APPP_ID API_KEY = API_KEY SECRET_KEY = SECRET_KEY
 

shuaDao.py

<>
#coding=utf-8 import autopy import time import win32api import win32con from
imageGrabUtil import screenshot from baiduAipUtil import characterRecognition
import sys defaultencoding = 'utf-8' if sys.getdefaultencoding() !=
defaultencoding: reload(sys) sys.setdefaultencoding(defaultencoding) #刷道(队长模式)
#time.sleep(5) win32api.keybd_event(18,0,0,0) #alt键位码是18
win32api.keybd_event(9,0,0,0) #tab键位码是9 time.sleep(0.5)
win32api.keybd_event(13,0,0,0) #enter键位码是13
win32api.keybd_event(18,0,win32con.KEYEVENTF_KEYUP,0) #释放按键
win32api.keybd_event(9,0,win32con.KEYEVENTF_KEYUP,0)
win32api.keybd_event(13,0,win32con.KEYEVENTF_KEYUP,0) time.sleep(2) def
mousemove_click(x,y): autopy.mouse.smooth_move(x, y) autopy.mouse.click()
mousemove_click(809,222)#移动到刷道按钮 mousemove_click(1101,646)#点击前往
time.sleep(10)#从其他地图走到轩辕庙陆压真人处花费10s mousemove_click(1449,730)#点击便捷组队
mousemove_click(998,799)#点击创建队伍 mousemove_click(1121,781)#点击开始匹配 for i in
range(1,10,1): teamFileName = 'judgeTeamCount' time.sleep(3) screenshot(391,
156, 1582, 853,teamFileName)#截图 judgeTeamStr =
characterRecognition('E:\\python_project\\Asktao_Automation\\resource\\'+teamFileName+'.png')#文字识别
#每个人守护顺序不一样,按需修改 if '斗阙长老' not in judgeTeamStr and '白骨长老' not in judgeTeamStr:
#这两个守护不在,说明队伍已有三人,开始刷道 mousemove_click(1524,234) #点击关闭按钮 mousemove_click(809,
222) # 移动到刷道按钮 mousemove_click(1101, 646) # 点击前往 mousemove_click(1446,
661)#点击【伏魔】我这就去 break time.sleep(600)#休息十分钟后再次查看是否组到人 #刷道十轮之后的操作 for j in
range(1,10,1): time.sleep(780)#平民伏魔一般780s之内,土豪伏魔有300s的,按需修改 taskFileName =
'judgeTaskAccomplish' time.sleep(3) screenshot(500, 164, 1701,
866,taskFileName) judgeTaskStr =
characterRecognition('E:\\python_project\\Asktao_Automation\\resource\\'+taskFileName+'.png')
if '【伏魔】我这就去' in judgeTaskStr: mousemove_click(1446, 661) # 点击【伏魔】我这就去 else:
time.sleep(60) #防止780s内还没有完成伏魔操作,再等60s,以防万一 mousemove_click(1446, 661) #
点击【伏魔】我这就去
<>

 

 

效果如下:

鉴于博客园只能上传10MB以下的GIF,所以我没有上传完整的效果图

亲测可用,大概十分钟左右可以匹配到三个人,就开始刷道

10轮刷道为一组,组数可以自己将循环数设大一点,我这里设的是10

有的时候匹配不到人,比如像白天就比较难匹配到人。可以把截图判断长老是否存在的那部分,多循环几次

 

再次强调,我的代码不一定在你的电脑上可以运行,我的电脑分辨率是1920*1080,模拟器的位置是默认的放在中央,模拟器移动的话丈量的坐标都不一样

制作外挂最重要的是思想方法



来源:https://www.cnblogs.com/Java-Starter/p/9588829.html
<https://www.cnblogs.com/Java-Starter/p/9588829.html>

郑州正规不孕不育医院 <http://byby.tjyy120.com/>

郑州专业妇科医院 <http://www.zzchxb110.com/>

郑州专业妇科医院 <http://www.zzyytj.com/>

郑州人流医院 <http://www.changhong110.com/>

友情链接
KaDraw流程图
API参考文档
OK工具箱
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:[email protected]
QQ群:637538335
关注微信