6 Star 94 Fork 21

LanRenZhiNeng/MingChaoAI

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
auto.py 85.91 KB
一键复制 编辑 原始数据 按行查看 历史
老大哥 提交于 2024-09-10 12:21 . 更新到1.48
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840
# -*- coding: utf-8 -*-
import random
import threading
import traceback
from PIL import Image
import tangbaowss
from lanrentools.findimg import *
from lanrentools.moni import *
from logger_module import logger
from screenshot import screenshot
from lanrenonnx import LanRenOnnxYolov
from lanrenocr import LanRenOcr
import pyautogui
def 保存图片(img,filename):
# 保存位图对象到文件
img_pil = Image.fromarray(img[..., [2, 1, 0]])
img_pil.save(filename, format='JPEG', quality=90)
def 跑步():
pyautogui.keyDown('w')
def 开伞():
__t=time.time()
if state.状态_开伞时间 > 2 or state.状态_开伞时间==-1:
state.状态_开伞时间=__t
logger.info("检测到可能在下落 打滑翔伞")
pyautogui.keyDown('space')
time.sleep(0.2)
pyautogui.keyUp('space')
time.sleep(0.4)
pyautogui.keyDown('space')
time.sleep(0.2)
pyautogui.keyUp('space')
state.计次_误差过大 += 1
state.状态_开伞时间=-1
def find_dict_index(dict_list, key, value):
max_sim = 0
index = None
for i, dictionary in enumerate(dict_list):
if dictionary.get(key) == value:
if dictionary.get('sim') > max_sim:
max_sim = dictionary.get('sim')
index = i
return index != None, index
def find_dict_num(dict_list, key, value):
num_ = 0
for i, dictionary in enumerate(dict_list):
if dictionary.get(key) == value:
num_ += 1
return num_
def find_label_in_txt(txt):
for lb in state.f_labels:
if txt.find(lb)!=-1:
return True
return False
class YolovMingChao(LanRenOcr):
def __init__(self, weights, providers=["CUDAExecutionProvider",'CPUExecutionProvider'],dic_labels={},model_h=320, model_w=320):
super().__init__()
pyautogui.PAUSE = 0.01
pyautogui.FAILSAFE = False
self.yolov = LanRenOnnxYolov(weights=weights, providers=providers,dic_labels=dic_labels,model_h=model_h, model_w=model_w)
state.状态_YOLOV = True
self.interaction_label = ["怪物", "声骸", "矿石","无音区开关"]
self.centre_point = [(1920 // 2), (1080 // 2) + 200]
self.key_w_down = True
self.小地图区域 = (87 - 10, 45 - 10, 246 + 10, 204 + 10)
def run_fight(self,wakuang=False,daguai=False):
# 获取窗口句柄
hwnd = win32gui.FindWindow(state.GAME_CLASS, state.GAME_TITLE) # 替换成你实际的窗口句柄
while True:
if state.状态_循环开关 == False:
logger.info("强制退出!")
pyautogui.keyUp('w')
state.状态_是否回放中 = False
state.计数_没找到任何目标 = 0
tangbaowss.send_msg("是否回放#@@#假")
state.状态_检测中=False
return
if get_window_handle_at_mouse_position() == hwnd:
break
state.计数_没找到任何目标 = 0
state.计数_没找到怪物 = 0
state.状态_在爬墙 = False
state.状态_检测中 = True
state.状态_开伞时间 = -1
历史_上次玩家高度 = 0.1
玩家高度 = 0.1
计数_没有玩家 = 0
计次_没发现爬墙=0
计次_没找血条且连招停止=0
isIn_wxl = False
set_window_activate(hwnd)
jiaoben = (os.path.abspath(os.path.join(state.PATH_JIAOBEN, state.LIANZHAO)))
# 临时发送消息给指定客户端
message = f"解析脚本#@@#{jiaoben}"
tangbaowss.send_msg(message)
time.sleep(2)
while True:
try:
if state.状态_循环开关 == False:
state.状态_是否回放中 = False
state.计数_没找到任何目标 = 0
state.状态_检测中 = False
tangbaowss.send_msg("是否回放#@@#假")
return
time.sleep(0.1)
rect = win32gui.GetWindowRect(hwnd)
w_p, h_p = (rect[2] - rect[0]) - 1920, (rect[3] - rect[1]) - 1080
# 设定截图区域的左上角坐标 (x, y) 和右下角坐标 (x, y)
left, top, right, bottom = 0, 0, 1920, 1080 # 替换成你实际的区域坐标
p_left = rect[0] + w_p
p_top = rect[1] + h_p
计数_没有玩家 += 1
if state.状态_寻路中 == False:
state.计数_没找到任何目标 += 1
state.计数_没找到怪物 += 1
if state.状态_已经有寻路了 == False:
state.状态_是否回放中 = False
state.计数_没找到任何目标 = 0
tangbaowss.send_msg("是否回放#@@#假")
state.状态_检测中 = False
state.状态_寻路中=True
logger.info("识别退出!")
return
if state.状态_全局暂停:
tangbaowss.send_msg("是否回放#@@#假")
time.sleep(2)
continue
if get_window_handle_at_mouse_position() != hwnd:
tangbaowss.send_msg("是否回放#@@#假")
time.sleep(0.1)
# 激活hwnd
hwnd = win32gui.FindWindow(state.GAME_CLASS, state.GAME_TITLE) # 替换成你实际的窗口句柄
set_window_activate(hwnd)
logger.info("激活游戏窗口!")
time.sleep(0.2)
if state.状态_传送中:
time.sleep(1)
continue
if state.状态_开了地图:
time.sleep(0.5)
continue
# 设定保存截图的文件夹路径和文件名前缀
# filename = f"./原神截图/{int(time.time())}{random.randint(1000,9999)}.jpg"
ret_scr = screenshot(hwnd, left, top, right, bottom, filename=None)
if type(ret_scr) == bool:
hwnd = win32gui.FindWindow(state.GAME_CLASS, state.GAME_TITLE) # 替换成你实际的窗口句柄
logger.info("截图失败了!可能是内存溢出了")
time.sleep(2)
continue
datas, state.图片_YOLOV = self.yolov.detect(ret_scr, plot_box=state.开关_是否展预测结果)
if state.开关_是否展预测结果:
state.QT_信号.mysig_show_yolov.emit()
if state.状态_全局暂停:
pyautogui.keyUp('w')
tangbaowss.send_msg("是否回放#@@#假")
time.sleep(2)
continue
if datas == []:
if state.状态_是否回放中 == False and state.状态_开了地图==False and not state.状态_开了地图:
if state.状态_在爬墙 == False and state.状态_寻路中 == True and (wakuang or daguai):
计数_没有玩家 = 0
if state.状态_开伞时间 > 2 or state.状态_开伞时间 == -1:
ttt=threading.Thread(target=开伞)
if state.python_var > 9:
ttt.daemon = True
else:
ttt.setDaemon(True)
ttt.start()
else:
# 将离屏幕中心最近的点排在前面
datas = sorted(datas, key=self.distance_to_target)
isIn, idex = find_dict_index(datas, 'label', '在爬墙')
if isIn:
if datas[idex]['sim']>0.76:
state.状态_在爬墙 = True
计次_没发现爬墙=0
state.状态_是否回放中 = False
tangbaowss.send_msg("是否回放#@@#假")
#state.状态_寻路中 = True
self.key_w_down = True
pyautogui.keyDown('w')
#print("在爬墙",datas[idex])
else:
计次_没发现爬墙+=1
if 计次_没发现爬墙>3:
state.状态_在爬墙 = False
计次_没发现爬墙=0
isIn_wxl, _ = find_dict_index(datas, 'label', '滑翔翼')
isIn_jhdh, idex = find_dict_index(datas, 'label', 'F交互')
if isIn_jhdh: # 路过的顺手捡了
tangbaowss.send_msg("是否暂停#@@#真")
pyautogui.keyUp('w')
txt = self.get_text(ret_scr[datas[idex]["points"][0][1]:datas[idex]["points"][1][1], datas[idex]["points"][0][0]:datas[idex]["points"][1][0]])
if find_label_in_txt(txt):
state.状态_寻路中 = False
self.key_w_down = False
state.计次_识别次数 = 0
state.计数_卡主次数 = 0
logger.info(f"交互:{txt}")
state.状态_有目标 = True
pyautogui.keyDown('f')
time.sleep(0.1)
pyautogui.keyUp('f')
time.sleep(0.3)
state.计数_没找到任何目标 =12
ret_scr = screenshot(hwnd, left, top, right, bottom, filename=None)
datas, state.图片_YOLOV = self.yolov.detect(ret_scr, plot_box=state.开关_是否展预测结果)
else:
if txt!="":
logger.info(f"发现:{txt} {datas[idex]["points"]}")
tangbaowss.send_msg("是否暂停#@@#假")
state.状态_在水面, idex = find_dict_index(datas, 'label', '在水面')
if state.状态_在水面:
logger.info("在水面!")
state.状态_是否回放中 = False
tangbaowss.send_msg("是否回放#@@#假")
state.状态_寻路中 = True
self.key_w_down = True
跑步()
isIn, idex = find_dict_index(datas, 'label', '确定')
if isIn:
if state.状态_寻路中:
state.状态_寻路中 = False
state.状态_有目标 = True
state.状态_是否回放中 = False
if self.key_w_down:
self.key_w_down = False
pyautogui.keyUp('w')
tangbaowss.send_msg("是否暂停#@@#真")
time.sleep(0.2)
if not self.find_xiacihuifu(hwnd, 601,465,1236,823, p_left,
p_top):
mouse_move(p_left + datas[idex]["x"], p_top + datas[idex]["y"])
logger.info(f"发现确定按钮,可能是吃复活药{datas[idex]} 或者是领取奖励")
time.sleep(0.1)
mouse_left_down()
time.sleep(0.1)
mouse_left_up()
time.sleep(0.5)
ret_scr = screenshot(hwnd, left, top, right, bottom, filename=None)
datas, state.图片_YOLOV = self.yolov.detect(ret_scr, plot_box=state.开关_是否展预测结果)
isIn, idex = find_dict_index(datas, 'label', '确定')
tangbaowss.send_msg("是否暂停#@@#假")
if not isIn:
logger.info("停止脚本")
tangbaowss.send_msg("是否回放#@@#假")
time.sleep(2)
else:
pyautogui.keyDown('w')
time.sleep(2)
tangbaowss.send_msg("是否暂停#@@#假")
isIn, idex = find_dict_index(datas, 'label', '玩家')
if isIn:
玩家高度 = datas[idex]["points"][1][1] - datas[idex]["points"][0][1]
计数_没有玩家 = 0
isIn, idex = find_dict_index(datas, 'label', '关闭')
if isIn and state.状态_开了地图==False:
if state.状态_寻路中:
state.状态_寻路中 = False
state.状态_有目标 = True
logger.info(f"发现关闭按钮 点错了界面{datas[idex]}")
if not state.状态_开了地图:
pyautogui.keyDown('esc')
time.sleep(0.2)
pyautogui.keyUp('esc')
time.sleep(1)
if not state.状态_开了地图:
mouse_moveR(6 * 180, 0)
time.sleep(2)
if not state.状态_开了地图:
pyautogui.keyDown("w")
time.sleep(0.1)
pyautogui.keyUp("w")
self.key_w_down = False
ret_scr = screenshot(hwnd, left, top, right, bottom, filename=None)
datas, state.图片_YOLOV = self.yolov.detect(ret_scr, plot_box=state.开关_是否展预测结果)
isIn, idex = find_dict_index(datas, 'label', '点击')
if isIn:
if state.状态_寻路中:
state.状态_寻路中 = False
state.状态_有目标 = True
state.状态_是否回放中 = False
if self.key_w_down:
self.key_w_down = False
pyautogui.keyUp('w')
tangbaowss.send_msg("是否暂停#@@#真")
time.sleep(0.2)
mouse_move(p_left + datas[idex]["x"], p_top + datas[idex]["y"])
logger.info(f"发现月卡界面或奖励领取界面{datas[idex]} ")
time.sleep(0.1)
mouse_left_down()
time.sleep(0.1)
mouse_left_up()
tangbaowss.send_msg("是否暂停#@@#假")
time.sleep(1)
continue
isIn, idex = find_dict_index(datas, 'label', '复苏')
if isIn:
if datas[idex]["sim"]>0.8:
if state.状态_寻路中:
state.状态_寻路中 = False
state.状态_是否回放中 = False
self.key_w_down = False
tangbaowss.send_msg("是否回放#@@#假")
time.sleep(0.3)
mouse_move(p_left + datas[idex]["x"], p_top + datas[idex]["y"])
logger.info(f"发现复活界面 全军覆没了!点击复苏,并且重试任务{datas[idex]} ")
time.sleep(0.1)
mouse_left_down()
time.sleep(0.1)
mouse_left_up()
mouse_left_down()
time.sleep(0.1)
mouse_left_up()
pyautogui.keyUp('w')
time.sleep(10)
state.计次_定位失败 = 999
state.状态_是否回放中 = False
state.计数_没找到任何目标 = 0
state.状态_检测中 = False
return False
for data in datas:
# 发现怪物则进行视角移动 以及 接近目标
if data["label"] in self.interaction_label:
if state.状态_寻路中 == False:
# 将它的中心点和游戏正中间进行靠近
if data["label"] == "怪物" and data["points"][1][0] - \
data["points"][0][0] >= 80:
if not daguai:
continue
state.计数_没找到任何目标 = 0
angle=get_angle(self.centre_point, (data["x"], data["y"]))
set_angle(0, angle)
pyautogui.keyDown('w')
if random.randint(0, 50) == 5:
pyautogui.keyDown('space')
time.sleep(0.2)
pyautogui.keyUp('space')
if random.randint(0, 50) == 5:
pyautogui.keyDown('x')
time.sleep(0.2)
pyautogui.keyUp('x')
self.key_w_down = True
break # 只判断第一只怪
elif data["label"] == "矿石":
if not wakuang:
continue
state.计数_没找到任何目标 = 0
set_angle(0, get_angle(self.centre_point, (data["x"], data["y"])))
# 如果矿石就再旁边则直接连招
if self.centre_point[1] - data["points"][1][1] <= 250:
if self.key_w_down:
self.key_w_down = False
time.sleep(0.2)
pyautogui.keyUp('w')
state.计数_卡主次数 = 0
state.计次_识别次数 = 0
if not state.状态_是否回放中:
logger.info("在挖矿中....")
pyautogui.press("x")
state.状态_是否回放中 = True
tangbaowss.send_msg("脚本执行#@@#2")
else:
pyautogui.keyDown('w')
if random.randint(0, 50) == 5:
pyautogui.keyDown('space')
time.sleep(0.2)
pyautogui.keyUp('space')
self.key_w_down = True
break # 只判断第1个矿
else: # '发现声骸' 或 '无音区开关'
state.计数_没找到任何目标 = 0
angle_now = 0
angle_target = get_angle(self.centre_point, (data["x"], data["y"]))
set_angle(angle_now, angle_target)
pyautogui.keyDown('w')
if random.randint(0, 50) == 5:
pyautogui.keyDown('space')
time.sleep(0.2)
pyautogui.keyUp('space')
self.key_w_down = True
break # 只判断第一个采集物
else:
if state.状态_开了地图:
continue
if data["sim"]>=0.75:
if state.状态_在爬墙==True:
continue
if data["label"] == "矿石":
if not wakuang:
continue
logger.info("发现有矿石.顺手挖一下吧!")
elif data["label"] == "怪物" and data["points"][1][
0] - data["points"][0][0] >= 90 :
if not daguai:
continue
mouse_middle_down()
time.sleep(0.2)
mouse_middle_up()
logger.info("发现有怪拦路.顺手消灭吧!")
elif data["label"] == "声骸":
if not wakuang and not daguai:
continue
logger.info("发现有声骸.顺手捡一下吧!")
elif data["label"] =="无音区开关" and data["points"][1][
0] - data["points"][0][0] >= 300:
if not wakuang and not daguai:
continue
logger.info("发现有无音区开关.顺手开启一下吧")
else:
continue
logger.info(str(data))
set_angle(0, get_angle(self.centre_point, (data["x"], data["y"])))
state.计时_未寻路 = int(time.time())
state.状态_寻路中 = False
state.游戏_打怪前坐标 = copy.copy(state.游戏_当前目标坐标)
state.计数_没找到任何目标 = 0
state.计数_没找到怪物 = 0
pyautogui.keyUp('w')
self.key_w_down = False
state.计数_卡主次数 = 0
state.计次_识别次数 = 0
mouse_left_down()
time.sleep(0.1)
mouse_left_up()
break
if state.状态_开了地图 :
continue
if state.状态_寻路中 == True and state.状态_在爬墙 == False and isIn_wxl == False and (wakuang or daguai):
if 计数_没有玩家 >= 2 or (历史_上次玩家高度 / 玩家高度 >= 1.4):
计数_没有玩家 = 0
if state.状态_开伞时间 > 2 or state.状态_开伞时间 == -1:
ttt = threading.Thread(target=开伞)
if state.python_var > 9:
ttt.daemon = True
else:
ttt.setDaemon(True)
ttt.start()
if 计数_没有玩家 == 0:
历史_上次玩家高度 = copy.copy(玩家高度)
if state.状态_寻路中 == False:
# 如果按下了W键了,并且当前没有任何目标等于4次了,则松开w键
if state.计数_没找到任何目标 == 6:
self.key_w_down = False
state.计次_识别次数 = 0
pyautogui.keyUp('w')
if state.计次_定位失败 > 0:
state.计数_没找到怪物 = 0
isIn, idex = find_dict_index(datas, 'label', '血条')
if isIn:
if datas[idex]["sim"]>=0.7:
state.计数_没找到任何目标 = 0
state.计数_没找到怪物 = 0
if datas[idex]["points"][1][0] - datas[idex]["points"][0][0] >= 160:
if not daguai:
continue
# 如果血条符合长度直接连招
if self.key_w_down:
self.key_w_down = False
pyautogui.keyUp('w')
state.计次_识别次数 = 0
state.计数_卡主次数=0
if not state.状态_是否回放中 and not state.状态_在爬墙:
logger.info("在连招中2....")
计次_没找血条且连招停止=0
pyautogui.keyDown('x')
time.sleep(0.2)
pyautogui.keyUp('x')
state.状态_是否回放中 = True
tangbaowss.send_msg("脚本执行#@@#2")
elif not state.状态_是否回放中 and not state.状态_寻路中:
计次_没找血条且连招停止+=1
if state.ON_LIANZHAOBUJIANCE==0 and state.计数_没找到怪物 >= 18 and state.计次_定位失败 == 0 and state.状态_是否回放中 == True:
state.状态_是否回放中 = False
tangbaowss.send_msg("是否回放#@@#假")
if state.状态_开了地图:
continue
# 如果连续8次没找到目标,则进行旋转
if 30 > state.计数_没找到任何目标 >= 15 or (state.计数_没找到任何目标 >= 1 and state.计数_没找到怪物 >= 13 and state.状态_是否回放中 == True):
state.计数_卡主次数 = 0
state.计次_识别次数 = 0
历史_上次玩家高度 = 0
if state.状态_开了地图:
continue
if state.计数_没找到任何目标 == 15:
if state.计次_定位失败 == 0:
if state.状态_是否回放中 == False:
logger.info("重置视角")
self.key_w_down = False
mouse_left_up()
pyautogui.keyUp('w')
pyautogui.keyDown('x')
time.sleep(0.1)
pyautogui.keyUp('x')
# 重置镜头
mouse_middle_down()
time.sleep(0.2)
mouse_middle_up()
time.sleep(0.3)
state.计次_识别次数 = 0
state.计数_卡主次数 = 0
else:
state.计数_没找到任何目标 = 0
else:
state.计数_没找到任何目标 = 0
else:
mouse_moveR(int(6 * 40), 0)
# 如果连续 n次没找到目标,则继续寻路X
elif state.计数_没找到任何目标 >= 30:
if state.状态_开了地图:
continue
if not state.状态_是否回放中:
logger.info("附近没有怪和采集物了.继续寻路吧!")
state.状态_是否回放中 = False
tangbaowss.send_msg("是否回放#@@#假")
state.状态_寻路中 = True
state.计次_识别次数 = 0
state.计数_卡主次数 = 0
state.计数_没找到任何目标 = 0
mouse_left_up()
ttt = threading.Thread(target=跑步)
if state.python_var > 9:
ttt.daemon = True
else:
ttt.setDaemon(True)
ttt.start()
continue
if 计次_没找血条且连招停止>=200 :
logger.info("附近可能还有目标,但是打不到.继续寻路吧! 计次_没找血条且连招停止"+str(state.计时_未寻路))
state.状态_是否回放中 = False
tangbaowss.send_msg("是否回放#@@#假")
state.状态_寻路中 = True
state.计数_卡主次数 = 0
计次_没找血条且连招停止=0
mouse_left_up()
state.计数_没找到任何目标 = 0
state.游戏_打怪前坐标 = [0, 0]
ttt = threading.Thread(target=跑步)
if state.python_var > 9:
ttt.daemon = True
else:
ttt.setDaemon(True)
ttt.start()
for i in range(10):
time.sleep(0.5)
if state.状态_已经有寻路了 == False:
state.状态_是否回放中 = False
state.计数_没找到任何目标 = 0
tangbaowss.send_msg("是否回放#@@#假")
state.状态_检测中 = False
logger.info("寻路退出!")
return
time_now=time.time()
if time_now-state.计时_未寻路 >= state.TIMEOUT_DAGUAI and state.计时_未寻路!=0:
if state.状态_开了地图:
continue
logger.info("附近可能还有目标,但是打不到.继续寻路吧! "+str(state.计时_未寻路))
state.状态_是否回放中 = False
tangbaowss.send_msg("是否回放#@@#假")
state.状态_寻路中 = True
state.计数_卡主次数 = 0
mouse_left_up()
state.计数_没找到任何目标 = 0
计次_没找血条且连招停止=0
state.游戏_打怪前坐标 = [0, 0]
ttt = threading.Thread(target=跑步)
if state.python_var > 9:
ttt.daemon = True
else:
ttt.setDaemon(True)
ttt.start()
for i in range(10):
time.sleep(0.5)
if state.状态_已经有寻路了 == False:
state.状态_是否回放中 = False
state.计数_没找到任何目标 = 0
tangbaowss.send_msg("是否回放#@@#假")
state.状态_检测中 = False
logger.info("寻路退出!")
return
except:
time.sleep(0.3)
logger.error(traceback.format_exc())
def run_fuben(self, cishu=99, level=0,islingjiang=True):
state.状态_已经有寻路了 = True
# 获取窗口句柄
hwnd = win32gui.FindWindow(state.GAME_CLASS, state.GAME_TITLE) # 替换成你实际的窗口句柄
set_window_activate(hwnd)
while True:
if state.状态_循环开关 == False:
logger.info("强制退出!")
pyautogui.keyUp('w')
state.状态_已经有寻路了 = False
state.状态_是否回放中 = False
tangbaowss.send_msg("是否回放#@@#假")
state.状态_需重新传送 = False
return False
if get_window_handle_at_mouse_position() == hwnd:
break
rect = win32gui.GetWindowRect(hwnd)
w_p, h_p = (rect[2] - rect[0]) - 1920, (rect[3] - rect[1]) - 1080
# 设定截图区域的左上角坐标 (x, y) 和右下角坐标 (x, y)
left, top, right, bottom = 0, 0, 1920, 1080 # 替换成你实际的区域坐标
p_left = rect[0] + w_p
p_top = rect[1] + h_p
paimeng_img = cv2.imdecode(np.fromfile(file="datas/背包图标.png", dtype=np.uint8), cv2.IMREAD_UNCHANGED)
chongxintiaozhan_img = cv2.imdecode(np.fromfile(file="./datas/重新挑战.png", dtype=np.uint8),
cv2.IMREAD_UNCHANGED)
kkk = self.处理异常情况(hwnd, left, top, right, bottom, p_left, p_top)
if kkk == 0:
logger.info("在意外界面 超时!")
time.sleep(3)
state.状态_需重新传送 = False
state.状态_已经有寻路了 = False
return False
elif kkk == -1:
logger.info("全军覆没了!")
time.sleep(3)
state.状态_需重新传送 = True
state.状态_已经有寻路了 = False
return False
计数_没有玩家 = 0
jiaoben = (os.path.abspath(os.path.join(state.PATH_JIAOBEN, state.LIANZHAO)))
# 临时发送消息给指定客户端
message = f"解析脚本#@@#{jiaoben}"
tangbaowss.send_msg(message)
try:
# 往前走或者往后走,直到找到 F
if not self.find_f_keep_going(hwnd,1158, 420, 1346, 687, p_left, p_top,False):
state.状态_已经有寻路了=False
if islingjiang:
state.状态_需重新传送 = True
else:
state.状态_需重新传送 = False
return False
if islingjiang:
#有些需要对话和再继续按F
pyautogui.keyDown('space')
time.sleep(0.2)
pyautogui.keyUp('space')
time.sleep(0.2)
pyautogui.keyDown('space')
time.sleep(0.2)
pyautogui.keyUp('space')
time.sleep(0.2)
pyautogui.keyDown('space')
time.sleep(0.2)
pyautogui.keyUp('space')
time.sleep(3)
pyautogui.keyUp('f')
time.sleep(0.2)
pyautogui.keyDown('f')
time.sleep(2)
if level>0:
# 选择等级
if not self.find_danrentiaozhan(hwnd, left, top, right, bottom, p_left,p_top): state.状态_需重新传送 = True;return False
mouse_move(p_left + state.fuben_level_point[level-1][0], p_top + state.fuben_level_point[level-1][1])
time.sleep(0.2)
mouse_left_down()
time.sleep(0.2)
mouse_left_up()
time.sleep(1)
# 点击 单人挑战
if not self.click_danrentiaozhan(hwnd, left, top, right, bottom, p_left,p_top): state.状态_需重新传送 = True;return False
# 判断弹窗是否有树脂不够提醒
if self.find_shuzhibugou(hwnd, left, top, right, bottom, p_left, p_top):
if not islingjiang:
mouse_move(p_left + 1275,p_top + 683)
time.sleep(0.2)
mouse_left_down()
time.sleep(0.2)
mouse_left_up()
time.sleep(0.2)
mouse_left_down()
time.sleep(0.2)
mouse_left_up()
time.sleep(1)
else:
pyautogui.keyDown('esc')
time.sleep(0.1)
pyautogui.keyUp('esc')
time.sleep(2)
pyautogui.keyDown('esc')
time.sleep(0.1)
pyautogui.keyUp('esc')
state.状态_已经有寻路了 = False
logger.info("没体力了 成功退出副本!")
time.sleep(10)
state.状态_需重新传送 = False
state.状态_已经有寻路了=False
return True
# 如果没提醒则选择阵容
if not self.click_kaishitiaozhan(hwnd, left, top, right, bottom, p_left, p_top):
pyautogui.keyDown('esc')
time.sleep(0.1)
pyautogui.keyUp('esc')
state.状态_已经有寻路了 = False
state.状态_需重新传送 = True
return False
# 开始yolov自动进入副本
except:
time.sleep(0.5)
logger.error(traceback.format_exc())
state.状态_需重新传送 = True
state.状态_已经有寻路了 = False
return False
# 0 镜头对准北方向 走过去开副本
# 1 开始打怪阶段
# 2 打完了 开始找生命树 并且把自己移动到0° 对准生命树的位置
# 3 走路到 领取奖励 直到点击 继续挑战为止 完成一轮
if not islingjiang:
阶段 = 1
else:
阶段 = 0
计次_离开=0
计时_阶段3_开始时间 = 0
计次_阶段0 = 0
state.计数_没找到怪物=0
time.sleep(3)
for i in range(cishu):
logger.info(f"刷副本中 {i + 1}/{cishu}")
while True:
time.sleep(0.01)
try:
if state.状态_循环开关 == False:
state.状态_是否回放中 = False
tangbaowss.send_msg("是否回放#@@#假")
state.状态_需重新传送 = False
state.状态_已经有寻路了 = False
return False
rect = win32gui.GetWindowRect(hwnd)
w_p, h_p = (rect[2] - rect[0]) - 1920, (rect[3] - rect[1]) - 1080
# 设定截图区域的左上角坐标 (x, y) 和右下角坐标 (x, y)
left, top, right, bottom = 0, 0, 1920, 1080 # 替换成你实际的区域坐标
p_left = rect[0] + w_p
p_top = rect[1] + h_p
if state.状态_全局暂停:
tangbaowss.send_msg("是否回放#@@#假")
time.sleep(2)
continue
if get_window_handle_at_mouse_position() != hwnd:
# 激活hwnd
hwnd = win32gui.FindWindow(state.GAME_CLASS, state.GAME_TITLE) # 替换成你实际的窗口句柄
set_window_activate(hwnd)
# 设定保存截图的文件夹路径和文件名前缀
# filename = f"./datas/lanrenyolov{random.randint(1, 20)}.jpg"
# 游戏全图
ret_scr = screenshot(hwnd, left, top, right, bottom, filename=None)
if type(ret_scr) == bool:
hwnd = win32gui.FindWindow(state.GAME_CLASS, state.GAME_TITLE) # 替换成你实际的窗口句柄
logger.info("截图失败了!可能是内存溢出了")
time.sleep(2)
continue
# -----------------------------YOLOV检测--------------------------------------------------
datas, state.图片_YOLOV = self.yolov.detect(ret_scr, plot_box=state.开关_是否展预测结果)
if state.开关_是否展预测结果:
state.QT_信号.mysig_show_yolov.emit()
if state.状态_全局暂停:
tangbaowss.send_msg("是否回放#@@#假")
time.sleep(2)
continue
if datas == [] and islingjiang:
pass
else:
# 将离屏幕中心最近的点排在前面
datas = sorted(datas, key=self.distance_to_target)
if 阶段 == 0: # 走过去开副本
pyautogui.keyDown('w')
计次_阶段0 += 1
if 计次_阶段0 >= 2000:
pyautogui.keyDown('esc')
time.sleep(0.1)
pyautogui.keyUp('esc')
time.sleep(1)
state.状态_已经有寻路了 = False
logger.info("没体力了 成功退出副本!")
time.sleep(10)
state.状态_需重新传送 = False
state.状态_已经有寻路了 = False
return True
# if self.click_dimaiyichang(hwnd, left, top, right, bottom, p_left, p_top):
# time.sleep(1)
# continue
isIn, idex = find_dict_index(datas, 'label', '确定')
isIn2, idex = find_dict_index(datas, 'label', '取消')
# 判断弹窗是否有树脂不够提醒 如果发现 则点击退出返回 阶段4走起
if isIn or isIn2:
pyautogui.keyDown('esc')
time.sleep(0.1)
pyautogui.keyUp('esc')
time.sleep(1)
state.状态_已经有寻路了 = False
logger.info("没体力了 成功退出副本!")
time.sleep(10)
state.状态_需重新传送 = True
state.状态_已经有寻路了 = False
return True
isIn, idex = find_dict_index(datas, 'label', 'F交互')
if isIn: # 路过的顺手捡了
if datas[idex]["sim"]>=0.85:
pyautogui.keyUp('w')
logger.info("发现 F 交互 1")
pyautogui.keyDown('f')
time.sleep(0.1)
pyautogui.keyUp('f')
阶段 = 1
time.sleep(2)
isIn, idex = find_dict_index(datas, 'label', '副本开关')
if isIn: # 路过的顺手捡了
set_angle(0,
get_angle(self.centre_point,
(datas[idex]["x"], datas[idex]["y"])))
pyautogui.keyDown('w')
else:
pyautogui.keyUp('w')
pyautogui.keyDown('d')
time.sleep(0.2)
pyautogui.keyUp('d')
time.sleep(0.2)
mouse_middle_down()
time.sleep(0.1)
mouse_middle_up()
time.sleep(0.4)
pyautogui.keyDown('w')
elif 阶段 == 1: # 1 开始打怪阶段
计次_阶段0 = 0
isIn, idex = find_dict_index(datas, 'label', 'F交互')
if isIn and datas[idex]["points"][0][0]>300: # 路过的顺手捡了
if not islingjiang:
txt = self.get_text(ret_scr[datas[idex]["points"][0][1]-20:datas[idex]["points"][1][1]+20,
datas[idex]["points"][0][0]-20:datas[idex]["points"][1][0]+20])
if find_label_in_txt(txt):
pyautogui.keyUp('w')
logger.info("发现 吸收声骸")
pyautogui.keyDown('f')
time.sleep(0.1)
pyautogui.keyUp('f')
计次_离开=30
else:
pyautogui.keyUp('w')
logger.info("发现 F 交互")
pyautogui.keyDown('f')
time.sleep(0.1)
pyautogui.keyUp('f')
isIn, idex = find_dict_index(datas, 'label', '确定')
if isIn:
tangbaowss.send_msg("是否暂停#@@#真")
time.sleep(0.2)
mouse_move(p_left + datas[idex]["x"], p_top + datas[idex]["y"])
logger.info(f"发现确定按钮,可能是吃复活药{datas[idex]}")
time.sleep(0.1)
mouse_left_down()
time.sleep(0.1)
mouse_left_up()
time.sleep(0.5)
ret_scr = screenshot(hwnd, left, top, right, bottom, filename=None)
datas, state.图片_YOLOV = self.yolov.detect(ret_scr, plot_box=state.开关_是否展预测结果)
isIn, idex = find_dict_index(datas, 'label', '确定')
tangbaowss.send_msg("是否暂停#@@#假")
if not isIn:
logger.info("停止脚本")
tangbaowss.send_msg("是否回放#@@#假")
ttx=self.get_text(ret_scr[243:335,41:279])
if not islingjiang:
if "离开" in ttx or ttx=="":
if ttx=="":
res = template_matching(ret_scr[972:1061, 1428:1557], paimeng_img, mask=None)
if res!=[]:
计次_离开 += 1
else:
计次_离开+=1
if state.状态_是否回放中:
logger.info("停止脚本")
state.状态_是否回放中=False
tangbaowss.send_msg("是否回放#@@#假")
mouse_left_up()
pyautogui.keyUp('w')
isIn, idex = find_dict_index(datas, 'label', '声骸')
if isIn:
# pyautogui.keyDown('f')
# time.sleep(0.1)
# pyautogui.keyUp('f')
set_angle(0, get_angle(self.centre_point,
(datas[idex]["x"], datas[idex]["y"])))
# 不在则继续跟着怪物方向走
pyautogui.keyDown('w')
self.key_w_down = True
if 计次_离开 %6==0 and not isIn:
pyautogui.keyUp('w')
pyautogui.keyDown('d')
time.sleep(0.2)
pyautogui.keyUp('d')
time.sleep(0.2)
mouse_middle_down()
time.sleep(0.1)
mouse_middle_up()
time.sleep(0.4)
elif 计次_离开>=45:
pyautogui.keyDown('esc')
time.sleep(0.1)
pyautogui.keyUp('esc')
time.sleep(2)
mouse_move(p_left + 1292, p_top + 680)
time.sleep(0.2)
mouse_left_down()
time.sleep(0.2)
mouse_left_up()
state.状态_需重新传送 = False
state.状态_已经有寻路了 = False
pyautogui.keyUp('w')
计次_离开=0
logger.info("离开副本!")
time.sleep(10)
return True
else:
计次_离开 = 0
if not state.状态_是否回放中:
mouse_middle_down()
time.sleep(0.1)
mouse_middle_up()
logger.info("在连招中....")
pyautogui.press("x")
state.状态_是否回放中 = True
tangbaowss.send_msg("脚本执行#@@#2")
else:
if "领取" in ttx:
阶段 = 2
logger.info("发现副本 开关 停止脚本")
tangbaowss.send_msg("是否回放#@@#假")
continue
# 判断是否打完了副本
isIn, idex = find_dict_index(datas, 'label', '副本开关')
if isIn:
阶段 = 2
logger.info("发现副本 开关 停止脚本")
tangbaowss.send_msg("是否回放#@@#假")
continue
isIn, idex = find_dict_index(datas, 'label', '怪物')
if not isIn:
state.计数_没找到怪物+=1
if random.randint(1, 20) == 2:
mouse_middle_down()
time.sleep(0.2)
mouse_middle_up()
if state.计数_没找到怪物>=15 :
tangbaowss.send_msg("是否回放#@@#假")
pyautogui.keyUp('w')
pyautogui.keyDown('d')
time.sleep(0.2)
pyautogui.keyUp('d')
time.sleep(0.2)
mouse_middle_down()
time.sleep(0.1)
mouse_middle_up()
time.sleep(0.4)
else:
state.计数_没找到怪物=0
set_angle(0, get_angle(self.centre_point, (datas[idex]["x"], datas[idex]["y"])))
# 如果怪物就再旁边则直接连招
if self.centre_point[1] - datas[idex]["points"][1][1] <= 200 and datas[idex]["points"][1][0] - \
datas[idex]["points"][0][0] >= 60 and "离开" not in ttx and not "领取" in ttx:
if self.key_w_down:
self.key_w_down = False
pyautogui.keyUp('w')
if not state.状态_是否回放中 :
logger.info("在连招中....")
pyautogui.press("x")
mouse_middle_down()
time.sleep(0.1)
mouse_middle_up()
state.状态_是否回放中 = True
tangbaowss.send_msg("脚本执行#@@#2")
else:
# 不在则继续跟着怪物方向走
pyautogui.keyDown('w')
self.key_w_down = True
ret_sw = template_matching(ret_scr[891:949, 1063:1350], chongxintiaozhan_img, mask=None)
if ret_sw!= [] :
if ret_sw[0]["confidence"]>=0.85:
mouse_move(p_left + ret_sw[0]["result"][0], p_top + ret_sw[0]["result"][1])
time.sleep(0.2)
mouse_left_down()
time.sleep(0.2)
mouse_left_up()
logger.info("全军覆没了!")
time.sleep(3)
elif 阶段 == 2: # 2 走路到 领取奖励 直到点击 继续挑战为止 完成一轮
isIn, idex = find_dict_index(datas, 'label', '怪物')
if isIn:
阶段 = 1
state.状态_是否回放中 = True
state.计数_没找到怪物 = 0
tangbaowss.send_msg("脚本执行#@@#2")
continue
isIn, idex = find_dict_index(datas, 'label', '声骸')
if isIn:
阶段 = 1
state.状态_是否回放中 = True
state.计数_没找到怪物 = 0
tangbaowss.send_msg("脚本执行#@@#2")
continue
isIn, idex = find_dict_index(datas, 'label', '副本开关')
if isIn: # 路过的顺手捡了
set_angle(0,
get_angle(self.centre_point,
(datas[idex]["x"], datas[idex]["y"])))
pyautogui.keyDown('w')
else:
pyautogui.keyUp('w')
pyautogui.keyDown('d')
time.sleep(0.2)
pyautogui.keyUp('d')
time.sleep(0.2)
mouse_middle_down()
time.sleep(0.1)
mouse_middle_up()
time.sleep(0.4)
isIn, idex = find_dict_index(datas, 'label', 'F交互')
if isIn: # 路过的顺手捡了
pyautogui.keyUp('w')
logger.info("发现 F 交互")
pyautogui.keyDown('f')
time.sleep(0.1)
pyautogui.keyUp('f')
isIn, idex = find_dict_index(datas, 'label', '确定')
if isIn : # 路过的顺手捡了
if datas[idex]['sim']>0.9:
logger.info("发现 确定 领取奖励")
mouse_move(p_left + datas[idex]["x"], p_top + datas[idex]["y"])
time.sleep(0.2)
mouse_left_down()
time.sleep(0.2)
mouse_left_up()
time.sleep(2)
continue
isIn, idex = find_dict_index(datas, 'label', '重新挑战')
if isIn: # 路过的顺手捡了
if datas[idex]['sim'] >= 0.87:
logger.info("发现 重新挑战")
mouse_move(p_left + 1219, p_top + 931)
time.sleep(1)
mouse_left_down()
time.sleep(0.2)
mouse_left_up()
阶段= 3
time.sleep(1)
continue
if time.time()-计时_阶段3_开始时间>10:
rand_cz=random.randint(0,3)
if rand_cz==0:
pyautogui.keyDown('d')
time.sleep(1)
pyautogui.keyUp('d')
elif rand_cz==1:
pyautogui.keyDown('a')
time.sleep(1)
pyautogui.keyUp('a')
elif rand_cz==2:
pyautogui.keyDown('x')
time.sleep(0.3)
pyautogui.keyUp('x')
else:
pyautogui.keyDown('space')
time.sleep(0.3)
pyautogui.keyDown('space')
计时_阶段3_开始时间=time.time()
elif 阶段==3:
isIn, idex = find_dict_index(datas, 'label', '确定')
isIn2, idex = find_dict_index(datas, 'label', '取消')
# 判断弹窗是否有树脂不够提醒 如果发现 则点击退出返回 阶段4走起
if isIn or isIn2:
pyautogui.keyDown('esc')
time.sleep(0.1)
pyautogui.keyUp('esc')
time.sleep(2)
mouse_move(p_left + 718, p_top + 931)
time.sleep(0.2)
mouse_left_down()
time.sleep(0.2)
mouse_left_up()
state.状态_已经有寻路了 = False
logger.info("没体力了 成功退出副本!")
time.sleep(8)
state.状态_需重新传送 = False
pyautogui.keyUp('w')
return True
else:
pyautogui.keyUp('w')
阶段 = 0
break
except:
logger.error(traceback.format_exc())
time.sleep(0.5)
state.状态_已经有寻路了 = False
logger.info("刷副本全部完成!")
def run_chuansongjiaoben(self, jiaoben):
global new_msg
try:
hwnd = win32gui.FindWindow(state.GAME_CLASS, state.GAME_TITLE) # 替换成你实际的窗口句柄
if state.状态_循环开关 == False:
tangbaowss.send_msg("是否回放#@@#假")
logger.info("强制退出!")
return False
if get_window_handle_at_mouse_position() == hwnd:
set_window_activate(hwnd)
time.sleep(0.2)
rect = win32gui.GetWindowRect(hwnd)
w_p, h_p = (rect[2] - rect[0]) - 1920, (rect[3] - rect[1]) - 1080
# 设定截图区域的左上角坐标 (x, y) 和右下角坐标 (x, y)
left, top, right, bottom = 0, 0, 1920, 1080 # 替换成你实际的区域坐标
p_left = rect[0] + w_p
p_top = rect[1] + h_p
set_window_activate(hwnd)
kkk=self.处理异常情况(hwnd,left,top,right,bottom,p_left,p_top)
if kkk==0:
logger.info("在意外界面 超时!")
time.sleep(3)
state.状态_需重新传送 = False
return False
elif kkk==-1:
logger.info("全军覆没了!")
time.sleep(3)
state.状态_需重新传送 = True
return False
pyautogui.keyUp('w')
tangbaowss.send_msg(f"解析脚本#@@#{jiaoben}")
time.sleep(2)
state.状态_是否回放中 = True
tangbaowss.send_msg("脚本执行#@@#1")
while True:
try:
time.sleep(0.1)
if state.状态_是否回放中 == False:
state.状态_需重新传送 = False
return True
if state.状态_循环开关 == False:
state.状态_需重新传送 = False
tangbaowss.send_msg("是否回放#@@#假")
return False
if get_window_handle_at_mouse_position() != hwnd:
# 激活hwnd
hwnd = win32gui.FindWindow(state.GAME_CLASS, state.GAME_TITLE) # 替换成你实际的窗口句柄
set_window_activate(hwnd)
time.sleep(0.2)
except:
time.sleep(0.5)
except:
logger.error(traceback.format_exc())
state.状态_需重新传送 = False
tangbaowss.send_msg("是否回放#@@#假")
return False
def run_jiaoben(self,jiaoben,is_auto_f):
hwnd = win32gui.FindWindow(state.GAME_CLASS, state.GAME_TITLE) # 替换成你实际的窗口句柄
rect = win32gui.GetWindowRect(hwnd)
w_p, h_p = (rect[2] - rect[0]) - 1920, (rect[3] - rect[1]) - 1080
# F交互框位置
left_dh, top_dh, right_dh, bottom_dh = [1224,582,1403,641] # 替换成你实际的区域坐标
p_left = rect[0] + w_p
p_top = rect[1] + h_p
set_window_activate(hwnd)
# 判断是否卡在了对话界面
left, top, right, bottom = 0, 0, 1920, 1080 # 替换成你实际的区域坐标
kkk = self.处理异常情况(hwnd, left, top, right, bottom, p_left, p_top)
if kkk == 0:
logger.info("在意外界面 超时!")
time.sleep(3)
state.状态_需重新传送 = False
state.状态_已经有寻路了 = False
return False
elif kkk == -1:
logger.info("全军覆没了!")
time.sleep(3)
state.状态_需重新传送 = True
state.状态_已经有寻路了 = False
return False
if state.状态_循环开关 == False:
logger.info("强制退出!")
state.状态_已经有寻路了 = False
return False
message = f"解析脚本#@@#{jiaoben}"
tangbaowss.send_msg(message)
time.sleep(2)
tangbaowss.send_msg("脚本执行#@@#1")
state.状态_是否回放中 = True
try:
while True:
try:
time.sleep(0.1)
if state.状态_是否回放中 == False:
state.状态_需重新传送 = False
state.状态_已经有寻路了 = False
logger.info("脚本运行完毕!")
return True
if state.状态_循环开关 == False:
state.状态_需重新传送 = False
state.状态_已经有寻路了 = False
tangbaowss.send_msg("是否回放#@@#假")
logger.info("强制退出!")
return False
if get_window_handle_at_mouse_position() != hwnd:
# 激活hwnd
hwnd = win32gui.FindWindow(state.GAME_CLASS, state.GAME_TITLE) # 替换成你实际的窗口句柄
set_window_activate(hwnd)
time.sleep(0.2)
if is_auto_f:
if self.find_f(hwnd, 1229,565,1305,659, p_left, p_top):
time.sleep(0.2)
logger.info(f"顺手捡东西!")
state.状态_有目标 = True
pyautogui.keyDown('f')
time.sleep(0.1)
pyautogui.keyUp('f')
time.sleep(0.1)
pyautogui.keyDown('f')
time.sleep(0.1)
pyautogui.keyUp('f')
except:
time.sleep(0.5)
except:
logger.error(traceback.format_exc())
state.状态_需重新传送 = False
state.状态_已经有寻路了 = False
tangbaowss.send_msg("是否回放#@@#假")
return False
def run_jixing(self):
'''
领取电台奖励
:return:
'''
global new_msg
hwnd = win32gui.FindWindow(state.GAME_CLASS, state.GAME_TITLE) # 替换成你实际的窗口句柄
rect = win32gui.GetWindowRect(hwnd)
w_p, h_p = (rect[2] - rect[0]) - 1920, (rect[3] - rect[1]) - 1080
# 设定截图区域的左上角坐标 (x, y) 和右下角坐标 (x, y)
left, top, right, bottom = 0, 0, 1920, 1080 # 替换成你实际的区域坐标
p_left = rect[0] + w_p
p_top = rect[1] + h_p
hwnd = win32gui.FindWindow(state.GAME_CLASS, state.GAME_TITLE) # 替换成你实际的窗口句柄
set_window_activate(hwnd)
time.sleep(0.2)
paimeng_img = cv2.imdecode(np.fromfile(file="datas/背包图标.png", dtype=np.uint8), cv2.IMREAD_UNCHANGED)
paimeng_mask = None
big_img = screenshot(hwnd, left, top, right, bottom, None)
if template_matching(big_img, paimeng_img, mask=paimeng_mask) == []:
pyautogui.keyDown("esc")
time.sleep(0.1)
pyautogui.keyUp("esc")
time.sleep(2)
pyautogui.keyDown('alt')
time.sleep(1)
if not self.click_jixing(hwnd, left, top, right, bottom, p_left, p_top): logger.info(
"没有电台要领取");pyautogui.keyUp('alt');return
time.sleep(1)
pyautogui.keyUp('alt')
time.sleep(2)
mouse_move(p_left + 76, p_top + 323)
time.sleep(0.2)
mouse_left_down()
time.sleep(0.2)
mouse_left_up()
if not self.click_jixing_yijianlingqu(hwnd, left, top, right, bottom, p_left, p_top): logger.info(
"领取电台任务经验失败");return
time.sleep(1)
mouse_move(p_left + 77, p_top + 190)
time.sleep(0.2)
mouse_left_down()
time.sleep(0.2)
mouse_left_up()
time.sleep(1)
mouse_left_down()
time.sleep(0.2)
mouse_left_up()
time.sleep(1)
if not self.click_jixing_yijianlingqu(hwnd, left, top, right, bottom, p_left, p_top): logger.info(
"没有奖励能领取");return
time.sleep(1)
mouse_left_down()
time.sleep(0.2)
mouse_left_up()
time.sleep(1)
pyautogui.keyDown("esc")
time.sleep(0.1)
pyautogui.keyUp("esc")
def run_huanjue(self,path_list=[],zhanchagn="1"):
global new_msg
hwnd = win32gui.FindWindow(state.GAME_CLASS, state.GAME_TITLE) # 替换成你实际的窗口句柄
rect = win32gui.GetWindowRect(hwnd)
w_p, h_p = (rect[2] - rect[0]) - 1920, (rect[3] - rect[1]) - 1080
# 设定截图区域的左上角坐标 (x, y) 和右下角坐标 (x, y)
left, top, right, bottom = 0, 0, 1920, 1080 # 替换成你实际的区域坐标
p_left = rect[0] + w_p
p_top = rect[1] + h_p
hwnd = win32gui.FindWindow(state.GAME_CLASS, state.GAME_TITLE) # 替换成你实际的窗口句柄
set_window_activate(hwnd)
time.sleep(0.2)
kkk = self.处理异常情况(hwnd, left, top, right, bottom, p_left, p_top)
if kkk == 0:
logger.info("在意外界面 超时!")
time.sleep(3)
state.状态_需重新传送 = False
return False
elif kkk == -1:
logger.info("全军覆没了!")
time.sleep(3)
state.状态_需重新传送 = True
return False
#按了后看有没有打开成功
n=0
while True:
if n==0:
n=0
kkk = self.处理异常情况(hwnd, left, top, right, bottom, p_left, p_top)
if kkk == 0:
logger.info("在意外界面 超时!")
time.sleep(3)
state.状态_需重新传送 = False
return False
elif kkk == -1:
logger.info("全军覆没了!")
time.sleep(3)
state.状态_需重新传送 = True
return False
pyautogui.keyDown("x")
time.sleep(0.2)
pyautogui.keyUp("x")
pyautogui.keyDown("l")
time.sleep(0.2)
pyautogui.keyUp("l")
time.sleep(2)
elif n>=20:
n = 0
time.sleep(1)
if state.状态_循环开关 == False:
state.状态_需重新传送 = False
state.状态_已经有寻路了 = False
tangbaowss.send_msg("是否回放#@@#假")
logger.info("强制退出!")
return False
if get_window_handle_at_mouse_position() != hwnd:
# 激活hwnd
hwnd = win32gui.FindWindow(state.GAME_CLASS, state.GAME_TITLE) # 替换成你实际的窗口句柄
set_window_activate(hwnd)
time.sleep(0.2)
if state.状态_全局暂停:
tangbaowss.send_msg("是否回放#@@#假")
time.sleep(2)
continue
if self.click_kuaisubiandui(hwnd, left, top, right, bottom , p_left, p_top):
time.sleep(2)
break
n += 1
#加载角色图片数据
img_datas=[]
point_list=[[250,259],
[482,248],
[712,266]
]
for item in path_list:
img_datas.append( cv2.imdecode(np.fromfile(file=item, dtype=np.uint8),cv2.IMREAD_UNCHANGED))
#将历史角色清空掉
for point in point_list:
#点击对应坑位
mouse_move(p_left +point[0],p_top +point[1])
time.sleep(0.2)
mouse_left_down()
time.sleep(0.2)
mouse_left_up()
time.sleep(0.2)
logger.info("清空角色成功!")
# 循环选择角色
a = 0
for i,img in enumerate(img_datas):
ret =False
while not ret:
logger.info(str(a))
if state.状态_循环开关 == False:
state.状态_需重新传送 = False
state.状态_已经有寻路了 = False
tangbaowss.send_msg("是否回放#@@#假")
logger.info("强制退出!")
return False
if get_window_handle_at_mouse_position() != hwnd:
# 激活hwnd
hwnd = win32gui.FindWindow(state.GAME_CLASS, state.GAME_TITLE) # 替换成你实际的窗口句柄
set_window_activate(hwnd)
time.sleep(0.2)
if state.状态_全局暂停:
tangbaowss.send_msg("是否回放#@@#假")
time.sleep(2)
continue
ret= find_img_and_click(img, hwnd, left, top, right, bottom, p_left, p_top, f"勾选 角色{i+1}", 1,
1,
threshold=0.76)
if ret:
time.sleep(1)
break
if 3<a<7:
pyautogui.moveTo(p_left +979,p_top +415)
pyautogui.dragTo(p_left +979,p_top +833, duration=0.5, tween=pyautogui.easeOutSine)
else:
pyautogui.moveTo(p_left +979, p_top +833)
pyautogui.dragTo(p_left +979, p_top +415, duration=0.5, tween=pyautogui.easeOutSine)
a+=1
if a==7:
a=0
time.sleep(1)
#保存配置
mouse_move(p_left +1625,p_top +991)
time.sleep(0.2)
mouse_left_down()
time.sleep(0.2)
mouse_left_up()
time.sleep(5)
if state.状态_循环开关 == False:
state.状态_需重新传送 = False
state.状态_已经有寻路了 = False
tangbaowss.send_msg("是否回放#@@#假")
logger.info("强制退出!")
return False
pyautogui.keyDown("esc")
time.sleep(0.1)
pyautogui.keyUp("esc")
time.sleep(2)
pyautogui.keyDown(zhanchagn)
time.sleep(0.1)
pyautogui.keyUp(zhanchagn)
time.sleep(2)
state.状态_需重新传送 = False
state.状态_已经有寻路了 = False
return True
def 处理异常情况(self,hwnd,left,top,right,bottom,p_left,p_top):
'''
:param hwnd:
:param left:
:param top:
:param right:
:param bottom:
:param p_left:
:param p_top:
:return:
'''
paimeng_img = cv2.imdecode(np.fromfile(file="datas/背包图标.png", dtype=np.uint8), cv2.IMREAD_UNCHANGED)
mask = None
# 判断是否卡在了对话界面
for nnn in range(120):
if state.状态_循环开关 == False:
logger.info("强制退出!")
pyautogui.keyUp('w')
state.状态_已经有寻路了 = False
state.状态_是否回放中 = False
tangbaowss.send_msg("是否回放#@@#假")
state.状态_需重新传送 = False
return 1
big_img = screenshot(hwnd, left, top, right, bottom, None)
rrrr = template_matching(big_img, paimeng_img, mask=mask)
if rrrr == []:
rdd = random.randint(1, 4)
if rdd == 1:
mouse_move(p_left + 1431, p_top + 717)
time.sleep(0.2)
mouse_left_down()
time.sleep(0.2)
mouse_left_up()
time.sleep(0.2)
elif rdd == 2:
pyautogui.keyDown("esc")
time.sleep(0.1)
pyautogui.keyUp("esc")
time.sleep(1)
else:
pyautogui.keyDown('space')
time.sleep(0.1)
pyautogui.keyUp('space')
logger.info("未知界面 按esc 和 点击对话! " + str(nnn))
# 判断是否死亡
ret_sw = self.find_zhuyidiren(hwnd,487,757,1649,1034, p_left, p_top)
if ret_sw:
return -1
else:
if rrrr != []:
return 1
time.sleep(1)
return 0
def find_f_keep_going(self, hwnd, left, top, right, bottom, p_left, p_top, isFanxiang):
img = cv2.imdecode(np.fromfile(file="./datas/F.png", dtype=np.uint8), cv2.IMREAD_UNCHANGED)
if isFanxiang:
keepKey = 's'
else:
keepKey = 'w'
if find_img_and_click(img, hwnd, left, top, right, bottom, p_left, p_top, "点击 F", 100, 0.1, False,
keepKey=keepKey,threshold= 0.75):
if isFanxiang:
pyautogui.keyUp('s')
else:
pyautogui.keyUp('w')
pyautogui.keyDown('f')
time.sleep(0.2)
pyautogui.keyUp('f')
time.sleep(0.3)
pyautogui.keyDown('f')
time.sleep(0.2)
pyautogui.keyUp('f')
return True
else:
return False
def click_danrentiaozhan(self, hwnd, left, top, right, bottom, p_left, p_top):
img = cv2.imdecode(np.fromfile(file="./datas/单人挑战.png", dtype=np.uint8), cv2.IMREAD_UNCHANGED)
return find_img_and_click(img, hwnd, left, top, right, bottom, p_left, p_top, "点击 单人挑战",double_click=True)
def find_danrentiaozhan(self, hwnd, left, top, right, bottom, p_left, p_top):
img = cv2.imdecode(np.fromfile(file="./datas/单人挑战.png", dtype=np.uint8), cv2.IMREAD_UNCHANGED)
return find_img_and_click(img, hwnd, left, top, right, bottom, p_left, p_top, "查找 单人挑战",is_click=False)
def click_dimaiyichang(self, hwnd, left, top, right, bottom, p_left, p_top):
img = cv2.imdecode(np.fromfile(file="./datas/地脉异常.png", dtype=np.uint8), cv2.IMREAD_UNCHANGED)
return find_img_and_click(img, hwnd, left, top, right, bottom, p_left, p_top, "点击 地脉异常", 1, 0.01,
threshold=0.76)
def click_jixing(self, hwnd, left, top, right, bottom, p_left, p_top):
img = cv2.imdecode(np.fromfile(file="./datas/纪行.png", dtype=np.uint8), cv2.IMREAD_UNCHANGED)
mask = img[:, :, 3] # 提取透明度通道作为掩码
return find_img_and_click(img, hwnd, left, top, right, bottom, p_left, p_top, "点击 纪行", 10, 1,
threshold=0.76, mask=mask, double_click=True)
def click_jixing_renwu(self, hwnd, left, top, right, bottom, p_left, p_top):
img = cv2.imdecode(np.fromfile(file="./datas/纪行_任务.png", dtype=np.uint8), cv2.IMREAD_UNCHANGED)
mask = img[:, :, 3] # 提取透明度通道作为掩码
return find_img_and_click(img, hwnd, left, top, right, bottom, p_left, p_top, "点击 纪行_任务", 10, 1,
threshold=0.6, mask=mask)
def click_jixing_yijianlingqu(self, hwnd, left, top, right, bottom, p_left, p_top):
img = cv2.imdecode(np.fromfile(file="./datas/纪行_一键领取.png", dtype=np.uint8), cv2.IMREAD_UNCHANGED)
return find_img_and_click(img, hwnd, left, top, right, bottom, p_left, p_top, "点击 纪行_一键领取", 10, 1,
threshold=0.76)
def click_kuaisubiandui(self, hwnd, left, top, right, bottom, p_left, p_top):
img = cv2.imdecode(np.fromfile(file="./datas/快速编队.png", dtype=np.uint8), cv2.IMREAD_UNCHANGED)
return find_img_and_click(img, hwnd, left, top, right, bottom, p_left, p_top, "点击 快速编队", 1, 1,
threshold=0.76)
def find_baocunpeizhi(self, hwnd, left, top, right, bottom, p_left, p_top):
img = cv2.imdecode(np.fromfile(file="./datas/保存配置.png", dtype=np.uint8), cv2.IMREAD_UNCHANGED)
return find_img_and_click(img, hwnd, left, top, right, bottom, p_left, p_top, "查找 保存配置", 1, 1,
threshold=0.76,is_click=False)
def click_jixing_jixing(self, hwnd, left, top, right, bottom, p_left, p_top):
img = cv2.imdecode(np.fromfile(file="./datas/纪行_纪行.png", dtype=np.uint8), cv2.IMREAD_UNCHANGED)
mask = img[:, :, 3] # 提取透明度通道作为掩码
return find_img_and_click(img, hwnd, left, top, right, bottom, p_left, p_top, "点击 纪行_纪行", 10, 1,
threshold=0.76, mask=mask)
def click_kaishitiaozhan(self, hwnd, left, top, right, bottom, p_left, p_top):
img = cv2.imdecode(np.fromfile(file="./datas/开始挑战.png", dtype=np.uint8), cv2.IMREAD_UNCHANGED)
return find_img_and_click(img, hwnd, left, top, right, bottom, p_left, p_top, "点击 开始挑战")
def find_shuzhibugou(self, hwnd, left, top, right, bottom, p_left, p_top):
img = cv2.imdecode(np.fromfile(file="./datas/树脂不够.png", dtype=np.uint8), cv2.IMREAD_UNCHANGED)
mask = None
return find_img_and_click(img, hwnd, left, top, right, bottom, p_left, p_top, "点击 树脂不够", 2,
threshold=0.65, is_click=False, mask=mask)
def find_f(self, hwnd, left, top, right, bottom, p_left, p_top):
img = cv2.imdecode(np.fromfile(file="./datas/f.png", dtype=np.uint8), cv2.IMREAD_UNCHANGED)
mask =None# img[:, :, 3] # 提取透明度通道作为掩码
return find_img_and_click(img, hwnd, left, top, right, bottom, p_left, p_top, "寻找 F", 1,step=0.001,
threshold=0.75, is_click=False, mask=mask)
def find_zhuyidiren(self, hwnd, left, top, right, bottom, p_left, p_top):
img = cv2.imdecode(np.fromfile(file="./datas/注意敌人.png", dtype=np.uint8), cv2.IMREAD_UNCHANGED)
return find_img_and_click(img, hwnd, left, top, right, bottom, p_left, p_top, "点击 注意敌人", 1,
step=0.01,
threshold=0.85, is_click=True)
def find_zhuyidiren2(self, hwnd, left, top, right, bottom, p_left, p_top):
img = cv2.imdecode(np.fromfile(file="./datas/重新挑战.png", dtype=np.uint8), cv2.IMREAD_UNCHANGED)
return find_img_and_click(img, hwnd, left, top, right, bottom, p_left, p_top, "点击 注意敌人", 1,step=0.01,
threshold=0.85, is_click=True)
def find_duihuahuopengren(self, hwnd, left, top, right, bottom, p_left, p_top):
imgs = [cv2.imdecode(np.fromfile(file="./datas/对话.png", dtype=np.uint8), cv2.IMREAD_UNCHANGED),
cv2.imdecode(np.fromfile(file="./datas/烹饪.png", dtype=np.uint8), cv2.IMREAD_UNCHANGED),
]
return find_imgs_and_click(imgs, hwnd, left, top, right, bottom, p_left, p_top, "发现 对话或烹饪", 1,
step=0.01, is_click=False,isMask=True)
def find_xiacihuifu(self, hwnd, left, top, right, bottom, p_left, p_top):
imgs = [cv2.imdecode(np.fromfile(file="./datas/下次恢复.png", dtype=np.uint8), cv2.IMREAD_UNCHANGED),
]
return find_imgs_and_click(imgs, hwnd, left, top, right, bottom, p_left, p_top, "", 1,
step=0.01, is_click=False)
def find_pianpianhua(self, hwnd, left, top, right, bottom, p_left, p_top):
imgs = [cv2.imdecode(np.fromfile(file="./datas/薄荷.png", dtype=np.uint8), cv2.IMREAD_UNCHANGED),
cv2.imdecode(np.fromfile(file="./datas/甜甜花.png", dtype=np.uint8), cv2.IMREAD_UNCHANGED)
]
return find_imgs_and_click(imgs, hwnd, left, top, right, bottom, p_left, p_top, "发现 骗骗花", 1,
step=0.01, is_click=False)
def distance_to_target(self, d):
h = d["points"][1][0] - d["points"][0][0]
w = d["points"][1][1] - d["points"][0][1]
# # # 计算距离的平方,这里使用欧几里得距离的平方作为衡量标准
dist = (d["x"] - self.centre_point[0]) ** 2 + (d["y"] - self.centre_point[1]) ** 2
angle = get_angle(self.centre_point, [d["x"], d["y"]])
if angle >= 300 or angle <= 60:
dist *= 999
if w < 60:
dist *= 0.1
return dist + w + h
if __name__ == '__main__':
while True:
time.sleep(0.0001)
pass
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/LanRenZhiNeng/ming-chao-ai.git
git@gitee.com:LanRenZhiNeng/ming-chao-ai.git
LanRenZhiNeng
ming-chao-ai
MingChaoAI
master

搜索帮助