forked from brycole/gemstone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgearinfo.lic
407 lines (335 loc) · 11.8 KB
/
gearinfo.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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
#gearinfo:
# Store and retrieve information about your gear!
# Type: ;gearinfo help for more information.
#
# This is an early version, please report bugs to [email protected]
#
#Geldan - 11/9/2010
#
#Store and retrieve info about gear.
#To add items, just hold one in your hands:
# ;gearinfo add description of the item to store:
#To get information about items you are holding:
# ;gearinfo (info|show)
#To view items in your open containers:
# ;gearinfo (con|container)
#To view all items you have saved:
# ;gearinfo allgear
#To toggle between short and long names:
# ;gearinfo short=(on|true|off|false)
#To wrap description names at n characters:
# ;gearinfo wrapdesc=(off|false|n)
#To automatically pause after showing n items:
# ;gearinfo pause=(off|false|n)
#To delete an item hold it in your hand and:
# ;gearinfo delete
#To delete any item:
# ;gearinfo delete <item name>
#To search in open containers:
# ;gearinfo search (desc|name|both) term1 term2 "a multiword term"
#To search all known items:
# ;gearinfo searchall (desc|name|both) term1 term2 "a multiword term"
#
# ;gearinfo container in a locker room will now show the contents of a locker
status_tags
silence_me
Settings ||= Hash.new
Settings['settings'] ||= Hash.new
$settings = Settings['settings']
Settings['gear'] ||= Hash.new
$gear = Settings['gear']
SHORT_NAMES = "__use_short_names__"
PAUSE = "__pause__"
WRAP = "__wrap__"
SEPERATOR = "\r\n\t\t\t"
$settings[SHORT_NAMES] ||= false
$settings[PAUSE] ||= 0
$settings[WRAP] ||= 0
$items_printed = 0
$name_filter = //
$desc_filter = //
#Convert old style
old = CharSettings.to_hash
old.each_pair {|key,val|
next if $settings[key] or $gear[key]
if key[0..1] == "__" ; $settings[key] = val
else ; $gear[key] = val ; end
}
class GearInfo
def initialize(id,noun=nil,name=nil,before=nil,after=nil)
@id = id.strip ; @noun = noun.strip ; @name = name.strip ; @before = before.strip ; @after = after.strip
if @id !~ /^[0-9]+$/
@noun, @before, @name, @after = id.split("|", 4)
@id = nil
end
end
def full_name
return @name if $settings[SHORT_NAMES]
return ("#{@before} #{@name} #{@after}").to_s.strip
end
def key
return ("#{@noun}|#{@before}|#{@name}|#{@after}").to_s.strip
end
end
before_dying {
puts "\r\n"
Settings.save
UpstreamHook.remove('invisinv')
DownstreamHook.remove('invisinv')
}
#Make inventory checks invisible
$invscan = proc { |server_string|
if server_string.strip.length == 0
nil
next
end
case server_string
when /You glance down/
nil
else
server_string
end
}
DownstreamHook.remove('invisinv')
#increment PAUSE and pause if we should.
def check_pause
$items_printed += 1
if $settings[PAUSE] > 0 and $items_printed.to_i % $settings[PAUSE].to_i == 0
puts "\r\n#{monsterbold_start}----------#{monsterbold_end} Type: ;u #{Script.self.name} to continue. #{monsterbold_start}----------#{monsterbold_end}"
pause_script
end
end
######################## Output and Formatting #################################
def print_heading
puts "\r\n#{monsterbold_start}Gear Info:#{monsterbold_end}\r\n---------------\r\n"
end
def wrap_text(txt, col = $settings[WRAP])
return txt if $settings[WRAP] <= 0
txt.gsub(/(.{1,#{col}})( +|$\n?)|(.{1,#{col}})/, "\\1\\3#{SEPERATOR}")
end
def print_item(item)
desc = $gear[item.key]
if $name_filter != // and $desc_filter != // #Search name and desc
return if item.full_name !~ $name_filter and desc !~ $desc_filter
else #Search one
return if item.full_name !~ $name_filter or desc !~ $desc_filter
end
desc = wrap_text(desc) if desc.length > $settings[WRAP]
puts "\t\t#{monsterbold_start}#{item.full_name}:#{SEPERATOR}#{monsterbold_end}#{desc}\r\n"
end
def print_container(containerid)
return if containerid == nil
empty = true
item = nil
items = Array.new
GameObj.containers[containerid].each {|val|
item = GearInfo.new(val.id,val.noun,val.name,val.before_name,val.after_name)
if $gear[item.key]
if $name_filter != // and $desc_filter != // #Search name and desc
empty = false if $gear[item.key] =~ $desc_filter or item.full_name =~ $name_filter
else #Search one
empty = false if $gear[item.key] =~ $desc_filter and item.full_name =~ $name_filter
end
items.push(item)
check_pause
end
}
if not empty
container = GearInfo.new(containerid,GameObj[containerid].noun,GameObj[containerid].name,GameObj[containerid].before_name,GameObj[containerid].after_name)
puts "\t#{container.full_name}:\r\n"
for item in items ; print_item(item) ; end
puts "\r\n"
end
end
def print_containers()
conts = GameObj.containers
locker = GameObj['locker']
fput "look in locker" if GameObj['locker']
conts[locker.id] = locker.contents
conts.each_key { |key|
next if !GameObj[key]
print_container(key)
}
end
def print_all()
$gear.each_pair {|key,val|
item = GearInfo.new(key)
print_item(item)
check_pause
}
end
###############################################################################
def save_settings(filename)
puts "\tSorry, saving isn't supported yet.\r\n"
end
def load_settings(filename)
puts "\tSorry, loading isn't supported yet.\r\n"
end
#Can't just use right_hand and left_hand because they may not be complete
def update_hands()
#populate hands, right, and left
result = nil
DownstreamHook.add('invisinv', $invscan)
result = dothistimeout "inv hands", 3, /You have/
DownstreamHook.remove('invisinv')
result = result.gsub("You have ", "")
result = result.split(/in your .*? hand and|in your .*? hand./)
hands = Array.new
result.each { |item|
item = item.gsub(/.*>(.*?)<a exist/, "\\1<a exist")
before, id, noun, name, after = item.match(/(.*?)<a exist=['"](.*?)['"] noun=['"](.*?)['"]>(.*?)<\/a>(.*?)$/).captures
obj = GearInfo.new(id, noun, name, before, after)
hands.push(obj) if obj.key != "|||"
}
return nil if hands.length == 0
return hands
end
def find_by_name(name)
name = /#{name}/i if name.class == String
found = Array.new
$gear.each_key {|key|
item = GearInfo.new(key)
found.push(item) if item.full_name =~ name
}
return nil if found.length == 0
return found
end
cmd = variable[1].downcase
case cmd
when "add", "replace"
hands = update_hands()
print_heading
if not hands ; puts "\tYour hands are empty!\r\n" ; exit ; end
if hands.length > 1 ; puts "\tOnly hold one item when adding a description.\r\n" ; exit ; end
if $gear[hands[0].key] and variable[1].downcase != "replace"
puts "\tDid not add #{monsterbold_start}#{hands[0].full_name}#{monsterbold_end} because it was already defined.\r\n"
exit
end
$gear[hands[0].key] = variable[2..-1].join(" ").to_s
puts "\tAdded:\t#{monsterbold_start}#{hands[0].full_name}:#{monsterbold_end}\t#{$gear[hands[0].key]}\r\n"
when /^inf/, "show"
hands = update_hands() ; right = hands[0] ; left = hands[1]
print_heading
if not $gear[right.key] and not $gear[left.key] ; puts "\tYou aren't holding anything that has been cataloged!\r\n" ; exit ; end
print_item(right) if right and $gear[right.key]
print_item(left) if left and $gear[left.key]
when /^con/
print_heading
print_containers()
when "allknowngear", "allgear", "showallgear"
print_heading
print_all()
when /^short=(.*?)$|^short$/
val = $1.strip
print_heading
if val =~ /^(?:on|true)$/
$settings[SHORT_NAMES] = true
puts "\tNow using short names.\r\n"
elsif val =~ /^(?:off|false)$/
$settings[SHORT_NAMES] = false
puts "\tNow using full names.\r\n"
else
puts "\tProper usage is ;#{Script.self.name} short=(on|off|true|false)\r\n"
end
when /^pause=(.*?)$|^pause$/
val = $1
print_heading
if val =~/^(?:false|off|0)$/
puts "\tWill not pause the script when displaying long lists.\r\n"
$settings[PAUSE] = 0
elsif val =~/^(?:[0-9]+)$/
puts "\tWill pause after every #{"#{val} " if val.to_i != 1}item#{if val.to_i == 1 ; " is" ; else ; "s are" ; end} displayed.\r\n"
$settings[PAUSE] = val.to_i
else
puts "\tProper usage is ;#{Script.self.name} pause=(false|off|#)\r\n"
end
when /^wrapdesc=(.*?)$|^wrapdesc$/
val = $1
print_heading
if val =~/^(?:false|off|0)$/
puts "\tWill not wrap descriptions.\r\n"
$settings[WRAP] = 0
elsif val =~ /^(?:[0-9]+)$/
val = val.to_i
val = 50 if val < 50
puts "\tWill wrap descriptions at#{" the minimum value of" if val == 50} #{val}."
$settings[WRAP] = val
else
puts "\tProper usage is ;#{Script.self.name} wrapdesc=(false|off|#)\r\n"
end
when /^search/
terms = nil
type = "both"
if variable[2] =~ /(^desc|^name$|^both$)/
terms = /#{variable[3..-1].join("|")}/i
type = $1.strip
else
terms = /#{variable[2..-1].join("|")}/i
end
$desc_filter = terms if type =~ /^desc|^both$/
$name_filter = terms if type =~ /^name$|^both$/
print_heading
if cmd =~ /^search$/
print_containers()
elsif cmd =~ /^searchall$/
print_all()
end
when "delete"
hands = update_hands()
item = nil
print_heading
name = variable[2..-1].join(" ").to_s
if name == ""
item = hands[0]
if not hands ; puts "\tYour hands are empty. Either hold an item to delete, or use ;#{Script.self.name} delete <item name>\r\n\r\n" ; exit ; end
if hands.length > 1 ; puts "\tOnly hold one item when deleting a description.\r\n" ; exit ; end
elsif name
items = find_by_name(name)
if not items
puts "\tDid not find any items by that name!\r\n\r\n"
elsif items.length == 1
item = items[0]
else
puts "\tResults:\r\n"
items.each {|i| print_item(i)}
puts "\tPlease narrow your search!\r\n"
end
end
puts "\tDeleted:\t#{monsterbold_start}#{item.full_name}#{monsterbold_end}.\r\n" if $gear.delete(item.key)
when "clearall"
when "save"
filename = variable[2].downcase
print_heading
save_settings(filename)
when "load"
filename = variable[2].downcase
print_heading
load_settings(filename)
when "help"
print_heading
puts "Store and retrieve info about gear.\r\n"
puts "To add items, just hold one in your hands:\r\n"
puts "\t\t;#{Script.self.name} add description of the item to store:\r\n"
puts "To get information about items you are holding:\r\n"
puts "\t\t;#{Script.self.name} (info|show)\r\n"
puts "To view items in your open containers:\r\n"
puts "\t\t;#{Script.self.name} (con|container)\r\n"
puts "To view all items you have saved:\r\n"
puts "\t\t;#{Script.self.name} allgear\r\n"
puts "To toggle between short and long names:\r\n"
puts "\t\t;#{Script.self.name} short=(on|true|off|false)\r\n"
puts "To wrap description names at n characters:\r\n"
puts "\t\t;#{Script.self.name} wrapdesc=(off|false|n)\r\n"
puts "To automatically pause after showing n items:\r\n"
puts "\t\t;#{Script.self.name} pause=(off|false|n)\r\n"
puts "To delete an item hold it in your hand and:\r\n"
puts "\t\t;#{Script.self.name} delete\r\n"
puts "To delete any item:\r\n"
puts "\t\t;#{Script.self.name} delete <item name>\r\n"
puts "To search open containers:\r\n"
puts "\t\t;#{Script.self.name} search (desc|name|both) term1 term2 \"a multiword term\"\r\n"
puts "To search all known items:\r\n"
puts "\t\t;#{Script.self.name} searchall (desc|name|both) term1 term2 \"a multiword term\"\r\n"
else
echo "Unknown command."
end