mirror of
https://github.com/ok-oldking/ok-wuthering-waves.git
synced 2025-06-06 17:05:54 +00:00
优化中英文游戏客户端下 声骸拾取
This commit is contained in:
parent
c1f0166b24
commit
8167c2b09a
@ -1,11 +1,12 @@
|
|||||||
from ok.feature.FindFeature import FindFeature
|
from ok.feature.FindFeature import FindFeature
|
||||||
from ok.logging.Logger import get_logger
|
from ok.logging.Logger import get_logger
|
||||||
from ok.task.TriggerTask import TriggerTask
|
from ok.task.TriggerTask import TriggerTask
|
||||||
|
from src.task.BaseWWTask import BaseWWTask
|
||||||
|
|
||||||
logger = get_logger(__name__)
|
logger = get_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class AutoPickTask(TriggerTask, FindFeature):
|
class AutoPickTask(TriggerTask, BaseWWTask, FindFeature):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
@ -21,13 +22,7 @@ class AutoPickTask(TriggerTask, FindFeature):
|
|||||||
self.sleep(0.2)
|
self.sleep(0.2)
|
||||||
|
|
||||||
def trigger(self):
|
def trigger(self):
|
||||||
f_search_box = self.get_box_by_name('pick_up_f')
|
if f := self.find_one('pick_up_f', box=self.f_search_box,
|
||||||
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,
|
|
||||||
threshold=0.8):
|
threshold=0.8):
|
||||||
dialog_search = f.copy(x_offset=f.width * 2, width_offset=f.width * 2, height_offset=f.height * 2,
|
dialog_search = f.copy(x_offset=f.width * 2, width_offset=f.width * 2, height_offset=f.height * 2,
|
||||||
y_offset=-f.height,
|
y_offset=-f.height,
|
||||||
|
@ -7,13 +7,13 @@ from ok.config.ConfigOption import ConfigOption
|
|||||||
from ok.feature.FindFeature import FindFeature
|
from ok.feature.FindFeature import FindFeature
|
||||||
from ok.logging.Logger import get_logger
|
from ok.logging.Logger import get_logger
|
||||||
from ok.ocr.OCR import OCR
|
from ok.ocr.OCR import OCR
|
||||||
from ok.task.BaseTask import BaseTask
|
|
||||||
from ok.task.TaskExecutor import CannotFindException
|
from ok.task.TaskExecutor import CannotFindException
|
||||||
from ok.util.list import safe_get
|
from ok.util.list import safe_get
|
||||||
from src.char import BaseChar
|
from src.char import BaseChar
|
||||||
from src.char.BaseChar import Priority
|
from src.char.BaseChar import Priority
|
||||||
from src.char.CharFactory import get_char_by_pos
|
from src.char.CharFactory import get_char_by_pos
|
||||||
from src.combat.CombatCheck import CombatCheck
|
from src.combat.CombatCheck import CombatCheck
|
||||||
|
from src.task.BaseWWTask import BaseWWTask
|
||||||
|
|
||||||
logger = get_logger(__name__)
|
logger = get_logger(__name__)
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ key_config_option = ConfigOption('Game Hotkey Config', {
|
|||||||
}, description='In Game Hotkey for Skills')
|
}, description='In Game Hotkey for Skills')
|
||||||
|
|
||||||
|
|
||||||
class BaseCombatTask(BaseTask, FindFeature, OCR, CombatCheck):
|
class BaseCombatTask(BaseWWTask, FindFeature, OCR, CombatCheck):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
@ -53,7 +53,7 @@ class BaseCombatTask(BaseTask, FindFeature, OCR, CombatCheck):
|
|||||||
exception_type = NotInCombatException
|
exception_type = NotInCombatException
|
||||||
raise exception_type(message)
|
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.wait_until(lambda: self.in_combat(), time_out=wait_combat_time, raise_if_not_found=True)
|
||||||
self.sleep(wait_before)
|
self.sleep(wait_before)
|
||||||
self.wait_until(lambda: self.in_combat(), time_out=3, raise_if_not_found=True)
|
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:
|
if self.debug:
|
||||||
self.screenshot(f'out of combat break {self.out_of_combat_reason}')
|
self.screenshot(f'out of combat break {self.out_of_combat_reason}')
|
||||||
break
|
break
|
||||||
|
self.middle_click()
|
||||||
|
self.sleep(0.2)
|
||||||
|
|
||||||
def run_in_circle_to_find_echo(self, circle_count=3):
|
def run_in_circle_to_find_echo(self, circle_count=3):
|
||||||
directions = ['w', 'a', 's', 'd']
|
directions = ['w', 'a', 's', 'd']
|
||||||
@ -81,7 +83,8 @@ class BaseCombatTask(BaseTask, FindFeature, OCR, CombatCheck):
|
|||||||
for direction in directions:
|
for direction in directions:
|
||||||
if total_index > 2 and (total_index + 1) % 2 == 0:
|
if total_index > 2 and (total_index + 1) % 2 == 0:
|
||||||
duration += step
|
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:
|
if picked:
|
||||||
self.mouse_up(key="right")
|
self.mouse_up(key="right")
|
||||||
return True
|
return True
|
||||||
@ -196,15 +199,15 @@ class BaseCombatTask(BaseTask, FindFeature, OCR, CombatCheck):
|
|||||||
self.screenshot('not_in_combat_calling_check_combat')
|
self.screenshot('not_in_combat_calling_check_combat')
|
||||||
self.raise_not_in_combat('combat check not in 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:
|
if time_out <= 0:
|
||||||
return
|
return
|
||||||
start = time.time()
|
start = time.time()
|
||||||
if running:
|
if running:
|
||||||
self.mouse_down(key='right')
|
self.mouse_down(key='right')
|
||||||
self.send_key_down(direction)
|
self.send_key_down(direction)
|
||||||
f_found = self.wait_feature('pick_up_f', horizontal_variance=0.01, vertical_variance=0.01, threshold=0.8,
|
f_found = self.wait_until(lambda: self.find_f_with_text(exclude_text=exclude_text), time_out=time_out,
|
||||||
wait_until_before_delay=0, time_out=time_out, raise_if_not_found=False)
|
raise_if_not_found=False)
|
||||||
if f_found:
|
if f_found:
|
||||||
self.send_key('f')
|
self.send_key('f')
|
||||||
self.sleep(0.1)
|
self.sleep(0.1)
|
||||||
@ -233,19 +236,20 @@ class BaseCombatTask(BaseTask, FindFeature, OCR, CombatCheck):
|
|||||||
|
|
||||||
def handle_claim_button(self):
|
def handle_claim_button(self):
|
||||||
if self.wait_feature('cancel_button', raise_if_not_found=False, horizontal_variance=0.1,
|
if self.wait_feature('cancel_button', raise_if_not_found=False, horizontal_variance=0.1,
|
||||||
vertical_variance=0.1,
|
vertical_variance=0.1, time_out=1.5, threshold=0.8):
|
||||||
use_gray_scale=True, time_out=2, threshold=0.8):
|
|
||||||
self.send_key('esc')
|
self.send_key('esc')
|
||||||
self.sleep(0.05)
|
self.sleep(0.05)
|
||||||
logger.info(f"found a claim reward")
|
logger.info(f"found a claim reward")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def walk_until_f(self, direction='w', time_out=0, raise_if_not_found=True, backward_time=0):
|
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_one('pick_up_f', horizontal_variance=0.01, vertical_variance=0.01, threshold=0.8):
|
if not self.find_f_with_text(exclude_text=exclude_text):
|
||||||
if backward_time > 0:
|
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 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:
|
else:
|
||||||
self.send_key('f')
|
self.send_key('f')
|
||||||
if self.handle_claim_button():
|
if self.handle_claim_button():
|
||||||
|
36
src/task/BaseWWTask.py
Normal file
36
src/task/BaseWWTask.py
Normal file
@ -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
|
@ -26,7 +26,6 @@ class FarmEchoTask(BaseCombatTask):
|
|||||||
self.last_drop = False
|
self.last_drop = False
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
# return self.run_in_circle_to_find_echo()
|
|
||||||
self.handler.post(self.mouse_reset, 0.01)
|
self.handler.post(self.mouse_reset, 0.01)
|
||||||
if not self.in_team()[0]:
|
if not self.in_team()[0]:
|
||||||
self.log_error('must be in game world and in teams', notify=True)
|
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)
|
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')
|
logger.info(f'farm echo move {self.config.get("Entrance Direction")} walk_until_f to find echo')
|
||||||
if self.config.get('Entrance Direction') == 'Forward':
|
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
|
raise_if_not_found=False) # find and pick echo
|
||||||
logger.debug(f'farm echo found echo move forward walk_until_f to find echo')
|
logger.debug(f'farm echo found echo move forward walk_until_f to find echo')
|
||||||
else:
|
else:
|
||||||
@ -79,7 +78,7 @@ class FarmEchoTask(BaseCombatTask):
|
|||||||
y = 0.17
|
y = 0.17
|
||||||
x = 0.15
|
x = 0.15
|
||||||
distance = 0.08
|
distance = 0.08
|
||||||
|
|
||||||
logger.info(f'choose level {start}')
|
logger.info(f'choose level {start}')
|
||||||
self.click_relative(x, y + (start - 1) * distance)
|
self.click_relative(x, y + (start - 1) * distance)
|
||||||
self.sleep(0.5)
|
self.sleep(0.5)
|
||||||
|
@ -178,7 +178,7 @@ class FarmWorldBossTask(BaseCombatTask):
|
|||||||
self.sleep(5)
|
self.sleep(5)
|
||||||
self.wait_in_team_and_world(time_out=20)
|
self.wait_in_team_and_world(time_out=20)
|
||||||
logger.info(f'farm echo move forward walk_until_f to find echo')
|
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
|
raise_if_not_found=False): # find and pick echo
|
||||||
logger.debug(f'farm echo found echo move forward walk_until_f to find echo')
|
logger.debug(f'farm echo found echo move forward walk_until_f to find echo')
|
||||||
self.incr_drop(True)
|
self.incr_drop(True)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user