forked from elanthia-online/dr-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
carve-lockpicks.lic
296 lines (269 loc) · 12.5 KB
/
carve-lockpicks.lic
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
=begin
Need these settings in your yaml:
#Header
lockpick_carve_settings:
grand_container: carryall # bag for complete grandmaster's lockpicks
master_container: toolkit # bag for completed master's lockpicks
trash_container: # bag for anything less than master/grandmaster, blank to dispose
pocket_container: watery portal # source of fresh keyblank pockets
initial_grand: false # true/false as to whether to initial your grandmasters' lockpicks
full_rings_container: backpack # bag for full rings, can't be either grand/master bag
ring_picks: true # true/false as a default to put carved picks on rings
carve_past_ring_capacity: false # true/false to continue carving after you've run out of lockpick rings
The only container that can be a portal/eddy is the pocket container.
All containers must be unique
=end
custom_require.call(%w[common common-items common-crafting])
class CarveLockpicks
def initialize
arg_definitions = [
[
{ name: 'ring', regex: /ring/i, optional: true, description: 'Put completed batches of lockpicks on rings, need rings in the same bag as the lockpicks (grands rings in grands bag)' },
{ name: 'ratio_last', regex: /ratio_last/i, optional: true, description: 'Displays most recent percentage of grandmaster to master picks carved from last run.' },
{ name: 'ratio_all', regex: /ratio_all/i, optional: true, description: 'Displays overall percentage of grandmaster to master picks carved from all runs.' },
{ name: 'ratio_reset', regex: /ratio_reset/i, optional: true, description: 'Delete all past recorded carving projects data' },
{ name: 'script_summary', optional: true, description: 'Carves lockpicks with carving knife, drawing from keyblank pockets until empty.' }
],
[
{ name: 'buy_rings', regex: /buy_rings/i, description: 'Buy rings from a shop' },
{ name: 'pockets', regex: /\d+/, description: 'How many pockets you\'re carving' },
{ name: 'masters_ordinal', options: $ORDINALS },
{ name: 'grands_ordinal', options: $ORDINALS }
]
]
@@grands_count = 0
@@masters_count = 0
UserVars.grands_ratio ||= {}
args = parse_args(arg_definitions)
@settings = get_settings
@bag = @settings.crafting_container
@bag_items = @settings.crafting_items_in_container
@belt = @settings.engineering_belt
@lockpick_carve_settings = @settings.lockpick_carve_settings
@master_batch, @grand_batch = [true, true] if args.ring || @lockpick_carve_settings['ring_picks']
@grands_ring_ready = (25 - DRCI.count_items_in_container('lockpick', @lockpick_carve_settings['grand_container']))
@masters_ring_ready = (25 - DRCI.count_items_in_container('lockpick', @lockpick_carve_settings['master_container']))
echo "Grands on hand: #{25 - @grands_ring_ready}" if @grands_ring_ready < 25
echo "Masters on hand: #{25 - @masters_ring_ready}" if @masters_ring_ready < 25
purchase_rings(args.pockets.to_i, args.masters_ordinal, args.grands_ordinal) if args.buy_rings
if args.ratio_last
DRC.message("Most recent percentage of Grandmaster's to Master's picks: #{UserVars.grands_ratio.to_a.last.last}")
exit
elsif args.ratio_all
DRC.message("Average of all recorded carving projects to date, Grandmaster's percentages: #{calc_ratio}")
exit
elsif args.ratio_reset
UserVars.grands_ratio = {}
DRC.message("Resetting past carving projects data. Historical data: #{UserVars.grands_ratio}")
exit
end
main_loop
end
def main_loop
DRCC.get_crafting_item("carving knife", @bag, @bag_items, @belt)
# fetches from portal if the next pocket isn't immediately accessible
if DRCI.exists?('keyblank pocket') || (DRCI.get_item?('keyblank pocket', @lockpick_carve_settings['pocket_container']) && DRCI.put_away_item?("keyblank pocket", @lockpick_carve_settings['full_rings_container']))
loop do
check_status
get_keyblank
carve
end
else
DRCC.stow_crafting_item("carving knife", @bag, @belt)
exit
end
end
def calc_ratio
total = 0
UserVars.grands_ratio.values.each { |v| total += v }
total = total / UserVars.grands_ratio.size
return total.round
end
def purchase_rings(pockets, mord, gord)
# getting ring count for each based on past performance
if UserVars.grands_ratio.empty?
DRC.message('No data with which to do a ratio calculation, so doing an even split')
@mrings, @grings = [pockets + 1, pockets + 1]
else
total_rings = (pockets * 50) / 25
@grings = (calc_ratio / 100.to_f * total_rings).round
@mrings = total_rings - @grings
@grings += [@grings / 5, 1].max
@mrings += [@mrings / 5, 1].max
end
DRC.message("Buying:\nMaster's rings: #{@mrings}\nGrandmaster's rings: #{@grings}")
sleep 1
verify_funds("lockpick ring", mord, gord)
grings.times do
DRCT.buy_item(Room.current.id, "#{gord} lockpick ring")
DRCI.put_away_item?("lockpick ring", @lockpick_carve_settings['grand_container'])
end
mrings.times do
DRCT.buy_item(Room.current.id, "#{mord} lockpick ring")
DRCI.put_away_item?("lockpick ring", @lockpick_carve_settings['master_container'])
end
exit
end
def verify_funds(item, *ords)
total_needed, currency = [0, '']
counts = [@mrings, @grings]
ords.each do |ord|
case DRC.bput("shop #{ord} #{item}", /^I could not find/, /Cost: (\d+) (\w+)/)
when /(\d+) (\w+)/
cost = Regexp.last_match(1).to_i
currency = Regexp.last_match(2)
total_needed += cost * counts.shift
else
DRC.message("Cannot find #{ord} #{item} to purchase here.")
exit
end
end
DRC.message("Total purchase price is: #{DRCM.minimize_coins(total_needed)}")
sleep 1
current_coin = DRCM.check_wealth(currency)
if (current_coin < total_needed)
DRC.message("Need coin in the amount of: #{DRCM.minimize_coins(total_needed - current_coin)}")
sleep 1
exit
else
DRC.message("Sufficient coin on hand, purchasing.")
sleep 1
end
end
def check_status
spell_list = @settings.waggle_sets['carve'].join(' ').split(' ').map(&:capitalize)
spell_list.reject! { |spell| spell =~ /delay|khri|puncture|slice|impact|fire|cold|electric/i }
DRC.wait_for_script_to_complete('buff', ['carve']) unless spell_list.all? { |name| DRSpells.active_spells["Khri #{name}"] }
DRC.bput("sit", 'You sit', 'You are already sitting', 'You rise', 'While swimming?') unless sitting?
end
def get_keyblank
case DRC.bput("get keyblank from my keyblank pocket", 'You get', 'What were you referring to', 'You need a free hand')
when /What were you referring to/
case DRC.bput("count my keyblank pocket", 'nothing inside the keyblank pocket', 'It looks like there', 'I could not find what you were referring to')
when /nothing inside the keyblank pocket/
empty_pocket
when /It looks like there/
DRC.bput("open my keyblank pocket", 'You open a')
when /I could not find what you were referring to/
DRCC.stow_crafting_item("carving knife", @bag, @belt)
exit
end
get_keyblank
when /You need a free hand/
if /referring/ =~ DRC.bput("Put my keyblank in my keyblank pocket", 'You put a', 'What were you referring to')
fput('stow left')
end
get_keyblank
end
end
def carve
loop do
case DRC.bput("carve my #{DRC.left_hand} with my knife", /proudly glance down at a (grand)?master/, /but feel your knife slip/, /^You are too injured to do any carving/, /^Roundtime/, /^It would be better to find a creature to carve/)
when /proudly glance down at a grandmaster/
DRC.bput("carve my lockpick with my knife", 'With the precision and skill') if @lockpick_carve_settings['initial_grand']
@@grands_count += 1
@grands_ring_ready -= 1
stow_lockpick(@lockpick_carve_settings['grand_container'])
when /proudly glance down at a master/
@@masters_count += 1
@masters_ring_ready -= 1
stow_lockpick(@lockpick_carve_settings['master_container'])
when /It would be better to find a creature to carve/
# Unmatched failure, or we carved a lesser pick
if @lockpick_carve_settings['trash_container'] && DRC.left_hand
DRCI.put_away_item?('lockpick', @lockpick_carve_settings['trash_container'])
elsif DRC.left_hand
DRCI.dispose_trash('lockpick', @settings.worn_trashcan, @settings.worn_trashcan_verb)
end
when /You are too injured to do any carving/
DRC.message("Need to be completely wound-free, go get healed")
DRC.bput("Put my keyblank in my keyblank pocket", 'You put a')
DRCC.stow_crafting_item("carving knife", @bag, @belt)
exit
end
waitrt?
break unless DRC.left_hand.match?(/lockpick|keyblank/)
end
end
def stow_lockpick(container)
# Unless we can stow it (eg full bag), we call it quits
unless DRCI.put_away_item?('lockpick', container)
DRC.message("Bag's full, exiting")
DRCC.stow_crafting_item("carving knife", @bag, @belt)
exit
end
# Ring a set of 25
if @grands_ring_ready <= 0 && @grand_batch
ring_batch('grand')
return
elsif @masters_ring_ready <= 0 && @master_batch
ring_batch('master')
return
end
end
def empty_pocket
DRCI.get_item?('keyblank pocket')
DRCI.dispose_trash("keyblank pocket", @settings.worn_trashcan, @settings.worn_trashcan_verb) if DRCI.in_hands?('keyblank pocket')
return unless /referring/ =~ DRC.bput("open my keyblank pocket", 'You open', 'What were you referring', 'That is already open')
if DRCI.get_item?("keyblank pocket", @lockpick_carve_settings['pocket_container']) # fetches from portal if the next pocket isn't immediately accessible via open
DRCI.put_away_item?("keyblank pocket", @lockpick_carve_settings['full_rings_container'])
DRC.bput("open my keyblank pocket", 'You open', 'What were you referring', 'That is already open')
else
DRCC.stow_crafting_item("carving knife", @bag, @belt)
exit
end
end
def ring_batch(type)
DRCC.stow_crafting_item("carving knife", @bag, @belt)
unless DRCI.get_item?('lockpick ring', @lockpick_carve_settings["#{type}_container"])
DRC.message("Out of empty rings for #{type} picks")
case type
when /grand/
@grand_batch = false
@grands_ring_ready = 25
else
@master_batch = false
@masters_ring_ready = 25
end
stow_lockpick(@lockpick_carve_settings["#{type}_container"])
exit unless @lockpick_carve_settings['carve_past_ring_capacity']
DRCC.get_crafting_item("carving knife", @bag, @bag_items, @belt)
return
end
25.times do
DRCI.get_item?('lockpick', @lockpick_carve_settings["#{type}_container"])
DRCI.put_away_item?('lockpick', 'lockpick ring')
end
unless DRCI.put_away_item?('lockpick ring', @lockpick_carve_settings['full_rings_container'])
DRC.message("Out of room for rings")
exit
end
if type == 'grand'
@grands_ring_ready = 25
else
@masters_ring_ready = 25
end
DRCC.get_crafting_item("carving knife", @bag, @bag_items, @belt)
end
before_dying do
percentage = (@@grands_count.to_f / (@@grands_count + @@masters_count).to_f) * 100
exit if percentage.nan?
DRC.message("Total grandmaster's picks: #{@@grands_count}")
DRC.message("Total master's picks: #{@@masters_count}")
DRC.message("Grandmaster's percentage: #{percentage.round(2)}%")
unless UserVars.grands_ratio.empty?
total = 0
UserVars.grands_ratio.values.each { |v| total += v }
total = total / UserVars.grands_ratio.size
if total > percentage
DRC.message("This was a bad run, past carving projects yielded #{(total - percentage).round(2)}% more Grandmaster's than Master's picks")
elsif total < percentage
DRC.message("Nice job, this run beat your past projects by carving #{(percentage - total).round(2)}% more Grandmaster's than Master's picks")
else
DRC.message("Consistent with past performance, no gain or loss in ratio of Grandmaster's to Master's picks")
end
end
UserVars.grands_ratio.store(Time.now, percentage.round)
end
end
CarveLockpicks.new