Ejemplo n.º 1
0
    def _enhance_choose_simple(self, current_index=0, skip_first_screenshot=True):
        """
        Description:
            Simplified _enhance_choose focuses only on
            appearance of info_bars, stat gauge is ignored
            Minimum 2 times before swiping, if maximum of
            4 times is detected, a forced swipe is initiated
            A maximum of 4 ships will be checked to account
            for 'in battle' status, hard-coded otherwise if
            desired can be configurable

        Pages:
            in: page_ship_enhance, without info_bar
            out: EQUIP_CONFIRM
        """
        end_activate_timer = Timer(2, count=2) if self.config.DEVICE_CONTROL_METHOD == 'minitouch' else Timer(2, count=1)
        next_timer = Timer(2, count=1).start()
        trapped_timer = Timer(15, count=3).start()
        trapped = False
        while 1:
            if skip_first_screenshot:
                skip_first_screenshot = False
            else:
                self.device.screenshot()

            if self.appear(EQUIP_CONFIRM, offset=(30, 30)):
                return True, current_index

            if not end_activate_timer.reached_and_reset():
                continue

            ensured = self.equip_sidebar_ensure(index=4)
            if ensured:
                self.wait_until_appear(ENHANCE_RECOMMEND, offset=(5, 5), skip_first_screenshot=True)
            else:
                continue

            if trapped or self.info_bar_count():
                if trapped or next_timer.reached():
                    logger.info('Unable to enhance this ship, swipe to next')
                    swiped = self.equip_view_next(check_button=ENHANCE_RECOMMEND)
                    self.ensure_no_info_bar()
                    if not swiped or current_index >= 3:
                        logger.info('Cannot swipe or ship check threshold reached, exiting current category')
                        return False, current_index
                    else:
                        next_timer.reset()
                        trapped_timer.reset()
                        trapped = False
                        logger.info(f'Try next ship: {3 - current_index}/3 remaining until give up')
                        current_index += 1
                        continue

            if not trapped_timer.reached_and_reset() and self.appear_then_click(ENHANCE_RECOMMEND, offset=(5, 5), interval=2):
                self.device.sleep(0.3)
                self.device.click(ENHANCE_CONFIRM)
            else:
                logger.warning('Current status appears trapped, will force swipe to next ship')
                trapped = True
Ejemplo n.º 2
0
    def _enhance_choose_simple(self, skip_first_screenshot=True):
        """
        Description:
            Simplified _enhance_choose focuses only on
            appearance of info_bars, stat gauge is ignored
            Minimum 2 times before swiping, if maximum of
            6 times is detected, a forced swipe is initiated
            Starting from the first failed enhance,
            next 3 adjacent ships are checked before giving up

        Pages:
            in: page_ship_enhance, without info_bar
            out: EQUIP_CONFIRM
        """
        end_activate_timer = Timer(2, count=2)
        next_timer = Timer(2, count=1).start()
        next_count = 0
        trapped_timer = Timer(25, count=5).start()
        trapped = False
        while 1:
            if skip_first_screenshot:
                skip_first_screenshot = False
            else:
                self.device.screenshot()

            if self.appear(EQUIP_CONFIRM, offset=(30, 30)):
                return True

            if not end_activate_timer.reached_and_reset():
                continue

            ensured = self.equip_sidebar_ensure(index=4)
            if ensured:
                self.wait_until_appear(ENHANCE_RECOMMEND, offset=(5, 5), skip_first_screenshot=True)
            else:
                continue

            if trapped or self.info_bar_count():
                if trapped or next_timer.reached():
                    logger.info('Unable to enhance this ship, swipe to next')
                    swiped = self.equip_view_next(check_button=ENHANCE_RECOMMEND)
                    self.ensure_no_info_bar()
                    if not swiped or next_count >= 3:
                        return False
                    else:
                        next_timer.reset()
                        trapped_timer.reset()
                        trapped = False
                        logger.info(f'Try next ship: {3 - next_count}/3 remaining until give up')
                        next_count += 1
                        continue

            if not trapped_timer.reached_and_reset() and self.appear_then_click(ENHANCE_RECOMMEND, offset=(5, 5), interval=2):
                self.device.sleep(0.3)
                self.device.click(ENHANCE_CONFIRM)
            else:
                logger.warning('Current status appears trapped, will force swipe to next ship')
                trapped = True
