Exemplo n.º 1
0
    def unable_handler(self, coords):
        """
        Method called when the path to the boss fleet is obstructed by mobs: it procedes to switch targets to the mobs
        which are blocking the path.
        
        Args:
            coords (list): coordinate_x, coordinate_y. These coordinates describe the boss location.
        """
        Logger.log_debug("Unable to reach boss function started.")
        closest_to_boss = self.get_closest_target(self.blacklist, coords)

        Utils.touch(closest_to_boss)
        Utils.wait_update_screen(1)

        if Utils.find("combat/alert_unable_reach"):
            Logger.log_warning("Unable to reach next to boss.")
            self.blacklist.append(closest_to_boss)

            while True:
                closest_enemy = self.get_closest_target(self.blacklist)
                Utils.touch(closest_enemy)
                Utils.update_screen()

                if Utils.find("combat/alert_unable_reach"):
                    self.blacklist.append(closest_to_boss)
                else:
                    break

            self.movement_handler(closest_enemy)
            self.battle_handler()
            return
        else:
            self.movement_handler(closest_to_boss)
            self.battle_handler()
            return
Exemplo n.º 2
0
    def select_daily(self):

        Utils.wait_update_screen(1)

        # while True:

        if not Utils.find("combat/daily_attempts"):
            Utils.touch_randomly(self.region["center_daily"])
            Logger.log_info("Found daily challenge.")
            Utils.script_sleep(1)
            Utils.update_screen()
            # continue
        if Utils.find("combat/daily_attempts"):
            Utils.touch_randomly(self.region["select_daily"])
            Logger.log_info("Select daily challenge.")
            Utils.script_sleep(1)
            Utils.update_screen()
            # continue
        if Utils.find("combat/daily_out"):
            Logger.log_info("You're out of daily stage challenges.")
            Utils.touch_randomly(self.region["menu_nav_back"])
            # return True
        Utils.wait_update_screen(1)

        self.start_daily()
Exemplo n.º 3
0
    def retreat_handler(self):
        """ Retreats if necessary.
        """
        while True:
            Utils.wait_update_screen(2)

            if Utils.find("combat/alert_morale_low"):
                Utils.touch_randomly(self.region['close_info_dialog'])
                self.exit = 3
                continue
            if Utils.find("menu/button_sort"):
                Utils.touch_randomly(self.region['close_info_dialog'])
                self.exit = 4
                continue
            if Utils.find("combat/menu_formation"):
                Utils.touch_randomly(self.region["menu_nav_back"])
                continue
            if Utils.find("combat/button_retreat"):
                Utils.touch_randomly(self.region['retreat_button'])
                continue
            if Utils.find("menu/button_confirm"):
                Utils.touch_randomly(self.region['dismiss_commission_dialog'])
                continue
            if Utils.find("menu/attack"):
                if self.exit != 1 and self.exit != 2 and self.exit != 5:
                    Logger.log_msg("Retreating...")
                return
Exemplo n.º 4
0
    def refill_dorm(self):
        """
        This method refill the dorm supplies with 10 oxy cola (150 minutes) if the supplies bar is empty.
        """

        Utils.script_sleep(5)
        Logger.log_debug("Refilling dorm supplies if empty.")

        while True:
            Utils.wait_update_screen(1)
            if Utils.find("headquarters/dorm_summary_confirm_button"):
                # dismiss dorm summary, if any
                Utils.touch_randomly(self.region["confirm_dorm_summary"])
                continue
            if Utils.find("headquarters/give_food_button"):
                # dismiss notification by tapping ignore
                Utils.touch_randomly(self.region["ignore_give_food_button"])
                continue
            if Utils.find("headquarters/supplies_bar_empty"):
                # proceed to refill
                Utils.touch_randomly(self.region["supplies_bar"])
                Utils.script_sleep(1)
                # tap oxy cola ten times
                for i in range(0, 10):
                    Utils.touch_randomly(self.region["oxy_cola"])
                Logger.log_msg("Refilled dorm supplies.")
                # tap out
                Utils.touch_randomly(self.region["exit_snacks_menu"])
            else:
                # exit loop
                Logger.log_debug("Ending refill loop.")
                break
Exemplo n.º 5
0
    def combat_handler(self):
        Logger.log_msg("Starting combat.")
        Utils.touch_randomly(self.region['menu_combat_start'])
        Utils.script_sleep(4)

        while True:
            Utils.wait_update_screen(1)

            if Utils.find("combat/combat_pause", 0.7):
                Logger.log_debug("In battle.")
                Utils.script_sleep(5)
                continue
            if Utils.find("combat/menu_touch2continue"):
                Utils.touch_randomly(self.region['tap_to_continue'])
                continue
            if Utils.find("menu/item_found"):
                Utils.touch_randomly(self.region['tap_to_continue'])
                Utils.script_sleep(1)
                continue
            if Utils.find("combat/button_confirm"):
                Logger.log_msg("Combat ended.")
                Utils.touch_randomly(self.region['combat_end_confirm'])
                self.stats.increment_combat_done()
                Utils.script_sleep(1)
                return
            if Utils.find("combat/commander"):
                # prevents fleet with submarines from getting stuck at combat end screen
                Utils.touch_randomly(self.region["combat_dismiss_surface_fleet_summary"])
                Utils.script_sleep(1)
                continue
            if Utils.find("combat/menu_combat_finished"):
                Utils.touch_randomly(self.region['dismiss_combat_finished'])
                Utils.script_sleep(1)
                continue
Exemplo n.º 6
0
    def feed_snacks(self):
        Utils.touch_randomly(self.region["supplies_bar"])
        Utils.script_sleep(1)
        Utils.update_screen()
        alert_found = Utils.find("menu/alert_close")
        retry_counter = 0
        while retry_counter < 40 and self.get_dorm_bar_empty(
                self.stop_feed_threshold) and not alert_found:
            retry_counter += 1
            find_food = False
            for idx in self.supply_order:
                region = self.supply_region[idx]
                if Utils.get_region_color_average(
                        region)[2] < self.supply_whiteout_threshold:
                    Utils.touch_randomly(region)
                    find_food = True
                    break
            if not find_food:
                break
            else:
                Utils.wait_update_screen(0.5)
                alert_found = Utils.find("menu/alert_close")

        if alert_found:
            Utils.touch_randomly(alert_found)
            Utils.wait_update_screen(1)
        # tap out
        Utils.touch_randomly(self.region["exit_snacks_menu"])
Exemplo n.º 7
0
    def refill_dorm(self):
        """
        This method refill the dorm supplies with 10 oxy cola (150 minutes) if the supplies bar is empty.
        """

        Utils.script_sleep(5)
        Logger.log_debug("Refilling dorm supplies if empty.")

        while True:
            Utils.wait_update_screen(1)
            if Utils.find("headquarters/dorm_summary_confirm_button"):
                # dismiss dorm summary, if any
                Utils.touch_randomly(self.region["confirm_dorm_summary"])
                continue
            if Utils.find("headquarters/give_food_button"):
                # dismiss notification by tapping ignore
                Utils.touch_randomly(self.region["ignore_give_food_button"])
                continue
            if self.get_dorm_bar_empty(self.start_feed_threshold, True):
                # proceed to refill
                self.feed_snacks()
                break
            else:
                # exit loop
                Logger.log_debug("Ending refill loop.")
                break
