Skip to content

Commit c81c0ce

Browse files
author
Jc
committed
Updating function for Season 3 Duras Trials and fixing Sunday Tower selection menu
1 parent d6b295f commit c81c0ce

5 files changed

Lines changed: 100 additions & 60 deletions

File tree

AutoAFK2.py

Lines changed: 99 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,7 @@ def formation_handler(formation_number=1, already_open=False):
755755
logger.info('Loading formation #' + str(math.trunc(globals()['formation'])))
756756
counter = 1
757757
unowned_counter = 0
758+
wait()
758759
if already_open is False: # Sometimes we're already in the formations menu
759760
click('buttons/records', seconds=3)
760761
while counter != formation_number:
@@ -772,6 +773,8 @@ def formation_handler(formation_number=1, already_open=False):
772773
unowned_counter += 1
773774
if unowned_counter > 7:
774775
logger.info('All formations contained an unowned hero!')
776+
click_location('neutral') # Close windows back to battle screen
777+
click_location('neutral') # Close windows back to battle screen
775778
break
776779
click('buttons/confirm', suppress=True)
777780

@@ -1102,12 +1105,56 @@ def handle_charms():
11021105
# Handles navigating the charms screen
11031106
def go_back(exit_mode=False):
11041107
click('buttons/confirm', suppress=True)
1105-
click('buttons/back', suppress=True)
1106-
click('buttons/back', suppress=True)
1108+
click('buttons/back2', suppress=True, region=regions['bottom_buttons'])
11071109
if exit_mode is True:
11081110
click('buttons/back', suppress=True)
11091111
click('buttons/back2', suppress=True)
11101112

1113+
# Handle Battles
1114+
def handle_battle(floor_type=''):
1115+
while True:
1116+
click('buttons/battle', retry=1, suppress=True, seconds=0)
1117+
if isVisible('labels/multiple_attempts', seconds=0):
1118+
logger.info('Out of tries!\n')
1119+
click('buttons/confirm')
1120+
if floor_type == 'nightmare': # Exit back to charm row selection screen
1121+
click('buttons/back', suppress=True, seconds=2)
1122+
click('buttons/back2', suppress=True, seconds=2)
1123+
else: # Else just exit back to the Dawnrise/Nightmare screen to we can naviate to Nightmare next
1124+
click('buttons/back', suppress=True, seconds=2)
1125+
break
1126+
click('buttons/confirm', retry=1, suppress=True, seconds=0)
1127+
if isVisible('buttons/retry', retry=1, click=True, seconds=4, region=(650, 1750, 200, 150)):
1128+
# Increment defeats
1129+
globals()['stage_defeats'] += 1
1130+
# If were past the defeat cap handle formation change, else standard log output
1131+
if globals()['stage_defeats'] >= 1 and globals()['stage_defeats'] % config.getint('PUSHING', 'defeat_limit') == 0:
1132+
globals()['formation'] = (globals()['stage_defeats'] / config.getint('PUSHING',
1133+
'defeat_limit')) + 1 # number of defeats / defeat_limit, plus 1 as we start on formation #1
1134+
logger.info('Defeat #' + str(globals()['stage_defeats']) + ' trying next formation')
1135+
formation_handler(globals()['formation'])
1136+
else:
1137+
logger.info('Defeat #' + str(globals()['stage_defeats']) + ' Retrying')
1138+
# Handle different victory screens for Dawnrise/Nightmare
1139+
if floor_type == 'dawnrise':
1140+
if isVisible('buttons/next2', retry=1, click=True, seconds=5):
1141+
logger.info('Victory!\n')
1142+
globals()['stage_defeats'] = 0
1143+
formation_handler()
1144+
if isVisible('buttons/retry2', retry=1, seconds=5):
1145+
logger.info('Victory! Highest stage cleared!\n')
1146+
click('buttons/back', suppress=True, seconds=2)
1147+
break
1148+
elif floor_type == 'nightmare':
1149+
if isVisible('buttons/continue_green', retry=1, click=True, seconds=5, grayscale=False, confidence=0.95): # High confidence so we don't catch the greyscale version
1150+
logger.info('Victory!\n')
1151+
globals()['stage_defeats'] = 0
1152+
formation_handler()
1153+
if isVisible('buttons/continue_green', retry=1, click=True, seconds=5):
1154+
logger.info('Victory! Highest stage cleared!\n')
1155+
click('buttons/back', suppress=True, seconds=2)
1156+
click('buttons/back2', suppress=True, seconds=2)
1157+
11111158
top_max_floor = False
11121159
bottom_max_floor = False
11131160

