Skip to content

Commit

Permalink
Season 3 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jc committed Jan 15, 2025
1 parent c98c6a9 commit 1b2062c
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 90 deletions.
217 changes: 127 additions & 90 deletions AutoAFK2.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
first_stage_won = False

# placeholder gets replaced during build process with release tag.
version = '0.9.14'
version = '3.1.1'

# Current time in UTC for tracking which towers/events are open
currenttimeutc = datetime.now(timezone.utc)
Expand Down Expand Up @@ -319,20 +319,20 @@ def claim_afk_rewards():
clickXY(100, 1800, seconds=4) # Open AFK Rewards
clickXY(750, 1750, seconds=4) # Clear Pop-Up

if isVisible('labels/afk_rewards_woi', region=[0, 680, 150, 200]):
if isVisible('labels/afk_rewards_coe', region=[0, 680, 150, 200]):
clickXY(550, 1400) # Click Chest
clickXY(550, 1080) # Click Collect
wait(2) # Wait and claim again to complete daily quest
clickXY(550, 1400) # Click Chest
clickXY(550, 1080) # Click Collect

# Fast rewards
if isVisible('labels/afk_rewards_woi', region=[0, 680, 150, 200]):
if isVisible('labels/afk_rewards_coe', region=[0, 680, 150, 200]):
for _ in range(config.getint('ACTIVITIES', 'fast_rewards')):
if isVisible('buttons/fast_rewards', click=True):
logger.info('Fast reward #' + str(_ + 1) + ' claimed')
click('buttons/confirm', suppress=True)
clickXY(1000, 1800)
clickXY(800, 1800)

clickXY(100, 1800) # Close
if safe_open_and_close(name=inspect.currentframe().f_code.co_name, state='close'):
Expand Down Expand Up @@ -385,7 +385,7 @@ def emporium_purchases():

click('buttons/main_menu', region=regions['main_menu'])
click('buttons/emporium', region=regions['menu_activities'], seconds=2)
clickXY(100, 700, seconds=2) # guild store
click('buttons/guild_store')
if isVisible('labels/emporium_guild', region=regions['top_third']):
if isVisible('emporium/guild_summoncard'):
click('emporium/guild_summoncard', region=regions['middle_third'])
Expand All @@ -394,7 +394,7 @@ def emporium_purchases():
click_location('neutral')
else:
logger.info('Daily card already purchased!')
click('buttons/back2', region=regions['back'])
click('buttons/back2', region=regions['back'], seconds=2)
click('buttons/back', region=regions['back'])
if safe_open_and_close(name=inspect.currentframe().f_code.co_name, state='close'):
logger.info('Daily summon card purchased!\n')
Expand Down Expand Up @@ -431,6 +431,7 @@ def arena(battles=9):
clickXY(550, 1800)
if isVisible('buttons/skip_inverse', seconds=0, region=regions['x3_and_skip']):
click('buttons/skip_inverse', seconds=3, region=regions['x3_and_skip'])
click('buttons/confirm', suppress=True)
logger.info('Skip available, skipping the fight')
timeout += 1
if timeout > 40: # Should be about 10 seconds longer than a full fight at 2x
Expand Down Expand Up @@ -463,6 +464,7 @@ def dream_realm():

clickXY(450, 1825, seconds=3)
click('buttons/dream_realm', region=regions['battle_modes'], seconds=3)
clickXY(1000, 50) # Clear new season info popup

# First collect rewards
if isVisible('buttons/battle', region=regions['bottom_buttons']):
Expand All @@ -486,6 +488,8 @@ def dream_realm():
if timer > 60:
logger.info('DR Timer Exceeded!')
break
if isVisible('labels/dr_first_kill'):
clickXY(550, 1800) # clear rewards popup
pass
click('labels/tap_to_close', region=regions['bottom_buttons'], seconds=5, suppress=True)
if isVisible('buttons/deny', click=True, seconds=3):
Expand All @@ -508,7 +512,7 @@ def single_recruit():
# Navigate and open all hero recruitment
clickXY(300, 1850, seconds=6)
clickXY(420, 700, seconds=6)
click('buttons/all_hero_recruitment', seconds=6)
click('buttons/all_hero_recruitment', seconds=7)

