forked from elanthia-online/dr-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hunting-buddy.lic
232 lines (201 loc) · 7.33 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
=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
data = get_data('hunting')
@escort_zones = data.escort_zones
@hunting_zones = data.hunting_zones
hunting_info = []
if @settings.hunting_file_list || args.flex.any?
(args.flex.any? ? args.flex : @settings.hunting_file_list).each do |file|
hunting_info += file == 'setup' ? get_settings.hunting_info : get_settings([file]).hunting_info
end
else
hunting_info = @settings.hunting_info
end
@hunting_info = format_hunting_info(hunting_info)
end
def main
check_bundling_rope
check_prehunt_buffs
@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']
duration = info[:duration]
stop_on_skills = info['stop_on']
# Execute scripts to run before the hunt
execute_actions(before_actions)
if all_skills_at_cap?(stop_on_skills)
# Execute scripts to run after the hunt
execute_actions(after_actions)
next
end
next unless find_hunting_room?(info[:zone])
args.each_with_index { |arg, index| hunt(arg, duration ? duration[index] : nil, stop_on_skills ? stop_on_skills[index] : nil) }
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 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 || []
if rooms = @hunting_zones[zone_name]
@exit = nil
find_empty_room(rooms, @settings.safe_room,
lambda do
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')
fput("say #{@settings.empty_hunting_room_messages.sample}")
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
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)
else
escort_info = @escort_zones[zone_name]
unless escort_info
echo "FAILED TO FIND HUNTING ZONE #{zone_name} 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']
end
true
end
def all_skills_at_cap?(stop_on_skills)
stop_on_skills && stop_on_skills.flatten.all? { |skill| DRSkill.getxp(skill) >= 32 }
end
def hunt(args, duration, stop_on_skills)
echo("***STATUS*** beginning hunt '#{args}' for '#{duration}' minutes")
verify_script('combat-trainer')
start_script('combat-trainer', args)
pause 1 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 all_skills_at_cap?(stop_on_skills)
echo('***STATUS*** stopping due to 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 (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) < 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) < 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']]
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']
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
end
$HUNTING_BUDDY = HuntingBuddy.new
$HUNTING_BUDDY.main