-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandomEventHandler.py
More file actions
139 lines (118 loc) · 4.51 KB
/
Copy pathrandomEventHandler.py
File metadata and controls
139 lines (118 loc) · 4.51 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import logging
from mouseFunctions import Mouse
from time import sleep, time
from utils.fernsUtils import recursiveTruncateRandGauss, getElapsedTime
from verification import getText, verifyText
from pyautogui import ImageNotFoundException
logger = logging.getLogger(__name__)
CHECKTIMER_FALSEPOSITIVE = 180
CHECKTIMER_POSITIVE = 600
NPC_HIGHLIGHTCOLOR = (0,255,255)
RANDOM_EVENT_NPCNAMES = [
"Bee Keeper", "Capt' Arnav", "Niles", "Miles", "Giles",
"Count Check", "Sergeant Damient", "Drunken dwarf",
"Evil Bob", "Servant", "Postie Pete", "Molly", "Freaky Forester",
"Genie", "Leo", "Dr Jekyll", "Prince", "Princess", "Mysterious Old Man",
"Flippa", "Tilt", "Quiz Master", "Rick Turpentine", "Sandwich Lady",
"Strange Plant", "Dunce", "Mr. Mordaut"
]
class RandomEventHandler():
def __init__(self, mouse:Mouse):
self.mouse = mouse
self.lastEventWasLocal = None
self.lastTimeChecked = time()
def findDismiss(self):
dismissImgPath = "img/randomEventDismiss.png"
try:
x,y = self.mouse.findImageSimple(dismissImgPath)
return x,y
except ImageNotFoundException:
return 0,0
def dismissRandomEvent(self,x,y):
"""
rightclick
find "dismiss"
click dismiss
"""
self.mouse.mouseClick(x,y,but="right")
x,y = self.findDismiss()
if x == 0 and y == 0:
logger.info("dismiss not found, someone elses randomevent, returning to normal function")
self.lastEventWasLocal = False
self.lastTimeChecked = time()
else:
self.mouse.moveMouseToArea(x,y,areaVariance=5,bezier=True)
sleep(round(recursiveTruncateRandGauss(0.6,0.05,0.7,0.5),4))
self.mouse.mouseClick(x,y)
logger.info("dismissed random event")
self.lastEventWasLocal = True
self.lastTimeChecked = time()
def verifyRandomEventNPC(self):
"""
check against the list of all the random event names, if it's one of them return true
"""
hoverTextRegion = (8,31,200,20)
l,t,w,h = hoverTextRegion
potentialNPCname = getText(l,t,w,h)
for name in RANDOM_EVENT_NPCNAMES:
if verifyText(potentialNPCname, name):
return True
self.lastEventWasLocal = False
self.lastTimeChecked = time()
return False
def findRandomEventNPC(self):
try:
x,y = self.mouse.findColorsIteratively(NPC_HIGHLIGHTCOLOR)
return x,y
except TypeError:
logger.debug("Random Event NPC not found")
return 0,0
def canCheckForEvent(self)->bool:
print(getElapsedTime(self.lastTimeChecked))
if self.lastEventWasLocal == None:
return True
if self.lastEventWasLocal == True and getElapsedTime(self.lastTimeChecked) >= CHECKTIMER_POSITIVE:
return True
elif self.lastEventWasLocal == False and getElapsedTime(self.lastTimeChecked) >= CHECKTIMER_FALSEPOSITIVE:
return True
else:
return False
def randomEventHandler(self):
"""
decide if we should act afk or not
need to enable "remove others menu option" from random event plugin
"""
"""
maybe better to only check in an area around me like lets say 2 loops in the find image iteratively
"""
"""
if last check was not mine
don't check again for 2 mins, if mine does show up, it will look lik
if the random event was mine don't check for another 8 mins
"""
if not self.canCheckForEvent():
logger.debug("not checking for radnom event too little time has passed since last check")
print("not checking for event")
else:
logger.info("checking for random event")
x,y = self.findRandomEventNPC()
print(x,y)
if x > 1 or y > 1:
x,y=self.mouse.moveMouseToArea(x,y,areaVariance=5,bezier=True)
sleep(round(recursiveTruncateRandGauss(0.6,0.05,0.7,0.5),4))
if self.verifyRandomEventNPC():
self.dismissRandomEvent(x,y)
return True
else:
print("random event not found")
return False
def main():
sleep(2)
m = Mouse()
reh = RandomEventHandler(m)
while True:
reh.randomEventHandler()
sleep(1)
pass
if __name__ == "__main__":
main()