Example #1
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 #2
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