Exemplo n.º 8
0
    def start_commission(self):
        Logger.log_debug("Starting commission.")
        tapped_recommend = False

        while True:
            Utils.update_screen()

            if self.commission_start_attempts > 10:
                Logger.log_warning("Failed to start commission.")
                Utils.touch_randomly(self.region["dismiss_message"])
                break
            if Utils.find("commission/alert_begun"):
                Logger.log_msg("Successfully started commission.")
                Utils.touch_randomly(self.region["dismiss_message"])
                self.stats.increment_commissions_started()
                break
            if Utils.find("menu/button_confirm"):
                Logger.log_debug("Found commission oil warning message.")
                Utils.touch_randomly(self.region["oil_warning"])
                continue
            if tapped_recommend and Utils.find("commission/button_ready"):
                Logger.log_debug("Found commission start button.")
                Utils.touch_randomly(self.region["commission_start"])
                tapped_recommend = False
                continue
            if Utils.find("commission/button_recommend"):
                Logger.log_debug("Found commission recommend button.")
                Utils.touch_randomly(self.region["commission_recommend"])
                tapped_recommend = True
                self.commission_start_attempts += 1
                continue

        Utils.wait_update_screen(1)
        return not (Utils.find("commission/commissions_full")
                    or self.commission_start_attempts > 10)
Exemplo n.º 9
0
    def event_logic_wrapper(self):
        """Method that fires off the necessary child methods that encapsulates
        the entire action of completing an event
        """
        if self.config.events['name'] == 'Crosswave' and not self.finished:
            Logger.log_msg("Opening event menu.")

            while not Utils.find("menu/operation"):
                Utils.find_and_touch("event/crosswave/menu_button")
                Utils.wait_update_screen(1)

            Logger.log_msg("Event levels: " + str(self.levels))

            while ('EX' in self.levels):
                Utils.update_screen()
                if Utils.find("event/crosswave/ex_completed", 0.98):
                    Logger.log_info("No more EX combats to do.")
                    break

                Utils.touch_randomly(self.region['crosswave_ex'])
                if self.pre_combat_handler():
                    self.combat_handler()
                    Logger.log_msg("Finished EX crosswave combat.")
            while ('H' in self.levels):
                Utils.update_screen()
                if Utils.find("event/crosswave/hard_completed"):
                    Logger.log_info("No more hard combats to do.")
                    break

                Utils.touch_randomly(self.region['crosswave_hard'])
                if self.pre_combat_handler():
                    self.combat_handler()
                    Logger.log_msg("Finished hard crosswave combat.")
            while ('N' in self.levels):
                Utils.update_screen()
                if Utils.find("event/crosswave/normal_completed"):
                    Logger.log_info("No more normal combats to do.")
                    break

                Utils.touch_randomly(self.region['crosswave_normal'])
                if self.pre_combat_handler():
                    self.combat_handler()
                    Logger.log_msg("Finished normal crosswave combat.")
            while ('E' in self.levels):
                Utils.update_screen()
                if Utils.find("event/crosswave/easy_completed"):
                    Logger.log_info("No more easy combats to do.")
                    break

                Utils.touch_randomly(self.region['crosswave_easy'])
                if self.pre_combat_handler():
                    self.combat_handler()
                    Logger.log_msg("Finished easy crosswave combat.")

            Logger.log_msg("Finished all event combats, going back to menu.")

            Utils.menu_navigate("menu/button_battle")
            self.finished = True
            return
Exemplo n.º 10
0
 def select_ships(self):
     Logger.log_msg("Selecting ships for retirement.")
     Utils.touch_randomly(self.region['button_batch_retire'])
     Utils.wait_update_screen(0.7)
     if Utils.find("retirement/no_batch", similarity=0.9):
         for i in range(0, 7):
             Utils.touch_randomly(self.region['select_ship_{}'.format(i)])
     else:
         Utils.touch_randomly(self.region['close_batch_retire'])
Exemplo n.º 11
0
    def skill_levelling(self):
        """
        This method ensures that the skills currently being levelled continue to do so.
        The skillbooks used are the ones indicated by the SkillBookTier setting in the config.ini file.
        """
        Utils.script_sleep(5)
        Logger.log_msg("Levelling the skills of the previously chosen ships.")

        while True:
            Utils.wait_update_screen(1)

            if Utils.find_and_touch("menu/button_confirm"):
                Logger.log_msg("Starting/ending skill levelling session.")
                Utils.script_sleep(3.5)
                continue
            if Utils.find("headquarters/skill_exp_gain"):
                if Utils.find_and_touch(
                        "headquarters/t{}_offense_skillbook".format(
                            self.config.academy["skill_book_tier"]), 0.99):
                    # levelling offesinve skill
                    Logger.log_msg("Selected T{} offensive skill book.".format(
                        self.config.academy["skill_book_tier"]))
                    self.stats.increment_offensive_skillbook_used()
                elif Utils.find_and_touch(
                        "headquarters/t{}_defense_skillbook".format(
                            self.config.academy["skill_book_tier"]), 0.99):
                    # levelling defesinve skill
                    Logger.log_msg("Selected T{} defensive skill book.".format(
                        self.config.academy["skill_book_tier"]))
                    self.stats.increment_defensive_skillbook_used()
                elif Utils.find_and_touch(
                        "headquarters/t{}_support_skillbook".format(
                            self.config.academy["skill_book_tier"]), 0.99):
                    # levelling support skill
                    Logger.log_msg("Selected T{} support skill book.".format(
                        self.config.academy["skill_book_tier"]))
                    self.stats.increment_support_skillbook_used()
                else:
                    Logger.log_warning(
                        "Skillbook specified not found. Cancelling lesson.")
                    Utils.touch_randomly(self.region["cancel_lesson_button"])
                    continue
                Utils.script_sleep(1)
                Utils.touch_randomly(self.region["start_lesson_button"])
                continue
            if Utils.find("headquarters/tactical_class"):
                # exit tactical class
                Utils.touch_randomly(self.region["button_back"])
                Logger.log_msg("All classes have started.")
                Utils.script_sleep(1)
                break
Exemplo n.º 12
0
 def research_cycle(self):
     Utils.wait_update_screen(1)
     if not self.config.research['8Hours'] and Utils.find(
             "research/8h", 0.99):
         return False
     if not self.config.research['6Hours'] and Utils.find(
             "research/6h", 0.99):
         return False
     if not self.config.research['5Hours'] and Utils.find(
             "research/5h", 0.99):
         return False
     if not self.config.research['4Hours'] and Utils.find(
             "research/4h", 0.99):
         return False
     if not self.config.research['2Hours30Minutes'] and Utils.find(
             "research/2_30h", 0.99):
         return False
     if not self.config.research['2Hours'] and Utils.find(
             "research/2h", 0.99):
         return False
     if not self.config.research['1Hour30Minutes'] and Utils.find(
             "research/1_30h", 0.99):
         return False
     if not self.config.research['1Hour'] and Utils.find(
             "research/1h", 0.99):
         return False
     if not self.config.research['30Minutes'] and Utils.find(
             "research/30m", 0.99):
         return False
     if self.config.research['WithoutRequirements'] and not Utils.find(
             "research/nothing", 0.99):
         return False
     if not self.config.research['AllowConsumingCoins'] and Utils.find(
             "research/coins", 0.99):
         return False
     if not self.config.research['AllowConsumingCubes'] and Utils.find(
             "research/cubes", 0.99):
         return False
     if self.config.research[
             'AwardMustContainPRBlueprint'] and not Utils.find(
                 "research/PRBlueprint"):
         return False
     if not self.config.research['AllowFreeProjects'] and Utils.find(
             "research/free", 0.99):
         return False
     if not self.config.research['12Hours'] and Utils.find(
             "research/12h", 0.99):
         return False
     else:
         return True
