AxelBjork / Rush-Royale-Bot

Python based bot for Rush Royale
MIT License
29 stars 19 forks source link

Buy all 6 units from store and refresh (perfected!) #86

Open Newb420 opened 1 year ago

Newb420 commented 1 year ago

first start by finding Def find_store_refresh and Def refresh_shop, we're combining these 2 functions together so delete them. next replace the 2 functions we deleted with

# Refresh items in shop when available
def refresh_and_buy(self):
    self.click_button((100, 1500))  # Click store button
    time.sleep(1)  # Add a 2-second delay here
    self.click_button((100, 1500))  # Click store button
    self.click_button((450, 1300))  # Click store button
    [self.swipe([0, 0], [2, 0]) for i in range(15)]  # Swipe to top
    time.sleep(2)  # Add a 2-second delay here
    # Perform one small downward scroll
    self.swipe([2, 0], [0, 0])  # Smaller downward swipe
    time.sleep(0.5)  # Add a 0.5-second delay here
    self.click(30, 150)  # Stop scroll
    time.sleep(1)  # Add a 0.5-second delay here
    # Click on the six items based on provided coordinates
    item_coords = [(156, 287), (458, 288), (753, 287), (152, 724), (444, 735), (748, 724)]
    for coord in item_coords:
        self.click_button(coord)  # Click on item
        time.sleep(1)  # Add a 0.5-second delay here
        self.click(400, 1130)  # Buy
        time.sleep(1)  # Add a 0.5-second delay here
        self.click(30, 150)  # Remove pop-up
        time.sleep(1)  # Add a 0.5-second delay here
    # Locate the refresh button
    avail_buttons = self.get_current_icons(available=True)
    if (avail_buttons == 'refresh_active.png').any(axis=None):
        pos = get_button_pos(avail_buttons, 'refresh_active.png')
        self.click_button(pos)  # Click on the active refresh button
        self.watch_ads()  # Call watch_ads after clicking the active refresh button
    elif (avail_buttons == 'refresh_inactive.png').any(axis=None):
        self.logger.warning('Refresh button is inactive, skipping refresh.')

    self.store_visited = True
    self.logger.warning('Bought store units!')

Now located the Def watch_ads

def watch_ads(self):
    avail_buttons = self.get_current_icons(available=True)
    time.sleep(2)  # Add a 2-second delay here
    # Watch ad if available
    if (avail_buttons == 'battle_icon.png').any(axis=None):
        if not self.store_visited:
            self.refresh_and_buy() # CAll refresh_and_buy first
    elif (avail_buttons == 'quest_done.png').any(axis=None):
        pos = get_button_pos(avail_buttons, 'quest_done.png')
        self.click_button(pos)
        self.click(700, 600)  # collect second completed quest
        self.click(700, 400)  # collect second completed quest
        [self.click(150, 250) for i in range(2)]  # click dailies twice
        self.click(420, 420)  # collect ad chest
    elif (avail_buttons == 'ad_season.png').any(axis=None):
        pos = get_button_pos(avail_buttons, 'ad_season.png')
        self.click_button(pos)
    elif (avail_buttons == 'ad_pve.png').any(axis=None):
        pos = get_button_pos(avail_buttons, 'ad_pve.png')
        self.click_button(pos)
    elif (avail_buttons == 'ad_fight_end.png').any(axis=None):
        pos = get_button_pos(avail_buttons, 'ad_fight_end.png')
        self.click_button(pos)
        self.logger.info('Watched all ads!')
        return
    # Actively check for the "home_screen" state
    attempts = 0
    while attempts < 18:  # Wait for 30 seconds (2-second intervals) before attempting to click the X mark
        avail_buttons, status = self.battle_screen()
        if status == 'menu' or status == 'home':
            self.logger.info('FINISHED AD')
            return
        time.sleep(2)
        attempts += 1
    # Attempt to click the X mark for 10 seconds
    attempts = 0
    while attempts < 8:  # Attempt to click the X mark for 10 seconds (2-second intervals)
        avail_buttons = self.get_current_icons(available=True)
        if (avail_buttons == 'x_mark.png').any(axis=None):
            pos = get_button_pos(avail_buttons, 'x_mark.png')
            self.click_button(pos)
        elif (avail_buttons == 'x_mark1.png').any(axis=None):
            pos = get_button_pos(avail_buttons, 'x_mark1.png')
            self.click_button(pos)
        else:
            self.click(870, 30)  # attempt to skip forward/click X
            self.click(870, 100)  # click X playstore popup
        avail_buttons, status = self.battle_screen()
        if status == 'menu' or status == 'home':
            self.logger.info('FINISHED AD')
            return
        time.sleep(2)
        attempts += 1
    # If the bot hasn't returned to the home screen after 40 seconds:
    self.logger.info(f'AD TIME {attempts} {status}')
    self.shell(f'input keyevent {const.KEYCODE_BACK}')  # Force back
    # Restart game if can't escape ad
    self.restart_RR()           

Add refresh_buitton to icon folder refresh_button add x_mark and x_mark1

x_mark1 x_mark lastly go to bot_handler and change the line that starts with #wait for game to load

# Wait for game to load
while (not bot.bot_stop):
    bot.store_visited = False  # Reset the store_visited attribute at the beginning of each loop iteration

i also have function to watch add in store whenever available if anyone wants it leave a comment or lmk if you're having issues with implementing the store

discord newb4u