-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
293 lines (255 loc) · 10.7 KB
/
main.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# from . import A
import win32api
import win32con
import Tkinter as tk
from Tkinter import *
import datetime
import time
import threading
import pyautogui
from PIL import ImageTk, Image
import tkMessageBox as messagebox
import numpy
import mss
from key_control.dd import dd,ddClick
import analisys as analisys
sct= mss.mss()
sct_health= mss.mss()
# The screen part to capture
# Grab the data
rgb1 = numpy.array([1,1,0])
print rgb1
on_hit = False
thead_arr = []
class getPicTask(threading.Thread):
def __init__(self):
self._running = True
def terminate(self):
self._running = False
def run(self, i):
_sct= mss.mss()
def getNowTime():
now=datetime.datetime.now()
timestamp = time.mktime(now.timetuple())
return timestamp
isFishing=False
isSpace=False
interval_drink=getNowTime()
interval_change_rod=getNowTime()
while (self._running):
# print datetime.datetime.now()
# im = pyautogui.screenshot(region=(0, 0, 200, 200))
# print datetime.datetime.now()
#print datetime.datetime.now()
if (getNowTime()-interval_change_rod)>(4.5*60*60):
#wait 600 sec and make drive
interval_change_rod=getNowTime()
dd('0')
print "change rod"
if (getNowTime()-interval_drink)>(10*60):
#wait 600 sec and make drive
interval_drink=getNowTime()
ddClick(1291,340)
time.sleep(1)
ddClick(1577,654)
print "make drink"
if analisys.BDOCompareFishingSpace():
startTime=getNowTime()
time.sleep(1)
dd('space')
time.sleep(1)
isSpace=True
while isSpace and self._running:
if (getNowTime()-startTime)>3:
isSpace=False
sct_img = _sct.grab({'top': 400, 'left': 998, 'width': 100, 'height': 30})
im = Image.frombytes('RGB', sct_img.size, sct_img.bgra, 'raw',
'BGRX')
#mss.tools.to_png(sct_img.rgb, sct_img.size, output='dummy.png')
img = ImageTk.PhotoImage(im)
img_panel.configure(image=img)
img_panel.image = img
v_top=4
v_bottom=25
if isFishing==False:
for index in range(0, 92):
rt, gt, bt = im.getpixel((index, v_top))
rb, gb, bb = im.getpixel((index, v_bottom))
if rt==gt==bt==rb==gb==bb==222:
isFishing=True
else:
#print datetime.datetime.now()
#im.save("general.png")
#image.open("newone.png").convert("RGB").save("newone.png")
key_x = 95
key_x_limit = 96
diff=95
key_y = 7
key_y_limit = 22
isTouch = True
for index in range(key_y, key_y_limit):
r, g, b = im.getpixel((key_x-diff, index))
if r < 125 and g < 125 and b < 125:
isTouch = False
if isTouch:
#print datetime.datetime.now()
dd('space')
#print datetime.datetime.now()
print "catch"
isGame=False
while isFishing and self._running:
sct_img = sct.grab({'top': 400, 'left': 998, 'width': 100, 'height': 30})
im = Image.frombytes('RGB', sct_img.size, sct_img.bgra, 'raw',
'BGRX')
for index in range(0, 92):
rt, gt, bt = im.getpixel((index, v_top))
rb, gb, bb = im.getpixel((index, v_bottom))
if not(rt>=222 and gt>=222 and bt>=222 and rb>=222 and gb >=222 and bb>=222):
isGame=True
if isGame:
isFishing=False
game_img=analisys.captureFishingGame()
keyboardData=analisys.analisysHLSKeyBoard(numpy.array(game_img))
if len(keyboardData['sort_key'])==0:
keyboardData=analisys.analisysHSVKeyBoard(numpy.array(game_img))
if len(keyboardData['sort_key'])>0:
for key in keyboardData['sort_key']:
collection=keyboardData['data']
#print collection[key]
dd(collection[key])
time.sleep(0.1)
else:
#mss.tools.to_png(game_img.rgb, game_img.size, output="log"+timestamp.__str__()+".png")
print "fail not find game"
time.sleep(1)
print "catch end "
time.sleep(2)
print "start capture package "
if analisys.isCapturePackage():
dd('r')
else:
try:
pos=analisys.isCapturePackageByMouse()
for x,y in pos:
ddClick(x,y)
except:
print('error to click')
print "end capture package"
isSpace=False
img = ImageTk.PhotoImage(im)
img_panel.configure(image=img)
img_panel.image = img
time.sleep(1)
dd('space')
time.sleep(10)
#pyautogui.keyDown('space')
#pyautogui.keyUp('space')
#pyautogui.press('space')
#96 110~119
#pyautogui.pixel(200, 200)
#if impx==(185,192,179):
#print 'this is a number: ', i, impx
else:
time.sleep(1)
class talkback(threading.Thread):
def __init__(self):
self._running = True
def terminate(self):
self._running = False
def run(self):
while (self._running):
sct_img = sct_health.grab({'top': 959, 'left': 809, 'width': 300, 'height': 18})
im = Image.frombytes('RGB', sct_img.size, sct_img.bgra, 'raw','BGRX')
voteAttack=0
for index in range(270, 290):
r,g,b= im.getpixel((index, 4))
if r<20 and b<20 and g<20 and r==g==b :
print voteAttack
voteAttack+=1
#if r!=204:
if voteAttack>7 :
mss.tools.to_png(sct_img.rgb, sct_img.size, output='dummy.png')
for x in thead_arr:
x.terminate()
time.sleep(3)
dd('enter')
time.sleep(0.2)
dd('QUEST')
time.sleep(0.2)
dd('QUEST')
time.sleep(0.2)
dd('QUEST')
time.sleep(0.2)
dd('enter')
time.sleep(60)
dd('space')
time.sleep(300)
getPic = getPicTask()
thread = threading.Thread(target=getPic.run, args=(11, ))
thread.start()
thead_arr.append(getPic)
else:
time.sleep(2)
window = tk.Tk()
window.title('for test')
window.geometry('300x400')
screenWidth, screenHeight = pyautogui.size()
#im = pyautogui.screenshot(region=(0, 0, 100, 100))
sct_img = sct.grab({'top': 400, 'left': 998, 'width': 100, 'height': 30})
im=Image.frombytes('RGB', sct_img.size, sct_img.bgra, 'raw', 'BGRX')
var = tk.StringVar()
#pyautogui.alert(text='', title='', button='OK')
screen = tk.Label(
window,
text=screenWidth.__str__() + ',' + screenHeight.__str__(),
bg='white',
font=('Arial', 12),
width=20,
height=2)
#l = tk.Label(window, text='OMG! this is TK!', bg='green', font=('Arial', 12), width=15, height=2)
print im
img = ImageTk.PhotoImage(im)
img_panel = tk.Label(window, image=img)
#screen.pack()
img_panel.pack()
#color = win32gui.GetPixel(win32gui.GetDC(win32gui.GetActiveWindow()), x , y)
def hit_me():
on_hit = True
getPic = getPicTask()
thread = threading.Thread(target=getPic.run, args=(11, ))
thread.start()
thead_arr.append(getPic)
currentMouseX, currentMouseY = pyautogui.position()
fb_str = "%s %s" % (currentMouseX, currentMouseY)
def stop_me():
for x in thead_arr:
x.terminate()
for x in thead_arr_main:
x.terminate()
thead_arr_main=[]
def talk_back():
print "start talk"
talk = talkback()
talk_thread = threading.Thread(target=talk.run)
talk_thread.start()
thead_arr_main.append(talk)
def ColorDistance(rgb1,rgb2):
'''d = {} distance between two colors(3)'''
rm = 0.5*(rgb1[0]+rgb2[0])
d = sum((2+rm,4,3-rm)*(rgb1-rgb2)**2)**0.5
return d
frame=Frame(window)
frame.grid(row=1, column=0, columnspan=3)
b = tk.Button(frame, text='hit me', command=hit_me).grid(row=0,column=0)
b = tk.Button(frame, text='stop me', command=stop_me).grid(row=0,column=1)
b = tk.Button(frame, text='talk back', command=talk_back).grid(row=0,column=2)
frame.pack()
def on_closing():
if messagebox.askokcancel("Quit", "Do you want to quit?"):
for x in thead_arr:
x.terminate()
for x in thead_arr_main:
x.terminate()
window.destroy()
window.protocol("WM_DELETE_WINDOW", on_closing)
window.mainloop()