Exemplo n.º 13
0
    def start_project(self):
        Utils.touch_randomly(self.region['commence_tab'])
        Utils.wait_update_screen(1)
        #solution for projects that don't require confirmation.
        if Utils.find("research/terminate", 0.99):
            return True

        if Utils.find("research/confirm", 0.99):
            Utils.touch_randomly(self.region['confirm_tab'])
            Utils.wait_update_screen(1)
            if Utils.find("research/terminate", 0.99):
                return True

            else:
                return False
Exemplo n.º 14
0
    def pre_combat_handler(self):
        """Handles pre-combat stuff like fleet selection and starts combat_handler function.
        """
        while True:
            Utils.wait_update_screen(1)

            if Utils.find("combat/menu_select_fleet"):
                Logger.log_debug("Found event fleet go button.")
                Utils.touch_randomly(self.region['menu_fleet_go'])
                continue
            if Utils.find("menu/alert_close"):
                Utils.touch_randomly(self.region['close_info_dialog'])
                continue
            if Utils.find("combat/menu_formation"):
                Logger.log_debug("Found formation asset.")
                return True
Exemplo n.º 15
0
    def reach_map(self):
        """
        Method to move to the world where the specified map is located.
        Only works with worlds added to assets (from 1 to 8) and some event maps.
        Also checks if hard mode is enabled.
        """
        _map = 0

        if not self.chapter_map[0].isdigit():
            letter = self.chapter_map[2:3]
            event_maps = ['A', 'B', 'C', 'D']

            Utils.touch_randomly(self.region['event_button'])
            Utils.wait_update_screen(1)
            # Utils.script_sleep(1)
            # Utils.touch_randomly(self.region['visitors_red'])
            # Utils.wait_update_screen(1)
            # Utils.script_sleep(1)

            if event_maps.index(letter) < 2 and Utils.find("menu/button_normal_mode", 0.8) or \
               event_maps.index(letter) > 1 and not Utils.find("menu/button_normal_mode", 0.8):
                Utils.touch_randomly(self.region['normal_mode_button'])
                Utils.wait_update_screen(1)
        else:
            for x in range(1, 14):
                if Utils.find("maps/map_{}-1".format(x), 0.99):
                    _map = x
                    break

            if _map != 0:
                taps = int(self.chapter_map.split("-")[0]) - _map
                for x in range(0, abs(taps)):
                    if taps >= 1:
                        Utils.touch_randomly(self.region['map_nav_right'])
                        Logger.log_debug("Swiping to the right")
                        Utils.wait_update_screen()
                    else:
                        Utils.touch_randomly(self.region['map_nav_left'])
                        Logger.log_debug("Swiping to the left")
                        Utils.wait_update_screen()

        if Utils.find('maps/map_{}'.format(self.chapter_map), 0.99):
            Logger.log_msg("Successfully reached the world where map is located.")
        else:
            Logger.log_error("Cannot find the specified map, please move to the world where it's located.")
            while not Utils.find('maps/map_{}'.format(self.chapter_map), 0.99):
                Utils.wait_update_screen(1)
Exemplo n.º 16
0
    def research_logic_wrapper(self):
        Logger.log_msg("Found lab alert.")
        Utils.touch_randomly(self.region["lab_tab"])

        while True:
            Utils.wait_update_screen(1)

            if self.config.research['enabled'] and Utils.find(
                    "research/research_academy_alert", 0.99):
                Logger.log_msg("Found research academy alert.")
                Utils.touch_randomly(self.region['research_academy'])
                Utils.script_sleep(1)
                Logger.log_msg("Searching for completed research.")

                if not self.collecting_research():
                    Logger.log_msg("Did not found any completed research.")

                started = False
                Logger.log_msg("Searching for project that matches config.")
                for research_loop in range(0, 5):
                    if not self.research_cycle():
                        Utils.touch_randomly(self.region['right_arrow'])
                    else:
                        if self.start_project() == True:
                            Logger.log_success("Project started.")
                            started = True
                            break
                        else:
                            Logger.log_warning(
                                "Unable to start project. Finding a new one.")
                            Utils.touch_randomly(self.region['right_arrow'])

                if started == False:
                    Logger.log_error(
                        "Unable to find project that matches current configuration."
                    )

                Logger.log_msg("Going back to main menu.")
            else:
                Logger.log_msg(
                    "Shipyard or Fleet Tech alert detected, ignoring it.")
            Utils.touch_randomly(self.region['main_menu_button'])
            Utils.wait_update_screen(1)
            return True
Exemplo n.º 17
0
    def reach_map(self):
        """
        Method to move to the world where the specified map is located. 
        Only works with worlds added to assets (from 1 to 8).
        Also checks if hard mode is enabled.
        """
        _map = 0

        if Utils.find("menu/button_normal_mode"):
            Logger.log_debug("Disabling hard mode.")
            Utils.touch_randomly(Region(88, 990, 80, 40))
            Utils.wait_update_screen(1)

        if not self.chapter_map[0].isdigit():
            Utils.find_and_touch("menu/button_event")
            Utils.wait_update_screen(1)
        else:
            for x in range(1, 9):
                if Utils.find("maps/map_{}-1".format(x), 0.99):
                    _map = x
                    break

            if _map != 0:
                taps = int(self.chapter_map.split("-")[0]) - _map
                for x in range(0, abs(taps)):
                    if taps >= 1:
                        Utils.touch_randomly(Region(1831, 547, 26, 26))
                        Logger.log_debug("Swiping to the right")
                        Utils.wait_update_screen()
                    else:
                        Utils.touch_randomly(Region(65, 547, 26, 26))
                        Logger.log_debug("Swiping to the left")
                        Utils.wait_update_screen()

        if Utils.find('maps/map_{}'.format(self.chapter_map), 0.99):
            Logger.log_msg(
                "Successfully reached the world where map is located.")
        else:
            Logger.log_error(
                "Cannot find the specified map, please move to the world where it's located."
            )
            while not Utils.find('maps/map_{}'.format(self.chapter_map), 0.99):
                Utils.wait_update_screen(1)
Exemplo n.º 18
0
 def collecting_research(self):
     Utils.touch_randomly(self.region['project_click'])
     Utils.wait_update_screen(1)
     if Utils.find("research/item_found"):
         Logger.log_msg("Found completed research project.")
         Utils.touch_randomly(self.region['project_click'])
         Utils.script_sleep(1)
         Utils.touch_randomly(self.region['project_click'])
         return True
     else:
         #solution for azur lane bug
         for searching in range(0, 5):
             Utils.touch_randomly(self.region['right_arrow'])
             Utils.wait_update_screen(1)
             if Utils.find("research/item_found"):
                 Logger.log_msg("Found completed research project.")
                 Utils.script_sleep(1.5)
                 Utils.touch_randomly(self.region['project_click'])
                 Utils.script_sleep(1)
                 Utils.touch_randomly(self.region['project_click'])
                 return True
