文章目录
- 原理
- 主要代码
- 全部代码
原理
对战宫殿是让宠物自己打,不需要我们选技能,所以用来刷对战点数很合适。
需要准备三个主力。
主要是根据屏幕截图进行各种操作。
1,外面的对话,除了选自由级以外,其他都是直接点A键。
所以要判断一下【自由级这三个字的区域】。
elif is_same_img(img, data_waimian): # 外面自由级press2(DOWN)press(A)
没有这三个字的时候,判断【右上角那个告示栏】。
elif is_same_img(img, data_waimian_2): # 外面其他press(A)
2,报名的时候选择参战的宠物。判断【可用】两个字。
elif is_same_img(img, data_xuan_ren):c.release(ACCELERATE)press(A)press(A)press(DOWN)press(A)press(A)press(DOWN)press(A)press(A)press(A)c.press(ACCELERATE)
3,战斗前的废话,下一场前的废话,随便找一块就行。
if is_same_img(img, data_xiuxi) or is_same_img(img, data_xiuxi_2): # 休息时候的废话press(A)
4,战斗中的废话,在右下角找一个绿色的像素点就行。
elif img.getpixel(data_feihua[0]) == data_feihua[1]: # 战斗废话press(A)
5,战斗。就判断【战斗】那几个字。
elif is_same_img(img, data_zhandou): # 自动战斗press(A)
6,换人。判断【下面那行字】
elif is_same_img(img, data_huan_ren):press2(DOWN)press(A)press(A)press(A)press(B)
主要代码
img = ImageGrab.grab()if is_same_img(img, data_xiuxi) or is_same_img(img, data_xiuxi_2): # 休息时候的废话press(A)elif img.getpixel(data_feihua[0]) == data_feihua[1]: # 战斗废话press(A)elif is_same_img(img, data_zhandou): # 自动战斗press(A)elif is_same_img(img, data_waimian): # 外面自由级press2(DOWN)press(A)elif is_same_img(img, data_waimian_2): # 外面其他press(A)elif is_same_img(img, data_xuan_ren):c.release(ACCELERATE)press(A)press(A)press(DOWN)press(A)press(A)press(DOWN)press(A)press(A)press(A)c.press(ACCELERATE)elif is_same_img(img, data_huan_ren):press2(DOWN)press(A)press(A)press(A)press(B)
全部代码
main.py
from PIL import ImageGrabfrom cai_yang import is_same_img
from core import *
# 脚本核心
def a1():global state_can_attackimg = ImageGrab.grab()if is_same_img(img, data_xiuxi) or is_same_img(img, data_xiuxi_2): # 休息时候的废话press(A)elif img.getpixel(data_feihua[0]) == data_feihua[1]: # 战斗废话press(A)elif is_same_img(img, data_zhandou): # 自动战斗press(A)elif is_same_img(img, data_waimian): # 外面自由级press2(DOWN)press(A)elif is_same_img(img, data_waimian_2): # 外面其他press(A)elif is_same_img(img, data_xuan_ren):c.release(ACCELERATE)press(A)press(A)press(DOWN)press(A)press(A)press(DOWN)press(A)press(A)press(A)c.press(ACCELERATE)elif is_same_img(img, data_huan_ren):press2(DOWN)press(A)press(A)press(A)press(B)
if __name__ == '__main__':# 键盘事件处理def a0(key):if key == kb.Key.f12:global state12state12 = not state12print(f"自动练级:{state12}")# 模拟器加速if state12:c.press(ACCELERATE)else:c.release(ACCELERATE)# 开关state12 = False# 是否能够战斗state_can_attack = True# 监听键盘with kb.Listener(on_press=a0):while True:if state12:a1()
core.py
import timefrom pynput import keyboard as kbfrom settings import *
c = kb.Controller()
def press(key, interval=0.2, interval2=0.1): # 按一下c.press(key)time.sleep(interval)c.release(key)time.sleep(interval2)
def press2(key): # 走一步c.release(ACCELERATE)press(key, interval2=1)c.press(ACCELERATE)
cai_yang.py
from PIL import Imageimport random
# 获得采样数据
def cai_yang(target: Image, rec: (int, int, int, int), count):result = []i = 1while i <= count:# 随机XYx, y = random.randint(rec[0], rec[2]), random.randint(rec[1], rec[3])result.append(((x, y), target.getpixel((x, y))))i = i + 1return result
# 获得对比结果
def is_same_img(img: Image, data):for i in data:if img.getpixel(i[0]) != i[1]:return Falsereturn True
settings.py
from PIL import Imagefrom cai_yang import cai_yang
# 图片采样数据
data_xiuxi = cai_yang(Image.open("休息.png"), (753, 478, 1133, 642), 12)
data_xiuxi_2 = cai_yang(Image.open("休息2.png"), (753, 478, 1133, 642), 12)
data_zhandou = cai_yang(Image.open("战斗.png"), (1513, 817, 1792, 916), 12)
data_feihua = ((1525, 820), (72, 152, 120))
data_waimian = cai_yang(Image.open("外面.png"), (1147, 382, 1535, 705), 12)
data_waimian_2 = cai_yang(Image.open("外面.png"), (1508, 205, 1590, 274), 12)
data_xuan_ren = cai_yang(Image.open("选人.png"), (155, 398, 369, 477), 12)
data_huan_ren = cai_yang(Image.open("换人.png"), (53, 917, 805, 1027), 12)
# 键位设置
UP = "w"
DOWN = "s"
LEFT = "a"
RIGHT = "d"
ACCELERATE = "u"
A = "j"
B = "k"