-
Notifications
You must be signed in to change notification settings - Fork 8
/
useimbed.lic
332 lines (314 loc) · 12.5 KB
/
useimbed.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
=begin
This script was originally intended to use mage rechargable gems and make sure the
last charge was never used so they would never crumble. It can now also be used
with worn rechargables or rechargable wands.
This script expects each rechargable to have a unique name. If you're using a common
rechargable such as an oak wand, or if you have two rechargable uncut diamonds, you
should probably make use of the dyers tent.
Settings are shared with the chargeimbed script. Use that script while recharging
and the tracking is updated automatically.
;useimbed help
author: Tillmen (tillmen@lichproject.org)
game: Gemstone
tags: magic
version: 0.3
required: Lich >= 4.6.0
changelog:
0.3 (2015-08-31):
check for and release prepared spell
0.2 (2015-03-14):
allow multiple imbeds for the same spell
change stance for some spells
=end
# fixme: automatically find item name when adding new items
Vars.imbeds = Hash.new unless Vars.imbeds.class == Hash
if script.vars[1] == 'add'
script.vars.shift
unless name = script.vars.find { |var| var.split(' ').length > 1 }
echo 'error: missing imbed name (use quotes)'
exit
end
unless charges = script.vars.find { |var| var =~ /^[0-9][0-9]?$/ }
echo 'error: missing number of charges'
exit
end
unless spell = script.vars.find { |var| var =~ /^[0-9]{3,4}$/ }
echo 'error: missing spell number'
exit
end
unless activator = script.vars.find { |var| var =~ /^(?:rub|tap|wave|raise|eat|drink|throw|sprinkle)$/ }
echo 'error: missing activator'
exit
end
last_charge = script.vars.any? { |var| var =~ /^use\-?last\-?charge$/i }
worn = script.vars.any? { |var| var.downcase == 'worn' }
output = "\n"
output.concat " imbed name: #{name}\n"
output.concat " activator: #{activator}\n"
output.concat " spell number: #{spell}\n"
output.concat " current charges: #{charges}\n"
output.concat " worn: #{worn}\n"
output.concat " use last charge: #{last_charge}\n"
output.concat "\n"
output.concat " to add this item, type #{monsterbold_start};u #{script.name}#{monsterbold_end} \n"
output.concat " to cancel, type #{monsterbold_start};k #{script.name}#{monsterbold_end} \n"
output.concat "\n"
if defined?(_respond)
_respond output
else
puts output
end
pause_script
Vars.imbeds[name] = { :spell => spell.to_i, :charges => charges.to_i, :activator => activator, :worn => worn, :use_last_charge => last_charge }
echo 'imbed was added'
exit
elsif script.vars[1] =~ /^del(?:ete)?$/
imbed_name, imbed_info = Vars.imbeds.find { |iname,iinfo| iname == script.vars[2..-1].join(' ') }
if imbed_name
Vars.imbeds.delete(imbed_name)
echo "#{imbed_name} was deleted"
else
echo 'no matching imbed found'
echo "current imbeds: #{Vars.imbeds.keys.join(', ')}"
end
exit
elsif script.vars[1] == 'list'
max_name = 0
Vars.imbeds.keys.each { |name| max_name = [ max_name, name.length ].max }
output = "\n#{'name'.ljust(max_name)} spell charges activator worn use-last spell name\n"
output.concat "#{'----'.ljust(max_name)} ----- ------- --------- ---- -------- ----------\n"
if script.vars[2] == 'charges'
Vars.imbeds.sort { |a,b| b[1][:charges] <=> a[1][:charges] }.each { |imbed|
output.concat "#{imbed[0].ljust(max_name)} #{imbed[1][:spell].to_s.rjust(5)} #{imbed[1][:charges].to_s.rjust(7)} #{imbed[1][:activator].rjust(9)} #{if imbed[1][:worn]; 'yes'; else; ' no'; end} #{if imbed[1][:use_last_charge]; 'yes'; else ' no'; end} #{Spell[imbed[1][:spell]].name}\n"
}
else
Vars.imbeds.sort { |a,b| a[1][:spell] <=> b[1][:spell] }.each { |imbed|
output.concat "#{imbed[0].ljust(max_name)} #{imbed[1][:spell].to_s.rjust(5)} #{imbed[1][:charges].to_s.rjust(7)} #{imbed[1][:activator].rjust(9)} #{if imbed[1][:worn]; 'yes'; else; ' no'; end} #{if imbed[1][:use_last_charge]; 'yes'; else ' no'; end} #{Spell[imbed[1][:spell]].name}\n"
}
end
output.concat "\n"
respond output
exit
elsif script.vars[1] !~ /^[0-9]+$/
output = "\n"
output.concat " Imbeds must be added to the script before they can be used:\n"
output.concat "\n"
output.concat " ;useimbed add \"<imbed name>\" <spell number> <activator> <current charges> [worn] [use-last-charge]\n"
output.concat " ;useimbed add \"polished silver wand\" 901 wave 10 use-last-charge\n"
output.concat " ;useimbed add \"very ugly necklace\" 406 rub 6 worn use-last-charge\n"
output.concat " ;useimbed add \"cloudy white diamond\" 410 tap 40\n"
output.concat " ;useimbed delete \"cloudy white diamond\"\n"
output.concat "\n"
output.concat " The name of the imbed must be an exact match to the GameObj name, and it must be in quotes.\n"
output.concat "\n"
output.concat " ;useimbed list\n"
output.concat "\n"
output.concat " ;useimbed 406\n"
output.concat " ;useimbed 901 kobold\n"
output.concat "\n"
respond output
exit
end
if Vars.magicsack.nil? or Vars.magicsack.empty?
echo 'error: magicsack is not set. (;set change magicsack <container name>)'
exit
end
unless magicsack = (GameObj.inv.find { |obj| obj.name =~ /\b#{Regexp.escape(Vars.magicsack.strip)}$/i } || GameObj.inv.find { |obj| obj.name =~ /\b#{Regexp.escape(Vars.magicsack).sub(' ', ' .*')}$/i })
echo 'error: failed to find your magicsack'
exit
end
close_magicsack = false
open_magicsack = proc {
if magicsack.contents.nil?
open_result = dothistimeout "open ##{magicsack.id}", 5, /^You open|^That is already open\.$/
if open_result =~ /^You open/
close_magicsack = true
else
dothistimeout "look in ##{magicsack.id}", 5, /In .*? you see/
if magicsack.contents.nil?
echo 'error: failed to find magicsack contents'
exit
end
end
end
}
if script.vars[2]
target = "at #{script.vars[2..-1].join(' ')}"
else
target = ''
end
usedit = false
messages = Array.new
Vars.imbeds.each_pair { |imbed_name,imbed_info|
next if imbed_info[:spell] != script.vars[1].to_i
if (imbed_info[:charges] <= 0) or ((imbed_info[:use_last_charge] != true) and (imbed_info[:charges] <= 1))
messages.push "#{imbed_name} is out of charges"
next
end
if imbed_info[:worn]
if imbed = GameObj.inv.find { |obj| obj.name == imbed_name }
Spell.lock_cast
waitrt?
waitcastrt?
if Spell[imbed_info[:spell]].stance and (checkstance != 'offensive')
dothistimeout 'stance offensive', 5, /^You are now in an? \w+ stance\.$|^You are unable to change your stance\.$/
end
if checkprep != 'None'
put 'release'
end
dothistimeout "#{imbed_info[:activator]} ##{imbed.id} #{target}", 2, /^You (?:rub|tap)/
Spell.unlock_cast
imbed_info[:charges] = imbed_info[:charges].to_i - 1
respond "[ #{imbed_name}: #{imbed_info[:charges]} charges remaining. ]"
if Spell[imbed_info[:spell]].stance and (checkstance !~ /guarded|defensive/)
dothistimeout 'stance guarded', 5, /^You are now in an? \w+ stance\.$|^You are unable to change your stance\.$/
end
usedit = true
break
else
open_magicsack.call
if imbed = magicsack.contents.find { |obj| obj.name == imbed_name }
Spell.lock_cast
waitrt?
waitcastrt?
empty_hand
dothistimeout "get ##{imbed.id}", 2, /^You remove/
dothistimeout "wear ##{imbed.id}", 2, /^You/
if Spell[imbed_info[:spell]].stance and (checkstance != 'offensive')
dothistimeout 'stance offensive', 5, /^You are now in an? \w+ stance\.$|^You are unable to change your stance\.$/
end
if checkprep != 'None'
put 'release'
end
dothistimeout "#{imbed_info[:activator]} ##{imbed.id} #{target}", 2, /^You (?:rub|tap|raise|wave)/
Spell.unlock_cast
imbed_info[:charges] = imbed_info[:charges].to_i - 1
respond "[ #{imbed_name}: #{imbed_info[:charges]} charges remaining. ]"
if Spell[imbed_info[:spell]].stance and (checkstance !~ /guarded|defensive/)
dothistimeout 'stance guarded', 5, /^You are now in an? \w+ stance\.$|^You are unable to change your stance\.$/
end
fill_hand
usedit = true
break
else
messages.push "warning: failed to find imbed: #{imbed_name}"
end
end
else
open_magicsack.call
if imbed = magicsack.contents.find { |obj| obj.name == imbed_name }
Spell.lock_cast
waitrt?
waitcastrt?
empty_hand
dothistimeout "get ##{imbed.id}", 2, /^You remove/
if Spell[imbed_info[:spell]].stance and (checkstance != 'offensive')
dothistimeout 'stance offensive', 5, /^You are now in an? \w+ stance\.$|^You are unable to change your stance\.$/
end
if checkprep != 'None'
put 'release'
end
dothistimeout "#{imbed_info[:activator]} ##{imbed.id} #{target}", 2, /^You (?:rub|tap|raise|wave)/
Spell.unlock_cast
imbed_info[:charges] = [imbed_info[:charges].to_i, 40].min - 1
respond "[ #{imbed_name}: #{imbed_info[:charges]} charges remaining. ]"
if Spell[imbed_info[:spell]].stance and (checkstance !~ /guarded|defensive/)
dothistimeout 'stance guarded', 5, /^You are now in an? \w+ stance\.$|^You are unable to change your stance\.$/
end
dothistimeout "put ##{imbed.id} in ##{magicsack.id}", 2, /^You put/
fill_hand
usedit = true
break
else
messages.push "failed to find imbed: #{imbed_name}"
end
end
}
fput "close ##{magicsack.id}" if close_magicsack
unless usedit
if messages.empty?
echo "cannot find an imbed for spell number #{script.vars[1]}"
else
messages.each { |m| echo(m) }
end
end
=begin
imbed_name, imbed_info = UserVars.imbeds.find { |iname,iinfo| iinfo[:spell] == script.vars[1].to_i }
if imbed_name
unless (imbed_info[:use_last_charge] == true and imbed_info[:charges] > 0) or (imbed_info[:charges] > 1)
echo "#{imbed_name} is out of charges."
exit
end
if imbed_info[:worn]
if imbed = GameObj.inv.find { |obj| obj.name == imbed_name }
Spell.lock_cast rescue()
waitrt?
waitcastrt?
if (imbed_info[:spell] == 518) and (checkstance != 'offensive')
dothistimeout 'stance offensive', 5, /^You are now in an? \w+ stance\.$|^You are unable to change your stance\.$/
end
dothistimeout "#{imbed_info[:activator]} ##{imbed.id} #{target}", 2, /^You (?:rub|tap)/
Spell.unlock_cast rescue()
imbed_info[:charges] = imbed_info[:charges].to_i - 1
respond "[ #{imbed_name}: #{imbed_info[:charges]} charges remaining. ]"
if (imbed_info[:spell] == 518) and checkstance !~ /guarded|defensive/
dothistimeout 'stance guarded', 5, /^You are now in an? \w+ stance\.$|^You are unable to change your stance\.$/
end
UserVars.save
else
open_magicsack.call
if imbed = magicsack.contents.find { |obj| obj.name == imbed_name }
Spell.lock_cast rescue()
waitrt?
waitcastrt?
empty_hand
dothistimeout "get ##{imbed.id}", 2, /^You remove/
dothistimeout "wear ##{imbed.id}", 2, /^You/
if (imbed_info[:spell] == 518) and (checkstance != 'offensive')
dothistimeout 'stance offensive', 5, /^You are now in an? \w+ stance\.$|^You are unable to change your stance\.$/
end
dothistimeout "#{imbed_info[:activator]} ##{imbed.id} #{target}", 2, /^You (?:rub|tap|raise|wave)/
Spell.unlock_cast rescue()
imbed_info[:charges] = imbed_info[:charges].to_i - 1
respond "[ #{imbed_name}: #{imbed_info[:charges]} charges remaining. ]"
if (imbed_info[:spell] == 518) and checkstance !~ /guarded|defensive/
dothistimeout 'stance guarded', 5, /^You are now in an? \w+ stance\.$|^You are unable to change your stance\.$/
end
# dothistimeout "remove ##{imbed.id} in ##{magicsack.id}", 2, /^You/
# dothistimeout "put ##{imbed.id} in ##{magicsack.id}", 2, /^You put/
fill_hand
UserVars.save
else
echo "failed to find imbed: #{imbed_name}"
end
end
else
open_magicsack.call
if imbed = magicsack.contents.find { |obj| obj.name == imbed_name }
Spell.lock_cast rescue()
waitrt?
waitcastrt?
empty_hand
dothistimeout "get ##{imbed.id}", 2, /^You remove/
if (imbed_info[:spell] == 518) and (checkstance != 'offensive')
dothistimeout 'stance offensive', 5, /^You are now in an? \w+ stance\.$|^You are unable to change your stance\.$/
end
dothistimeout "#{imbed_info[:activator]} ##{imbed.id} #{target}", 2, /^You (?:rub|tap|raise|wave)/
Spell.unlock_cast rescue()
imbed_info[:charges] = [imbed_info[:charges].to_i, 40].min - 1
respond "[ #{imbed_name}: #{imbed_info[:charges]} charges remaining. ]"
if (imbed_info[:spell] == 518) and checkstance !~ /guarded|defensive/
dothistimeout 'stance guarded', 5, /^You are now in an? \w+ stance\.$|^You are unable to change your stance\.$/
end
dothistimeout "put ##{imbed.id} in ##{magicsack.id}", 2, /^You put/
fill_hand
UserVars.save
else
echo "failed to find imbed: #{imbed_name}"
end
end
fput "close ##{magicsack.id}" if close_magicsack
else
echo 'no matching imbed found'
end
=end