@@ -1123,74 +1170,62 @@ def go_back(exit_mode=False):
11231170

11241171
if isVisible('buttons/featured_heroes', retry=5, region=regions['top_third']):
11251172

1173+
# TODO Rewrite using regions for the 6 charm stages, to better handle duplicate code for top/bottom row
1174+
11261175
# Check top row
11271176
logger.info('Checking top row Charm Trials..')
11281177
globals()['stage_defeats'] = 0
11291178
if isVisible('buttons/rate_up', grayscale=True, click=True, region=(50, 1175, 950, 150), confidence=0.75, seconds=4):
1130-
clickXY(750, 1800, seconds=6)
1131-
if isVisible('buttons/sweep_buttons', seconds=0):
1132-
logger.info('Max floor reached! Checking bottom row..\n')
1133-
top_max_floor = True
1134-
go_back()
1135-
if top_max_floor is False:
1179+
1180+
# Handle top row Dawnrise
1181+
logger.info('Checking Dawnrise')
1182+
clickXY(400, 1800, seconds=7)
1183+
if isVisible('buttons/sweep', seconds=0, retry=2, region=regions['bottom_third']):
1184+
logger.info('Max Dawnrise floor reached!\n')
1185+
else:
1186+
if isVisible('buttons/battle', click=True, seconds=6, region=regions['bottom_third']):
1187+
logger.info('Dawnrise battle found!\n')
1188+
formation_handler(globals()['formation'])
1189+
handle_battle(floor_type='dawnrise')
1190+
1191+
# Handle top row Nightmare
1192+
logger.info('Checking Nightmare')
1193+
clickXY(830, 1800, seconds=7)
1194+
if isVisible('buttons/battle', click=True, seconds=6, region=regions['bottom_third']):
11361195
formation_handler(globals()['formation'])
1137-
while 1 == 1:
1138-
click('buttons/battle', retry=1, suppress=True, seconds=0)
1139-
if isVisible('labels/multiple_attempts', seconds=0):
1140-
logger.info('Out of tries! Checking bottom row..\n')
1141-
go_back()
1142-
break
1143-
click('buttons/confirm', retry=1, suppress=True, seconds=0)
1144-
if isVisible('buttons/retry', retry=1, click=True, seconds=4, region=(650, 1750, 200, 150)):
1145-
# Increment defeats
1146-
globals()['stage_defeats'] += 1
1147-
# If were past the defeat cap handle formation change, else standard log output
1148-
if globals()['stage_defeats'] >= 1 and globals()['stage_defeats'] % config.getint('PUSHING', 'defeat_limit') == 0:
1149-
globals()['formation'] = (globals()['stage_defeats'] / config.getint('PUSHING', 'defeat_limit')) + 1 # number of defeats / defeat_limit, plus 1 as we start on formation #1
1150-
logger.info(str(globals()['stage_defeats']) + ' defeats, trying next formation')
1151-
formation_handler(globals()['formation'])
1152-
else:
1153-
logger.info('Defeat #' + str(globals()['stage_defeats']) + '! Retrying')
1154-
if isVisible('buttons/next2', retry=1, click=True, seconds=5):
1155-
logger.info('Victory!\n')
1156-
globals()['stage_defeats'] = 0
1157-
formation_handler()
1196+
handle_battle(floor_type='nightmare')
1197+
else:
1198+
logger.info('Max Nightmare floor reached!\n')
1199+
click('buttons/back2', suppress=True, seconds=2)
11581200
else:
11591201
logger.info("Top row not found..")
11601202

