文章目录
- 原理
- 全部代码
原理
老样子。
治疗路径,练级路径。
def zhi_liao(): # 去治疗walk(RIGHT)walk(RIGHT)press(UP, 0.4)for i in [1, 2, 3, 4]:press(A)for i in [1, 2, 3, 4]:press(B)press(DOWN, 0.4)press(LEFT)
def chu_qu(): # 右逛c.press(B)press(RIGHT, 0.6)c.release(B)
def hui_qu(): # 左逛c.press(B)press(LEFT, 0.6)c.release(B)
全部代码
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
main.py
from PIL import ImageGrabfrom cai_yang import is_same_img
from core import *
# 脚本核心
def a1():global state_can_attackif is_same_img(ImageGrab.grab(), data_safe): # 在安全区if state_can_attack: # 去战斗chu_qu()else: # 去治疗zhi_liao()state_can_attack = Trueelif ImageGrab.grab().getpixel(data_attack[0]) == data_attack[1]: # 在战斗if is_same_img(ImageGrab.grab(), data_pp): # 没PPstate_can_attack = Falseif state_can_attack == False: # 逃跑tao_pao()else: # 战斗zhan_dou()else: # 战斗外hui_qu()
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 walk(key): # 走一步c.release(ACCELERATE)press(key)c.press(ACCELERATE)
def zhi_liao(): # 去治疗walk(RIGHT)walk(RIGHT)press(UP, 0.4)for i in [1, 2, 3, 4]:press(A)for i in [1, 2, 3, 4]:press(B)press(DOWN, 0.4)press(LEFT)
def tao_pao(): # 逃跑for i in [1, 2, 3]:press(B)press(DOWN)press(RIGHT)press(A)for i in [1, 2, 3]:press(B)
def chu_qu(): # 右逛c.press(B)press(RIGHT, 0.6)c.release(B)
def hui_qu(): # 左逛c.press(B)press(LEFT, 0.6)c.release(B)
def zhan_dou(): # 战斗press(A)
settings.py
from PIL import Imagefrom cai_yang import cai_yang
# 图片采样数据
data_safe = cai_yang(Image.open("安全区.png"), (1362, 820, 1600, 1006), 12)
data_pp = cai_yang(Image.open("没有PP.png"), (110, 815, 722, 1018), 12)
# 像素数据
data_attack = ((876, 306), (32, 160, 64))
# 键位设置
UP = "w"
DOWN = "s"
LEFT = "a"
RIGHT = "d"
ACCELERATE = "u"
A = "j"
B = "k"