Exemplo n.º 19
0
    def daily_logic_wrapper(self):
        """Method that fires off the necessary child methods that encapsulates
        the entire action of sortieing combat fleets and resolving combat.
        """
        Utils.update_screen()

        while True:

            if Utils.find("menu/button_battle"):
                Logger.log_debug("Found menu battle button.")
                Utils.touch_randomly(self.region["menu_button_battle"])
                Utils.wait_update_screen(1)
                continue
            if Utils.find("combat/daily_menu"):
                Logger.log_debug("Found Daily Raid button.")
                Utils.touch_randomly(self.region["start_daily"])
                Utils.wait_update_screen(1)
                continue
            if Utils.find("combat/daily_locked3"):
                self.swipe()
            if Utils.find("combat/tactical_training") and not Utils.find(
                    "combat/tactical_training_out") and not Utils.find(
                        "combat/daily_locked"):
                self.select_daily()
            else:
                self.swipe()
            if Utils.find("combat/advance_mission") and not Utils.find(
                    "combat/advance_mission_out") and not Utils.find(
                        "combat/daily_locked"):
                self.select_daily()
            else:
                self.swipe()
            if Utils.find("combat/escort_mission") and not Utils.find(
                    "combat/escort_mission_out") and not Utils.find(
                        "combat/daily_locked"):
                self.select_daily()
            else:
                self.swipe()
            if Utils.find("combat/supply_line"):
                Logger.log_info("Supply line is not supported yet.")
                Utils.touch_randomly(self.region["swipe"])
                Utils.wait_update_screen(1)
            if Utils.find("combat/fierce_assault"):
                Logger.log_info("Fierce assault is not supported yet.")
                Utils.touch_randomly(self.region["swipe"])
                Utils.wait_update_screen(1)
            if Utils.find("menu/home_button"):
                Logger.log_info("Back to main screen.")
                Utils.touch_randomly(self.region["home_button"])
                break
Exemplo n.º 20
0
    def commission_logic_wrapper(self):
        """Method that fires off the necessary child methods that encapsulates
        the entire action of starting and completing commissions.
        """
        Logger.log_msg("Found commission completed alert.")
        Utils.touch_randomly(self.region["left_menu"])

        Utils.script_sleep(1)
        Utils.touch_randomly(self.region["collect_oil"])
        Utils.touch_randomly(self.region["collect_gold"])

        self.attempts_count = 0

        while True:
            Utils.update_screen()

            if Utils.find("commission/button_completed") and (
                    lambda x: x > 332 and x < 511)(
                        Utils.find("commission/button_completed").y):
                Logger.log_debug("Found commission complete button.")
                self.completed_handler()
            if Utils.find("commission/alert_available",
                          0.9) and (lambda x: x > 332 and x < 511)(Utils.find(
                              "commission/alert_available", 0.9).y):
                Logger.log_debug("Found commission available indicator.")
                if self.attempts_count > 2:
                    Logger.log_msg(
                        "Exceeded number of tries allowed. Resuming with other tasks."
                    )
                    Utils.touch_randomly(self.region["dismiss_side_tab"])
                    break
                Utils.touch_randomly(self.region["button_go"])
                self.attempts_count += 1
                self.commission_start_attempts = 0
                Utils.wait_update_screen(1)

                while not Utils.find("menu/commission"):
                    Utils.touch_randomly(self.region["button_go"])
                    Utils.wait_update_screen(1)
                    if Utils.find_and_touch("menu/alert_close"):
                        Utils.script_sleep(1)

                if self.urgent_handler():
                    self.daily_handler()
                Utils.touch_randomly(self.region["button_back"])
                continue
            if Utils.find("commission/button_go") and (
                    lambda x: x > 332 and x < 511)(
                        Utils.find("commission/button_go").y):
                Logger.log_msg("All commissions are running.")
                Utils.touch_randomly(self.region["dismiss_side_tab"])
                break

        Utils.wait_update_screen()
        return True
Exemplo n.º 21
0
    def commission_logic_wrapper(self):
        """Method that fires off the necessary child methods that encapsulates
        the entire action of starting and completing commissions.
        """
        Logger.log_msg("Found commission completed alert.")
        Utils.touch_randomly(self.region["left_menu"])

        Utils.script_sleep(1)
        Utils.touch_randomly(self.region["collect_oil"])
        Utils.touch_randomly(self.region["collect_gold"])

        while True:
            Utils.wait_update_screen(1)
            Utils.avoid_stuck_routine()

            if Utils.find("commission/button_completed") and (
                    lambda x: x > 332 and x < 511)(
                        Utils.find("commission/button_completed").y):
                Logger.log_debug("Found commission complete button.")
                self.completed_handler()
            if Utils.find("commission/alert_available",
                          0.9) and (lambda x: x > 332 and x < 511)(Utils.find(
                              "commission/alert_available", 0.9).y):
                Logger.log_debug("Found commission available indicator.")
                Utils.touch_randomly(self.region["button_go"])
                Utils.wait_update_screen(1)

                while not Utils.find("menu/commission"):
                    Utils.touch_randomly(self.region["button_go"])
                    Utils.wait_update_screen(1)

                if self.urgent_handler():
                    self.daily_handler()
                Utils.touch_randomly(self.region["button_back"])
                continue
            if Utils.find("commission/button_go") and (
                    lambda x: x > 332 and x < 511)(
                        Utils.find("commission/button_go").y):
                Logger.log_msg("All commissions are running.")
                Utils.touch_randomly(self.region["dismiss_side_tab"])
                break

        Utils.wait_update_screen()
        return True
Exemplo n.º 22
0
    def collect_dorm_balloons(self):
        """"
        This method finds and collects all the dorm tokens and affinity points visible to the script.
        The various swipes may not work if there is a shipgirl at the starting point of the swipe.
        For this reason the wrapper to this methoed iterates its cycle for three times, refreshing the dorm.
        """
        Utils.script_sleep(1)
        # tap dorm eye in order to hide UI
        Utils.touch_randomly(self.region["dorm_eye_button"])
        Logger.log_debug("Collecting all visible dorm tokens/affinity points.")

        for i in range(0, 4):
            Utils.wait_update_screen(1)
            # since a rather low similarity is used, the variable j ensures a finite loop
            j = 0
            while Utils.find_and_touch("headquarters/dorm_token",
                                       0.75) and j < 5:
                Logger.log_msg("Collected dorm token.")
                Utils.wait_update_screen()
                j += 1
            j = 0
            while Utils.find_and_touch("headquarters/affinity_point",
                                       0.75) and j < 5:
                Logger.log_msg("Collected affinity points.")
                Utils.wait_update_screen()
                j += 1
            if i == 0:
                # swipe right and refresh
                Utils.swipe(960, 540, 560, 540, 300)
                continue
            if i == 1:
                # swipe left (also countering the previous swipe) and refresh
                Utils.swipe(960, 540, 1760, 540, 300)
                continue
            if i == 2:
                # undo previous swipe
                Utils.swipe(960, 540, 560, 540, 300)
                # swipe up and refresh
                Utils.swipe(960, 540, 960, 790, 300)
                continue
            if i == 3:
                # swipe bottom (also countering the previous swipe) and refresh
                Utils.swipe(960, 540, 960, 40, 300)
                continue

        # restore UI
        Utils.touch_randomly(self.region["dorm_eye_button"])