11611203
# Check bottom row
1162-
logger.info('Checking bottom row Charm Trials..')
1204+
logger.info('Checking bottom row Charm Dawnrise Trials..')
11631205
globals()['stage_defeats'] = 0
11641206
globals()['formation'] = 1 # Reset on new levels
11651207
if isVisible('buttons/rate_up', grayscale=True, click=True, region=(50, 1400, 950, 150), confidence=0.75, seconds=3):
1166-
clickXY(750, 1800, seconds=6)
1167-
if isVisible('buttons/sweep_buttons', seconds=0):
1168-
logger.info('Max floor reached! Checking bottom row..\n')
1169-
bottom_max_floor = True
1170-
go_back()
1171-
if bottom_max_floor is False:
1172-
formation_handler()
1173-
while 1 == 1:
1174-
click('buttons/battle', retry=1, suppress=True, seconds=0)
1175-
if isVisible('labels/multiple_attempts', seconds=0):
1176-
logger.info('Out of tries! Exiting..\n')
1177-
go_back(exit_mode=True)
1178-
break
1179-
click('buttons/confirm', retry=1, suppress=True, seconds=0)
1180-
if isVisible('buttons/retry', retry=1, click=True, seconds=4, region=(650, 1750, 200, 150)):
1181-
# Increment defeats
1182-
globals()['stage_defeats'] += 1
1183-
# If were past the defeat cap handle formation change, else standard log output
1184-
if globals()['stage_defeats'] >= 1 and globals()['stage_defeats'] % config.getint('PUSHING', 'defeat_limit') == 0:
1185-
globals()['formation'] = (globals()['stage_defeats'] / config.getint('PUSHING', 'defeat_limit')) + 1 # number of defeats / defeat_limit, plus 1 as we start on formation #1
1186-
logger.info(str(globals()['stage_defeats']) + ' defeats, trying next formation')
1187-
formation_handler(globals()['formation'])
1188-
else:
1189-
logger.info('Defeat #' + str(globals()['stage_defeats']) + '! Retrying')
1190-
if isVisible('buttons/next2', retry=1, click=True, seconds=5):
1191-
logger.info('Victory!')
1192-
globals()['stage_defeats\n'] = 0
1193-
formation_handler()
1208+
1209+
# Handle bottom row Dawnrise
1210+
logger.info('Checking Dawnrise')
1211+
clickXY(400, 1800, seconds=7)
1212+
if isVisible('buttons/sweep', seconds=0, retry=2, region=regions['bottom_third']):
1213+
logger.info('Max Dawnrise floor reached!\n')
1214+
else:
1215+
if isVisible('buttons/battle', click=True, seconds=6, region=regions['bottom_third']):
1216+
logger.info('Dawnrise battle found!\n')
1217+
formation_handler(globals()['formation'])
1218+
handle_battle(floor_type='dawnrise')
1219+
1220+
# Handle bottom row Nightmare
1221+
logger.info('Checking Nightmare')
1222+
clickXY(830, 1800, seconds=7)
1223+
if isVisible('buttons/battle', click=True, seconds=6, region=regions['bottom_third']):
1224+
formation_handler(globals()['formation'])
1225+
handle_battle(floor_type='nightmare')
1226+
else:
1227+
logger.info('Max Nightmare floor reached!\n')
1228+
go_back(exit_mode=True)
11941229
else:
11951230
logger.info("Bottom row not found..")
11961231
else:
@@ -1305,7 +1340,7 @@ def emit(self, record):
13051340
4: ["Push Graveborn Tower"],
13061341
5: ["Push Lightbringer Tower", "Push Mauler Tower"],
13071342
6: ["Push Wilder Tower", "Push Graveborn Tower"],
1308-
7: ["Push Lightbringer Tower", "Push Wilder Tower", "Push Mauler Tower", "Push Graveborn Tower"]}
1343+
7: ["Push Lightbringer Tower", "Push Wilder Tower", "Push Graveborn Tower", "Push Mauler Tower"]}
13091344

13101345
# Add tower to the list if it's unlocked
13111346
for day, towers in open_towers.items():
@@ -1344,13 +1379,17 @@ def emit(self, record):
13441379

13451380
if selection == 3:
13461381
if day == 7:
1347-
blind_push('push_tower', 'wilder')
1382+
blind_push('push_tower', 'graveborn')
13481383

13491384
if selection == 4:
13501385
day = currenttimeutc.isoweekday()
13511386
if day == 7:
13521387
blind_push('push_tower', 'mauler')
13531388

1389+
if selection == 5:
1390+
SelectionMenu.get_selection(options, title='Welcome to AutoAFK2! Select an activity:', subtitle='Note that to stop a task or start a new one you have to restart the bot. Questions? Jc.2 @ Discord')
1391+
selection += 1 # Non-zero index to make things easier to read
1392+
13541393
if selection == 3:
13551394
safe_open_and_close(name=inspect.currentframe().f_code.co_name, state='open')
13561395
logger.info('Auto-pushing AFK Stages')

img/buttons/continue_green.png

17.6 KB
Loading

img/buttons/retry2.png

13.9 KB
Loading

img/buttons/sweep.png

13.2 KB
Loading

settings.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ port = 5555
2121
auto_find_device = True
2222
loading_multiplier = 1
2323
collect_daily_rewards = True
24+
use_level_up_all = True
2425

2526
[PUSHING]
2627
defeat_limit = 5

0 commit comments

Comments
 (0)