-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFaladorWestMiner.py
executable file
·265 lines (247 loc) · 10.5 KB
/
FaladorWestMiner.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
#!/usr/bin/env python3
# Copyright 2020 by Benjamin J. Land (a.k.a. BenLand100)
#
# This file is part of srbot.
#
# srbot is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# srbot is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with srbot. If not, see <https://www.gnu.org/licenses/>.
from srbot import *
import argparse
parser = argparse.ArgumentParser('Mines in West Falador mine and bankes in Falador West Bank')
parser.add_argument('item',help='iron,bronze')
args = parser.parse_args()
#Mining script requires agility shortcut Falador west
west_road = [122,117,70]
east_road = [121,119,97]
wall_color = [190,184,155]
mine_rock_color = [97,58,3]
mine_area_color = [56,47,18]
inner_wall_color = [60,60,50]
outer_wall_color = [73,64,41]
copper_color = [168,120,76]
tin_color = [149,138,138]
iron_color = [60,35,28]
if args.item == 'bronze':
rocks = [(1,copper_color,(0.02,0.08,0.08),[223,129,59]),(1,tin_color,0.025,[139,130,129])] #copper&tin
elif args.item == 'iron':
rocks = [(1,iron_color,(0.02,0.08,0.08),[78,48,36])] #iron
else:
raise RuntimeError('Unknown rock to mine: '+args.item)
mm_east_tol = (0.05,0.1,0.1)
mm_west_tol = (0.05,0.08,0.08)
mine_icon = load_image('mine_icon.png')
agility_icon = load_image('agility_icon.png')
def count_rocks(weighted=True,rocks=None):
'''finds the weighted count of each rock in the inventory for each rock the rocks list'''
raw_counts = np.asarray([(count_inv(color=invc,tol=tol,mode='hsl'),weight) for weight,color,tol,invc in rocks])
return raw_counts[:,0]/raw_counts[:,1] if weighted else raw_counts[:,0]
def fast_mine(points):
if len(points) == 0:
return False
counts = count_inv(color=[119,96,67],tol=0.02)
clusters,_ = cluster(points,10)
points = np.asarray([np.mean(cluster,axis=0) for cluster in clusters],dtype=np.float64)
points = closest_exp([msw/2,msh/2],points,10,N=5)
if points is None or not confirm_click(points):
return False
return True
def find_rock(rock):
weight,color,tol,bmp = rock
mainscreen = get_mainscreen()
found = find_colors(color,mainscreen,tol=tol,mode='hsl')
b = find_colors(np.asarray([107,88,28]),mainscreen,tol=0.02)
return filter_near(found,b,10)
def mine(rocks=rocks,noob_factor=0.5):
'''mines the next rock based on weights in rocks structure
finds rock based on color of ore plus proximity to generic rock color
confirms uptext hovering over rock before mining
waits for rock to appear in inventory before proceeding'''
counts = count_rocks(rocks=rocks)
print('Weighted totals:',counts)
minidx = np.argmin(counts)
rock = rocks[minidx]
counts = count_inv(color=[119,96,67],tol=0.02)
mined = False
invc_before = count_inv(color=[119,96,67],tol=0.02)
while True:
found = find_rock(rock)
if not fast_mine(found):
break
if count_inv() >= 28:
break
for i in range(int(100*noob_factor)):
sleep(0.05)
invc_now = count_inv(color=[119,96,67],tol=0.02)
if np.any(invc_now != invc_before):
mined = True
invc_before = invc_now
break
else:
break
return mined
def west_of_wall():
'''returns true if character is closer to west road or mine colors than east road or mine colors'''
minimap = get_minimap()
if len(find_best_bitmap(mine_icon,minimap,0.05)) > 0:
print('at mine')
return True
west = find_colors(west_road,minimap,tol=mm_west_tol,mode='hsl')
clusters,counts = cluster(west,radius=2)
if len(counts) > 0 and np.max(counts) > 100:
west = concatenate(*clusters[counts > 25])
else:
west = []
npc_points = find_colors([255,255,0],minimap,tol=0.05,mode='hsl')
bank_points = concatenate(*[find_colors(bank_floor,minimap,tol=0.085,mode='hsl') for bank_floor in bank_floor_colors])
clusters,counts = cluster(bank_points)
if len(counts) < 1 or np.count_nonzero(counts>20) < 1:
bank_points = np.asarray([])
else:
bank_points = clusters[np.random.choice(np.nonzero(counts>20)[0])]
bank_points = filter_near(bank_points,npc_points,6)
if len(bank_points) < 10:
a = find_colors([154,91,39],minimap,tol=(0.05,0.08,0.1),mode='hsl')
b = find_colors([54,43,8],minimap,tol=(0.03,0.05,0.05),mode='hsl')
rocks = filter_near(a,b,5)
west = concatenate(rocks,west)
east = find_colors(east_road,minimap,tol=mm_east_tol,mode='hsl')
clusters,counts = cluster(east,radius=2)
if len(counts) > 0 and np.max(counts) > 100:
east = concatenate(*clusters[counts > 10])
else:
east = []
print('Locating... E:',len(east),'W:',len(west),'B',len(bank_points))
west_best = 9001 if len(west) == 0 else np.min(np.sum(np.square(west-[mmxc-mmxs,mmyc-mmys]),axis=-1))
east_best = 9001 if len(east) == 0 else np.min(np.sum(np.square(east-[mmxc-mmxs,mmyc-mmys]),axis=-1))
if west_best <= east_best:
print('west of wall')
return True
else:
print('east of wall')
return False
def jump_wall():
'''The Donald can't stop us!
tries to get as close as possible to boundary between east and west road colors on minimap
looks for proximity of wall color, east, and west road colors on mainscreen
attempts to confirm uptext hovering over possible wall locations
returns true if successfully jumped'''
minimap = get_minimap()
east = find_colors(east_road,minimap,tol=mm_east_tol,mode='hsl')
west = find_colors(west_road,minimap,tol=mm_west_tol,mode='hsl')
print('Road points... E:',len(east),'W:',len(west))
if len(west) == 0 or len(east) == 0:
return False
border = filter_near(east,west,3)
print('Boundary:',len(border))
if len(border) <= 3: #try the agility icon
agility = find_best_bitmap(agility_icon,minimap,mode='xcorr',tol=0.18)
else:
agility = None
np.random.shuffle(border)
if len(border) > 3 or len(agility) > 0:
border = border[0] if len(border) > 3 else (agility[np.random.randint(len(agility))]+[5,5])
click_mouse(*(border+[mmxs,mmys]))
flag_wait()
mainscreen = get_mainscreen()
wall_points = find_colors(wall_color,mainscreen,tol=0.07,mode='hsl')
inner_wall_points = find_colors(inner_wall_color,mainscreen,tol=0.07,mode='hsl')
outer_wall_points = find_colors([73,64,41],mainscreen,tol=0.07,mode='hsl')
wall_points = filter_near(filter_near(wall_points,inner_wall_points,10),outer_wall_points,10)
return confirm_click(wall_points)
return False
target()
miss = 0
total_trips = 0
total_ores = 0
start_time = mark_time()
last_mine = mark_time()
while True:
client = get_client()
if len(find_bitmap(loginscreen,client)) > 0:
login()
continue
if mark_time()-last_mine > 10*60:
raise RuntimeError('Haven\'t mined in 10 minutes, giving up because something ain\'t right.')
inv_count = count_inv()
inv_full = inv_count == 28
print('Total items:',inv_count)
if inv_full:
if west_of_wall():
if not jump_wall():
minimap = get_minimap()
west = filter_radius(find_colors(west_road,minimap,tol=mm_west_tol,mode='hsl'),[mmxc-mmxs,mmyc-mmys],70)
print('Moving east:',len(west))
if len(west):
click_mouse(*(west[np.argsort(west[:,0])[-1]]+(mmxs,mmys)))
sleep(2.0)
else:
click_mouse(mmxc+20,mmyc)
flag_wait(imax=10)
print('Crossed wall west->east')
else:
if open_bank():
deposit_all()
total_ores += inv_count
total_trips = total_trips + 1
if np.random.random() < 0.5:
polish_minimap(min_same=35,horizontal=False)
txt = 'Completed %i inventories (%i ore @ %0.2f s/ore)'%(total_trips,total_ores,(mark_time()-start_time)/total_ores)
print(txt)
continue
else:
if west_of_wall():
if not mine(rocks):
print('No rock found!')
miss = miss + 1
if miss < 5:
sleep(0.5)
continue
print('Trying new position...')
minimap = get_minimap()
a = find_colors(mine_rock_color,minimap,tol=(0.05,0.08,0.1),mode='hsl')
b = find_colors(mine_area_color,minimap,tol=(0.03,0.05,0.05),mode='hsl')
mine_loc = filter_near(a,b,5)
mine_loc = filter_radius(mine_loc,[mmxc-mmxs,mmyc-mmys],50)
if len(mine_loc):
np.random.shuffle(mine_loc)
#delta = np.random.random()*30-20
click_mouse(*(mine_loc[0]+(mmxs,mmys)))#+(delta,-2*delta)))
flag_wait()
continue
west = find_colors(west_road,minimap,tol=mm_west_tol,mode='hsl')
west = filter_radius(west,[mmxc-mmxs,mmyc-mmys],70)
print('Moving west:',len(west))
if len(west):
click_mouse(*(west[np.argsort(west[:,0])[0]]+(mmxs,mmys)))
sleep(0.5)
else:
print('Got lost going to mine!')
else:
last_mine = mark_time()
miss = 0
else:
if not jump_wall():
minimap = get_minimap()
east = filter_radius(find_colors(east_road,minimap,tol=mm_east_tol,mode='hsl'),[mmxc-mmxs,mmyc-mmys],70)
print('Moving west:',len(east))
if len(east):
click_mouse(*(east[np.argsort(east[:,0]-0.5*east[:,1])[0]]+(mmxs,mmys)))
sleep(2.0)
else:
print('Got lost going to wall!')
else:
miss = 9999 #to move west immediately
run_on()
click_mouse(mmxc-20,mmyc)
flag_wait(imax=10)
print('Crossed wall east->west')