Exemplo n.º 23
0
    def event_logic_wrapper(self):
        """Method that fires off the necessary child methods that encapsulates
        the entire action of completing an event
        """
        event = self.config.events['name']
        events = ['Crosswave', 'Royal_Maids']

        if event in events and not self.finished:
            Logger.log_msg("Opening event menu.")

            while not Utils.find("menu/operation"):
                Utils.find_and_touch(f"event/{event}/menu_button")
                Utils.wait_update_screen(1)

            Logger.log_msg("Event levels: " + str(self.levels))

            while ('EX' in self.levels):
                Utils.wait_update_screen(1)
                if Utils.find(f"event/{event}/ex_completed", 0.98):
                    Logger.log_info("No more EX combats to do.")
                    break

                Utils.touch_randomly(self.region[f'{event.lower()}_ex'])
                if self.pre_combat_handler():
                    self.combat_handler()
                    Logger.log_msg(f"Finished EX {event.replace('_', ' ')} combat.")
            while ('H' in self.levels):
                Utils.wait_update_screen(1)
                if Utils.find(f"event/{event}/hard_completed"):
                    Logger.log_info("No more Hard combats to do.")
                    break

                Utils.touch_randomly(self.region[f'{event.lower()}_hard'])
                if self.pre_combat_handler():
                    self.combat_handler()
                    Logger.log_msg(f"Finished Hard {event.replace('_', ' ')} combat.")
            while ('N' in self.levels):
                Utils.wait_update_screen(1)
                if Utils.find(f"event/{event}/normal_completed"):
                    Logger.log_info("No more Normal combats to do.")
                    break

                Utils.touch_randomly(self.region[f'{event.lower()}_normal'])
                if self.pre_combat_handler():
                    self.combat_handler()
                    Logger.log_msg(f"Finished Normal {event.replace('_', ' ')} combat.")
            while ('E' in self.levels):
                Utils.wait_update_screen(1)
                if Utils.find(f"event/{event}/easy_completed"):
                    Logger.log_info("No more Easy combats to do.")
                    break

                Utils.touch_randomly(self.region[f'{event.lower()}_easy'])
                if self.pre_combat_handler():
                    self.combat_handler()
                    Logger.log_msg(f"Finished Easy {event.replace('_', ' ')} combat.")

            Logger.log_msg("Finished all event combats, going back to menu.")

            Utils.menu_navigate("menu/button_battle")
            self.finished = True
            return
Exemplo n.º 24
0
    def clear_map(self):
        """ Clears map.
        """
        self.combats_done = 0
        self.kills_count = 0
        self.enemies_list.clear()
        self.mystery_nodes_list.clear()
        self.blacklist.clear()
        self.swipe_counter = 0
        Logger.log_msg("Started map clear.")
        Utils.script_sleep(2.5)

        while Utils.find("combat/fleet_lock", 0.99):
            Utils.touch_randomly(self.region["fleet_lock"])
            Logger.log_warning("Fleet lock is not supported, disabling it.")
            Utils.wait_update_screen()

        #swipe map to fit everything on screen
        swipes = {
            'E-SP1': lambda: Utils.swipe(960, 540, 1400, 640, 300),
            'E-SP2': lambda: Utils.swipe(960, 540, 1500, 540, 300),
            'E-SP3': lambda: Utils.swipe(960, 540, 1300, 740, 300),
            '7-2': lambda: Utils.swipe(960, 540, 1300, 600, 300),
            '12-2': lambda: Utils.swipe(1000, 570, 1300, 540, 300),
            '12-3': lambda: Utils.swipe(1250, 530, 1300, 540, 300),
            '12-4': lambda: Utils.swipe(960, 300, 960, 540, 300),
            '13-1': lambda: Utils.swipe(1020, 500, 1300, 540, 300),
            '13-2': lambda: Utils.swipe(1125, 550, 1300, 540, 300),
            '13-3': lambda: Utils.swipe(1150, 510, 1300, 540, 300),
            '13-4': lambda: Utils.swipe(1200, 450, 1300, 540, 300)
        }
        swipes.get(self.chapter_map,
                   lambda: Utils.swipe(960, 540, 1300, 540, 300))()

        # disable subs' hunting range
        if self.config.combat["hide_subs_hunting_range"]:
            Utils.script_sleep(0.5)
            Utils.touch_randomly(self.region["open_strategy_menu"])
            Utils.script_sleep()
            Utils.touch_randomly(self.region["disable_subs_hunting_radius"])
            Utils.script_sleep()
            Utils.touch_randomly(self.region["close_strategy_menu"])

        target_info = self.get_closest_target(self.blacklist)

        while True:
            Utils.update_screen()

            if Utils.find("combat/alert_unable_battle"):
                Utils.touch_randomly(self.region['close_info_dialog'])
                self.exit = 5
            if self.config.combat[
                    'retreat_after'] != 0 and self.combats_done >= self.config.combat[
                        'retreat_after']:
                Logger.log_msg("Retreating after defeating {} enemies".format(
                    self.config.combat['retreat_after']))
                self.exit = 2
            if self.exit != 0:
                self.retreat_handler()
                return True
            if self.kills_count >= self.kills_before_boss[
                    self.chapter_map] and Utils.find_in_scaling_range(
                        "enemy/fleet_boss"):
                Logger.log_msg("Boss fleet was found.")

                if self.config.combat['boss_fleet']:
                    s = 0
                    swipes = {
                        0: lambda: Utils.swipe(960, 240, 960, 940, 300),
                        1: lambda: Utils.swipe(1560, 540, 260, 540, 300),
                        2: lambda: Utils.swipe(960, 940, 960, 240, 300),
                        3: lambda: Utils.swipe(260, 540, 1560, 540, 300)
                    }

                    Utils.touch_randomly(self.region['button_switch_fleet'])
                    Utils.wait_update_screen(2)
                    boss_region = Utils.find_in_scaling_range(
                        "enemy/fleet_boss")

                    while not boss_region:
                        if s > 3: s = 0
                        swipes.get(s)()

                        Utils.wait_update_screen(0.5)
                        boss_region = Utils.find_in_scaling_range(
                            "enemy/fleet_boss")
                        s += 1
                    # swipe to center the boss fleet on the screen
                    # first calculate the translation vector coordinates
                    horizontal_translation = 150 if boss_region.x < 960 else -150
                    angular_coefficient = -1 * ((540 - boss_region.y) /
                                                (960 - boss_region.x))
                    Utils.swipe(
                        boss_region.x + horizontal_translation, boss_region.y +
                        int(horizontal_translation * angular_coefficient),
                        960 + horizontal_translation, 540 +
                        int(horizontal_translation * angular_coefficient), 300)
                    Utils.wait_update_screen()

                boss_region = Utils.find_in_scaling_range("enemy/fleet_boss",
                                                          similarity=0.9)
                #extrapolates boss_info(x,y,enemy_type) from the boss_region found
                boss_info = [boss_region.x + 50, boss_region.y + 25, "boss"]
                self.clear_boss(boss_info)
                continue
            if target_info == None:
                target_info = self.get_closest_target(
                    self.blacklist,
                    mystery_node=(
                        not self.config.combat["ignore_mystery_nodes"]))
            if target_info:
                #tap at target's coordinates
                Utils.touch(target_info[0:2])
                Utils.update_screen()
            else:
                continue
            if Utils.find("combat/alert_unable_reach", 0.8):
                Logger.log_warning("Unable to reach the target.")
                self.blacklist.append(target_info[0:2])
                target_info = None
                continue
            else:
                movement_result = self.movement_handler(target_info)
                if movement_result == 1:
                    self.battle_handler()
                target_info = None

                self.blacklist.clear()
                continue
