From 02bf30f77e6a8ffbc98f7561447afa5cf985c296 Mon Sep 17 00:00:00 2001 From: "firedcto@gmail.com" Date: Thu, 8 Aug 2024 18:35:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BB=8A=E6=B1=90E4=E4=B8=8D?= =?UTF-8?q?=E5=96=B7,=20=E6=88=96=E6=8F=90=E5=89=8D=E8=B7=B3=E5=87=BA?= =?UTF-8?q?=E6=88=98=E6=96=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/char/BaseChar.py | 17 +++++++++++------ src/char/Jinhsi.py | 8 +++----- src/combat/CombatCheck.py | 19 ++++++++++++++----- src/task/BaseCombatTask.py | 2 +- 4 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/char/BaseChar.py b/src/char/BaseChar.py index 36ad641..b455cbb 100644 --- a/src/char/BaseChar.py +++ b/src/char/BaseChar.py @@ -163,13 +163,14 @@ class BaseChar: if sec > 0: self.task.sleep_check_combat(sec + self.sleep_adjust, check_combat=check_combat) - def click_resonance(self, post_sleep=0, has_animation=False, send_click=True): + def click_resonance(self, post_sleep=0, has_animation=False, send_click=True, animation_min_duration=0): clicked = False self.logger.debug(f'click_resonance start') last_click = 0 last_op = 'click' resonance_click_time = 0 animated = False + start = time.time() while True: if resonance_click_time != 0 and time.time() - resonance_click_time > 8: self.task.in_liberation = False @@ -179,7 +180,6 @@ class BaseChar: if has_animation: if not self.task.in_team()[0]: self.task.in_liberation = True - self.task.last_liberation = time.time() animated = True if time.time() - resonance_click_time > 6: self.task.in_liberation = False @@ -187,13 +187,17 @@ class BaseChar: self.task.next_frame() self.check_combat() continue + else: + self.task.in_liberation = False + now = time.time() self.check_combat() current_resonance = self.current_resonance() - if not self.resonance_available(current_resonance): + if not self.resonance_available(current_resonance) and ( + not has_animation or now - start > animation_min_duration): self.logger.debug(f'click_resonance not available break') break self.logger.debug(f'click_resonance resonance_available click {current_resonance}') - now = time.time() + if now - last_click > 0.1: if ((current_resonance == 0) and send_click) or last_op == 'resonance': self.task.click() @@ -293,6 +297,7 @@ class BaseChar: self.task.next_frame() if clicked: if self.task.wait_until(lambda: not self.task.in_team()[0], time_out=0.6): + self.task.in_liberation = True self.logger.debug(f'not in_team successfully casted liberation') else: self.task.in_liberation = False @@ -300,11 +305,11 @@ class BaseChar: return False start = time.time() while not self.task.in_team()[0]: - self.task.last_liberation = time.time() + self.task.in_liberation = True clicked = True if send_click: self.task.click(interval=0.1) - if self.task.last_liberation - start > 7: + if time.time() - start > 7: self.task.in_liberation = False self.task.raise_not_in_combat('too long a liberation, the boss was killed by the liberation') self.task.next_frame() diff --git a/src/char/Jinhsi.py b/src/char/Jinhsi.py index 08f00fe..39313ae 100644 --- a/src/char/Jinhsi.py +++ b/src/char/Jinhsi.py @@ -64,20 +64,18 @@ class Jinhsi(BaseChar): self.incarnation = False self.logger.info(f'handle_incarnation click_resonance start') start = time.time() - liberated = False while True: current_res = self.current_resonance() if current_res > 0 and not self.has_cd('resonance'): - self.logger.debug(f'handle_incarnation current_res: {current_res} breaking') + self.logger.info(f'handle_incarnation current_res: {current_res} breaking') if self.task.debug: self.task.screenshot(f'handle_incarnation e available') # self.send_resonance_key() break self.task.click(interval=0.1) - if not liberated or not self.task.in_team()[0]: - self.check_combat() + self.check_combat() - self.click_resonance(has_animation=True, send_click=True) + self.click_resonance(has_animation=True, animation_min_duration=1) if not self.click_echo(): self.task.click() # if self.task.debug: diff --git a/src/combat/CombatCheck.py b/src/combat/CombatCheck.py index c86cbb0..07c061a 100644 --- a/src/combat/CombatCheck.py +++ b/src/combat/CombatCheck.py @@ -17,7 +17,7 @@ class CombatCheck: self._in_combat = False self.boss_lv_template = None self.boss_lv_mask = None - self.in_liberation = False # return True + self._in_liberation = False # return True self.has_count_down = False self.last_out_of_combat_time = 0 self.last_combat_check = 0 @@ -26,7 +26,17 @@ class CombatCheck: self.boss_health = None self.out_of_combat_reason = "" self.combat_check_interval = 0.8 - self.last_liberation = 0 + self._last_liberation = 0 + + @property + def in_liberation(self): + return self._in_liberation + + @in_liberation.setter + def in_liberation(self, value): + self._in_liberation = value + if value: + self._last_liberation = time.time() def reset_to_false(self, recheck=False, reason=""): if self.should_check_monthly_card() and self.handle_monthly_card(): @@ -59,7 +69,7 @@ class CombatCheck: return False def recent_liberation(self): - return time.time() - self.last_liberation < 0.3 + return time.time() - self._last_liberation < 0.4 def check_count_down(self): count_down_area = self.box_of_screen_scaled(3840, 2160, 1820, 266, 2100, @@ -137,7 +147,6 @@ class CombatCheck: def in_combat(self, rechecked=False): if self.in_liberation or self.recent_liberation(): - self.last_combat_check = time.time() logger.debug('in liberation return True') return True if self._in_combat: @@ -219,7 +228,7 @@ class CombatCheck: texts = self.ocr(box=self.box_of_screen(1269 / 3840, 10 / 2160, 2533 / 3840, 140 / 2160, hcenter=True), target_height=540, name='boss_lv_text') boss_lv_texts = find_boxes_by_name(texts, - [re.compile(r'(?i)^L[V].*')]) + [re.compile(r'(?i)^L[Vv].*')]) if len(boss_lv_texts) > 0: logger.debug(f'boss_lv_texts: {boss_lv_texts}') self.boss_lv_box = boss_lv_texts[0] diff --git a/src/task/BaseCombatTask.py b/src/task/BaseCombatTask.py index 63a1585..c008c2a 100644 --- a/src/task/BaseCombatTask.py +++ b/src/task/BaseCombatTask.py @@ -72,7 +72,7 @@ class BaseCombatTask(BaseWWTask, FindFeature, OCR, CombatCheck): raise e except NotInCombatException as e: logger.info(f'combat_once out of combat break {e}') - # self.screenshot(f'combat_once out of combat break {self.out_of_combat_reason}') + # self.screenshot(f'combat_once_ooc {self.out_of_combat_reason}') break self.wait_in_team_and_world(time_out=10) self.sleep(1)