-
Notifications
You must be signed in to change notification settings - Fork 3
/
qverb.lic
94 lines (79 loc) · 2.64 KB
/
qverb.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
=begin
Searches your containers for a particular item -- using ANY adjective(s). Grabs that item, activates it using the
verb you specify, then returns it -- quickly.
All three related commands are sent simultaneously.
RT/Cast RT will be waited for at the start, but is otherwise not checked for.
e.g. ;qverb rub black crystal
Intended to be added to aliases -- e.g. ;alias add ;disk=;qverb rub black crystal
author: LostRanger ([email protected])
game: GemStone
tags: utility
required: Lich >= 4.6.0.
version: 0.1 (2019-05-28)
changelog:
version 0.1 (2019-05-28)
* Initial release
=end
def help
name = $lich_char + script.name
msg = []
msg << "Usage: #{name} <VERB> <ITEM>"
msg << "Example: #{name} rub black crystal"
msg << ''
msg << 'The specified ITEM will be searched for among all your containers, grabbed, <VERB>ed, and returned.'
msg << 'All three of these commands will be sent simultaneously.'
msg << ''
msg << '#{name} will wait for RT/CastRT before starting, but will not otherwise wait on roundtime.'
respond msg
end
# Patterns to match an item. Stolen from ;box
def get_item_patterns(name, strip_my=true)
name = name.gsub(/^\s*my\s+/, '')
words = name.strip.split(/\s+/)
words.map!{|w| Regexp::escape(w)}
if words.length == 1 # Just one word
return [
/^#{words[0]}$/i,
/\b#{words[0]}$/i,
/^#{words[0]}\S+$/i,
/\b#{words[0]}\S+$/i,
]
end
return [
# All words are exact matches.
/^#{words.join("\\b.*\\b")}$/i,
# Fully anchored suffix matches.
/^#{words.join("\\S*\\s+(?:.*\\s+)?")}\S*$/i,
# All words are prefix matches, not neccessarily anchored
/\s+#{words.join(".*\\s+")}\S*$/i
]
end
verb, what = script.vars[0].strip.split(/\s+/, 2)
unless what
name = $lich_char + script.name
echo "Usage: #{name} <VERB> <ITEM>"
echo "See #{name} ;help for details."
exit
end
if verb.downcase == 'help'
help
exit
end
def find_item(pattern, in_id)
return nil unless GameObj.containers[in_id]
return GameObj.containers[in_id].find{|x| x.full_name =~ pattern}
end
patterns = get_item_patterns(what)
patterns.each do |pattern|
GameObj.inv.each{|container|
if item = find_item(pattern, container.id)
waitrt?
waitcastrt?
put "get ##{item.id}"
put "#{verb} ##{item.id}"
put "put ##{item.id} in ##{container.id}"
exit
end
}
end
echo "Could not find anything in your inventory matching '#{what}'. You may need to look in containers first."