Exemplo n.º 25
0
    def battle_handler(self, boss=False):
        Logger.log_msg("Starting combat.")

        # enhancecement and retirement flags
        enhancement_failed = False
        retirement_failed = False
        while not (Utils.find("combat/menu_loading", 0.8)):
            Utils.update_screen()
            if Utils.find("menu/button_sort"):
                if self.config.enhancement[
                        'enabled'] and not enhancement_failed:
                    if not self.enhancement_module.enhancement_logic_wrapper(
                            forced=True):
                        enhancement_failed = True
                elif self.config.retirement[
                        'enabled'] and not retirement_failed:
                    if not self.retirement_module.retirement_logic_wrapper(
                            forced=True):
                        retirement_failed = True
                else:
                    self.retreat_handler()
                    return False
            elif Utils.find("combat/alert_morale_low"):
                self.retreat_handler()
                return False
            elif Utils.find("combat/combat_pause", 0.7):
                Logger.log_warning(
                    "Loading screen was not found but combat pause is present, assuming combat is initiated normally."
                )
                break
            else:
                Utils.touch_randomly(self.region["menu_combat_start"])
                Utils.script_sleep(1)

        Utils.script_sleep(4)

        # flags
        in_battle = True
        items_received = False
        locked_ship = False
        confirmed_fight = False
        defeat = False
        confirmed_fleet_switch = False
        while True:
            Utils.update_screen()

            if in_battle and Utils.find("combat/combat_pause", 0.7):
                Logger.log_debug("In battle.")
                Utils.script_sleep(2.5)
                continue
            if not items_received:
                if Utils.find("combat/menu_touch2continue"):
                    Logger.log_debug("Combat ended: tap to continue")
                    Utils.touch_randomly(self.region['tap_to_continue'])
                    in_battle = False
                    continue
                if Utils.find("menu/item_found"):
                    Logger.log_debug("Combat ended: items received screen")
                    Utils.touch_randomly(self.region['tap_to_continue'])
                    Utils.script_sleep(1)
                    continue
                if (not locked_ship) and Utils.find("combat/alert_lock"):
                    Logger.log_msg("Locking received ship.")
                    Utils.touch_randomly(self.region['lock_ship_button'])
                    locked_ship = True
                    continue
                if Utils.find("menu/drop_elite"):
                    Logger.log_msg("Received ELITE ship as drop.")
                    Utils.touch_randomly(self.region['dismiss_ship_drop'])
                    Utils.script_sleep(2)
                    continue
                elif Utils.find("menu/drop_rare"):
                    Logger.log_msg("Received new RARE ship as drop.")
                    Utils.touch_randomly(self.region['dismiss_ship_drop'])
                    Utils.script_sleep(2)
                    continue
                elif Utils.find("menu/drop_ssr"):
                    Logger.log_msg("Received SSR ship as drop.")
                    Utils.touch_randomly(self.region['dismiss_ship_drop'])
                    Utils.script_sleep(2)
                    continue
                elif Utils.find("menu/drop_common"):
                    Logger.log_msg("Received new COMMON ship as drop.")
                    Utils.touch_randomly(self.region['dismiss_ship_drop'])
                    Utils.script_sleep(2)
                    continue
            if not in_battle:
                if (not confirmed_fight
                    ) and Utils.find("combat/button_confirm"):
                    Logger.log_msg("Combat ended.")
                    items_received = True
                    confirmed_fight = True
                    Utils.touch_randomly(self.region["combat_end_confirm"])
                    if boss:
                        return True
                    Utils.wait_update_screen(3)
                if (not confirmed_fight) and Utils.find("combat/commander"):
                    items_received = True
                    # prevents fleet with submarines from getting stuck at combat end screen
                    Utils.touch_randomly(
                        self.region["combat_dismiss_surface_fleet_summary"])
                    continue
                if defeat and not confirmed_fleet_switch:
                    if Utils.find("combat/alert_unable_battle"):
                        Utils.touch_randomly(self.region['close_info_dialog'])
                        Utils.script_sleep(3)
                        self.exit = 5
                        return False
                    if Utils.find("combat/alert_fleet_cannot_be_formed"):
                        # fleet will be automatically switched
                        Utils.touch_randomly(self.region['close_info_dialog'])
                        confirmed_fleet_switch = True
                        self.enemies_list.clear()
                        self.mystery_nodes_list.clear()
                        self.blacklist.clear()
                        Utils.script_sleep(3)
                        continue
                    else:
                        # flagship sunk, but part of backline still remains
                        # proceed to retreat
                        Utils.script_sleep(3)
                        self.exit = 5
                        return False
                if confirmed_fight and Utils.find("menu/button_confirm"):
                    Logger.log_msg("Found commission info message.")
                    Utils.touch_randomly(self.region["combat_com_confirm"])
                    continue
                if confirmed_fight and Utils.find("combat/button_retreat"):
                    #Utils.touch_randomly(self.region["hide_strat_menu"])
                    if confirmed_fleet_switch:
                        # if fleet was defeated and it has now been switched
                        return False
                    else:
                        # fleet won the fight
                        self.combats_done += 1
                        self.kills_count += 1
                        if self.kills_count >= self.kills_before_boss[
                                self.chapter_map]:
                            Utils.script_sleep(2.5)
                        return True
                if confirmed_fight and Utils.find_and_touch(
                        "combat/defeat_close_button"):
                    Logger.log_debug("Fleet was defeated.")
                    defeat = True
                    Utils.script_sleep(3)
