Example #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
Example #2
0
    def clear_boss(self, boss_info):
        Logger.log_debug("Started boss function.")

        self.enemies_list.clear()
        self.mystery_nodes_list.clear()
        self.blacklist.clear()

        while True:
            #tap at boss' coordinates
            Utils.touch(boss_info[0:2])
            Utils.update_screen()

            if Utils.find("combat/alert_unable_reach", 0.8):
                Logger.log_msg("Unable to reach boss.")
                #handle boss' coordinates
                if not self.unable_handler(boss_info[0:2]):
                    return
                continue
            else:
                self.movement_handler(boss_info)
                if self.battle_handler(boss=True):
                    self.exit = 1
                    Logger.log_msg("Boss successfully defeated.")
                Utils.script_sleep(3)
                return
Example #3
0
    def movement_handler(self, target_info):
        """
        Method that handles the fleet movement until it reach its target (mystery node or enemy node).
        If the coordinates are wrong, they will be blacklisted and another set of coordinates to work on is obtained.
        If the target is a mystery node and what is found is ammo, then the method will fall in the blacklist case
        and search for another enemy: this is inefficient and should be improved, but it works.

        Args:
            target_info (list): coordinate_x, coordinate_y, type. Describes the selected target.
        Returns:
            (int): 1 if a fight is needed, otherwise 0.
        """
        Logger.log_msg("Moving towards objective.")
        count = 0
        location = [target_info[0], target_info[1]]
        Utils.script_sleep(1)

        while True:
            Utils.update_screen()
            event = self.check_movement_threads()

            if event["combat/button_evade"]:
                Logger.log_msg("Ambush was found, trying to evade.")
                Utils.touch_randomly(self.region["combat_ambush_evade"])
                Utils.script_sleep(0.5)
                continue
            if event["combat/alert_failed_evade"]:
                Logger.log_warning("Failed to evade ambush.")
                Utils.touch_randomly(self.region["menu_combat_start"])
                self.battle_handler()
                continue
            if event["menu/item_found"]:
                Logger.log_msg("Item found on node.")
                Utils.touch_randomly(Region(661, 840, 598, 203))
                if Utils.find("combat/menu_emergency"):
                    Utils.script_sleep(1)
                    Utils.touch_randomly(self.region["hide_strat_menu"])
                if target_info[2] == "mystery_node":
                    Logger.log_msg("Target reached.")
                    return 0
                continue
            if event["menu/alert_info"]:
                Logger.log_debug("Found alert.")
                Utils.find_and_touch("menu/alert_close")
                continue
            if event["combat/menu_formation"] or event["combat/menu_loading"]:
                return 1
            else:
                if count != 0 and count % 3 == 0:
                    Utils.touch(location)
                if count > 21:
                    Logger.log_msg(
                        "Blacklisting location and searching for another enemy."
                    )
                    self.blacklist.append(location)
                    self.l.clear()

                    location = self.get_closest_target(self.blacklist)
                    count = 0
                count += 1
