-
Notifications
You must be signed in to change notification settings - Fork 3
/
inspect.lic
217 lines (190 loc) · 6.45 KB
/
inspect.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
=begin
Inspects an item, captures the resulting messaging, and adds more detailed information to it.
Currently this shows numerical capacities of containers and armor subgroup names on (most) armor.
Hint: ;alias add inspect=;inspect
If trusted, ;inspect will hide echoing the real INSPECT sent to the game to cut down on unneeded screen spam.
Trusting this script is entirely optional, and has no other effects on behavior.
author: LostRanger ([email protected])
game: GemStone
tags: inspect
required: Lich >= 4.6.0
version: 0.7 (2019-10-23)
changelog:
version 0.7 (2019-10-23)
* Now works with items in Trove
version 0.6 (2019-08-08)
* Now works with items in pawnshops and other similar locales.
* Now shows base item weights.
version 0.5 (2017-07-01)
* ;inspect by itself now shows the table of weights and item counts
version 0.4 (2017-06-23)
* Should now work for items in shops.
version 0.3 (2017-06-02)
* use a more sane method to identify the begin/end of INSPECT results. Should solve issues of the script not
always modifying output.
version 0.2 (2017-05-28)
* now with less global namespace pollution
* fixes wrong changelog date
version 0.1 (2017-05-07)
* initial release
=end
class InspectScript
WEIGHTS = {
'very small' => '0-4',
'small' => '5-7',
'fairly small' => '8-11',
'somewhat small' => '12-15',
'slightly small' => '16-19',
'medium' => '20-39',
'slightly large' => '40-49',
'fairly large' => '50-59',
'large' => '60-69',
'particularly large' => '70-79',
'very large' => '80-99',
'significant' => '100-119',
'exceptional' => '120-139',
'huge' => '140-159',
'incredible' => '160-179',
'enormous' => '180-199',
'gigantic' => '200+'
}
WEIGHT_PATTERN = /an? (\w+(?: \w+)?) amount/
COUNTS = {
'one' => '1',
'a couple' => '2',
'a few' => '3',
'several' => '4-6',
'a number' => '7-9',
'any number' => '10+'
}
COUNT_PATTERN = /(with enough space for (.*?)) ((?:of )?items?)/
# ARMOR_PATTERN = /(.*allows you to conclude that it is (.*?) armor that covers the (.*?)\.)(.*)/
ARMOR_PATTERN = /(.*is (.*?) armor that covers the (.*?)\.)(.*)/
ARMOR_GROUPS = {
'cloth' => 0,
'soft leather' => 1,
'rigid leather' => 2,
'chain' => 3,
'plate' => 4
}
ASG_BITS = {
1 => 1,
3 => 2,
7 => 3,
31 => 4
}
ASG_TABLE = {
1 => 'Normal Clothing',
2 => 'Robes',
5 => 'Light Leather',
6 => 'Full Leather',
7 => 'Reinforced Leather',
8 => 'Double Leather',
9 => 'Leather Breastplate',
10 => 'Cuirbouilli Leather',
11 => 'Studded Leather',
12 => 'Brigandine Armor',
13 => 'Chain Mail',
14 => 'Double Mail',
15 => 'Augmented Chain',
16 => 'Chain Hauberk',
17 => 'Metal Breastplate',
18 => 'Augmented Plate',
19 => 'Half Plate',
20 => 'Full Plate'
}
ASG_WEIGHTS = [
nil,
nil, 8, nil, nil,
10, 13, 15, 16,
16, 17, 20, 25,
25, 25, 26, 27,
23, 25, 50, 70
]
def initialize(script)
@script = script
@script.want_downstream = false
@script.want_downstream_xml = false
@started = false
@mainthread = nil
end
def show_tables
def tableize(what, title)
maxk = 0
maxv = 0
what.each{|k,v|
maxk = k.length if k.length > maxk
maxv = v.length if v.length > maxv
}
result = []
result << title.ljust(maxk + maxv + 3)
what.each{|k,v| result << "#{k.ljust(maxk)} = #{v.ljust(maxv)}" }
return result
end
weights = tableize(WEIGHTS, "CAPACITY")
counts = tableize(COUNTS, "# OF ITEMS")
# We should do this cleaner, but for now we know weights has the most items.
(0..weights.length-1).each{|ix|
respond "#{weights[ix]} #{counts[ix]}".strip
}
respond
respond "Type #{$lich_char}#{@script.name} <item> to inspect an item."
end
def hook(line) # and sinker
unless @started
# Look for 'You carefully inspect' to trigger activity.
if line =~ /^The following details about |(?:You carefully (?:inspect|examine).*<a)|(?:What were you referring to\?)|(?:You can't inspect that)/
@started = true
end
return line
end
line = (
line
.gsub(WEIGHT_PATTERN){|match| "#{match} (#{WEIGHTS[$1]} lbs)" }
.gsub(COUNT_PATTERN){|match| "#{$1} (#{COUNTS[$2]}) #{$3}" }
)
if line =~ ARMOR_PATTERN
before = $1
after = $4
group = ARMOR_GROUPS[$2]
return line unless group
coverage = $3.downcase.split(/(?:,| and | )+/)
bits = 0
bits += 1 if coverage.include?('torso')
bits += 2 if coverage.include?('arms')
bits += 4 if coverage.include?('legs')
bits += 8 if coverage.include?('neck')
bits += 16 if coverage.include?('head')
subgroup = ASG_BITS[bits]
return line if subgroup.nil?
if group == 0
return line unless subgroup == 1
subgroup = 2
else
subgroup += 4*group
end
weight = ASG_WEIGHTS[subgroup]
if weight
weight = ", base #{weight} lbs"
end
line = "#{before} (ASG #{subgroup}: #{ASG_TABLE[subgroup]}#{weight}) #{after}\n"
end
@mainthread.kill if line.include?('<prompt')
return line
end
def run(vars)
unless vars[0].length > 0
show_tables
return
end
silence_me if $SAFE == 0 # Trusting this script will prevent it from sending INSPECT, optional.
before_dying { DownstreamHook.remove("inspect_modify_hook") }
waitrt?
@mainthread = Thread.current
@script.want_downstream_xml = true
DownstreamHook.add("inspect_modify_hook", proc{|line| hook(line)})
fput "inspect #{vars[0]}"
sleep
end
end
InspectScript.new(script).run(script.vars)