From eb28485d5df22c20c8bfc9c7df5c4e6ef193152a Mon Sep 17 00:00:00 2001 From: X-Zero-L <98764734+X-Zero-L@users.noreply.github.com> Date: Wed, 30 Aug 2023 00:58:32 +0800 Subject: [PATCH] Fix: support (#64) * Fix: support * Upd: support * Upd: support * Upd: support * Upd: support * Upd: support * Upd: support * Upd: support --------- Co-authored-by: LmeSzinc --- assets/support/selected_character_arrow.png | Bin 0 -> 668 bytes tasks/combat/support.py | 170 ++++++++++++++++++-- 2 files changed, 161 insertions(+), 9 deletions(-) create mode 100644 assets/support/selected_character_arrow.png diff --git a/assets/support/selected_character_arrow.png b/assets/support/selected_character_arrow.png new file mode 100644 index 0000000000000000000000000000000000000000..8e079c820c33a370a4cffc69aef0c4dde00c0cc2 GIT binary patch literal 668 zcmV;N0%QG&P)}>`&0007GNklzu9h;NR^W0iTo-|HSA=0fh_aHwz97ky$p_KNY_ z?N-Om=X1GUuhV$EM-<8o)=eQNjE{LXK~Mk!6ex(Sr35IUir6p4Pp8wzKI{?mYPjmC z@<(UR3E+(pMcB`j^)X0_$LCuJ`9ze;LXH~ldZ9-+3NNcX)>IqHLT?bZt?&(D5fvIi zN>xA)o{3GeOkGw)l7nz>k*?83ULZ<{M#qO0E#rw0_hJ^_cv}sf z^V%Hn5~Q}|gk#DNNq$sHl6Y(K%!KKfX4YU7?*l&`MIu1U%T~iPuebDGy5C5M7V#oy z!v$+s)dKT08cRF7mco$UGsx#%Pi)jW-}U?w#(T=FX=}4F&U=plqHSrEyq$UNi?@O^ zsx^B}w$_YIx3)yD%y5pMMstokzLp9!<*_13OD`yY zg}F8~yFc{c6bxP&i*%A?W~s0Ek`lCm(-}z3j 0.75 + else None + ) + + +class NextSupportCharacter: + _arrow = ArrowWrapper( + name="NextSupportCharacterArrow", + share=Button( + file='./assets/support/selected_character_arrow.png', + area=None, + search=None, + color=None, + button=None, + ) + ) + _crop_area = (290, 115, 435, 634) + + def __init__(self, screenshot): + self.name = "SupportCharacterArrow" + self.screenshot = crop(screenshot, NextSupportCharacter._crop_area) + self.arrow_center = self._find_center() + self.button = self._get_next_support_character_button() + + def __bool__(self): + return self.button is not None + + def _find_center(self): + center = NextSupportCharacter._arrow.find_center(self.screenshot) + center = get_position_in_original_image( + center, NextSupportCharacter._crop_area) if center else None + return center + + def _get_next_support_character_button(self): + area = (self.arrow_center[0] - 200, min(self.arrow_center[1] + 65, 615), self.arrow_center[0] + 10, min( + self.arrow_center[1] + 80, 620)) if self.arrow_center and self.arrow_center[1] < 510 else None + return ButtonWrapper( + name="NextSupportCharacterButton", + share=Button( + file='./assets/support/selected_character_arrow.png', + area=area, + search=area, + # if next support was selected, the average color of the button will larger than 220 + color=(220, 220, 220), + button=area, + ) + ) if self.arrow_center and self.arrow_center[1] < 510 else None + + class SupportListScroll(Scroll): def cal_position(self, main): """ @@ -130,11 +205,18 @@ class CombatSupport(UI): return True # Click - if self.appear(COMBAT_TEAM_SUPPORT, interval=2): + if self.appear(COMBAT_TEAM_SUPPORT, interval=1): self.device.click(COMBAT_TEAM_SUPPORT) self.interval_reset(COMBAT_TEAM_SUPPORT) continue - if self.appear(COMBAT_SUPPORT_LIST, interval=2): + if self.appear(CANCEL_POPUP, interval=1): + logger.warning( + "selected identical character, trying select another") + self._cancel_popup() + self._select_next_support() + self.interval_reset(CANCEL_POPUP) + continue + if self.appear(COMBAT_SUPPORT_LIST, interval=1): if support_character_name != "FirstCharacter": self._search_support( support_character_name) # Search support @@ -167,7 +249,6 @@ class CombatSupport(UI): logger.info("Searching support") skip_first_screenshot = False - character = None while 1: if skip_first_screenshot: skip_first_screenshot = False @@ -175,7 +256,8 @@ class CombatSupport(UI): self.device.screenshot() if not support_character_name.startswith("Trailblazer"): - character = SupportCharacter(support_character_name, self.device.image) + character = SupportCharacter( + support_character_name, self.device.image) else: character = SupportCharacter(f"Stelle{support_character_name[11:]}", self.device.image) or SupportCharacter( @@ -223,3 +305,73 @@ class CombatSupport(UI): self.device.click(character) interval.reset() continue + + def _cancel_popup(self): + """ + Pages: + in: CANCEL_POPUP + out: COMBAT_SUPPORT_LIST + """ + logger.hr("Combat support cancel popup") + skip_first_screenshot = True + + while 1: + if skip_first_screenshot: + skip_first_screenshot = False + else: + self.device.screenshot() + + # End + if self.appear(COMBAT_SUPPORT_LIST): + logger.info("Popup canceled") + return + + if self.appear(CANCEL_POPUP): + self.device.click(CANCEL_POPUP) + continue + + def _select_next_support(self): + """ + Pages: + in: COMBAT_SUPPORT_LIST + out: COMBAT_SUPPORT_LIST + """ + skip_first_screenshot = True + scroll = SupportListScroll(area=COMBAT_SUPPORT_LIST_SCROLL.area, color=(194, 196, 205), + name=COMBAT_SUPPORT_LIST_SCROLL.name) + interval = Timer(1) + next_support = None + if scroll.appear(main=self): + while 1: + if skip_first_screenshot: + skip_first_screenshot = False + else: + self.device.screenshot() + + # End + if next_support and self._next_support_selected(next_support): + return + + if interval.reached(): + next_support = NextSupportCharacter(self.device.image) + if next_support: + logger.info("Next support found, clicking") + self.device.click(next_support.button) + elif not scroll.at_bottom(main=self): + scroll.next_page(main=self, page=0.4) + else: + logger.warning("No more support") + return + + interval.reset() + continue + + def _next_support_selected(self, next_support: NextSupportCharacter): + """ + Returns: + bool: True if selected else False + """ + if self.match_color(next_support.button, threshold=20): + logger.info("Next support selected") + return True + return False