Skip to content

Commit

Permalink
修复收菜可能无法领取任务
Browse files Browse the repository at this point in the history
修复点击界面或者退出可能会卡死
  • Loading branch information
ok-oldking committed Jun 8, 2024
1 parent aaf79ae commit 897ccd3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 25 deletions.
9 changes: 8 additions & 1 deletion task/AutoStartCombatTask.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

from ok.ocr.OCR import OCR
from ok.task.TriggerTask import TriggerTask

Expand All @@ -16,5 +18,10 @@ def run(self):
if start_combat:
self.click_box(start_combat)
# self.log_info(start_combat)
self.notification("点击开始战斗")
self.log_info("点击开始战斗", True)
self.sleep(2)
return True
click_to_continue = self.ocr(0.42, 0.74, 0.58, 0.97, match=re.compile(r"^点击"))
if click_to_continue:
self.click_box(click_to_continue)
return True
2 changes: 1 addition & 1 deletion task/DailyTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def claim_dayueka(self):

def claim_quest(self):
while True:
self.choose_main_menu(re.compile(r"完成"))
self.choose_main_menu(re.compile(r"(完成|任务)"))
claim = self.wait_ocr(0.8, 0.75, 0.93, 0.81, match=re.compile(r"领取"), time_out=4)
if not claim:
self.click_relative(0.36, 0.05)
Expand Down
32 changes: 9 additions & 23 deletions task/ManXunTask.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import queue
import re
import threading

from typing_extensions import override

Expand Down Expand Up @@ -70,10 +68,6 @@ def __init__(self):

def on_create(self):
self.log_debug('on_create')
self.update_stats_queue = queue.Queue()
self.update_stats_thread = threading.Thread(target=self.do_update_current_stats,
name=f"{self.__class__.__name__}_update_stats")
self.update_stats_thread.start()

def validate_config(self, key, value):
self.custom_routes.clear()
Expand All @@ -91,9 +85,6 @@ def validate_config(self, key, value):
return f'自定义路径配置格式错误:{v}'
self.log_info(f'加载自定义路径:{self.custom_routes}')

def on_destroy(self):
self.update_stats_queue.put(None)

def end(self, message, result=False):
self.log_info(f"执行结束:{message}")
return result
Expand Down Expand Up @@ -206,29 +197,24 @@ def stats_priority(self, gaowei):

def update_current_stats(self):
if self.to_update_stats:
if self.update_stats_queue.qsize() > 0:
self.log_error(f"update_stats_queue blocked {self.update_stats_queue.qsize()}")
return
self.to_update_stats = False
self.update_stats_queue.put(self.frame)

def do_update_current_stats(self):
while not self.exit_is_set():
frame = self.update_stats_queue.get()
if frame is None:
self.log_info("No frame in queue, destroyed")
return
self.ocr_stats(frame)
self.handler.post(lambda: self.do_update_current_stats(self.frame))

def do_update_current_stats(self, frame):
if frame is None:
self.log_info("No frame in queue, destroyed")
return
self.ocr_stats(frame)

def ocr_stats(self, frame=None):
boxes = self.ocr(box=self.stats_zone, match=re.compile(r'^[1-9]\d*$'), frame=frame)
if len(boxes) != 5:
self.log_error(f"无法找到5个属性, {boxes}")
# self.log_error(f"无法找到5个属性, {boxes}")
return False
else:
stats = [int(box.name) for box in boxes]
self.update_stats_for_anjiao(stats)
self.info['当前属性'] = stats
self.log_debug(f"ocr_stats {stats}")
return True

def update_stats_for_anjiao(self, stats):
Expand Down

0 comments on commit 897ccd3

Please sign in to comment.