forked from elanthia-online/dr-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhunting-buddy.lic
343 lines (303 loc) · 11.8 KB
/
hunting-buddy.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
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
=begin
Documentation: https://elanthipedia.play.net/Lich_script_repository#hunting-buddy
=end
custom_require.call(%w[common common-arcana common-items common-travel drinfomon events spellmonitor equipmanager])
class HuntingBuddy
include DRC
include DRCA
include DRCI
include DRCT
def initialize
arg_definitions = [[]]
args = parse_args(arg_definitions, true)
@settings = get_settings
@bail_on_familiar = @settings.stop_on_familiar_drag
data = get_data('hunting')
@escort_zones = data.escort_zones
@hunting_zones = data.hunting_zones
@stop_on_low_threshold = @settings.stop_on_low_threshold
@magic_exp_threshold = @settings.magic_exp_training_max_threshold
@magic_skills = ['Arcane Magic', 'Holy Magic', 'Life Magic', 'Elemental Magic',\
'Lunar Magic', 'Attunement', 'Arcana', 'Targeted Magic', 'Inner Fire',\
'Inner Magic', 'Augmentation', 'Debilitation', 'Utility', 'Warding', 'Sorcery']
hunting_info = []
if @settings.hunting_file_list || args.flex.any?
(args.flex.any? ? args.flex : @settings.hunting_file_list).each do |file|
if file == 'setup'
hunting_info += get_settings.hunting_info
else
# Hunting info from extra config needs the config name passed on in args.
infos = get_settings([file]).hunting_info
infos.each do |info|
info['args'] = info['args'] || []
(info['args'] << file) unless info['args'].include? file
end
hunting_info += infos
end
end
else
hunting_info = @settings.hunting_info
end
@hunting_info = format_hunting_info(hunting_info)
end
def need_boxes?
return false unless @settings.box_hunt_minimum
count_boxes(@settings) <= @settings.box_hunt_minimum
end
def main
check_bundling_rope
wait_for_script_to_complete('restock') unless @settings.sell_loot_skip_bank
@hunting_info.each do |info|
if @stop_hunting
echo('***STATUS*** stopping all hunting due to manual intervention')
break
end
if @stopped_for_bleeding
retreat
stop_script('tendme') if Script.running?('tendme')
break
end
args = info['args']
before_actions = info['before']
after_actions = info['after']
during_actions = info['during']
duration = info[:duration]
stop_on_skills = info['stop_on']
stop_on_low_skills = info['stop_on_low']
stop_on_boxes = info['boxes']
# Execute scripts to run before the hunt
execute_actions(before_actions)
if stop_on_boxes && !need_boxes?
echo('***STATUS*** Skipping hunt because of current boxes is more than the minimum.')
next
end
if all_skills_at_cap?(stop_on_skills)
stop_actions(during_actions)
# Execute scripts to run after the hunt
execute_actions(after_actions)
next
end
if stop_on_low_skills_too_low?(stop_on_low_skills)
stop_actions(during_actions)
# Execute scripts to run after the hunt
execute_actions(after_actions)
next
end
check_prehunt_buffs
next unless find_hunting_room?(info[:zone])
args.each_with_index do |arg, index|
if @stopped_for_bleeding
retreat
stop_script('tendme') if Script.running?('tendme')
break
end
execute_nonblocking_actions(during_actions)
hunt(arg, duration ? duration[index] : nil, stop_on_skills ? stop_on_skills[index] : nil, stop_on_low_skills ? stop_on_low_skills[index] : nil, stop_on_boxes ? stop_on_boxes[index] : nil)
end
stop_actions(during_actions)
wait_for_script_to_complete('bescort', @exit) if @exit
release_cyclics
# Execute scripts to run after the hunt
execute_actions(after_actions)
end
walk_to(@settings.safe_room)
EquipmentManager.new.wear_equipment_set?('standard')
end
def execute_actions(actions)
actions.each do |action|
echo "***STATUS*** EXECUTE #{action}"
action_parts = action.split(' ')
script_name = action_parts.shift
wait_for_script_to_complete(script_name, action_parts)
end
end
def execute_nonblocking_actions(actions)
actions.each do |action|
echo "***STATUS*** EXECUTE #{action}"
action_parts = action.split(' ')
script_name = action_parts.shift
start_script(script_name, action_parts)
end
end
def stop_actions(actions)
actions.each do |script_name|
stop_script(script_name) if Script.running?(script_name)
end
end
def check_bundling_rope
return unless @settings.skinning['skin']
return if wearing?('bundle')
description = 'bundling rope'
return if exists?(description)
room = get_data('town')[@settings.hometown]['tannery']['id']
name = get_data('town')[@settings.hometown]['tannery']['name']
walk_to(room)
bput("ask #{name} for #{description}", 'hands you')
bput("stow my #{description}", 'You put')
end
def check_prehunt_buffs
walk_to(@settings.prehunt_buffs)
wait_for_script_to_complete('buff', ['prehunt_buffs'])
end
def find_hunting_room?(zone_name)
UserVars.friends = @settings.hunting_buddies || []
zones = Array(zone_name).flatten.compact
rooms = @hunting_zones.values_at(*zones.select { |name| @hunting_zones.include?(name) }).flatten.compact unless @escort_zones.include?(zones.first)
if rooms.empty? || rooms.nil?
escort_info = @escort_zones[zones.first]
unless escort_info
echo "FAILED TO FIND THE HUNTING ZONE(S) #{zones} IN BASE.YAML"
return false
end
walk_to(escort_info['base'])
wait_for_script_to_complete('bescort', [escort_info['area'], escort_info['enter']])
@exit = [escort_info['area'], 'exit']
else
@exit = nil
find_empty_room(rooms, @settings.safe_room,
lambda do
return false if DRRoom.pcs.size > 2
return true if (DRRoom.pcs & UserVars.friends).any?
return false if (DRRoom.pcs - DRRoom.group_members).any?
# No visible friends in the room and no visible people
UserVars.friends.each { |friend| Flags.add("room-check-#{friend}", friend) }
Flags.add('room-check', 'says, ', 'say, ', 'You hear', 'Someone snipes a')
bput('search', 'roundtime')
data = reget(40).reverse.take_while { |x| x !~ /You search around/ }
if data.grep(/vague silhouette|You notice \w+, who is|see signs that/).any?
pause
waitrt?
return UserVars.friends.find { |friend| Flags["room-check-#{friend}"] }
end
fput("say #{@settings.empty_hunting_room_messages.sample}") unless @settings.empty_hunting_room_messages.empty?
20.times do |_|
pause 0.5
return true if UserVars.friends.find { |friend| Flags["room-check-#{friend}"] }
return false if Flags['room-check'] || !(DRRoom.pcs - DRRoom.group_members - UserVars.friends).empty?
end
true
end,
@settings.hunting_room_min_mana,
@settings.hunting_room_strict_mana)
end
true
end
def all_skills_at_cap?(stop_on_skills)
stop_on_skills && stop_on_skills.flatten.all? { |skill| DRSkill.getxp(skill) >= (@magic_skills.include?(skill) ? @magic_exp_threshold : 32) }
end
def stop_on_low_skills_too_low?(stop_on_low_skills)
stop_on_low_skills && stop_on_low_skills.flatten.any? { |skill| DRSkill.getxp(skill) < @stop_on_low_threshold }
end
def over_box_limit?
$COMBAT_TRAINER.get_process('loot').at_box_limit?
end
def hunt(args, duration, stop_on_skills, stop_on_low_skills, stop_on_boxes)
$COMBAT_TRAINER = nil
hunting_room = Room.current.id
Flags.add('familiar_drag', /^Your .+ grabs ahold of you and drags you .+, out of combat.+$/)
echo("***STATUS*** beginning hunt '#{args}' for '#{duration}' minutes")
verify_script('combat-trainer')
start_script('combat-trainer', args)
pause until $COMBAT_TRAINER.running
counter = 0
loop do
clear
if @settings.stop_hunting_if_bleeding && bleeding?
echo('***STATUS*** stopping due to bleeding')
@stopped_for_bleeding = true
break
end
if stop_on_boxes && over_box_limit?
echo('***STATUS*** stopping due to boxes')
break
end
if all_skills_at_cap?(stop_on_skills)
echo('***STATUS*** stopping due to capped skills')
break
end
if stop_on_low_skills_too_low?(stop_on_low_skills)
echo("***STATUS*** stopping due to low skills: #{stop_on_low_skills}")
break
end
if @stop_hunting || @next_hunt
echo('***STATUS*** stopping due to manual intervention')
@next_hunt = false
break
end
if duration && (counter / 60) >= duration
echo('***STATUS*** stopping due to time')
break
end
if Flags['familiar_drag'] && @bail_on_familiar
echo('***STATUS*** stopping due to familiar dragging from stun')
Flags.reset('familiar_drag')
break
end
if Flags['familiar_drag'] && !@bail_on_familiar
echo('***STATUS*** heading back to room - familiar drug while stunned')
DRCT.walk_to(hunting_room)
Flags.reset('familiar_drag')
end
if (counter % 60).zero?
if duration
if stop_on_skills
echo("***STATUS*** #{duration - (counter / 60)} minutes of hunting remaining or waiting on #{stop_on_skills.select { |skill| DRSkill.getxp(skill) < (@magic_skills.include?(skill) ? @magic_exp_threshold : 32) }.join(', ')}")
else
echo("***STATUS*** #{duration - (counter / 60)} minutes of hunting remaining")
end
else
echo("***STATUS*** #{counter / 60} minutes of hunting, still waiting on #{stop_on_skills.select { |skill| DRSkill.getxp(skill) < (@magic_skills.include?(skill) ? @magic_exp_threshold : 32) }.join(', ')}")
end
end
counter += 1
pause 1
end
$COMBAT_TRAINER.stop
pause 1 while $COMBAT_TRAINER.running || Script.running?('combat-trainer')
retreat
end
def format_hunting_info(hunting_info_raw)
hunting_info = []
hunting_info_raw.each do |info|
if hunting_info.empty? || hunting_info.last[:zone] != info[:zone]
if info['args'].flatten == info['args']
info['args'] = [info['args'] || []]
info[:duration] = [info[:duration]]
info['stop_on'] = [info['stop_on']]
info['stop_on_low'] = [info['stop_on_low']] if info['stop_on_low']
info['before'] = info['before']
info['after'] = info['after']
info['during'] = info['during']
info['boxes'] = info['boxes']
end
hunting_info << info
else
hunting_info.last['args'] << info['args']
hunting_info.last[:duration] << info[:duration]
hunting_info.last['stop_on'] << info['stop_on']
hunting_info.last['stop_on_low'] << info['stop_on_low']
hunting_info.last['before'] ||= info['before']
hunting_info.last['after'] ||= info['after']
hunting_info.last['during'] ||= info['during']
hunting_info.last['boxes'] ||= info['boxes']
end
end
hunting_info
end
def stop_hunting
@stop_hunting = true
end
def next_hunt
@next_hunt = true
end
end
before_dying do
['combat-trainer'].each do |script_name|
stop_script(script_name) if Script.running?(script_name)
end
DRCA.release_cyclics
Flags.delete('room-check')
Flags.delete('familiar_drag')
end
$HUNTING_BUDDY = HuntingBuddy.new
$HUNTING_BUDDY.main