-
Notifications
You must be signed in to change notification settings - Fork 0
/
getthefish.py
executable file
·149 lines (122 loc) · 4.64 KB
/
getthefish.py
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
140
141
142
143
144
145
146
147
148
149
import pyscreenshot as ImageGrab
import time
import pyautogui
import random
import jsonpickle
import json
def checkColor(color1, color2, delta):
if ((color2[0]-delta <= color1[0] <= color2[0]+delta)
and (color2[1]-delta <= color1[1] <= color2[1]+delta)
and (color2[2]-delta <= color1[2] <= color2[2]+delta)):
return True
else:
return False
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
class FishConfig():
def __init__(self):
self.jumpToBobber = True
self.verbose = False
self.thresholdBobber = 18
self.thresholdCatch = 60
self.bobbercolor = (72, 41, 12)
self.startPos = Point(200, 50)
self.endPos = Point(1100, 400)
class GetTheFish():
def __init__(self):
pyautogui.FAILSAFE = False
self.run = True
self.gui = False
self.fishConfig = FishConfig()
print(self.fishConfig.__dict__)
#print(json.dumps(self.fishConfig.__dict__))
self.save()
self.load()
def save(self):
with open('config.json', 'w') as file:
jsonpickle.set_encoder_options('simplejson', sort_keys=True, indent=4)
file.write(jsonpickle.encode(self.fishConfig))
def load(self):
with open('config.json', 'r') as file:
content = file.read()
self.fishConfig = jsonpickle.decode(content)
def log(self, text):
if self.fishConfig.verbose:
print(text)
def findbobber(self):
self.log("Searching for bobber")
image = ImageGrab.grab()
image.save("test.png")
for y in range(self.fishConfig.startPos.y, self.fishConfig.endPos.y):
for x in range(self.fishConfig.startPos.x, self.fishConfig.endPos.x):
color = image.getpixel((x, y))
if checkColor(color, self.fishConfig.bobbercolor, self.fishConfig.thresholdBobber):
end = time.time()
self.log("Bobber found at position: " + str(x) + ", " + str(y))
return Point(x, y)
self.log("Bobber not found")
return None
def waitforFish(self, bobberPos):
start = time.time()
fishtime = 0
oldx = oldy = 0
image = ImageGrab.grab(bbox=(bobberPos.x, bobberPos.y, bobberPos.x + 1, bobberPos.y + 1))
colorPosition = image.getpixel((0, 0))
while (fishtime < 20 and self.run):
image = ImageGrab.grab(bbox=(bobberPos.x, bobberPos.y, bobberPos.x + 1, bobberPos.y + 1))
color = image.getpixel((0, 0))
if not checkColor(color, colorPosition, self.fishConfig.thresholdCatch):
time.sleep(random.uniform(0.2, 0.9))
pyautogui.position(oldx, oldy)
pyautogui.moveTo(bobberPos.x, bobberPos.y)
pyautogui.click(button='right')
pyautogui.moveTo(oldx, oldy)
return True
fishtime = time.time() - start
return False
def fishing(self):
while (self.run):
self.save()
pyautogui.moveTo(self.fishConfig.startPos.x, self.fishConfig.startPos.y)
# pyautogui.press('1')
pyautogui.click(button='right')
pyautogui.click(button='right')
wait = random.uniform(2.1, 2.9)
self.log("Start fishing in " + str(round(wait, 1)) + " seconds")
time.sleep(wait)
bobberPos = self.findbobber()
if bobberPos != None:
bobberPos.x = bobberPos.x + 3
bobberPos.y = bobberPos.y + 5
pyautogui.moveTo(bobberPos.x, bobberPos.y)
# sys.exit(0)
self.log("Wait for Fish")
caught = self.waitforFish(bobberPos)
if caught:
self.log("Fish!")
else:
self.log("Fish gone!")
time.sleep(2)
self.log("Stopped fishing")
if __name__ == '__main__':
fish = GetTheFish()
fish.run()
#bobbercolor = (105,108,127)
# time.sleep(5)
# pos = pyautogui.position()
# print(pos)
# time.sleep(2)
# pyautogui.moveTo(pos[0], pos[1])
# time.sleep(2)
# image = ImageGrab.grab()
# color = image.getpixel((pos[0], pos[1]))
# print(color)
# sys.exit(0)
# time.sleep(3)
# pyautogui.moveTo(startPos[0], startPos[1])
# time.sleep(2)
# pyautogui.moveTo(endPos[0], endPos[1])
# pyautogui.moveTo(endPos[0], endPos[1])
# time.sleep(2)