Ejemplo n.º 3
0
    def globe_focus_to(self, zone):
        """
        Args:
            zone (str, int, Zone): Name in CN/EN/JP/TW, zone id, or Zone instance.

        Pages:
            in: IN_GLOBE
            out: IN_GLOBE, zone selected, ZONE_ENTRANCE
        """
        zone = self.name_to_zone(zone)
        logger.info(f'Globe focus_to: {zone.zone_id}')

        interval = Timer(2, count=2)
        while 1:
            if self.handle_zone_pinned():
                self.globe_update()
                continue

            self.globe_in_sight(zone)
            if interval.reached_and_reset():
                self.device.click(self.zone_to_button(zone))
                self.device.sleep(0.3)

            self.globe_update()

            if self.is_zone_pinned():
                if self.get_globe_pinned_zone() == zone:
                    logger.attr('Globe_pinned', zone)
                    break
Ejemplo n.º 4
0
    def globe_focus_to(self, zone):
        """
        Args:
            zone (str, int, Zone): Name in CN/EN/JP, zone id, or Zone instance.

        Pages:
            in: IN_GLOBE
            out: IN_GLOBE, zone selected, ZONE_ENTRANCE
        """
        zone = self.name_to_zone(zone)
        logger.info(f'Globe focus_to: {zone}')

        interval = Timer(2, count=2)
        while 1:
            if self.handle_zone_pinned():
                self.globe_update()
                continue

            self.globe_in_sight(zone)
            if interval.reached_and_reset():
                self.device.click(self.zone_to_button(zone))
                self.device.sleep(0.3)

            self.globe_update()

            if self.is_zone_pinned():
                location = self.screen2globe([ZONE_PINNED.button[:2]
                                              ])[0] + (0, 5)
                pinned_zone = self.camera_to_zone(location)
                if pinned_zone == zone:
                    logger.attr('Globe_pinned', pinned_zone)
                    break
Ejemplo n.º 5
0
    def _enhance_choose_simple(self, skip_first_screenshot=True):
        """
        Info:
            Simplified version of the legacy _enhance_choose
            Performs enhancements solely based on appearance
            of info bars

        Pages:
            in: page_ship_enhance, without info_bar
            out: EQUIP_CONFIRM
        """
        end_activate_timer = Timer(2, count=2)
        attempt_count = 0
        next_count = 0
        while 1:
            if skip_first_screenshot:
                skip_first_screenshot = False
            else:
                self.device.screenshot()

            if self.appear(EQUIP_CONFIRM, offset=(30, 30)):
                return True

            if not end_activate_timer.reached_and_reset():
                continue

            ensured = self.equip_sidebar_ensure(index=4)
            if ensured:
                self.wait_until_appear(ENHANCE_RECOMMEND,
                                       offset=(5, 5),
                                       skip_first_screenshot=True)
            else:
                continue

            if self.info_bar_count():
                if attempt_count >= 1:
                    logger.info('Unable to enhance this ship, swipe to next')
                    swiped = self.equip_view_next(
                        check_button=ENHANCE_RECOMMEND)
                    self.ensure_no_info_bar()
                    if not swiped or next_count >= 3:
                        return False
                    else:
                        attempt_count = 0
                        logger.info(
                            f'Try next ship: {3 - next_count}/3 remaining until give up'
                        )
                        next_count += 1
                        continue
                attempt_count += 1

            if self.appear_then_click(ENHANCE_RECOMMEND,
                                      offset=(5, 5),
                                      interval=2):
                self.device.sleep(0.3)
                self.device.click(ENHANCE_CONFIRM)
