-
Notifications
You must be signed in to change notification settings - Fork 3
/
rested.lic
328 lines (282 loc) · 11.3 KB
/
rested.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
=begin
Waits until you are clear as a bell and full on mana/stamina/spirit/HP, then logs you out. Keeps you in-game in the
meantime. Alternatively, waits for your XP to drop down to a target amount before logging you out.
If Dreaven or Iteno is in the room, assumes you're currently waiting for a Dreavening and keeps you online.
Useful for doing online absorption of XP after completing a bounty just before bed.
Previous versions of this stated that offline XP did not apply towards Lumnis. This is incorrect, they do.
author: LostRanger ([email protected])
game: GemStone
tags: utility
required: Lich >= 4.6.0.
version: 0.4 (2019-07-31)
changelog:
version 0.4 (2019-07-31)
* You can now ;rested <TARGET> to wait for a mindstate other than 'clear as a bell' before logging out.
For details, see ;rested help
* Now with builtin changelogs.
version 0.3 (2019-07-17)
* Supports waiting for Dreavenings. (You must already be at the table with Iteno or Dreaven.)
* Will not work if you are one of Dreaven's characters due to said Dreavening support. But you can fix that. :p
version 0.2 (2019-07-17)
* Never trust a 0.1 release.
version 0.1 (2019-07-17)
* Initial release
=end
module RestedScript
VERSION = '0.4 (2019-07-31)'
VERSION_INT = 4_000
def self.show_changelog(prev)
prev ||= 0
GameSettings[:current_version] = VERSION_INT
changelog = {
4_000 => [
"Version 0.4 changes:",
'',
" * Added ;rested help.",
'',
" * You can now ;rested <XP> to wait until that amount of XP to logout rather than being fully belled.",
" See the new ;rested help command for details.",
],
}
if prev != VERSION_INT
msg = []
msg << "<preset id='speech'>--------------------</preset>"
msg << "<preset id='speech'>Welcome to #{$lich_char}#{@script.name}</preset> <preset id='whisper'>#{VERSION}</preset>"
msg << ''
changelog.each do |version, notes|
if version > prev or version == VERSION_INT
msg += notes
msg << ''
end
end
msg << "For a more detailed changelog: <d>#{$lich_char}repo info #{@script.name}</d>."
msg << "To enable automatic updates: <d>#{$lich_char}repo set-updatable #{@script.name}</d>`."
msg << "For details on new features: <d>#{$lich_char}#{@script.name} help</d>"
msg << "For more LostRanger scripts: https://bit.ly/lostranger-scripts"
msg << ''
msg << "This message will not be displayed again until a new version is downloaded."
msg << "<preset id='speech'>--------------------</preset>"
send msg
end
end
def self.send(what)
unless $fake_stormfront
return _respond(what)
end
unless what.is_a?(Array)
what = [what]
end
return _respond what.map{|line|
if line =~ /^\s*<\/?output[^>]*>$/
nil
else
line = line.gsub(/<preset.*?>(.*?)<\/preset>/, "\\1")
line.gsub!('<pushBold/>', monsterbold_start)
line.gsub!('<popBold/>', monsterbold_end)
line.gsub!(/<\/?d.*?>/, '')
line
end
}.keep_if{|x| x}
end
def self.keepalive
@script.want_downstream = true
fput "experience"
@script.want_downstream = false
end
def self.waiting_on
result = []
dreavening_pc = GameObj.pcs.find{|pc| pc.noun =~ /^(?:Dreaven|Iteno)$/i}
result << "Dreavening (#{dreavening_pc.noun} is present)" if dreavening_pc
if saturated?
mind_value = 120 # Fakery
else
mind_value = XMLData.mind_value
end
result << "Mind (currently: #{XMLData.mind_text})" if mind_value > @mind_target
[
['Health', XMLData.health, XMLData.max_health],
['Mana', XMLData.mana, XMLData.max_mana],
['Stamina', XMLData.stamina, XMLData.max_stamina],
['Spirit', XMLData.spirit, XMLData.max_spirit],
].each do |name, cur, max|
result << "#{name} (#{cur}/#{max})" if cur < max
end
return nil if result.length == 0
return "Waiting for: #{result.join(', ')}"
end
def self.extend_timer
@mutex.synchronize do
now = Time.now
@sleep_until = [@sleep_until, now+30].max
if @last_nag.nil? or (now - @last_nag) > 15
send @warning_message
@last_nag = now
end
if now - @last_report > 15
result = self.waiting_on
if result
_respond "[#{result}]"
else
_respond "[You appear to be ready to log out.]"
end
@last_report = now
end
end
end
def self.show_help
msg = []
if $fake_stormfront
msg << "<pushBold/>This is #{$lich_char}#{@script.name} #{VERSION}<popBold/> "
else
msg << "<preset id='speech'>This is #{$lich_char}#{@script.name}</preset> <preset id='whisper'>#{VERSION}</preset>"
end
msg << "<output class='mono'/>"
msg << "Usage: <d>#{$lich_char}#{@script.name} help</d> - Shows this help."
msg << " <d>#{$lich_char}#{@script.name}</d> - Wait until you are clear as a bell to logout."
msg << " #{$lich_char}#{@script.name} TARGETMIND - Wait until you are at the specified mind status to log out."
msg << "<output class=''/>"
msg << "You will not be logged out until you are full on health, mana, stamina and spirit."
msg << ''
msg << "Mind status can be an approximate percentage or one of the following:"
msg << ''
msg << " belled (0%) ~ fresh (25%) ~ clear (50%) ~ muddled (62%) ~ becoming (75%) ~ numb (90%) ~ rest (100%)"
msg << " ignore or saturated (101%+)"
msg << ''
msg << "You can use 'ignore' or 'saturate' if you only want to wait on Dreavenings and HP/MP/Stamina/Spirit and don't care about your mind state."
send msg
return true
end
def self.run(script)
@script = script
script.want_downstream = false
script.want_upstream = false
@mind_target = 0
previous_version = GameSettings[:current_version] || 0
show_changelog(previous_version) unless previous_version == VERSION_INT
if script.vars[0]
arg = script.vars[0].downcase
if arg == 'help'
self.show_help
return
end
if arg =~ /^\d+$/
n = script.vars[0].to_i
if n < 25
arg = 'belled'
elsif n < 50
arg = 'fresh'
elsif n < 62
arg = 'clear'
elsif n < 75
arg = 'muddled'
elsif n < 90
arg = 'numb'
elsif n == 100
arg = 'rest'
else
arg = 'saturated'
end
end
mind_target_text = nil
case arg
when /bell/
@mind_target = 0
mind_target_text = 'clear as a bell'
when /fresh/
@mind_target = 25
mind_target_text = 'fresh and clear'
when /clear/
@mind_target = 50
mind_target_text = 'clear'
when /mud/
@mind_target = 62
mind_target_text = 'muddled'
when /bec/
@mind_target = 75
mind_target_text = 'becoming numb'
when /numb/
@mind_target = 90
mind_target_text = 'numb'
when /rest|must/
@mind_target = 100
mind_target_text = 'must rest'
when /ign|sat/
@mind_target = 120
mind_target_text = 'ignored (will not wait for XP absorption)'
else
echo "Unknown mind target `#{arg}`"
send "For options, see <d>#{$lich_char}#{@script.name} help</d>"
exit
end
echo "Target mind state: #{mind_target_text}"
else
send "For options, <d cmd='#{$lich_char}kill #{@script.name}'>kill this script</d>, then see <d>#{$lich_char}#{@script.name} help</d>"
@mind_target = 0
end
self.keepalive
if (result = waiting_on)
echo result
else
echo "You are already ready to log out. You could just type EXIT..."
end
now = Time.now
@sleep_until = now + 30
@last_action = now
@last_report = now
@last_nag = nil
@ready_since = nil
@warning_message = [
"#{monsterbold_start}Script '#{script.name}' is currently running. To avoid an unexpected logout, kill it with <d>#{$lich_char}kill #{script.name}</d>#{monsterbold_end}",
"[Your earliest possible automatic logout time has been changed to be 30 seconds from now.]"
]
@thread = Thread.current
@mutex = Mutex.new
self.hook
while true
n = @sleep_until - now
sleep n if n > 0
@mutex.synchronize do
now = Time.now
result = self.waiting_on
if result
if now - @last_report > 120 # Haven't reported on status in awhile
echo result
@last_report = now
end
if @ready_since
echo "We no longer appear to be ready for logoff, restarting countdown."
@ready_since = nil
end
@sleep_until = [@sleep_until, now+15].max
else
if @ready_since
if now - @ready_since > 15 # Have been ready for more than 15 seconds
echo "Goodbye!"
script.want_downstream = true
fput "exit"
exit
end
else
@ready_since = now
echo "We appear to be ready to logoff, waiting a few moments just in case that changes..."
end
sleep_until = [@sleep_until, now+5].max
end
if now - @last_action > 75 # Haven't done anything in awhile
self.keepalive
@last_action = now
end
end
end
end
def self.hook
before_dying { UpstreamHook.remove("rested_hook") }
UpstreamHook.add("rested_hook", proc do |xml|
next if xml =~ /^<c>_|^(?!<c>)</ # Ignore underscore commands and other XML sends.
self.extend_timer
@thread.wakeup
next xml
end)
end
end
RestedScript.run(script)