forked from elanthia-online/dr-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
astrology.lic
369 lines (315 loc) · 11.9 KB
/
astrology.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
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
=begin
Documentation: https://elanthipedia.play.net/Lich_script_repository#astrology
=end
custom_require.call(%w[common common-arcana common-travel common-moonmage equipmanager spellmonitor events])
class Astrology
def initialize
exit unless DRStats.moon_mage?
@settings = get_settings
arg_definitions = [
[],
[{ name: 'rtr', regex: /rtr/i, description: 'Runs Read the Ripples' }]
]
args = parse_args(arg_definitions)
# Make sure that our Cirlce is up-to-date - avoid using stale data for new characters who joined the guild
DRC.bput('info', 'Circle:') if DRStats.circle.zero?
@equipment_manager = EquipmentManager.new
@constellations = get_data('constellations').constellations
@finished_messages = get_data('constellations').observe_finished_messages
@success_messages = get_data('constellations').observe_success_messages
@divination_tool = @settings.divination_tool
@divination_bones_storage = @settings.divination_bones_storage
@have_telescope = @settings.have_telescope
@telescope_storage = @settings.telescope_storage
@telescope_name = @settings.telescope_name
@astral_place_source = @settings.astral_plane_training['train_source']
@astral_plane_destination = @settings.astral_plane_training['train_destination']
@prediction_pool_target = @settings.astrology_use_full_pools ? 10 : @settings.astrology_pool_target
@rtr_data = nil
@astrology_prediction_skills_magic = @settings.astrology_prediction_skills['magic']
@astrology_prediction_skills_lore = @settings.astrology_prediction_skills['lore']
@astrology_prediction_skills_offense = @settings.astrology_prediction_skills['offense']
@astrology_prediction_skills_defense = @settings.astrology_prediction_skills['defense']
@astrology_prediction_skills_survival = @settings.astrology_prediction_skills['survival']
DRC.message("Flags['rtr-expire'].nil? #{Flags['rtr-expire'].nil?}") if UserVars.astrology_debug
DRC.message("Flags['rtr-expire'] = #{Flags['rtr-expire']}") if UserVars.astrology_debug
do_buffs(@settings)
if args.rtr
check_ripples(@settings)
else
train_astrology(@settings)
end
end
def do_buffs(settings)
return unless settings
return unless settings.waggle_sets['astrology']
empty_hands
# Pop out rtr data from buffs and save it for later
buffs = settings.waggle_sets['astrology']
@rtr_data = buffs.select { |spell| spell.eql?('Read the Ripples') }
.values
.first
buffs.reject! { |spell| spell.eql?('Read the Ripples') }
buffs.each_value do |value|
next unless value['use_auto_mana']
DRCA.check_discern(value, settings)
end
DRCA.cast_spells(buffs, settings)
end
def visible_bodies
result = []
all_bodies = @constellations
case DRCMM.observe('heavens')
when "That's a bit hard to do while inside"
DRC.message("Must be outdoors to observe sky")
exit
end
until (line = get?) =~ /^Roundtime/i
result << all_bodies.find { |body| /\b#{body['name'].split.last}\b/i =~ line && line !~ /below the horizon/ }
end
result.compact.select { |data| data['circle'] <= DRStats.circle }
end
def check_attunement
return if DRSkill.getxp('Attunement') > 30
['', 'mana', 'moons', 'planets'].each do |target|
DRC.bput("perceive #{target}", 'roundtime')
waitrt?
end
end
def check_pools
pools = {
'lore' => 0,
'magic' => 0,
'survival' => 0,
'offensive combat' => 0,
'defensive combat' => 0,
'future events' => 0
}
pools_to_size = {
/You have no understanding of the celestial influences over/ => 0,
/You have a feeble understanding of the celestial influences over/ => 1,
/You have a weak understanding of the celestial influences over/ => 2,
/You have a fledgling understanding of the celestial influences over/ => 3,
/You have a modest understanding of the celestial influences over/ => 4,
/You have a decent understanding of the celestial influences over/ => 5,
/You have a significant understanding of the celestial influences over/ => 6,
/You have a potent understanding of the celestial influences over/ => 7,
/You have an insightful understanding of the celestial influences over/ => 8,
/You have a powerful understanding of the celestial influences over/ => 9,
/You have a complete understanding of the celestial influences over/ => 10
}
DRCMM.predict('all')
lines = reget(50).reverse
lines.select! { |line| line =~ /celestial influences/ }
pools.select! { |name, _level| pools[name] = lines.find { |line| line =~ /#{name}/ } }
pools.each { |name, text| pools_to_size.each { |match_text, value| pools[name] = value if match_text =~ text } }
DRC.message("pools: #{pools}") if UserVars.astrology_debug
waitrt?
pools
end
def check_events(pools)
waitrt?
prev_size = pools['future events']
result = nil
until ['You are unable to sense additional information'].include? result
result = DRCMM.study_sky
waitrt?
return if ['detect any portents'].include? result
pools = check_pools
break if pools['future events'] == prev_size
break if pools['future events'] == 10
prev_size = pools['future events']
end
DRCMM.predict('event')
end
def check_weather
DRC.message("Checking the weather") if UserVars.astrology_debug
DRCMM.predict('weather')
waitrt?
end
def rtr_active?
# DRSpells.active_spells sometimes shows RtR as inactive even though it is active
100.times do
pause 0.01
return true if DRSpells.active_spells.include?('Read the Ripples')
end
false
end
def check_ripples(settings)
return unless @rtr_data
return unless settings
return if !Flags['rtr-expire'].nil? && !Flags['rtr-expire']
empty_hands
DRCA.cast_spell(@rtr_data, settings)
perc_time = Time.now - 61
Flags.add('rtr-expire', get_data('spells').spell_data['Read the Ripples']['expire']) if rtr_active?
DRCMM.get_telescope?(@telescope_name, @telescope_storage) if @have_telescope
while rtr_active?
line = get?
if perc_time + 60 < Time.now
DRCA.perc_mana
perc_time = Time.now
end
res = @constellations.find { |body| /As your consciousness drifts amongst the currents of Fate, .* #{body['name']}/i =~ line }
observe_routine(res['name']) unless res.nil?
end
DRCMM.store_telescope?(@telescope_name, @telescope_storage) if @have_telescope
nil
end
def check_astral
return unless DRStats.circle > 99
return unless @astral_place_source
return unless @astral_plane_destination
return if !UserVars.astral_plane_exp_timer.nil? && Time.now - UserVars.astral_plane_exp_timer < 3600
DRC.wait_for_script_to_complete('bescort', ['ways', @astral_plane_destination])
UserVars.astral_plane_exp_timer = Time.now
DRC.wait_for_script_to_complete('bescort', ['ways', @astral_place_source])
exit
end
def empty_hands
DRCMM.store_telescope?(@telescope_name, @telescope_storage) if DRCI.in_hands?(@telescope_name)
@equipment_manager.empty_hands
end
def predict_all(pools)
skillset_to_pool = {
'offensive combat' => @astrology_prediction_skills_offense,
'defensive combat' => @astrology_prediction_skills_defense,
'magic' => @astrology_prediction_skills_magic,
'survival' => @astrology_prediction_skills_survival,
'lore' => @astrology_prediction_skills_lore,
'future events' => 'future events'
}
pools.reject { |_skill, size| (size < @prediction_pool_target) }
.each_key do |skill|
break if DRSkill.getxp('Astrology') > 30
align_routine(skillset_to_pool[skill])
end
end
def check_heavens
empty_hands
vis_bodies = visible_bodies
night = vis_bodies.find { |body| body['constellation'] }
best_eye_data = vis_bodies
.select { |data| @have_telescope || !data['telescope'] }
.max_by { |data| [data['pools'].values.compact.size, data['circle']] }
DRC.message("best_eye_data = #{best_eye_data}") if UserVars.astrology_debug
waitrt?
if @have_telescope
things_to_try = @constellations.select do |data|
data['telescope'] &&
data['circle'] <= DRStats.circle &&
data['circle'] > best_eye_data['circle'] &&
(night || !data['constellation']) &&
data['pools'].values.compact.size > best_eye_data['pools'].values.compact.size
end
things_to_try << best_eye_data
things_to_try.sort! { |data| data['circle'] }.reverse!
DRC.message("things_to_try = #{things_to_try}") if UserVars.astrology_debug
things_to_try.find do |data|
result = nil
DRCMM.get_telescope?(@telescope_name, @telescope_storage) if @have_telescope
until @finished_messages.include?(result)
return check_heavens if Flags['bad-search'] == 'is foiled by the daylight'
next if Flags['bad-search'] == 'turns up fruitless'
result = observe_routine(data['name'])
end
@success_messages.include?(result)
end
DRCMM.store_telescope?(@telescope_name, @telescope_storage) if @have_telescope
else
until observe_routine(best_eye_data['name'])
if Flags['bad-search']
check_heavens
return
end
end
end
pause 2
waitrt?
end
def get_healed
DRCMM.store_telescope?(@telescope_name, @telescope_storage) if @have_telescope
snapshot = Room.current.id
DRC.wait_for_script_to_complete('safe-room', ['force'])
DRCT.walk_to(snapshot)
do_buffs(@settings)
DRCMM.get_telescope?(@telescope_name, @telescope_storage) if @have_telescope
end
def observe_routine(body)
Flags.add('bad-search', 'is foiled by the (daylight|darkness)', 'turns up fruitless')
if @have_telescope
case DRCMM.center_telescope(body)
when /Center what/
DRCMM.get_telescope?(@telescope_name, @telescope_storage)
return observe_routine(body)
when /open it/
DRC.bput('open my telescope', 'extend your telescope')
return observe_routine(body)
when /The pain is too much/, /Your vision is too fuzzy/
get_healed
return observe_routine(body)
end
result = DRCMM.peer_telescope
case result
when /The pain is too much/, /Your vision is too fuzzy/
get_healed
return observe_routine(body)
when /open it/
DRC.bput('open my telescope', 'extend your telescope')
return observe_routine(body)
end
result
else
['Roundtime', 'Clouds obscure'].include?(DRCMM.observe(body))
end
end
def align_routine(skill)
if skill == 'future events'
DRCMM.predict('event')
return
end
DRCMM.align(skill)
waitrt?
if !@divination_bones_storage.empty?
DRCMM.roll_bones(@divination_bones_storage)
elsif !@divination_tool.empty?
DRCMM.use_div_tool(@divination_tool)
else
DRCMM.predict('future')
end
waitrt?
pause
pause 0.5 while stunned?
DRC.fix_standing
end
def train_astrology(settings)
return unless settings
return unless settings.astrology_training.is_a?(Array)
return if settings.astrology_training.none?
settings.astrology_training.each do |task|
break if DRSkill.getxp('Astrology') > 30
case task
when 'ways'
check_astral
when 'observe'
check_heavens
when 'rtr'
check_ripples(settings)
when 'weather'
check_weather
when 'events'
check_events(check_pools)
when 'attunement'
check_attunement
end
end
predict_all(check_pools)
DRCMM.predict('analyze')
waitrt?
end
end
before_dying do
Flags.delete('bad-search')
end
# Call this last to avoid the need for forward declarations
Astrology.new