在此首先对奋战在抗击冠状病毒一线的各界人士表示感谢,辛苦了!
最近一直在家自我隔离,入坑阴阳师,对内容玩法还处于一知半解中,但作为程序员应该时刻提醒自己用开发的眼光看问题(,ԾㅂԾ,很专业的样子),所以想用脚本实现一下阴阳师机械化的副本、主线任务、个人突破…。
需要解决几个问题
- 界面功能匹配识别;
- 模拟鼠标点击;
- 获取匹配内容的坐标;
- 逆向流程处理;
- 异常情况处理,例如:体力不足,被邀请;
- 全自动的设计,根据任务列表实现一键启动自动处理各种游戏内容。例如:上线领取每日奖励,体力不足刷突破,突破卷不足刷副本,每日定时活动;
自动化脚本beta版
# --coding:utf-8--
import os
import time
import pyautogui as pag
"""
获取鼠标位置坐标
"""
while True:
print("Press Ctrl-C to end")
x, y = pag.position()
pos = "Position:" + str(x).rjust(4) + ','+str(y).rjust(4)
print(pos)
time.sleep(0.3)
os.system('cls')
print('ending....')
# --coding:utf-8--
from PIL import ImageGrab
import uuid
def screen():
"""
自动截屏
:return:
"""
img = ImageGrab.grab(bbox=(5, 35, 1280, 750))
img_name = 'D:/code/2020/img/' + str(uuid.uuid4()) + '.jpg'
img.save(img_name, 'JPEG')
print("Success print screen !")
return img_name
# --coding:utf-8--
import cv2
import time
import screen
import pyautogui
def match(img, template):
res = cv2.matchTemplate(img, template, cv2.TM_CCOEFF_NORMED)
maxres = res.max()
return maxres
def yu_hun():
"""
自动刷御魂
:return:
"""
input('Selection level: ')
screen_img = cv2.imread(screen.screen(), 0)
start_img = cv2.imread("D:/code/2020/img/tan_suo.png", 0)
maxres = match(start_img, screen_img)
if maxres > 0.5:
pyautogui.click(680, 180, clicks=1, interval=0.0, button='left')
time.sleep(3)
screen_img = cv2.imread(screen.screen(), 0)
start_img = cv2.imread("D:/code/2020/img/yu_hun.png", 0)
maxres = match(start_img, screen_img)
if maxres > 0.5:
# 御魂
pyautogui.click(200, 700, clicks=1, interval=0.0, button='left')
time.sleep(3)
screen_img = cv2.imread(screen.screen(), 0)
start_img = cv2.imread("D:/code/2020/img/da_she.png", 0)
maxres = match(start_img, screen_img)
if maxres > 0.5:
# 大蛇
pyautogui.click(260, 360, clicks=1, interval=0.0, button='left')
time.sleep(3)
screen_img = cv2.imread(screen.screen(), 0)
start_img = cv2.imread("D:/code/2020/img/da_she_3.png", 0)
maxres = match(start_img, screen_img)
if maxres > 0.5:
# 层数
pyautogui.click(300, 450, clicks=1, interval=0.0, button='left')
time.sleep(3)
screen_img = cv2.imread(screen.screen(), 0)
start_img = cv2.imread("D:/code/2020/img/zu_dui.png", 0)
maxres = match(start_img, screen_img)
if maxres > 0.5:
# 组队
pyautogui.click(980, 670, clicks=1, interval=0.0, button='left')
time.sleep(3)
screen_img = cv2.imread(screen.screen(), 0)
start_img = cv2.imread("D:/code/2020/img/create_team.png", 0)
maxres = match(start_img, screen_img)
if maxres > 0.5:
# 创建队伍
pyautogui.click(1060, 660, clicks=1, interval=0.0, button='left')
time.sleep(3)
screen_img = cv2.imread(screen.screen(), 0)
start_img = cv2.imread("D:/code/2020/img/create.png", 0)
maxres = match(start_img, screen_img)
if maxres > 0.5:
pyautogui.click(760, 540, clicks=1, interval=0.0, button='left')
time.sleep(1)
pyautogui.click(870, 620, clicks=1, interval=0.0, button='left')
time.sleep(3)
else:
pass
else:
pass
else:
pass
else:
pass
else:
pass
else:
pass
else:
pass
pass
def main():
print('1、Yu Hun')
print('999、Hands Free')
to_do = input('Choose what you want to do: ')
if to_do == '1':
yu_hun()
else:
print("Invalid input %s" % to_do)
print(to_do)
if __name__ == '__main__':
main()
其他
以上是一个构思设计,求指点。
参考文档