Skip to content
This repository was archived by the owner on Mar 17, 2024. It is now read-only.

Commit 65a5da1

Browse files
committed
Bounty board rewrite to use images rather than pixel checking. Also fixes double bounty week breaking the old function
1 parent ae13488 commit 65a5da1

10 files changed

Lines changed: 39 additions & 69 deletions

File tree

AutoAFK.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
latest_release = 'Cannot retrieve!'
4444

4545

46-
version = "0.15.5"
46+
version = "0.15.6"
4747

4848
#Main Window
4949
class App(customtkinter.CTk):

activities.py

Lines changed: 30 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,11 @@ def handleBounties():
172172
config.read(settings) # Has to be read here again to update
173173
confirmLocation('darkforest', region=boundaries['darkforestSelect'])
174174
clickXY(600, 1320)
175-
if (isVisible('labels/bountyboard')):
175+
if isVisible('labels/bountyboard', retry=3):
176176
clickXY(650, 1700) # Solo tab
177-
click('buttons/collect_all', seconds=2, suppress=True)
178-
wait(2)
179-
if config.getboolean('BOUNTIES', 'dispatchDust') is True or config.getboolean('BOUNTIES', 'dispatchDiamonds') is True:
180-
dispatchSoloBounties(remaining=config.getint('BOUNTIES', 'remaining'), maxRefreshes=config.getint('BOUNTIES', 'refreshes'))
177+
isVisible('buttons/collect_all', seconds=3, click=True)
178+
if config.getboolean('BOUNTIES', 'solobounties'):
179+
dispatchSoloBounties(remaining=config.getint('BOUNTIES', 'remaining'), maxrefreshes=config.getint('BOUNTIES', 'refreshes'))
181180
clickXY(950, 1700) # Team tab
182181
click('buttons/collect_all', seconds=2, suppress=True)
183182
click('buttons/dispatch', confidence=0.8, suppress=True, grayscale=True)
@@ -188,80 +187,49 @@ def handleBounties():
188187
printError(' Bounty Board not found, attempting to recover')
189188
recover()
190189

191-
# Returns all found instances of the `Dispatch` button then checks pixel colour at an offset to see which resource it is
192-
def dispatchSoloBounties(remaining=2, maxRefreshes=3):
190+
# Loops through the bounty board returning found Dispatch buttons for dispatcher() to handle
191+
# maxrefreshes is how many times to refresh before hitting dispatch all
192+
# remaining is how many leftover bounties we should use dispatch all on rather than refresh again
193+
def dispatchSoloBounties(remaining=2, maxrefreshes=3):
193194
refreshes = 0
194-
while refreshes <= maxRefreshes:
195+
while refreshes <= maxrefreshes:
195196
if refreshes > 0:
196197
printWarning(' Board refreshed (#' + str(refreshes) + ')')
197-
dispatches = returnDispatchButtons()
198-
dispatcher(dispatches) # Send the list to the function to dispatch
198+
dispatcher(returnDispatchButtons()) # Send the list to the function to dispatch
199199
swipe(550, 800, 550, 500, duration=200, seconds=2) # scroll down
200-
dispatches = returnDispatchButtons(scrolled=True)
201-
dispatcher(dispatches) # Send the list to the function to dispatch
200+
dispatcher(returnDispatchButtons(scrolled=True)) # Send the list to the function to dispatch
202201
if refreshes >= 1: # quick read to see how many are left after the last dispatch, else we refresh the board needlessly before we do it
203-
dispatches = returnDispatchButtons(scrolled=True)
204-
if len(dispatches) <= remaining: # if <=remaining bounties left we just dispatch all and continue
202+
if len(returnDispatchButtons(scrolled=True)) <= remaining: # if <=remaining bounties left we just dispatch all and continue
205203
printWarning(' ' + str(remaining) + ' or less bounties remaining, dispatching..')
206204
click('buttons/dispatch', confidence=0.8, suppress=True, grayscale=True)
207205
click('buttons/confirm', suppress=True)
208206
return
209-
if refreshes < maxRefreshes:
207+
if refreshes < maxrefreshes:
210208
clickXY(90, 250)
211209
clickXY(700, 1250)
212210
refreshes += 1
213-
printGreen(' ' + str(maxRefreshes) + ' refreshes done, dispatching remaining..')
211+
printGreen(' ' + str(maxrefreshes) + ' refreshes done, dispatching remaining..')
214212
click('buttons/dispatch', confidence=0.8, suppress=True, grayscale=True)
215213
click('buttons/confirm', suppress=True)
216214

