文章目录
- 原理
- 全部代码
原理
全自动练级,只不过把回城治疗改成吃红苹果。
吃一个可以打十下,背包留10个基本就练满了。
吃完会自动停止。
if img.getpixel(data_attack[0]) == data_attack[1] or img.getpixel(data_attack_2[0]) == data_attack_2[1]: # 战斗中if is_same_img(ImageGrab.grab(), data_pp): # 没PPstate_can_attack = Falseif state_can_attack: # 战斗zhan_dou()else: # 逃跑tao_pao()
else:if state_can_attack: # 徘徊chu_qu()else: # 吃红苹果pp0()if is_same_img(ImageGrab.grab(), data_apple):pp1()state_can_attack = Trueelse:press(kb.Key.f12)
全部代码
main.py
from PIL import ImageGrabfrom core import *
from cai_yang import is_same_img
# 脚本核心
def a1():global state12global state_can_attackimg = ImageGrab.grab()if img.getpixel(data_attack[0]) == data_attack[1] or img.getpixel(data_attack_2[0]) == data_attack_2[1]: # 战斗中if is_same_img(ImageGrab.grab(), data_pp): # 没PPstate_can_attack = Falseif state_can_attack: # 战斗zhan_dou()else: # 逃跑tao_pao()else:if state_can_attack: # 徘徊chu_qu()else: # 吃红苹果pp0()if is_same_img(ImageGrab.grab(), data_apple):pp1()state_can_attack = Trueelse:press(kb.Key.f12)
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 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 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(): # 右逛press(RIGHT, 0.4)press(LEFT, 0.4)
def zhan_dou(): # 战斗press(A)
def pp0():press(START)press(A, interval2=1)
def pp1():press(A)press(DOWN)press(A)press(A)press(A)press(B)press(B)press(B)press(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
settings.py
from PIL import Image
from pynput import keyboard as kb
from cai_yang import cai_yang
# 图片采样数据
data_apple = cai_yang(Image.open("红苹果.png"), (67, 498, 265, 647), 12)
data_pp = cai_yang(Image.open("没有PP.png"), (110, 815, 722, 1018), 12)
# 像素数据
data_attack = ((1136, 550), (112, 120, 104))
data_attack_2 = ((151, 169), (112, 120, 104))
# 键位设置
UP = "w"
DOWN = "s"
LEFT = "a"
RIGHT = "d"
ACCELERATE = "u"
A = "j"
B = "k"
START = kb.Key.enter