Exemplo n.º 26
0
    def clear_map(self):
        """ Clears map.
        """
        Logger.log_msg("Started map clear.")
        Utils.script_sleep(2.5)

        while Utils.find("combat/fleet_lock", 0.99):
            Utils.touch_randomly(self.region["fleet_lock"])
            Logger.log_warning("Fleet lock is not supported, disabling it.")
            Utils.wait_update_screen()

        #swipe map to fit everything on screen
        swipes = {
            'E-C3': lambda: Utils.swipe(960, 800, 960, 400, 100),
            'E-A3': lambda: Utils.swipe(960, 800, 960, 400, 100),
            'E-SP5': lambda: Utils.swipe(350, 500, 960, 800, 100),
            '12-2': lambda: Utils.swipe(1000, 570, 1300, 540, 100),
            '12-3': lambda: Utils.swipe(1250, 530, 1300, 540, 100),
            '12-4': lambda: Utils.swipe(960, 300, 960, 540, 100),
            '13-1': lambda: Utils.swipe(1020, 500, 1300, 540, 100),
            '13-2': lambda: Utils.swipe(1125, 550, 1300, 540, 100),
            '13-3': lambda: Utils.swipe(1150, 510, 1300, 540, 100),
            '13-4': lambda: Utils.swipe(1200, 450, 1300, 540, 100)
        }
        swipes.get(self.chapter_map,
                   lambda: Utils.swipe(960, 540, 1300, 540, 100))()

        target_info = self.get_closest_target(self.blacklist)

        while True:
            Utils.update_screen()

            if Utils.find("combat/alert_unable_battle"):
                Utils.touch_randomly(self.region['close_info_dialog'])
                self.exit = 4
            if self.config.combat[
                    'retreat_after'] != 0 and self.combats_done >= self.config.combat[
                        'retreat_after']:
                Logger.log_msg("Retreating after defeating {} enemies".format(
                    self.config.combat['retreat_after']))
                self.exit = 5
            if self.exit != 0:
                self.retreat_handler()
                return True
            if Utils.find_in_scaling_range("enemy/fleet_boss"):
                Logger.log_msg("Boss fleet was found.")

                if self.config.combat['boss_fleet']:
                    s = 0
                    swipes = {
                        0: lambda: Utils.swipe(960, 240, 960, 940, 300),
                        1: lambda: Utils.swipe(1560, 540, 260, 540, 300),
                        2: lambda: Utils.swipe(960, 940, 960, 240, 300),
                        3: lambda: Utils.swipe(260, 540, 1560, 540, 300)
                    }

                    Utils.touch_randomly(self.region['button_switch_fleet'])
                    Utils.wait_update_screen(2)
                    boss_region = Utils.find_in_scaling_range(
                        "enemy/fleet_boss")

                    while not boss_region:
                        if s > 3: s = 0
                        swipes.get(s)()

                        Utils.wait_update_screen(0.5)
                        boss_region = Utils.find_in_scaling_range(
                            "enemy/fleet_boss")
                        s += 1
                    Utils.swipe(boss_region.x, boss_region.y, 960, 540, 300)
                    Utils.wait_update_screen()

                boss_region = Utils.find_in_scaling_range("enemy/fleet_boss")
                #extrapolates boss_info(x,y,enemy_type) from the boss_region found
                boss_info = [boss_region.x + 50, boss_region.y + 25, "boss"]
                self.clear_boss(boss_info)
                continue
            if target_info == None:
                if Utils.find("combat/question_mark", 0.9):
                    target_info = self.get_closest_target(self.blacklist,
                                                          mystery_node=True)
                else:
                    target_info = self.get_closest_target(self.blacklist)
                continue
            if target_info:
                #tap at target's coordinates
                Utils.touch(target_info[0:2])
                Utils.update_screen()
            if Utils.find("combat/alert_unable_reach", 0.8):
                Logger.log_warning("Unable to reach the target.")
                self.blacklist.append(target_info[0:2])
                target_info = None
                continue
            else:
                movement_result = self.movement_handler(target_info)
                if movement_result == 1:
                    self.battle_handler()
                target_info = None

                self.blacklist.clear()
                continue
Exemplo n.º 27
0
    def combat_logic_wrapper(self):
        """Method that fires off the necessary child methods that encapsulates
        the entire action of sortieing combat fleets and resolving combat.

        Returns:
            int: 1 if boss was defeated, 2 if morale is too low and 3 if dock is full.
        """
        self.exit = 0
        self.combats_done = 0
        self.l.clear()
        self.blacklist.clear()

        while True:
            Utils.wait_update_screen()

            if Utils.find("menu/button_sort"):
                Utils.touch_randomly(self.region['close_info_dialog'])
                self.exit = 3
            if Utils.find("combat/alert_morale_low"):
                Utils.touch_randomly(self.region['close_info_dialog'])
                self.exit = 2
                break
            if Utils.find("menu/button_confirm"):
                Logger.log_msg("Found commission info message.")
                Utils.touch_randomly(self.region["combat_com_confirm"])
                continue
            if Utils.find("menu/button_battle"):
                Logger.log_debug("Found menu battle button.")
                Utils.touch_randomly(self.region["menu_button_battle"])
                Utils.wait_update_screen(1)
                continue
            if Utils.find("combat/menu_fleet") and (
                    lambda x: x > 414 and x < 584)(
                        Utils.find("combat/menu_fleet").y
                    ) and not self.config.combat['boss_fleet']:
                if not self.chapter_map[0].isdigit(
                ) and string.ascii_uppercase.index(self.chapter_map[
                        2:3]) < 1 or self.chapter_map[0].isdigit():
                    Logger.log_msg(
                        "Removing second fleet from fleet selection.")
                    Utils.touch_randomly(self.region["clear_second_fleet"])
            if Utils.find("combat/menu_select_fleet"):
                Logger.log_debug("Found fleet select go button.")
                Utils.touch_randomly(self.region["fleet_menu_go"])
                Utils.script_sleep(1)
                continue
            if Utils.find("combat/button_go"):
                Logger.log_debug("Found map summary go button.")
                Utils.touch_randomly(self.region["map_summary_go"])
                continue
            if Utils.find("combat/button_retreat"):
                Logger.log_debug(
                    "Found retreat button, starting clear function.")
                if not self.clear_map():
                    self.stats.increment_combat_attempted()
                    break
            if self.exit == 1 or self.exit == 5:
                self.stats.increment_combat_done()
                break
            if self.exit > 1:
                self.stats.increment_combat_attempted()
                break
            if Utils.find("menu/button_normal_mode"
                          ) and self.chapter_map[0].isdigit():
                Logger.log_debug("Disabling hard mode.")
                Utils.touch_randomly(self.region['normal_mode_button'])
                Utils.wait_update_screen(1)
            if Utils.find_and_touch('maps/map_{}'.format(self.chapter_map),
                                    0.99):
                Logger.log_msg("Found specified map.")
                continue
            else:
                self.reach_map()
                continue

        Utils.script_sleep(1)
        Utils.menu_navigate("menu/button_battle")

        return self.exit
Exemplo n.º 28
0
    def combat_logic_wrapper(self):
        """Method that fires off the necessary child methods that encapsulates
        the entire action of sortieing combat fleets and resolving combat.

        Returns:
            int: 1 if boss was defeated, 2 if successfully retreated after the specified
                number of fights, 3 if morale is too low, 4 if dock is full and unable to
                free it and 5 if fleet was defeated.
        """
        self.exit = 0
        self.start_time = datetime.now()
        # enhancecement and retirement flags
        enhancement_failed = False
        retirement_failed = False

        # get to map
        map_region = self.reach_map()
        Utils.touch_randomly(map_region)

        while True:
            Utils.wait_update_screen()

            if self.exit == 1 or self.exit == 2:
                self.stats.increment_combat_done()
                time_passed = datetime.now() - self.start_time
                if self.stats.combat_done % self.config.combat['retire_cycle'] == 0 or ((self.config.commissions['enabled'] or \
                    self.config.dorm['enabled'] or self.config.academy['enabled']) and time_passed.total_seconds() > 3600) or \
                        not Utils.check_oil(self.config.combat['oil_limit']):
                    break
                else:
                    self.exit = 0
                    Logger.log_msg("Repeating map {}.".format(
                        self.chapter_map))
                    Utils.touch_randomly(map_region)
                    continue
            if self.exit > 2:
                self.stats.increment_combat_attempted()
                break
            if Utils.find("combat/button_go"):
                Logger.log_debug("Found map summary go button.")
                Utils.touch_randomly(self.region["map_summary_go"])
                Utils.wait_update_screen()
            if Utils.find("combat/menu_fleet") and (
                    lambda x: x > 414 and x < 584)(
                        Utils.find("combat/menu_fleet").y
                    ) and not self.config.combat['boss_fleet']:
                if not self.chapter_map[0].isdigit(
                ) and string.ascii_uppercase.index(self.chapter_map[
                        2:3]) < 1 or self.chapter_map[0].isdigit():
                    Logger.log_msg(
                        "Removing second fleet from fleet selection.")
                    Utils.touch_randomly(self.region["clear_second_fleet"])
            if Utils.find("combat/menu_select_fleet"):
                Logger.log_debug("Found fleet select go button.")
                Utils.touch_randomly(self.region["fleet_menu_go"])
                Utils.wait_update_screen(2)
            if Utils.find("combat/button_retreat"):
                Logger.log_debug(
                    "Found retreat button, starting clear function.")
                if not self.clear_map():
                    self.stats.increment_combat_attempted()
                    break
                Utils.wait_update_screen()
            if Utils.find("menu/button_confirm"):
                Logger.log_msg("Found commission info message.")
                Utils.touch_randomly(self.region["combat_com_confirm"])
                continue
            if Utils.find("menu/button_sort"):
                if self.config.enhancement[
                        'enabled'] and not enhancement_failed:
                    if not self.enhancement_module.enhancement_logic_wrapper(
                            forced=True):
                        enhancement_failed = True
                    Utils.script_sleep(1)
                    Utils.touch_randomly(map_region)
                    continue
                elif self.config.retirement[
                        'enabled'] and not retirement_failed:
                    if not self.retirement_module.retirement_logic_wrapper(
                            forced=True):
                        retirement_failed = True
                    else:
                        # reset enhancement flag
                        enhancement_failed = False
                    Utils.script_sleep(1)
                    Utils.touch_randomly(map_region)
                    continue
                else:
                    Utils.touch_randomly(self.region['close_info_dialog'])
                    self.exit = 4
                    break
            if Utils.find("combat/alert_morale_low"):
                Utils.touch_randomly(self.region['close_info_dialog'])
                self.exit = 3
                break

        Utils.script_sleep(1)
        Utils.menu_navigate("menu/button_battle")

        return self.exit
