Пример #1
0
    def start(first_run: bool) -> int:
        """Starts the process to complete a run for Raid Farming Mode and returns the number of items detected.

        Args:
            first_run (bool): Flag that determines whether or not to run the navigation process again. Should be False if the Farming Mode supports the "Play Again" feature for repeated runs.

        Returns:
            (int): Number of items detected.
        """
        from bot.game import Game

        number_of_items_dropped: int = 0

        # Start the navigation process.
        if first_run:
            Raid._navigate()
        else:
            # Check for Pending Battles and then perform navigation again.
            Game.check_for_pending()
            Raid._navigate()

        # Check for EP.
        Game.check_for_ep()

        # Check if the bot is at the Summon Selection screen.
        if ImageUtils.confirm_location("select_a_summon", tries=30):
            summon_check = Game.select_summon(Settings.summon_list,
                                              Settings.summon_element_list)

            if summon_check:
                # Select the Party.
                if Game.find_party_and_start_mission(Settings.group_number,
                                                     Settings.party_number):
                    # Handle the rare case where joining the Raid after selecting the Summon and Party led the bot to the Quest Results screen with no loot to collect.
                    if ImageUtils.confirm_location("no_loot", tries=2):
                        MessageLog.print_message(
                            "\n[RAID] Seems that the Raid just ended. Moving back to the Home screen and joining another Raid..."
                        )
                    elif CombatMode.start_combat_mode():
                        number_of_items_dropped = Game.collect_loot(
                            is_completed=True)
                else:
                    MessageLog.print_message(
                        "\n[RAID] Seems that the Raid ended before the bot was able to join. Now looking for another Raid to join..."
                    )
        else:
            raise RaidException(
                "Failed to arrive at the Summon Selection screen.")

        return number_of_items_dropped
Пример #2
0
    def _join_raid() -> bool:
        """Start the process to fetch a valid room code and join it.

        Returns:
            (bool): True if the bot arrived at the Summon Selection screen.
        """
        from bot.game import Game

        recovery_time = 15

        # Make preparations for farming raids by saving the location of the "Join Room" button and the "Room Code" textbox.
        join_room_button = ImageUtils.find_button("join_a_room")
        room_code_textbox = (join_room_button[0] - 185, join_room_button[1])

        # Loop and try to join a raid. If none of the room codes worked, wait before trying again with a new set of room codes for a maximum of 10 tries.
        tries = 10
        while tries > 0:
            room_code_tries = 5
            while room_code_tries > 0:
                # Attempt to find a room code.
                room_code = TwitterRoomFinder.get_room_code()

                if room_code != "":
                    # Select the "Room Code" textbox and then clear all text from it.
                    MouseUtils.move_and_click_point(
                        room_code_textbox[0],
                        room_code_textbox[1],
                        "template_room_code_textbox",
                        mouse_clicks=2)
                    MouseUtils.clear_textbox()

                    # Copy the room code to the clipboard and then paste it into the "Room Code" textbox.
                    MouseUtils.copy_to_clipboard(room_code)
                    MouseUtils.paste_from_clipboard()

                    # Now click on the "Join Room" button.
                    MouseUtils.move_and_click_point(join_room_button[0],
                                                    join_room_button[1],
                                                    "join_a_room")

                    # If the room code is valid and the raid is able to be joined, break out and head to the Summon Selection screen.
                    if Game.find_and_click_button(
                            "ok", suppress_error=True) is False:
                        # Check for EP.
                        Game.check_for_ep()

                        MessageLog.print_message(
                            f"[SUCCESS] Joining {room_code} was successful.")
                        Raid._raids_joined += 1

                        return ImageUtils.confirm_location("select_a_summon")
                    elif Game.check_for_pending() is False:
                        MessageLog.print_message(
                            f"[WARNING] {room_code} already ended or invalid.")
                    else:
                        # Move from the Home screen back to the Backup Requests screen after clearing out all the Pending Battles.
                        Game.find_and_click_button("quest")
                        Game.find_and_click_button("raid")
                        Game.find_and_click_button("enter_id")

                if Settings.enable_no_timeout is False:
                    room_code_tries -= 1

                Game.wait(1)

            tries -= 1
            MessageLog.print_message(
                f"\n[WARNING] Could not find any valid room codes. \nWaiting {recovery_time} seconds and then trying again with {tries} tries left before exiting."
            )
            Game.wait(recovery_time)

        raise RaidException(
            "Failed to find any valid room codes for 10 total times.")