Example #4
0
    def clear_map(self):
        Logger.log_msg("Started map clear.")
        Utils.script_sleep(2.5)

        #hide strat menu
        Utils.touch_randomly(self.region["hide_strat_menu"])
        #swipe map to the left
        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"):
                Logger.log_warning("Failed to defeat enemy.")
                Utils.touch_randomly(Region(869, 741, 185, 48))
                return False
            if self.exit is not 0:
                return True
            if Utils.find("enemy/fleet_boss", 0.9):
                Logger.log_msg("Boss fleet was found.")
                boss_region = Utils.find("enemy/fleet_boss", 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:
                if Utils.find("combat/question_mark", 0.9):
                    target_info = self.get_closest_target(self.blacklist,
                                                          mystery_node=True)
                    #if it is a mystery_node (question_mark), tap a bit lower
                    if target_info[2] == "mystery_node":
                        #coord_y += 140
                        target_info[1] += 140
                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
Example #5
0
 def clear_trash(self):
     """Finds trash mobs closest to the current fleet location and battles
     them until the boss spawns
     """
     while self.kills_needed > 0:
         blacklist = []
         tries = 0
         if self.resume_previous_sortie:
             self.resume_previous_sortie = False
             Utils.find_and_touch('combat_attack')
             Utils.script_sleep(2)
         else:
             self.avoided_ambush = True
         while not Utils.exists('combat_battle_start'):
             if Utils.find_and_touch('combat_evade'):
                 if Utils.wait_for_exist('combat_battle_start', 3):
                     self.avoided_ambush = False
                 else:
                     Logger.log_msg('Successfully avoided ambush.')
             elif Utils.find_and_touch('combat_items_received'):
                 pass
             else:
                 enemy_coord = self.get_closest_enemy()
                 if tries > 2:
                     blacklist.append(enemy_coord)
                     enemy_coord = self.get_closest_enemy(blacklist)
                 Logger.log_msg(
                     'Navigating to enemy fleet at {}'.format(enemy_coord))
                 Utils.touch(enemy_coord)
                 tries += 1
                 Utils.script_sleep(5)
         if self.conduct_prebattle_check():
             if self.conduct_battle():
                 self.need_to_refocus = True
             else:
                 self.resume_previous_sortie = True
                 while not (Utils.exists('home_menu_build')):
                     Utils.touch_randomly(self.region['nav_back'])
                 # Add logic for retirement here?
                 return False
         if self.avoided_ambush:
             self.kills_needed -= 1
         Logger.log_msg('Kills left for boss to spawn: {}'.format(
             self.kills_needed))
     Utils.script_sleep(1)
     return True
Example #6
0
    def unable_handler(self, coords, boss=False):
        """
        Method called when the path to the target (boss fleet or mystery node) 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 target's location.
        """
        if boss:
            Logger.log_debug("Unable to reach boss function started.")
        else:
            Logger.log_debug(
                "Unable to reach selected target function started.")
        self.blacklist.clear()
        closest_to_unreachable_target = self.get_closest_target(self.blacklist,
                                                                coords,
                                                                boss=boss)

        Utils.touch(closest_to_unreachable_target)
        Utils.update_screen()

        if Utils.find("combat/alert_unable_reach"):
            Logger.log_warning("Unable to reach next to selected target.")
            self.blacklist.append(closest_to_unreachable_target[0:2])

            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_enemy[0:2])
                else:
                    break

            self.movement_handler(closest_enemy)
            if not self.battle_handler():
                return False
            return True
        else:
            self.movement_handler(closest_to_unreachable_target)
            if not self.battle_handler():
                return False
            return True
Example #7
0
 def clear_boss(self):
     """Finds the boss and battles it
     """
     while not Utils.exists('combat_battle_start'):
         boss = None
         similarity = 0.8
         while boss is None:
             boss = Utils.scroll_find('combat_enemy_boss_alt', 250, 175,
                                      similarity)
             similarity -= 0.015
         Logger.log_msg('Boss found at: {}'.format([boss.x, boss.y]))
         Logger.log_msg('Focusing on boss')
         Utils.swipe(boss.x, boss.y, 640, 360, 250)
         boss = None
         while boss is None:
             boss = Utils.find('combat_enemy_boss_alt', similarity)
             similarity -= 0.015
         # Click slightly above boss to be able to click on it in case
         # the boss is obstructed by another fleet or enemy
         boss_coords = [boss.x + 50, boss.y - 15]
         Utils.touch(boss_coords)
         if Utils.wait_for_exist('combat_unable', 3):
             boss = Utils.scroll_find('combat_enemy_boss_alt', 250, 175,
                                      0.75)
             enemies = Utils.find_all('combat_enemy_fleet', 0.89)
             enemies.remove(boss)
             closest_to_boss = enemies[Utils.find_closest(enemies, boss)[1]]
             Utils.find_and_touch(closest_to_boss)
             if Utils.wait_for_exist('combat_unable', 3):
                 Utils.find_and_touch(self.get_closest_enemy())
                 if Utils.wait_for_exist('combat_battle_start', 3):
                     self.conduct_battle()
         else:
             Utils.script_sleep(5)
             if Utils.find_and_touch('combat_evade'):
                 if Utils.wait_for_exist('combat_battle_start', 3):
                     self.conduct_battle()
                     self.refocus_fleet()
             elif Utils.find_and_touch('combat_items_received'):
                 pass
     if self.conduct_prebattle_check():
         self.conduct_battle()
Example #8
0
    def clear_boss(self, boss_info):
        Logger.log_debug("Started boss function.")

        self.l.clear()
        self.blacklist.clear()

        while True:
            #tap at boss' coordinates
            Utils.touch(boss_info[0:2])
            Utils.update_screen()

            if Utils.find("combat/alert_unable_reach", 0.8):
                Logger.log_msg("Unable to reach boss.")
                #handle boss' coordinates
                self.unable_handler(boss_info[0:2])
                continue
            else:
                self.movement_handler(boss_info)
                if self.battle_handler(boss=True):
                    self.exit = 1
                return
Example #9
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
Example #10
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