@@ -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
218216def 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
266234def handleArenaOfHeroes (count , opponent ):
267235 counter = 0
0 commit comments