# Perform recruit, lots of long waits here as the animations are slow before we stabilise again
if isVisible('labels/all_hero_recruitment', region=regions['bottom_buttons']):
Expand Down Expand Up @@ -552,16 +556,19 @@ def collect_quests():
# Season Quests
logger.info(' Collecting Season Growth Trials')
clickXY(950, 1825, seconds=2)
# Season Growth Trials
while isVisible('labels/reward', click=True, region=(232, 451, 700, 100)):
while isVisible('buttons/quests_claim'):
click('buttons/quests_claim')

# Season Growth Quests
logger.info(' Collecting Season Growth Quests')
clickXY(300, 1670, seconds=2)
while isVisible('buttons/quests_claim'):
click('buttons/quests_claim')

# Season Growth Trials
clickXY(800, 1670, seconds=2)
while isVisible('labels/reward', click=True, region=(232, 451, 700, 100)):
while isVisible('buttons/quests_claim'):
click('buttons/quests_claim')

click('buttons/back2', region=regions['back'])
click('buttons/back', region=regions['back'])

Expand Down Expand Up @@ -606,24 +613,23 @@ def dust_level():
if safe_open_and_close(name=inspect.currentframe().f_code.co_name, state='close'):
logger.info('Heroes levelled!\n')

def farm_affinity(heroes=60): # 60 heros in game as of Tasi
logger.info('Clicking ' + str(heroes) + ' heroes for daily affinity bonus')
def farm_affinity(): # 100 is a failsafe in case we don't see Chippy
logger.info('Clicking all heroes for daily +6 affinity bonus')
safe_open_and_close(name=inspect.currentframe().f_code.co_name, state='open')

counter = 1
rare_counter = 0
clickXY(650, 1850, seconds=5) # Open heroes hall
clickXY(150, 1050, seconds=3) # Click top right hero

if isVisible('buttons/affinity', region=regions['top_third']):
while counter < heroes:
if counter % 10 == 0:
logger.info('Tapping ' + str(counter) + 'th hero')
clickXY(550, 1000, seconds=1)
clickXY(550, 1000, seconds=1)
clickXY(550, 1000, seconds=1)
clickXY(620, 1800, seconds=0.5)
while rare_counter < 3:
if isVisible('labels/rare_hero', region=[15, 5, 105, 65]):
logger.info('Hamster spotted!')
rare_counter += 1
for clicks in range(3):
clickXY(550, 1000, seconds=1)
clickXY(100, 1800, seconds=1)
clickXY(1000, 1100, seconds=1.5)
counter += 1
click('buttons/back', region=regions['back'], seconds=2)
click('buttons/back2', region=regions['back'])
if safe_open_and_close(name=inspect.currentframe().f_code.co_name, state='close'):
Expand Down Expand Up @@ -750,7 +756,7 @@ def formation_handler(formation_number=1, already_open=False):
# Handle 'Hero not owned' popup
if isVisible('labels/not_owned'):
while isVisible('labels/not_owned'): # Try next formation and check again
logger.info('Hero not owned, trying next formation..')
logger.info('Hero/Artifact not owned, trying next formation..')
clickXY(360, 1250)
clickXY(1000, 1025)
click('buttons/copy')
Expand Down Expand Up @@ -782,7 +788,7 @@ def blind_push(mode, tower=None, load_formation=True):
while True:
if isVisible("buttons/next", click=True, retry=3, seconds=5, region=regions['bottom_buttons']):
logger.info(faction + ' win detected, moving to next floor')
click("buttons/battle")
click("buttons/battle", retry=5)
elif isVisible("buttons/retry", region=regions['bottom_buttons']):
logger.info(faction + ' defeat!')
click("buttons/back")
Expand Down Expand Up @@ -919,77 +925,108 @@ def blind_push(mode, tower=None, load_formation=True):
elif load_formation is True:
formation_handler(globals()['formation'])

