-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmining.py
More file actions
442 lines (368 loc) · 17.4 KB
/
mining.py
File metadata and controls
442 lines (368 loc) · 17.4 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
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
# -*- coding: utf-8 -*-
# ! python3
# ======================================================================================================================
# Author: Half-Life
# Description: Скрипт на добычу руды по кочкам. Не обкапывает скалы!
# Чар должен иметь 100 LRC и около 65-70 тинкера.
# Делает лопаты.
# Реколится магией или чивой.
# Написан под RunUO.
# Тестировался на шарде UOAwakening.
# UOStealthClientVersion: 7.3.1
# Warning! Будьте бдительны! - Администрация многих игровых серверов
# враждебно относится к использованию стелс клиента на своих серверах.
# Заподозрив вас в использовании стелс клиента и других неправославных программ
# они начинают сатанеть и в порыве слепой ярости могут попасть по вам Банхаммером
# ======================================================================================================================
from datetime import datetime, timedelta
from stealthapi import *
# ======================================================================================================================
# CONSTANTS
# ======================================================================================================================
INGOTS_STORAGE = 0x4010303A # ID Контейнера в который скидывать металл и камни.
INGOTS_TYPE = 0x1BF2 # Тип металла (инготов).
USE_TRASH = True # Использовать треш. Если не надо установить False
TRASH = 0x40603E6E # ID Мусорки
HOME_RUNE_BOOK = 0x40258A6E # ID Рунабуки с рункой в дом
RUNE_BOOK_GUMP_ID = 0x554B87F3 # ID Гампа рунабуки.
HOME_RUNE = 1 # Номер рунки домой. Отсчёт начинается с 1.
RUNE_BOOK_SHIFT = 7 # Рекол. 5 - магия, 7 - чива.
RUNE_BOOKS = [0x40258C7E, 0x40258C14] # Рунабуки с рунками к кочкам.
ORE_TYPES = [0x19B9] # Типы руды.
GEM_TYPES = [0x3192, 0x3193, 0x3194, 0x3195, 0x3197, 0x3198, 0x5732] # Типы камней.
RESOURCES = ORE_TYPES + GEM_TYPES
TRASH_ITEMS = [0x0F27] # Типы мусора.
MINING_TYPE = 0x0F39 # Тип лопаты.
TINKER_TYPE = 0x1EB8 # Тип тинкер тулзы.
TK_NUM_FIRST = '15' # Номер кнопки 'Tools' в тинкер меню.
TK_NUM_SECOND = '23' # Номер кнопки 'Tinker's Tools' в тинкер меню.
TK_CRAFT_NUM_SECOND = '72' # Номер кнопки 'Shovel' в тинкер меню.
TOOLS_GUMP_ID = 0x38920ABD # ID Гампа тулзы.
IRON_COLOR = 0x0000 # Цвет обычного металла(инготов).
IRON_COUNT = 40 # Минимум металла для крафта лопат
WAIT_TIME = 500 # Время минимальной задержки. Лучше не менять.
WAIT_LAG_TIME = 10000 # Время кторое будет выжидаться при лаге. Лучше не менять.
# ======================================================================================================================
# Variables
# ======================================================================================================================
current_book, current_rune = 0, 0
# ======================================================================================================================
# Utils
# ======================================================================================================================
def wait_lag(wait_time=WAIT_TIME, lag_time=WAIT_LAG_TIME):
Wait(wait_time)
CheckLag(lag_time)
return
def close_gumps():
while IsGump():
if not Connected():
return False
if not IsGumpCanBeClosed(GetGumpsCount() - 1):
WaitGump('0')
else:
CloseSimpleGump(GetGumpsCount() - 1)
return True
# ======================================================================================================================
# Last Container
# ======================================================================================================================
class LastContainer(object):
DELAY = 10
def __eq__(self, other):
if self.serial == other:
return self.check_time(self.DELAY)
return False
def __call__(self, serial, graphic):
self.graphic = graphic
self.serial = serial
self.last_time = datetime.datetime.now()
def __init__(self):
self.serial = 0
self.last_time = datetime.datetime.now()
def check_time(self, seconds):
delta = timedelta(seconds=seconds)
if datetime.datetime.now() <= delta + self.last_time:
return True
return False
# ======================================================================================================================
# Check States
# ======================================================================================================================
def check_connection():
if not Connected():
AddToSystemJournal('Нет коннекта.')
while not Connected():
AddToSystemJournal('Пытаюсь законектиться...')
Wait(5000)
AddToSystemJournal('Есть коннект.')
close_gumps()
return
def check_dead():
if Dead():
AddToSystemJournal('Мне очень жаль. Вы умерли.')
AddToSystemJournal('Рунабука {0}'.format(GetToolTip(current_book).split('|')[-1]))
AddToSystemJournal('Рунка № # {0}'.format(current_rune))
quit('You are Dead.')
return
def check_states():
check_connection()
check_dead()
return
# ======================================================================================================================
# Check HP
# ======================================================================================================================
def check_hp():
if GetHP(Self()) == MaxLife():
return
SetAlarm()
AddToSystemJournal('Вас кто-то атакует.')
SendTextToUO('Guards')
while Life() != MaxLife():
check_states()
Cast('Close Wounds')
WaitTargetSelf()
wait_lag()
return
# ======================================================================================================================
# Check Ingots
# ======================================================================================================================
def check_ingots():
FindTypeEx(INGOTS_TYPE, IRON_COLOR, Backpack(), False)
count_in_pack = FindFullQuantity()
if count_in_pack < IRON_COUNT:
AddToSystemJournal('Проверяю металл.')
last_container = LastContainer()
SetEventProc('evDrawContainer', last_container)
while True:
check_states()
UseObject(INGOTS_STORAGE)
wait_lag(WAIT_TIME * 2)
if last_container == INGOTS_STORAGE:
SetEventProc('evDrawContainer', None)
break
FindTypeEx(INGOTS_TYPE, IRON_COLOR, INGOTS_STORAGE, False)
count_in_box = FindFullQuantity()
wait_lag()
AddToSystemJournal('Металла осталось: {0}'.format(count_in_box))
if count_in_box < IRON_COUNT:
AddToSystemJournal('Закончился металл. Стоп.')
quit('Закончился металл.')
Grab(FindItem(), IRON_COUNT - count_in_pack)
return
# ======================================================================================================================
# Unload
# ======================================================================================================================
def unload(items, container, msg):
AddToSystemJournal('Разгружаю {0}'.format(msg))
for item in items:
while FindType(item, Backpack()) > 1:
check_states()
MoveItem(FindItem(), GetQuantity(FindItem()), container, 0, 0, 0)
wait_lag()
AddToSystemJournal('Разгрузились.')
return
# ======================================================================================================================
# Drop Ore
# ======================================================================================================================
def drop_ore():
AddToSystemJournal('Сбрасываю баласт...')
counter = 0
while True:
counter += 1
FindTypeEx(ORE_TYPES[0], 0, Backpack(), False)
if Weight() < MaxWeight():
break
wait_lag()
if counter == 1:
Drop(FindItem(), 1, GetX(Self()) - 1, GetY(Self()), GetZ(Self()))
continue
if counter == 2:
Drop(FindItem(), 1, GetX(Self()) + 1, GetY(Self()), GetZ(Self()))
continue
if counter == 3:
Drop(FindItem(), 1, GetX(Self()), GetY(Self()) - 1, GetZ(Self()))
continue
if counter == 4:
Drop(FindItem(), 1, GetX(Self()), GetY(Self()) + 1, GetZ(Self()))
continue
elif counter == 5:
Drop(FindItem(), 1, GetX(Self()) + 1, GetY(Self()) + 1, GetZ(Self()))
continue
elif counter == 6:
Drop(FindItem(), 1, GetX(Self()) - 1, GetY(Self()) - 1, GetZ(Self()))
continue
elif counter == 7:
Drop(FindItem(), 1, GetX(Self()) + 1, GetY(Self()) - 1, GetZ(Self()))
continue
elif counter == 8:
Drop(FindItem(), 1, GetX(Self()) - 1, GetY(Self()) + 1, GetZ(Self()))
continue
else:
break
return
# ======================================================================================================================
# Recalling
# ======================================================================================================================
def degrees_to_coordinate(coordinate, center, size):
result = ((coordinate['deg'] * 100) + ((coordinate['min'] * 10) // 6))
if coordinate['dir'] == 'N' or coordinate['dir'] == 'W':
result = 36000 - result
result = int(round((center + (result * size) / 36000) % size, 0))
return result
def get_coordinates(destination):
position = {'x': 0, 'y': 0}
if GetGumpID(GetGumpsCount() - 1) != RUNE_BOOK_GUMP_ID:
return position
gump_info = GetGumpInfo(GetGumpsCount() - 1)
i = destination + destination
latitude_longitude = gump_info['GumpText'][i:i + 2]
latitude_text_id = latitude_longitude[0]['TextID']
longitude_text_id = latitude_longitude[1]['TextID']
coordinates = gump_info['Text'][latitude_text_id] + ' ' + gump_info['Text'][longitude_text_id]
coordinates = coordinates.replace('\'', ' ').replace('°', '').split(' ')
latitude = {
'deg': int(coordinates[0]),
'min': int(coordinates[1]),
'dir': coordinates[2],
}
longitude = {
'deg': int(coordinates[3]),
'min': int(coordinates[4]),
'dir': coordinates[5],
}
position['x'] = degrees_to_coordinate(longitude, 1323, 5120)
position['y'] = degrees_to_coordinate(latitude, 1624, 4096)
return position
def recall_to(rune_book, destination):
destination_position = {}
if rune_book == HOME_RUNE_BOOK:
AddToSystemJournal('Пытаюсь среколиться домой...')
else:
rune_book_name = GetToolTip(rune_book).split('|')[-1]
AddToSystemJournal('Пытаюсь среколиться... RuneBook - {0} Rune № #{1}'.format(rune_book_name, current_rune))
while True:
check_states()
close_gumps()
self_position = {'x': GetX(Self()), 'y': GetY(Self())}
if self_position != destination_position:
while GetGumpID(GetGumpsCount() - 1) != RUNE_BOOK_GUMP_ID:
UseObject(rune_book)
wait_lag()
destination_position = get_coordinates(destination - 1)
WaitGump(str(destination * 6 + RUNE_BOOK_SHIFT - 6))
wait_lag(WAIT_TIME * 4)
else:
close_gumps()
break
if InJournal('Thou art too encumbered to move.') > 0:
ClearJournal()
AddToSystemJournal('Перегруз!')
drop_ore()
AddToSystemJournal('Cреколились.')
return True
# ======================================================================================================================
# Check Weight
# ======================================================================================================================
def check_weight():
if MaxWeight() > Weight() + 60:
return
check_connection()
recall_to(HOME_RUNE_BOOK, HOME_RUNE)
unload(RESOURCES, INGOTS_STORAGE, msg='ресурсы')
if USE_TRASH:
unload(TRASH_ITEMS, TRASH, msg='мусор')
check_ingots()
recall_to(current_book, current_rune)
return
# ======================================================================================================================
# Event Create Tools
# ======================================================================================================================
def event_create_tools(num_f, num_s, name):
WaitGump(num_f)
WaitGump(num_s)
AddToSystemJournal(name)
wait_lag(WAIT_TIME * 2)
return
# ======================================================================================================================
# Check Tools
# ======================================================================================================================
def check_tool(check_type, count=1):
check_states()
CheckLag(WAIT_LAG_TIME)
return CountEx(check_type, 0, Backpack()) > count - 1
# ======================================================================================================================
# Create Tools
# ======================================================================================================================
def create_tk_tools():
SetEventProc('evIncomingGump', event_create_tools(TK_NUM_FIRST, TK_NUM_SECOND, 'Create tinker tools'))
while not check_tool(TINKER_TYPE, 2):
check_states()
if not IsGump():
UseType(TINKER_TYPE, 0)
SetEventProc('evIncomingGump', None)
return
def create_craft_tools():
if not check_tool(TINKER_TYPE, 2):
create_tk_tools()
SetEventProc('evIncomingGump', event_create_tools(TK_NUM_FIRST, TK_CRAFT_NUM_SECOND, 'Create mining tools'))
if not IsGump():
UseType(TINKER_TYPE, 0)
SetEventProc('evIncomingGump', None)
return check_tool(MINING_TYPE, 1)
# ======================================================================================================================
# Mine
# ======================================================================================================================
def mine():
AddToSystemJournal('Копаю.')
ClearJournal()
while InJournal('t mine there|is too far away|cannot be seen|is no metal here to mine') < 0:
check_states()
check_weight()
check_hp()
if TargetPresent():
CancelTarget()
while not check_tool(MINING_TYPE, 1):
create_craft_tools()
close_gumps()
UseType(MINING_TYPE, 0)
self_x = GetX(Self())
self_y = GetY(Self())
self_z = GetZ(Self())
WaitTargetTile(0, self_x, self_y, self_z)
wait_lag(WAIT_TIME, 0)
return AddToSystemJournal('Здесь металла нет.')
# ======================================================================================================================
# Set Mine Point
# ======================================================================================================================
def mine_point():
global current_book, current_rune
for current_book in RUNE_BOOKS:
for current_rune in range(1, 17):
check_states()
if recall_to(current_book, current_rune):
wait_lag()
mine()
return
# ======================================================================================================================
# Main
# ======================================================================================================================
if __name__ == '__main__':
# ==================================================================================================================
# Start Script
# ==================================================================================================================
ClearJournal()
ClearSystemJournal()
AddToSystemJournal('Стартуем')
SetARStatus(True)
check_states()
AddToSystemJournal('Закрываем гампы')
close_gumps()
AddToSystemJournal('Гампы закрыты')
recall_to(HOME_RUNE_BOOK, HOME_RUNE)
unload(RESOURCES, INGOTS_STORAGE, msg='ресурсы')
if USE_TRASH:
unload(TRASH_ITEMS, TRASH, msg='мусор')
check_ingots()
while True:
mine_point()
# ======================================================================================================================
# End Script
# ======================================================================================================================