-
Notifications
You must be signed in to change notification settings - Fork 0
/
mining.py
287 lines (263 loc) · 8.46 KB
/
mining.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
#standard imports
import sys
from System.Collections.Generic import List
from System import Byte, Int32
#global types
#generic
self = Player.Serial
self_pack = Player.Backpack.Serial
##Counts
oreCount = 0
##Ore, Colors
oreType = 0x19B9
ingotType = 0x1BF2
oreList = [
['iron', 0x0000, None],
['dullcopper', 0x0415, None],
['copper', 0x045F, None],
['bronze', 0x06D8, None],
['shadow', 0x0455, None],
['gold', 0x06B7, None],
['agapite', 0x097E, None],
['verite', 0x07D2, None],
['valorite', 0x0544, None],
]
##types lists
forgesList = List[int]((0x197A, 0x197E, 0x19A2, 0x1982, 0x1992, 0x1996, 0x199A, 0x0FB1))
tinkerTools = [0x1EB8, 0x1EBC]
minerTools = [0x0F39, 0x0E86]
## msg stubs
smeltSuccess = 'You smelt the ore removing the impurities and put the metal in your backpack.'
smeltFail = 'You burn away the impurities but are left with less useable metal.'
###################################
# Helper Functions
###################################
def getByItemID(itemid, source):
#find an item id in container serial
for item in Items.FindBySerial(source).Contains:
if item.ItemID == itemid:
return item
else:
Misc.NoOperation()
def countByItemID(itemid):
# Count the number of items found in backpack by the ItemID
count = 0
for item in Player.Backpack.Contains:
if item.ItemID == itemid:
count = count + 1
else:
Misc.NoOperation()
Misc.SendMessage('%i items found' % (count))
return count
###################################
###################################
# Get any mining tool as soon as one is found
def getMinerTool():
for item in minerTools:
miningTool = getByItemID(item, self_pack)
if miningTool is not None:
return miningTool
break
if miningTool is None:
craftPicks()
# If no mining tools present, use tinkertools to craft 3x pickaxes
def craftPicks():
countMinerTools = 0
for minertool in minerTools:
countMinerTools = countMinerTools + countByItemID(minertool)
while countMinerTools < 3:
for item in tinkerTools:
tinkerTool = getByItemID(item, self_pack)
if tinkerTool is not None:
if Gumps.HasGump():
Gumps.WaitForGump(949095101, 10000)
Gumps.SendAction(949095101, 0)
Items.UseItem(tinkerTool)
Gumps.WaitForGump(949095101, 10000)
Gumps.SendAction(949095101, 8)
Gumps.WaitForGump(949095101, 10000)
Gumps.SendAction(949095101, 114)
for minertool in minerTools:
countMinerTools = countMinerTools + countByItemID(minertool)
# Read journal to determine if there is no metal at this spot
def readJournal():
if Journal.Search('no metal'):
Journal.Clear()
return True
else:
Journal.Clear()
return False
# Move x steps in target direction
def move(x):
moveDirection = Player.Direction
for _ in range(x):
Player.Run(moveDirection)
Misc.Pause(200)
# Search for new ore whos Item object has not been added to the oreList
def searchForNewOre():
for item in Items.FindBySerial(self_pack).Contains:
if item.ItemID == oreType:
for ore in oreList:
if item.Hue == ore[1]:
if ore[2] is None:
ore[2] = item
moveOre([ore])
else:
Misc.NoOperation()
else:
Misc.NoOperation
# Search of ore to be added to Item Object listed in oreList
def searchForKnownOre():
for item in Items.FindBySerial(self_pack).Contains:
if item.ItemID == oreType:
for ore in oreList:
if item.Hue == ore[1]:
if ore[2] is None:
Misc.NoOperation()
else:
Items.Move(item, ore[2], 0)
Misc.Pause(550)
else:
Misc.NoOperation
# move the ore to the tile infront of you
def moveOre(oreList):
for ore in oreList:
if ore[2] is not None:
x, y, z = tileInFront()
Items.MoveOnGround(ore[2], 0, x, y, z)
Misc.Pause(550)
# Get the X Y Z for the tile in front of you
def tileInFront():
direction = Player.Direction
playerX = Player.Position.X
playerY = Player.Position.Y
playerZ = Player.Position.Z
if direction == 'Up':
tileX = playerX - 1
tileY = playerY - 1
tileZ = playerZ
elif direction == 'North':
tileX = playerX
tileY = playerY - 1
tileZ = playerZ
elif direction == 'Right':
tileX = playerX + 1
tileY = playerY - 1
tileZ = playerZ
elif direction == 'East':
tileX = playerX + 1
tileY = playerY
tileZ = playerZ
elif direction == 'Down':
tileX = playerX + 1
tileY = playerY + 1
tileZ = playerZ
elif direction == 'South':
tileX = playerX
tileY = playerY + 1
tileZ = playerZ
elif direction == 'Left':
tileX = playerX - 1
tileY = playerY + 1
tileZ = playerZ
elif direction == 'West':
tileX = playerX - 1
tileY = playerY
tileZ = playerZ
return tileX, tileY, tileZ
# Find a if a forge graphics is within 2 tiles of you
def nearForge():
forgeFilter = Items.Filter()
forgeFilter.Enabled = True
forgeFilter.OnGround = True
forgeFilter.Movable = False
forgeFilter.Graphics = forgesList
forgeFilter.RangeMax = 2
forges = Items.ApplyFilter(forgeFilter)
Misc.SendMessage
for forge in forges:
if 'forge' in forge.Name or 'bellows' in forge.Name:
return True
return False
#Were near a forge, so smelt everything we have!
def smeltAllOre():
#Move all ore to stacks
searchForKnownOre()
i = 0
for ore in oreList:
while ore[2] is not None:
if ore[0] == 'iron':
Misc.SendMessage('SMELT: ' + ore[0][:4] + ': ' + str(ore[2].Amount), ore[1])
Items.UseItem(ore[2])
Misc.Pause(550)
oreList[i][2] = None
break
elif ore[0] == 'shadow' or ore[0] == 'dullcopper' or ore[0] == 'copper':
Misc.SendMessage('SMELT: ' + ore[0][:4] + ': ' + str(ore[2].Amount), ore[1])
Items.UseItem(ore[2])
Misc.Pause(550)
if Journal.Search(smeltSuccess):
Journal.Clear()
oreList[i][2] = None
break
else:
for j in range(ore[2].Amount):
Misc.SendMessage('SMELT: ' + ore[0][:4] + ': ' + str(ore[2].Amount), ore[1])
Items.UseItem(ore[2])
Misc.Pause(550)
oreList[i][2] = None
break
i += 1
#Get the total ore count
def getOreCount():
searchForKnownOre()
oreCount = 0
for ore in oreList:
if ore[2] is not None:
oreCount = oreCount + ore[2].Amount
return oreCount
#Display pretty-like the ore counts
def printOreCounts():
total = 0
for ore in oreList:
if ore[2] is not None:
Misc.SendMessage(ore[0][:4] + ': ' + str(ore[2].Amount), ore[1])
total = total + ore[2].Amount
Misc.SendMessage('all : ' + str(total), 67)
#Main Handler for mining
def autoMiner():
while True:
#Get a mining tool!
miningTool = getMinerTool()
#Use found mining tool
Journal.Clear()
Items.UseItem(miningTool)
Target.WaitForTarget(2000,True)
Target.TargetExecuteRelative(self,1)
Misc.Pause(600)
#search pack for ore, add to stack
# searchForNewOre()
#
# #if overweight move known ore to stack
# if Player.Weight >= Player.MaxWeight:
# searchForKnownOre()
#
# #Determine if no metal left and move accordingly
# boolMove = readJournal()
# if boolMove:
# move(2)
# moveOre(oreList)
# if boolMove:
# move(1)
# boolMove = False
#
# #if near forge, smelt all!
# smeltAll = nearForge()
# if smeltAll:
# oreCount = getOreCount()
# if smeltAll and oreCount > 50:
# smeltAllOre()
#
# #print the ore counts
# printOreCounts()
autoMiner()