# If multis_first_victory we know we've won the first round, if not formation_swap it's not a multi so we jump to the second fight check
if isVisible('labels/multis_first_victory', seconds=0):
globals()['first_stage_won'] = True
if not isVisible('buttons/formation_swap', seconds=0):
globals()['first_stage_won'] = True
# Season 3 single stage code

# Start Battle
click('buttons/battle', retry=5, region=regions['bottom_buttons'], seconds=0)
click('buttons/confirm', seconds=0, suppress=True)

# In a multi first stage always gives 'Continue' screen so we check for that for victory/defeat markers
if globals()['first_stage_won'] is False:
result_value = isVisible_array(['labels/defeat', 'labels/victory'], confidence=0.9)
# Loop until we see either the Victory or Defeat screen
while result_value == 'not_found':
timeout += 1
if timeout > 100: # If nothing at 30 seconds start clicking in case battery saver mode is active
if timeout_warned is False:
logger.info('Possibly stuck, attempting to continue..')
debug_screen('battle_stuck')
timeout_warned = True
clickXY(550, 1100) # Second Battle
clickXY(900, 1800) # Start Battle button
if timeout > 200: # Still nothing at 60 seconds? Quit as somethings gone wrong and record the screen for debugging
logger.info('Battle timeout error!')
debug_screen('battle_timeout')
sys.exit(2)
result_value = isVisible_array(['labels/defeat', 'labels/victory'], confidence=0.9)
wait()
timeout = 0 # Reset timer after result found

# Take actions for victory or defeat
if result_value == 'labels/defeat':
globals()['stage_defeats'] += 1
logger.info('Defeat #' + str(globals()['stage_defeats']) + '! Retrying')
clickXY(550, 1800, seconds=3)
blind_push('afkstages', load_formation=False)
elif result_value == 'labels/victory':
globals()['stage_defeats'] = 0
logger.info('First round won!')
clickXY(730, 1800, seconds=3)
blind_push('afkstages', load_formation=False)

# Handle second stage or single stage logic
if globals()['first_stage_won'] is True:
# Wait for battle to end with either Continue button or Back button
while not isVisible('buttons/continue_stages', region=regions['bottom_buttons']):
timeout += 1
if timeout > 30: # If nothing at 30 seconds start clicking in case battery saver mode is active
click_location('neutral')
if timeout > 60: # Still nothing at 60 seconds? Quit as somethings gone wrong
logger.info('Battle timeout error!')
break
if isVisible('buttons/back', region=regions['bottom_buttons'], seconds=0):
break
wait()
# Continue on second battle is always defeat
if isVisible('buttons/continue_stages', region=regions['bottom_buttons']):
globals()['stage_defeats'] += 1
logger.info('Defeat #' + str(globals()['stage_defeats']) + '! Retrying')
clickXY(730, 1800, seconds=3)
blind_push('afkstages', load_formation=False)
# If we see a Back button we're at the Stage Passed screen (or seriously lost)
if isVisible('buttons/back', region=regions['bottom_buttons']):
globals()['stage_defeats'] = 0 # Reset defeats
globals()['formation'] = 1 # Reset formation
logger.info('Victory! Stage passed\n')
clickXY(750, 1800, seconds=4)
globals()['first_stage_won'] = False
blind_push('afkstages', load_formation=True)

# Wait til we see the back button in the post battle screen
while not isVisible('buttons/back', region=regions['bottom_buttons'], seconds=2):
timeout += 1
if timeout > 30: # If nothing at 30 seconds start clicking in case battery saver mode is active
click_location('neutral')
if timeout > 60: # Still nothing at 60 seconds? Quit as somethings gone wrong
logger.info('Battle timeout error!')
break
wait()
# Retry button indicates defeat, we run the defeat logic
if isVisible('buttons/retry', region=regions['bottom_buttons']):
globals()['stage_defeats'] += 1
logger.info('Defeat #' + str(globals()['stage_defeats']) + '! Retrying')
clickXY(730, 1800, seconds=3)
blind_push('afkstages', load_formation=False)
# Battle button indicated victory, we run the victory logic
if isVisible('buttons/battle', region=regions['bottom_buttons']):
globals()['stage_defeats'] = 0 # Reset defeats
globals()['formation'] = 1 # Reset formation
logger.info('Victory! Stage passed\n')
clickXY(750, 1800, seconds=4)
globals()['first_stage_won'] = False
blind_push('afkstages', load_formation=True)

