diff --git a/src/task/AutoPickTask.py b/src/task/AutoPickTask.py index 00a941e..a658625 100644 --- a/src/task/AutoPickTask.py +++ b/src/task/AutoPickTask.py @@ -1,11 +1,12 @@ from ok.feature.FindFeature import FindFeature from ok.logging.Logger import get_logger from ok.task.TriggerTask import TriggerTask +from src.task.BaseWWTask import BaseWWTask logger = get_logger(__name__) -class AutoPickTask(TriggerTask, FindFeature): +class AutoPickTask(TriggerTask, BaseWWTask, FindFeature): def __init__(self): super().__init__() @@ -21,13 +22,7 @@ class AutoPickTask(TriggerTask, FindFeature): self.sleep(0.2) def trigger(self): - f_search_box = self.get_box_by_name('pick_up_f') - f_search_box = f_search_box.copy(x_offset=-f_search_box.width / 2, - width_offset=f_search_box.width, - height_offset=f_search_box.height * 9, - y_offset=-f_search_box.height * 5, - name='search_dialog') - if f := self.find_one('pick_up_f', box=f_search_box, + if f := self.find_one('pick_up_f', box=self.f_search_box, threshold=0.8): dialog_search = f.copy(x_offset=f.width * 2, width_offset=f.width * 2, height_offset=f.height * 2, y_offset=-f.height, diff --git a/src/task/BaseCombatTask.py b/src/task/BaseCombatTask.py index 7293920..e921f2e 100644 --- a/src/task/BaseCombatTask.py +++ b/src/task/BaseCombatTask.py @@ -7,13 +7,13 @@ from ok.config.ConfigOption import ConfigOption from ok.feature.FindFeature import FindFeature from ok.logging.Logger import get_logger from ok.ocr.OCR import OCR -from ok.task.BaseTask import BaseTask from ok.task.TaskExecutor import CannotFindException from ok.util.list import safe_get from src.char import BaseChar from src.char.BaseChar import Priority from src.char.CharFactory import get_char_by_pos from src.combat.CombatCheck import CombatCheck +from src.task.BaseWWTask import BaseWWTask logger = get_logger(__name__) @@ -33,7 +33,7 @@ key_config_option = ConfigOption('Game Hotkey Config', { }, description='In Game Hotkey for Skills') -class BaseCombatTask(BaseTask, FindFeature, OCR, CombatCheck): +class BaseCombatTask(BaseWWTask, FindFeature, OCR, CombatCheck): def __init__(self): super().__init__() @@ -53,7 +53,7 @@ class BaseCombatTask(BaseTask, FindFeature, OCR, CombatCheck): exception_type = NotInCombatException raise exception_type(message) - def combat_once(self, wait_combat_time=180, wait_before=2): + def combat_once(self, wait_combat_time=180, wait_before=1): self.wait_until(lambda: self.in_combat(), time_out=wait_combat_time, raise_if_not_found=True) self.sleep(wait_before) self.wait_until(lambda: self.in_combat(), time_out=3, raise_if_not_found=True) @@ -70,6 +70,8 @@ class BaseCombatTask(BaseTask, FindFeature, OCR, CombatCheck): if self.debug: self.screenshot(f'out of combat break {self.out_of_combat_reason}') break + self.middle_click() + self.sleep(0.2) def run_in_circle_to_find_echo(self, circle_count=3): directions = ['w', 'a', 's', 'd'] @@ -81,7 +83,8 @@ class BaseCombatTask(BaseTask, FindFeature, OCR, CombatCheck): for direction in directions: if total_index > 2 and (total_index + 1) % 2 == 0: duration += step - picked = self.send_key_and_wait_f(direction, False, time_out=duration, running=True) + picked = self.send_key_and_wait_f(direction, False, time_out=duration, running=True, + exclude_text=self.absorb_echo_exclude_text) if picked: self.mouse_up(key="right") return True @@ -196,15 +199,15 @@ class BaseCombatTask(BaseTask, FindFeature, OCR, CombatCheck): self.screenshot('not_in_combat_calling_check_combat') self.raise_not_in_combat('combat check not in combat') - def send_key_and_wait_f(self, direction, raise_if_not_found, time_out, running=False): + def send_key_and_wait_f(self, direction, raise_if_not_found, time_out, running=False, exclude_text=None): if time_out <= 0: return start = time.time() if running: self.mouse_down(key='right') self.send_key_down(direction) - f_found = self.wait_feature('pick_up_f', horizontal_variance=0.01, vertical_variance=0.01, threshold=0.8, - wait_until_before_delay=0, time_out=time_out, raise_if_not_found=False) + f_found = self.wait_until(lambda: self.find_f_with_text(exclude_text=exclude_text), time_out=time_out, + raise_if_not_found=False) if f_found: self.send_key('f') self.sleep(0.1) @@ -233,19 +236,20 @@ class BaseCombatTask(BaseTask, FindFeature, OCR, CombatCheck): def handle_claim_button(self): if self.wait_feature('cancel_button', raise_if_not_found=False, horizontal_variance=0.1, - vertical_variance=0.1, - use_gray_scale=True, time_out=2, threshold=0.8): + vertical_variance=0.1, time_out=1.5, threshold=0.8): self.send_key('esc') self.sleep(0.05) logger.info(f"found a claim reward") return True - def walk_until_f(self, direction='w', time_out=0, raise_if_not_found=True, backward_time=0): - if not self.find_one('pick_up_f', horizontal_variance=0.01, vertical_variance=0.01, threshold=0.8): + def walk_until_f(self, direction='w', time_out=0, raise_if_not_found=True, backward_time=0, exclude_text=None): + if not self.find_f_with_text(exclude_text=exclude_text): if backward_time > 0: - if self.send_key_and_wait_f('s', raise_if_not_found, backward_time): + if self.send_key_and_wait_f('s', raise_if_not_found, backward_time, exclude_text=exclude_text): + logger.info('walk backward found f') return True - return self.send_key_and_wait_f(direction, raise_if_not_found, time_out) and self.sleep(0.5) + return self.send_key_and_wait_f(direction, raise_if_not_found, time_out, + exclude_text=exclude_text) and self.sleep(0.5) else: self.send_key('f') if self.handle_claim_button(): diff --git a/src/task/BaseWWTask.py b/src/task/BaseWWTask.py new file mode 100644 index 0000000..a5571d3 --- /dev/null +++ b/src/task/BaseWWTask.py @@ -0,0 +1,36 @@ +import re + +from ok.feature.FindFeature import FindFeature +from ok.logging.Logger import get_logger +from ok.ocr.OCR import OCR +from ok.task.BaseTask import BaseTask + +logger = get_logger(__name__) + + +class BaseWWTask(BaseTask, FindFeature, OCR): + + def __init__(self): + super().__init__() + self.absorb_echo_exclude_text = re.compile(r'(领取奖励|Claim)') + + @property + def f_search_box(self): + f_search_box = self.get_box_by_name('pick_up_f') + f_search_box = f_search_box.copy(x_offset=-f_search_box.width / 2, + width_offset=f_search_box.width, + height_offset=f_search_box.height * 9, + y_offset=-f_search_box.height * 5, + name='search_dialog') + return f_search_box + + def find_f_with_text(self, exclude_text=None): + f = self.find_one('pick_up_f', box=self.f_search_box, threshold=0.8) + if f and exclude_text: + search_text_box = f.copy(x_offset=f.width * 5, width_offset=f.width * 12, height_offset=1 * f.height, + y_offset=-0.5 * f.height) + text = self.ocr(box=search_text_box, match=exclude_text) + logger.debug(f'found f with text {text}, exclude_text {exclude_text}') + if len(text) > 0: + return False + return f diff --git a/src/task/FarmEchoTask.py b/src/task/FarmEchoTask.py index e6c66e8..c214e25 100644 --- a/src/task/FarmEchoTask.py +++ b/src/task/FarmEchoTask.py @@ -26,7 +26,6 @@ class FarmEchoTask(BaseCombatTask): self.last_drop = False def run(self): - # return self.run_in_circle_to_find_echo() self.handler.post(self.mouse_reset, 0.01) if not self.in_team()[0]: self.log_error('must be in game world and in teams', notify=True) @@ -53,7 +52,7 @@ class FarmEchoTask(BaseCombatTask): self.wait_in_team_and_world(time_out=20) logger.info(f'farm echo move {self.config.get("Entrance Direction")} walk_until_f to find echo') if self.config.get('Entrance Direction') == 'Forward': - dropped = self.walk_until_f(time_out=3, + dropped = self.walk_until_f(time_out=3, exclude_text=self.absorb_echo_exclude_text, raise_if_not_found=False) # find and pick echo logger.debug(f'farm echo found echo move forward walk_until_f to find echo') else: @@ -79,7 +78,7 @@ class FarmEchoTask(BaseCombatTask): y = 0.17 x = 0.15 distance = 0.08 - + logger.info(f'choose level {start}') self.click_relative(x, y + (start - 1) * distance) self.sleep(0.5) diff --git a/src/task/FarmWorldBossTask.py b/src/task/FarmWorldBossTask.py index b412a4b..b89df2d 100644 --- a/src/task/FarmWorldBossTask.py +++ b/src/task/FarmWorldBossTask.py @@ -178,7 +178,7 @@ class FarmWorldBossTask(BaseCombatTask): self.sleep(5) self.wait_in_team_and_world(time_out=20) logger.info(f'farm echo move forward walk_until_f to find echo') - if self.walk_until_f(time_out=6, backward_time=1, + if self.walk_until_f(time_out=6, backward_time=1, exclude_text=self.absorb_echo_exclude_text, raise_if_not_found=False): # find and pick echo logger.debug(f'farm echo found echo move forward walk_until_f to find echo') self.incr_drop(True)