forked from elanthia-online/dr-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.lic
285 lines (245 loc) · 9.01 KB
/
common.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
# quiet
=begin
Documentation: https://elanthipedia.play.net/Lich_script_development#common
=end
$ORDINALS = %w(first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth thirteenth)
custom_require.call(%w(spellmonitor))
module DRC
module_function
def bput(message, *matches)
waitrt?
timer = Time.now
log = []
matches.flatten!
matches.map! { |item| item.is_a?(Regexp) ? item : /#{item}/i }
clear
put message
while Time.now - timer < 15
response = get?
if response.nil?
pause 0.1
next
end
log += [response]
case response
when /(?:\.\.\.wait |Wait |\.\.\. wait )([0-9]+)/
pause Regexp.last_match(1).to_i
put message
timer = Time.now
next
when /Sorry, you may only type ahead/
pause 1
put message
timer = Time.now
next
when /^You are a bit too busy performing to do that/, /You should stop playing before you do that/
put 'stop play'
put message
timer = Time.now
next
when /^That would give away your hiding place/
put 'unhide'
put message
timer = Time.now
next
when /^You are still stunned/, /^You can't do that while entangled in a web/
pause 0.5
put message
timer = Time.now
next
end
matches.each do |match|
if (result = response.match(match))
return result.to_a.first
end
end
end
echo '*** No match was found after 15 seconds, dumping info'
echo "messages seen length: #{log.length}"
log.each { |logged_response| echo "message: #{logged_response}" }
echo "checked against #{matches}"
''
end
def wait_for_script_to_complete(name, args = [])
verify_script(name)
success = start_script(name, args.map { |arg| arg =~ /\s/ ? "\"#{arg}\"" : arg })
if success
pause 2
pause 1 while Script.running?(name)
end
success
end
def forage?(item)
snapshot = "#{right_hand}#{left_hand}"
while "#{right_hand}#{left_hand}" == snapshot
case bput("forage #{item}", 'Roundtime', 'The room is too cluttered to find anything here', 'You really need to have at least one hand free to forage properly')
when 'The room is too cluttered to find anything here'
return false unless kick_pile?
when 'You really need to have at least one hand free to forage properly'
echo 'WARNING: hands not emptied properly. Stowing...'
fput('stow right')
end
waitrt?
end
true
end
def collect(item)
case bput("collect #{item}",'You manage to collect a pile', 'The room is too cluttered')
when 'The room is too cluttered'
fput('kick pile')
fput('kick pile')
fput('kick pile')
fput("collect #{item}")
waitrt?
end
end
def kick_pile?(item = 'pile')
fix_standing
'take a step back and run up to' == bput("kick #{item}", 'I could not find', 'take a step back and run up to', 'Now what did the .* ever do to you')
end
def rummage(parameter, container)
result = DRC.bput("rummage /#{parameter} my #{container}", 'but there is nothing in there like that\.', 'looking for .* and see .*', 'While it\'s closed', 'I don\'t know what you are referring to', 'You feel about')
case result
when 'You feel about'
release_invisibility
return rummage(parameter, container)
when 'but there is nothing in there like that.', 'While it\'s closed', 'I don\'t know what you are referring to'
return []
end
text = result.match(/looking for .* and see (.*)\.$/).to_a[1]
list_to_nouns(text)
end
def get_boxes(container)
rummage('B', container)
end
def get_skins(container)
rummage('S', container)
end
def get_gems(container)
rummage('G', container)
end
def get_materials(container)
rummage('M', container)
end
# Take a game formatted list "an arrow, silver coins and a deobar strongbox"
# And return an array ["an arrow", "silver coins", "a deobar strongbox"]
# is this ever useful compared to the list_to_nouns?
def list_to_array(list)
list.strip.split(/,|\sand\s/)
end
# Take a game formatted list "an arrow, silver coins and a deobar strongbox"
# And return an array of nouns ["arrow", "coins", "strongbox"]
def list_to_nouns(list)
list_to_array(list)
.map { |long_name| get_noun(long_name) }
.compact
.select { |noun| noun != '' }
end
def get_noun(long_name)
long_name.strip.sub(/ with .*| labeled .+/, '').scan(/[a-z\-]+$/i).first
end
# Items class. Name is the noun of the object. Leather/metal boolean. Is the item worn (defaults to true). Does it hinder lockpicking? (false)
# Item.new(name:'gloves', leather:true, worn:true, hinders_locks:true, adjective:'ring', bound:true)
class Item
attr_accessor :name, :leather, :worn, :hinders_lockpicking, :container, :swappable, :tie_to, :adjective, :bound, :wield, :transforms_to, :transform_verb, :transform_text, :lodges
def initialize(name: nil, leather: nil, worn: false, hinders_locks: nil, container: nil, swappable: false, tie_to: nil, adjective: nil, bound: false, wield: false, transforms_to: nil, transform_text: nil, transform_verb: nil, lodges: true)
@name = name
@leather = leather
@worn = worn
@hinders_lockpicking = hinders_locks
@container = container
@swappable = swappable
@tie_to = tie_to
@adjective = adjective
@bound = bound
@wield = wield
@transforms_to = transforms_to
@transform_verb = transform_verb
@transform_text = transform_text
@lodges = lodges.nil? ? true : lodges
end
def short_name
@adjective ? "#{@adjective}.#{@name}" : @name
end
def short_regex
@adjective ? /#{adjective}.*\b#{@name}/i : /\b#{@name}/i
end
end
# windows only I believe.
def beep
echo("\a")
end
def fix_standing
loop do
break if standing?
bput('stand', 'You stand', 'You are so unbalanced', 'As you stand', 'You are already', 'weight of all your possessions', 'You are overburdened and cannot')
end
end
def listen?(teacher)
return false if teacher.nil?
return false if teacher.empty?
bad_classes = %w(Thievery Sorcery)
bad_classes += ['Life Magic', 'Holy Magic', 'Lunar Magic', 'Elemental Magic', 'Arcane Magic', 'Targeted Magic', 'Arcana', 'Attunement'] if DRStats.barbarian? || DRStats.thief?
bad_classes += ['Warding'] if DRStats.thief?
bad_classes += ['Utility'] if DRStats.barbarian?
case bput("listen to #{teacher}", 'begin to listen to \w+ teach the .* skill', 'already listening', 'could not find who', 'You have no idea', 'isn\'t teaching a class', 'don\'t have the appropriate training', 'Your teacher appears to have left', 'isn\'t teaching you anymore', 'experience differs too much from your own', 'but you don\'t see any harm in listening', 'invitation if you wish to join this class')
when /begin to listen to \w+ teach the (.*) skill/
return true if bad_classes.grep(/#{Regexp.last_match(1)}/i).empty?
bput('stop listening', 'You stop listening')
when 'already listening'
return true
when 'but you don\'t see any harm in listening'
bput('stop listening', 'You stop listening')
end
false
end
def assess_teach
case bput('assess teach', 'is teaching a class', 'No one seems to be teaching', 'You are teaching a class')
when 'No one seems to be teaching', 'You are teaching a class'
waitrt?
return {}
end
results = reget(20, 'is teaching a class')
waitrt?
results.each_with_object({}) do |line, hash|
line.match(/(.*) is teaching a class on (.*) which is still open to new students/) do |match|
teacher = match[1]
skill = match[2]
# Some classes match the first format, some have additional text in the 'skill' string that needs to be filtered
skill.match(/.* \(compared to what you already know\) (.*)/) { |m| skill = m[1] }
hash[teacher] = skill
end
end
end
def hide?
unless hiding?
case bput('hide', 'Roundtime', 'too busy performing', 'can\'t see any place to hide yourself')
when 'too busy performing'
bput('stop play', 'You stop playing', 'In the name of')
return hide?
end
pause
waitrt?
end
hiding?
end
def fix_dr_bullshit(string)
return string if string.split.length <= 2
string =~ /(\w+) .* (\w+)/
"#{Regexp.last_match(1)} #{Regexp.last_match(2)}"
end
def left_hand
GameObj.left_hand.name == 'Empty' ? nil : fix_dr_bullshit(GameObj.left_hand.name)
end
def right_hand
GameObj.right_hand.name == 'Empty' ? nil : fix_dr_bullshit(GameObj.right_hand.name)
end
def release_invisibility
get_data('spells')
.spell_data
.select { |_name, properties| properties['invisibility'] }
.select { |name, _properties| DRSpells.active_spells.keys.include?(name) }
.map { |_name, properties| properties['abbrev'] }
.each { |abbrev| fput("release #{abbrev}") }
end
end