# Season 2 multi battle legacy code

# # If multis_first_victory we know we've won the first round, if not formation_swap it's not a multi so we jump to the second fight check
# if isVisible('labels/multis_first_victory', seconds=0):
# globals()['first_stage_won'] = True
# if not isVisible('buttons/formation_swap', seconds=0):
# globals()['first_stage_won'] = True
#
# # Start Battle
# click('buttons/battle', retry=5, region=regions['bottom_buttons'], seconds=0)
# click('buttons/confirm', seconds=0, suppress=True)
#
# # In a multi first stage always gives 'Continue' screen so we check for that for victory/defeat markers
# if globals()['first_stage_won'] is False:
# result_value = isVisible_array(['labels/defeat', 'labels/victory'], confidence=0.9)
# # Loop until we see either the Victory or Defeat screen
# while result_value == 'not_found':
# timeout += 1
# if timeout > 100: # If nothing at 30 seconds start clicking in case battery saver mode is active
# if timeout_warned is False:
# logger.info('Possibly stuck, attempting to continue..')
# debug_screen('battle_stuck')
# timeout_warned = True
# clickXY(550, 1100) # Second Battle
# clickXY(900, 1800) # Start Battle button
# if timeout > 200: # Still nothing at 60 seconds? Quit as somethings gone wrong and record the screen for debugging
# logger.info('Battle timeout error!')
# debug_screen('battle_timeout')
# sys.exit(2)
# result_value = isVisible_array(['labels/defeat', 'labels/victory'], confidence=0.9)
# wait()
# timeout = 0 # Reset timer after result found
#
# # Take actions for victory or defeat
# if result_value == 'labels/defeat':
# globals()['stage_defeats'] += 1
# logger.info('Defeat #' + str(globals()['stage_defeats']) + '! Retrying')
# clickXY(550, 1800, seconds=3)
# blind_push('afkstages', load_formation=False)
# elif result_value == 'labels/victory':
# globals()['stage_defeats'] = 0
# logger.info('First round won!')
# clickXY(730, 1800, seconds=3)
# blind_push('afkstages', load_formation=False)
#
# # Handle second stage or single stage logic
# if globals()['first_stage_won'] is True:
# # Wait for battle to end with either Continue button or Back button
# while not isVisible('buttons/continue_stages', region=regions['bottom_buttons']):
# timeout += 1
# if timeout > 30: # If nothing at 30 seconds start clicking in case battery saver mode is active
# click_location('neutral')
# if timeout > 60: # Still nothing at 60 seconds? Quit as somethings gone wrong
# logger.info('Battle timeout error!')
# break
# if isVisible('buttons/back', region=regions['bottom_buttons'], seconds=0):
# break
# wait()
# # Continue on second battle is always defeat
# if isVisible('buttons/continue_stages', region=regions['bottom_buttons']):
# globals()['stage_defeats'] += 1
# logger.info('Defeat #' + str(globals()['stage_defeats']) + '! Retrying')
# clickXY(730, 1800, seconds=3)
# blind_push('afkstages', load_formation=False)
# # If we see a Back button we're at the Stage Passed screen (or seriously lost)
# if isVisible('buttons/back', region=regions['bottom_buttons']):
# globals()['stage_defeats'] = 0 # Reset defeats
# globals()['formation'] = 1 # Reset formation
# logger.info('Victory! Stage passed\n')
# clickXY(750, 1800, seconds=4)
# globals()['first_stage_won'] = False
# blind_push('afkstages', load_formation=True)
else:
logger.info('Something went wrong opening AFK Stages!')
recover()
Expand Down
Binary file added img/buttons/guild_store.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/labels/afk_rewards_coe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/labels/dr_first_kill.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/labels/rare_hero.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1b2062c

Please sign in to comment.