Skip to content

Commit

Permalink
Fixing stage pushing false positive. Nicer window name.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jc committed Nov 5, 2024
1 parent 75430af commit 88fcffc
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions AutoAFK2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from consolemenu import *
from consolemenu.items import *
from datetime import datetime, timezone
import ctypes

# Global variables for tracking time passed between team-up activities
global last_synergy
Expand All @@ -19,7 +20,7 @@
global first_stage_won
first_stage_won = False
# Version output so I can work out which version I'm actually running for debugging
version = '0.9.5'
version = '0.9.9'
# Current time in UTC for tracking which towers/events are open
currenttimeutc = datetime.now(timezone.utc)
# Game version to launch
Expand Down Expand Up @@ -131,6 +132,9 @@ def handle_exception(exc_type, exc_value, exc_traceback):
logger.info('Loaded settings file: ' + str(settings.split('\\')[-1]))
logger.info('Version: ' + version)

# Nice name for the window and debugging peoples screenshots
ctypes.windll.kernel32.SetConsoleTitleW("AutoAFK2 v" + version)

# Boot up activities before tasks are ran
connect_and_launch(port=config.get('ADVANCED', 'port'), server=globals()['server'])
resolutionCheck()
Expand Down Expand Up @@ -862,7 +866,7 @@ def auto_load_formation():

# For pushing afk stages
if mode == 'afkstages':
if isVisible('buttons/records', region=regions['bottom_buttons'], seconds=0, retry=5):
if isVisible('buttons/records', region=regions['bottom_buttons'], seconds=0, retry=10):

# Change formation if we we beat the 2nd round or have defeat >10 times in a row
if load_formation is True or globals()['afk_stage_defeats'] >= 10:
Expand All @@ -879,7 +883,7 @@ def auto_load_formation():
click('buttons/confirm', seconds=2, suppress=True)
if globals()['first_stage_won'] is True:
clickXY(550, 1100)
else:
elif load_formation is True:
logger.info('Loading formation')
click('buttons/records', seconds=2)
click('buttons/copy', seconds=1)
Expand All @@ -899,15 +903,18 @@ def auto_load_formation():
wait()

# Then check for Victory or Defeat
result_value = return_pixel_colour(1050, 1000, 2) # Returns blue value of a pixel in the floating victory/defeat pop up
if result_value > 100: # Blue above 100 is defeat screen
wait() # Small wait before we read to prevent false positives
result_value = return_pixel_colour(625, 1025, 2) # Returns blue value of a pixel in the floating victory/defeat pop up
if result_value > 140: # Blue above 140 is defeat screen
globals()['afk_stage_defeats'] += 1
logger.info('Defeat #' + str(globals()['afk_stage_defeats']) + '! Retrying')
clickXY(550, 1800, seconds=3)
clickXY(750, 1800, seconds=3)
blind_push('afkstages', load_formation=False)
elif result_value < 100: # Blue under 100 is orange-y, so the victory screen
elif result_value < 90: # Blue under 90 is orange-y, so the victory screen
globals()['afk_stage_defeats'] = 0
logger.info('First round won!')
# timestamp = datetime.now().strftime('%d-%m-%y_%H-%M-%S')
# save_screenshot('first_round_pass_' + timestamp)
clickXY(750, 1800, seconds=3)
blind_push('afkstages', load_formation=False)

Expand Down

0 comments on commit 88fcffc

Please sign in to comment.