-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbattle.py
More file actions
61 lines (48 loc) · 2.17 KB
/
battle.py
File metadata and controls
61 lines (48 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from routine import *
from __init__ import *
import pyautogui
class Battle(Routine):
__battle_index__ = 0
def execute(self) -> int:
if (self._disablePauseFor_(lambda: pyautogui.locateOnScreen(no_pvp, confidence=0.99)) != None and
len(self._disablePauseFor_(lambda: list(pyautogui.locateAllOnScreen(pvp_challenge, confidence = 0.9)))) == 0):
return 1
__btn_start__ = self._clickOn_(pvp)
if (__btn_start__ == None):
if (len(list(self._disablePauseFor_(lambda: pyautogui.locateAllOnScreen(pvp_challenge, confidence = 0.9)))) == 0):
raise RoutineException("Could not find the button to start fight")
else:
Battle.__battle_index__ = 0
if (__btn_start__ != None):
# Tries x times to challenge
for _ in range(Routine._command_retries_):
try:
self.__clickOnBtnChallenge__()
__btn_start__ = None
break
except RoutineException:
pyautogui.click(__btn_start__)
if (__btn_start__ != None):
raise RoutineException("Could not enter the battle")
for i in range(Routine._command_retries_):
# Checks if we left the challenge menu
try:
self.__clickOnBtnChallenge__()
except RoutineException:
break
if (i == Routine._command_retries_ - 1):
raise RoutineException("Could not challenge player")
# Go to next challenge
if (Battle.__battle_index__):
Battle.__battle_index__ = 0
else:
Battle.__battle_index__ = 1
return 0
def __clickOnBtnChallenge__(self):
# There's more than on challenge button.
locations = self._disablePauseFor_(lambda: tuple(pyautogui.locateAllOnScreen(pvp_challenge, confidence=0.9)))
if (len(locations) != 2):
raise RoutineException("Could not find all challenge buttons")
location = locations[self.__battle_index__]
pyautogui.click(location)
return location