Skip to content

Commit

Permalink
Improving event collecting and adding VN server support
Browse files Browse the repository at this point in the history
  • Loading branch information
Jc authored and Jc committed Aug 7, 2024
1 parent ba3118d commit 2852694
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 24 deletions.
59 changes: 39 additions & 20 deletions AutoAFK2.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,23 @@
version = '0.6.1'
# Current time in UTC for tracking which towers/events are open
currenttimeutc = datetime.now(timezone.utc)
# Game version to launch
global server
server = 'com.farlightgames.igame.gp'

# Configure launch arguments
parser = argparse.ArgumentParser()
parser.add_argument("-a", "--abyss", action='store_true', help = "Run the Trial of Abyss retry function")
parser.add_argument("-l", "--legend", action='store_true', help = "Run the Legend Trials retry function")
parser.add_argument("-t", "--teamup", action='store_true', help = "Run the Team-up function")
parser.add_argument("-d", "--dailies", action='store_true', help = "Run the Dailies function")
parser.add_argument("-q", "--quest", action='store_true', help = "Runs the Quest running function")
parser.add_argument("-afks", action='store_true', help = "Singles")
parser.add_argument("-afkm", action='store_true', help = "Multis")
parser.add_argument("-test", "--test", action='store_true', help = "Used for testing functions")
parser.add_argument("-dr", "--dream", action='store_true', help = "Run the Dream Realm function")
parser.add_argument("-c", "--config", metavar="CONFIG", default = "settings.ini", help = "Define alternative settings file to load")
parser.add_argument("-a", "--abyss", action='store_true', help="Run the Trial of Abyss retry function")
parser.add_argument("-l", "--legend", action='store_true', help="Run the Legend Trials retry function")
parser.add_argument("-t", "--teamup", action='store_true', help="Run the Team-up function")
parser.add_argument("-d", "--dailies", action='store_true', help="Run the Dailies function")
parser.add_argument("-q", "--quest", action='store_true', help="Runs the Quest running function")
parser.add_argument("-s", "--server", choices=['global', 'vn'], default='global', help="Select alernative game servers")
parser.add_argument("-afks", action='store_true', help="Singles")
parser.add_argument("-afkm", action='store_true', help="Multis")
parser.add_argument("-test", "--test", action='store_true', help="Used for testing functions")
parser.add_argument("-dr", "--dream", action='store_true', help="Run the Dream Realm function")
parser.add_argument("-c", "--config", metavar="CONFIG", default="settings.ini", help="Define alternative settings file to load")
parser.add_argument('--forceprint', action='store_true', help='Force print output')
args = vars(parser.parse_args())

Expand All @@ -41,6 +45,10 @@
settings = os.path.join(cwd, 'settings.ini')
config.read(settings)

# Change server if necessary
if args['server'] == 'vn':
globals()['server'] = 'com.farlightgames.igame.gp.vn'

# Make a nice name for the output log file
if settings == 'settings.ini':
logname = 'autoafk2.log'
Expand Down Expand Up @@ -117,7 +125,7 @@ def handle_exception(exc_type, exc_value, exc_traceback):
logger.info('Version: ' + version)

# Boot up activities before tasks are ran
connect_and_launch(port=config.get('ADVANCED', 'port'))
connect_and_launch(port=config.get('ADVANCED', 'port'), server=globals()['server'])
resolutionCheck()
waitUntilGameActive()

Expand Down Expand Up @@ -574,12 +582,16 @@ def claim_events():
click('buttons/event', region=regions['menu_activities'], seconds=3)

# All Heroes
if not isVisible('events/all_heroes', seconds=2) or not isVisible('events/all_heroes_inactive', seconds=2):
swipe(1000, 1800, 250, 1800, 500) # If we can't see it swipe the bar left
if isVisible('events/all_heroes', click=True, seconds=2) or isVisible('events/all_heroes_inactive', click=True, seconds=2):
if isVisible('events/all_heroes_claim', click=True, confidence=0.8, retry=10, yrelative=100):
logger.info('All Heroes claimed')
click_location('neutral')
elif not isVisible('events/all_heroes', seconds=2) or not isVisible('events/all_heroes_inactive', seconds=2):
swipe(1000, 1800, 250, 1800, 500, seconds=2) # If we can't see it swipe the bar left
if isVisible('events/all_heroes', click=True, seconds=2) or isVisible('events/all_heroes_inactive', click=True, seconds=2):
if isVisible('events/all_heroes_claim', click=True, confidence=0.8, retry=10, yrelative=100):
logger.info('All Heroes claimed')
click_location('neutral')

# Fishing Diary
if not isVisible('events/fishing_diary_inactive', seconds=2, region=regions['bottom_buttons']):
Expand Down Expand Up @@ -687,25 +699,32 @@ def blind_push(mode, tower=None, victory=True):
recover()

if mode == "dream_realm":
# TODO: rewrite, handle paid attempts and battle complete detection, and no battles left detection
logger.info('Auto-retrying Dream Realm')
safe_open_and_close(name=inspect.currentframe().f_code.co_name, state='open')

clickXY(450, 1825, seconds=3)
click('buttons/dream_realm', region=regions['battle_modes'], seconds=3)

for _ in range(10):
if isVisible('buttons/battle', region=regions['bottom_buttons'], click=True, seconds=5):
if isVisible('buttons/battle', region=regions['bottom_buttons'], click=True, seconds=3):
for _ in range(6):
if isVisible('buttons/battle', region=regions['bottom_buttons'], click=True, seconds=5): # Enter battle screen
logger.info('found')
if isVisible('buttons/battle', region=regions['bottom_buttons'], click=True, seconds=3): # Start battle
while not isVisible('labels/tap_to_close', region=regions['bottom_buttons']):
if isVisible('buttons/battle', region=regions['bottom_buttons']):
logger.info('break')
break
if isVisible('buttons/deny', click=True):
logger.info('break2')
break
else:
click_location('neutral')
while isVisible('labels/tap_to_close', region=regions['bottom_buttons']): # Few clicks to clear loot too
while isVisible('labels/tap_to_close', region=regions['bottom_buttons'], click=True): # Few clicks to clear loot too
click('labels/tap_to_close', region=regions['bottom_buttons'], seconds=4, suppress=True)
logger.info('Battle complete!')
else:
break
logger.info('Dream Realm Battle #' + str(_) + ' complete!')
wait(3)
else:
logger.info('not found')

if safe_open_and_close(name=inspect.currentframe().f_code.co_name, state='close'):
logger.info('Dream Realm attempts exhausted.\n')
Expand Down
8 changes: 4 additions & 4 deletions tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
global connect_attempts
connect_attempts = 1

def connect_and_launch(port):
def connect_and_launch(port, server):
global device
global connect_attempts

Expand Down Expand Up @@ -57,10 +57,10 @@ def connect_and_launch(port):
logger.info('Device ' + str(device.serial) + " connected successfully")

# Sometimes the game crashes when launching so we make sure its been running for 5 seconds before continuing
device.shell('monkey -p com.farlightgames.igame.gp 1')
device.shell('monkey -p ' + server + ' 1')
wait(5) # This long wait doesn't slow anything down as the game takes 60 seconds to load anyway
while device.shell('pidof com.farlightgames.igame.gp') == '':
device.shell('monkey -p com.farlightgames.igame.gp 1')
while device.shell('pidof ' + server) == '':
device.shell('monkey -p ' + server + ' 1')
wait(5) # This long wait doesn't slow anything down as the game takes 60 seconds to load anyway

def get_adb_device(port):
Expand Down

0 comments on commit 2852694

Please sign in to comment.