OK 今天又花了3个小时写这个脚本,那么目前已经实现了自动3本了,并且将他们封装起来现在我自己的代码看着特别舒服,所以花费了一大点时间,后期还是希望能够用QT实现界面化,当然也要学,真的好多东西要学!!!9敏
那今天还是用 Jupyter 的方式展现出来吧,因为我都是一个个小功能在jupyter实现完再搬到 Pycharm 里面的,这是个比较好用的方式,我实验一直是这样做的。
那首先今天也是库一小堆,加了个typing的库,不知道为啥今天要这个,昨天list都不用的。
from PIL import Image
import pyautogui
import random
import pygetwindow as gw
import time
from typing import List, Tuple
然后也是和昨天一样的一些自己写的tools
def get_window(title):
return gw.getWindowsWithTitle(title)[0]
def resize_image(original_path, scale_x, scale_y, save_path):
image = Image.open(original_path)
new_size = (int(image.width * scale_x), int(image.height * scale_y))
resized_image = image.resize(new_size, Image.ANTIALIAS)
resized_image.save(save_path)
return save_path
def random_delay(min_delay, max_delay):
delay = random.uniform(min_delay, max_delay)
time.sleep(delay)
return delay
def click_target(image_path, offset_x_ratio, offset_y_ratio, randomSacle_x, randomSacle_y, clickTimes, confidenceThreshold, duration = 5):
start_time = time.time()
end_time = start_time + duration
click_count = 0
while time.time() < end_time and click_count < clickTimes:
try:
match = pyautogui.locateOnScreen(image_path, confidence=confidenceThreshold)
if match:
print(f"找到一个匹配位置:{match}")
random_x = 2 * random.random() - 1
random_y = 2 * random.random() - 1
clickPos_x = match.left + match.width * offset_x_ratio + random_x * randomSacle_x
clickPos_y = match.top + match.height * offset_y_ratio + random_y * randomSacle_y
pyautogui.click(clickPos_x, clickPos_y, button='left')
click_count += 1
except Exception as e:
print("Error:", e)
time.sleep(1)
print("已经完成")
接着就是流水线工作了,能会侠士的肯定两个普通没问题,区别就在于69只有一个侠士和两个普通,所以到普通的那里其实封装好函数之后遍历两个match会更好,我写在pycharm上的就是这样的。
先得到窗口大小以及对导入一些button的img_path进行处理
window = get_window('梦幻西游:时空')
fubenButton1Path = resize_image(r"E:\footbook\fubenButton1.png", window.width/1111, window.height/655, 'E:\\footbook\\fubenButton1_newtest1.png')
fubenChoiceButton1Path = resize_image(r"E:\footbook\fubenChoiceButton1.png", window.width/1111, window.height/655, 'E:\\footbook\\fubenChoiceButton1_newtest1.png')
xiashiButton1Path = resize_image(r"E:\footbook\xiashiButton1.png", window.width/1111, window.height/655, 'E:\\footbook\\xiashiButton1_newtest1.png')
fubenGetInButton1Path = resize_image(r"E:\footbook\fubenGetInButton1.png", window.width/1111, window.height/655, 'E:\\footbook\\fubenGetInButton1_newtest1.png')
xiashiSkipPath = resize_image(r"E:\footbook\xiashiButton2.png", window.width/1111, window.height/655, 'E:\\footbook\\xiashiButton2_newtest1.png')
xiashiButton3Path = resize_image(r"E:\footbook\xiashiButton3.png", window.width/1111, window.height/655, 'E:\\footbook\\xiashiButton3_newtest1.png')
xiashiButton4Path = resize_image(r"E:\footbook\xiashiButton4.png", window.width/1111, window.height/655, 'E:\\footbook\\xiashiButton4_newtest1.png')
xiashiSkipPath = resize_image(r"E:\footbook\xiashiButton2.png", window.width/1111, window.height/655, 'E:\\footbook\\xiashiButton2_newtest1.png')
xiashiButton5Path = resize_image(r"E:\footbook\xiashiButton5.png", window.width/1111, window.height/655, 'E:\\footbook\\xiashiButton5_newtest1.png')
xiashiButton6Path = resize_image(r"E:\footbook\xiashiButton6.png", window.width/1111, window.height/655, 'E:\\footbook\\xiashiButton6_newtest1.png')
xiashiButton7Path = resize_image(r"E:\footbook\xiashiButton7.png", window.width/1111, window.height/655, 'E:\\footbook\\xiashiButton7_newtest1.png')
xiashiButton8Path = resize_image(r"E:\footbook\xiashiButton8.png", window.width/1111, window.height/655, 'E:\\footbook\\xiashiButton8_newtest1.png')
xiashiOverButtonPath = resize_image(r"E:\footbook\xiashiOverButton.png", window.width/1111, window.height/655, 'E:\\footbook\\xiashiOverButton_newtest1.png')
然后就是流水线工作
#侠士副本
click_target(fubenButton1Path, 0.5, 0.7, 5, 2, 1, 0.7) #图片路径,图片哪个区域可以点击
click_target(fubenChoiceButton1Path, 0.5, 0.5, 10, 3, 1, 0.85, 100)
click_target(xiashiButton1Path, 0.5, 0.5, 10, 3, 1, 0.85, 100)
click_target(fubenGetInButton1Path, 0.5, 0.5, 10, 3, 1, 0.85, 100)
click_target(xiashiSkipPath, 0.5, 0.5, 10, 3, 1, 0.85, 100)
click_target(xiashiButton3Path, 0.5, 0.5, 10, 3, 1, 0.85, 500)
click_target(xiashiButton4Path, 0.5, 0.5, 20, 3, 1, 0.85, 100)
click_target(xiashiSkipPath, 0.5, 0.5, 20, 3, 1, 0.85, 100)
click_target(xiashiButton5Path, 0.5, 0.5, 20, 3, 1, 0.85, 500)
click_target(xiashiButton6Path, 0.5, 0.5, 20, 3, 1, 0.85, 100)
click_target(xiashiSkipPath, 0.5, 0.5, 10, 3, 1, 0.85, 100)
click_target(xiashiButton7Path, 0.5, 0.5, 20, 3, 1, 0.85, 500)
click_target(xiashiButton8Path, 0.5, 0.5, 20, 3, 1, 0.85, 100)
click_target(xiashiSkipPath, 0.5, 0.5, 10, 3, 1, 0.85, 100)
click_target(xiashiOverButtonPath, 0.5, 0.5, 10, 3, 1, 0.85, 100)
然后就没了。对!没错就是没了,只是很浪费时间。当然后面的那些延时(100)可以适当根据队伍打的速度调。
那普通副本的代码就不整理啦。有需要的可以dd我打包给你~