217-
# Recieves a list of Dispatch buttons and checks/dispatches the resource
215+
# Recieves a list of Dispatch buttons Y coordinates and checks/dispatches the resource
218216
def dispatcher(dispatches):
219-
# print(str(len(dispatches)) + ' Dispatches found.') # Debugging
217+
# For loop over each button passed to the function
220218
for button in dispatches:
221-
border_blue = pixelCheck(190, button, 2, seconds=0) # Take a reading from the border of the icon
222-
border_red = pixelCheck(190, button, 0, seconds=0) # Take a reading from the border of the icon
223-
# printWarning('Blue: ' + str(border_blue) + '. Red: ' + str(border_red) + '.') # Debugging
224-
225-
if border_blue < 100 and border_red > 90: # Gold Border
226-
icon_blue = pixelCheck(110, button, 2, seconds=0) # Take a reading from the border of the icon
227-
if icon_blue > 200:
228-
# print('Shards Found')
229-
if config.getboolean('BOUNTIES', 'dispatchShards'):
230-
printGreen(' Dispatching Shards')
231-
clickXY(900, button)
232-
clickXY(350, 1150)
233-
clickXY(750, 1150)
234-
# printGreen(' Skipping Gold')
235-
# continue
236-
237-
elif border_blue > 205 and border_red > 100 and border_red < 120: # Blue Border
238-
# printGreen(' Skipping Soulstone')
239-
continue
240-
241-
elif border_blue >= 185 and border_red >= 105 and border_red <= 135: # Purple Border
242-
icon_red = pixelCheck(110, button, 0, seconds=0) # Take a reading from the border of the icon
243-
if icon_red > 200:
244-
# print('Juice Found')
245-
if config.getboolean('BOUNTIES', 'dispatchJuice'):
246-
printGreen(' Dispatching Juice')
247-
clickXY(900, button)
248-
clickXY(350, 1150)
249-
clickXY(750, 1150)
250-
else:
251-
# print('Dust Found')
252-
if config.getboolean('BOUNTIES', 'dispatchDust'):
253-
printGreen(' Dispatching Dust')
254-
clickXY(900, button)
255-
clickXY(350, 1150)
256-
clickXY(750, 1150)
257-
258-
elif border_blue >= 200 and border_red >= 200: # White Border
259-
# print('Diamonds Found')
260-
if config.getboolean('BOUNTIES', 'dispatchDiamonds'):
261-
printGreen(' Dispatching Diamonds')
262-
clickXY(900, button)
263-
clickXY(350, 1150)
264-
clickXY(750, 1150)
219+
# Names and Buttons
220+
bounty_types = {'dust': 'labels/bounties/dust', 'diamonds': 'labels/bounties/diamonds', 'juice': 'labels/bounties/juice',
221+
'shards': 'labels/bounties/shards', 'gold': 'labels/bounties/gold', 'soulstone': 'labels/bounties/soulstone'}
222+
# For each button we use `region=` to only check the resource in bounds to the left of it
223+
for resource, image in bounty_types.items():
224+
if isVisible(image, region=(30, button-100, 140, 160), seconds=0):
225+
if resource != 'gold' and resource != 'soulstone': # because there's no config setting for these
226+
if config.getboolean('BOUNTIES', 'dispatch' + resource): # If it's enabled dispatch
227+
printBlue('Dispatching ' + resource.title())
228+
clickXY(900, button)
229+
clickXY(350, 1150)
230+
clickXY(750, 1150)
231+
break # Once resource is found and actions taken move onto the next button to save unnecessary checks
232+
265233

266234
def handleArenaOfHeroes(count, opponent):
267235
counter = 0

img/labels/bounties/diamonds.png

7.44 KB
Loading

img/labels/bounties/dust.png

9.73 KB
Loading

img/labels/bounties/gold.png

7.69 KB
Loading

img/labels/bounties/juice.png

12.2 KB
Loading

img/labels/bounties/shards.png

11.9 KB
Loading

img/labels/bounties/soulstone.png

15.6 KB
Loading

settings.ini

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ gladiatorcollect = True
2828
activitybattles = 200
2929

3030
[BOUNTIES]
31+
solobounties = True
3132
teambounties = True
3233
dispatchdust = True
33-
dispatchdiamonds = True
34-
dispatchshards = True
35-
dispatchjuice = True
36-
refreshes = 5
34+
dispatchdiamonds = False
35+
dispatchshards = False
36+
dispatchjuice = False
37+
refreshes = 3
3738
remaining = 2
3839

3940
[EVENTS]

tools.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,10 @@ def selectOpponent(choice, seconds=1, hoe=False):
463463
def returnDispatchButtons(scrolled=False):
464464
screenshot = getFrame()
465465
search = Image.open(os.path.join(cwd, 'img', 'buttons', 'dispatch_bounties.png'))
466-
locations = {(820, 430, 170, 110), (820, 650, 170, 110), (820, 860, 170, 110), (820, 1070, 170, 110), (820, 1280, 170, 110)} # Location of the first 5 buttons
467-
locations_scrolled = {(820, 510, 170, 110), (820, 720, 170, 110), (820, 930, 170, 110), (820, 1140, 170, 110), (820, 1350, 170, 110)} # Location of the first 5 buttons after scrolling down
466+
locations = {(820, 430, 170, 120), (820, 650, 170, 120), (820, 860, 170, 120), (820, 1070, 170, 120), (820, 1280, 170, 120)} # Location of the first 5 buttons
467+
locations_scrolled = {(820, 460, 170, 160), (820, 670, 170, 160), (820, 880, 170, 160), (820, 1090, 170, 160), (820, 1300, 170, 160)} # Location of the first 5 buttons after scrolling down
468468
dispatchButtons = []
469+
wait()
469470

470471
# Different locations if we scrolled down
471472
if scrolled is True:

0 commit comments

Comments
 (0)