-
Notifications
You must be signed in to change notification settings - Fork 3
/
eget.lic
94 lines (76 loc) · 2.29 KB
/
eget.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). GETs the first match. (e=extended)
If you have a frosted almond cookie, any of these will work:
;eget frosted almond cookie
;eget frosted cookie
;eget almond cookie
;eget f a c
;eget cookie
Only searches your containers. 'my' is ignored (and always applied)
Written for Alanad
author: LostRanger ([email protected])
game: GemStone
tags: utility
required: Lich >= 4.6.0.
version: 0.1 (2019-05-27)
changelog:
version 0.1 (2019-05-27)
* Initial release
=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
what = script.vars[0].strip
unless what and what.length > 0
echo "Usage: ;eget <adjectives...> <noun>"
echo "Do not use MY"
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)
hands = [GameObj.right_hand, GameObj.left_hand].keep_if{|x| x.id}
patterns.each do |pattern|
GameObj.inv.each{|container|
if item = find_item(pattern, container.id)
put "get ##{item.id}"
exit
end
}
hands.each{|hand|
if item = find_item(pattern, hand.id)
put "get ##{item.id}"
exit
end
}
end
patterns.each do |pattern|
hands.each{|hand|
if hand.full_name =~ pattern
echo "You are already holding a #{hand.full_name}."
exit
end
}
end
echo "Could not find anything in your inventory matching '#{what}'. You may need to look in containers first."