Ejemplo n.º 6
0
    def _enhance_choose(self, skip_first_screenshot=True):
        """
        Pages:
            in: page_ship_enhance, without info_bar
            out: EQUIP_CONFIRM
        """
        end_activate_timer = Timer(2, count=2)
        while 1:
            if skip_first_screenshot:
                skip_first_screenshot = False
            else:
                self.device.screenshot()

            if self.appear(EQUIP_CONFIRM, offset=(30, 30)):
                return True

            if not end_activate_timer.reached_and_reset():
                continue

            self.equip_sidebar_ensure(index=4)
            self.wait_until_appear(ENHANCE_RECOMMEND, offset=(5, 5), skip_first_screenshot=True)

            status = color_bar_percentage(self.device.image, area=ENHANCE_RELOAD.area, prev_color=(231, 178, 74))
            logger.attr('Reload_enhanced', f'{int(status * 100)}%')
            choose = np.sum(np.array(self.device.image.crop(ENHANCE_FILLED.area)) > 200) > 100

            if self.info_bar_count():
                if status > 0.98:
                    logger.info('Fully enhanced for this ship')
                    swiped = self.equip_view_next(check_button=ENHANCE_RECOMMEND)
                    self.ensure_no_info_bar()
                    if not swiped:
                        return False
                    continue
                else:
                    if choose:
                        logger.info('Unable to enhance this ship')
                        swiped = self.equip_view_next(check_button=ENHANCE_RECOMMEND)
                        self.ensure_no_info_bar()
                        if not swiped:
                            return False
                        continue
                    else:
                        logger.info('Enhancement material exhausted')
                        return False

            if self.appear_then_click(ENHANCE_RECOMMEND, offset=(5, 5), interval=2):
                self.device.sleep(0.3)
                self.device.click(ENHANCE_CONFIRM)
Ejemplo n.º 7
0
    def _guild_operations_dispatch(self, skip_first_screenshot=True):
        """
        Executes the dispatch sequence

        Pages:
            in: GUILD_OPERATIONS_DISPATCH
            out: GUILD_OPERATIONS_MAP
        """
        confirm_timer = Timer(1.5, count=3).start()
        add_timer = Timer(1.5, count=3)
        close_timer = Timer(3, count=6).start()
        while 1:
            if skip_first_screenshot:
                skip_first_screenshot = False
            else:
                self.device.screenshot()

            if self.appear_then_click(GUILD_DISPATCH_QUICK,
                                      offset=(20, 20),
                                      interval=3):
                confirm_timer.reset()
                close_timer.reset()
                continue

            # Pseudo interval timer for template match_result calls
            if not add_timer.started() or add_timer.reached():
                sim, point = TEMPLATE_OPERATIONS_ADD.match_result(
                    self.device.image)
                if sim > 0.85:
                    # Use small area to reduce random click point
                    button = area_offset(area=(-2, -2, 24, 12), offset=point)
                    dispatch_add = Button(area=button,
                                          color=(),
                                          button=button,
                                          name='GUILD_DISPATCH_ADD')
                    self.device.click(dispatch_add)
                    confirm_timer.reset()
                    add_timer.reset()
                    close_timer.reset()
                    continue

            if self.appear(GUILD_DISPATCH_EMPTY, interval=3):
                self.device.click(GUILD_DISPATCH_RECOMMEND)
                confirm_timer.reset()
                close_timer.reset()
                continue

            if self.appear_then_click(GUILD_DISPATCH_FLEET,
                                      offset=(20, 20),
                                      interval=3):
                confirm_timer.reset()
                close_timer.reset()
                continue

            if self.handle_popup_confirm('GUILD_DISPATCH'):
                # Explicit click since GUILD_DISPATCH_FLEET
                # does not automatically turn into
                # GUILD_DISPATCH_IN_PROGRESS after confirm
                self.device.sleep((0.5, 0.8))
                self.device.click(GUILD_DISPATCH_CLOSE)
                confirm_timer.reset()
                close_timer.reset()
                continue

            if self.appear(GUILD_DISPATCH_IN_PROGRESS):
                # Independent timer used instead of interval
                # Since can appear if at least 1 fleet already
                # dispatched, don't want to exit prematurely
                if close_timer.reached_and_reset():
                    self.device.click(GUILD_DISPATCH_CLOSE)
                    confirm_timer.reset()
                    continue

            # End
            if self.appear(GUILD_OPERATIONS_ACTIVE_CHECK):
                if not self.info_bar_count() and confirm_timer.reached():
                    break
            else:
                confirm_timer.reset()