Exemplo n.º 29
0
    def combat_logic_wrapper(self):
        """Method that fires off the necessary child methods that encapsulates
        the entire action of sortieing combat fleets and resolving combat.

        Returns:
            int: 1 if boss was defeated, 2 if morale is too low and 3 if dock is full.
        """
        self.exit = 0
        self.l.clear()
        self.blacklist.clear()

        while True:
            Utils.wait_update_screen()

            if Utils.find("menu/button_sort"):
                Utils.touch_randomly(Region(1326, 274, 35, 35))
                self.exit = 3
            if Utils.find("combat/alert_morale_low"):
                Utils.touch_randomly(Region(1326, 274, 35, 35))
                self.exit = 2
                break
            if Utils.find("commission/button_confirm"):
                Logger.log_msg("Found commission info message.")
                Utils.touch_randomly(self.region["combat_com_confirm"])
                continue
            if Utils.find("menu/button_battle"):
                Logger.log_debug("Found menu battle button.")
                Utils.touch_randomly(self.region["menu_button_battle"])
                Utils.wait_update_screen(1)
                continue
            if Utils.find("combat/menu_select_fleet"):
                Logger.log_debug("Found fleet select go button.")
                Utils.touch_randomly(self.region["fleet_menu_go"])
                continue
            if Utils.find("combat/button_go"):
                Logger.log_debug("Found map summary go button.")
                Utils.touch_randomly(self.region["map_summary_go"])
                continue
            if Utils.find("combat/button_retreat"):
                Logger.log_debug(
                    "Found retreat button, starting clear function.")
                if not self.clear_map():
                    self.stats.increment_combat_attempted()
                    break
            if self.exit == 1:
                self.stats.increment_combat_done()
                break
            if self.exit > 1:
                self.stats.increment_combat_attempted()
                break
            if Utils.find("menu/button_normal_mode"):
                Logger.log_debug("Disabling hard mode.")
                Utils.touch_randomly(Region(88, 990, 80, 40))
                Utils.wait_update_screen(1)
            if Utils.find_and_touch('maps/map_{}'.format(self.chapter_map),
                                    0.8):
                Logger.log_msg("Found specified map.")
                continue
            else:
                self.reach_map()
                continue

        Utils.script_sleep(1)
        Utils.menu_navigate("menu/button_battle")

        return self.exit
Exemplo n.º 30
0
    def reach_map(self):
        """
        Method which returns the map region for the stage set in the configuration file.
        If the map isn't found, it navigates the map selection menu to get to the world where the specified map is located.
        Only works with standard maps up to worlds 13 and some event maps.
        Also checks if hard mode is enabled, and if it's legit to keep it so (event maps C and D).
        If nothing is found even after menu navigation, it stops the bot workflow until the user moves to the right 
        screen or the map asset is substituted with the right one.

        Returns:
            (Region): the map region of the selected stage.
        """
        Utils.wait_update_screen()
        # get to map selection menu
        if Utils.find("menu/button_battle"):
            Logger.log_debug("Found menu battle button.")
            Utils.touch_randomly(self.region["menu_button_battle"])
            Utils.wait_update_screen(2)

        # correct map mode
        if not self.chapter_map[0].isdigit():
            letter = self.chapter_map[2]
            event_maps = ['A', 'B', 'S', 'C', 'D']

            Utils.touch_randomly(self.region['event_button'])
            Utils.wait_update_screen(1)

            if event_maps.index(letter) < 3 and Utils.find("menu/button_normal_mode", 0.8) or \
               event_maps.index(letter) > 2 and not Utils.find("menu/button_normal_mode", 0.8):
                Utils.touch_randomly(self.region['normal_mode_button'])
                Utils.wait_update_screen(1)
        else:
            if Utils.find("menu/button_normal_mode"):
                Logger.log_debug("Disabling hard mode.")
                Utils.touch_randomly(self.region['normal_mode_button'])
                Utils.wait_update_screen(1)

        map_region = Utils.find('maps/map_{}'.format(self.chapter_map), 0.99)
        if map_region != None:
            Logger.log_msg("Found specified map.")
            return map_region
        else:
            # navigate map selection menu
            if not self.chapter_map[0].isdigit():
                if (self.chapter_map[2] == 'A' or self.chapter_map[2] == 'C') and \
                    (Utils.find('maps/map_E-B1', 0.99) or Utils.find('maps/map_E-D1', 0.99)):
                    Utils.touch_randomly(self.region['map_nav_left'])
                    Logger.log_debug("Swiping to the left")
                else:
                    Utils.touch_randomly(self.region['map_nav_right'])
                    Logger.log_debug("Swiping to the right")
            else:
                _map = 0
                for x in range(1, 14):
                    if Utils.find("maps/map_{}-1".format(x), 0.99):
                        _map = x
                        break
                if _map != 0:
                    taps = int(self.chapter_map.split("-")[0]) - _map
                    for x in range(0, abs(taps)):
                        if taps >= 1:
                            Utils.touch_randomly(self.region['map_nav_right'])
                            Logger.log_debug("Swiping to the right")
                            Utils.script_sleep()
                        else:
                            Utils.touch_randomly(self.region['map_nav_left'])
                            Logger.log_debug("Swiping to the left")
                            Utils.script_sleep()

        Utils.wait_update_screen()
        map_region = Utils.find('maps/map_{}'.format(self.chapter_map), 0.99)
        if map_region == None:
            Logger.log_error(
                "Cannot find the specified map, please move to the world where it's located."
            )
        while map_region == None:
            map_region = Utils.find('maps/map_{}'.format(self.chapter_map),
                                    0.99)
            Utils.wait_update_screen(1)

        Logger.log_msg("Found specified map.")
        return map_region