-
Notifications
You must be signed in to change notification settings - Fork 3
/
triage.lic
917 lines (781 loc) · 35.8 KB
/
triage.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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
=begin
Gives you a window showing the status of dead bodies. This build only works for clerics (and maybe paladins.)
While running, you can type TRIAGE (no semicolon) in game for various options. This may be shortened as far as TRIA
(TRI is TRIP):
TRIAGE
Shows the current list of bodies and their status in wide format.
(This is the same information available in the window in Stormfront.)
TRIAGE STATUS
Same as the above.
TRIAGE DEBUG
Toggles debug spam on/off.
TRIAGE LIFEKEEP <name> or TRIAGE LK <name>
Attempts to lifekeep <name>. This is the command that is sent if you click on "NO LK" from the window.
TRIAGE SHOW
Forces the window to visible. May be abbreviated as TRIAGE S
TRIAGE TALL
Changes the window format to be better suited for a tall but narrow display, using multiple lines per body.
TRIAGE WIDE
Changes the window format to be better suited for a wide display, using one line per body.
Configuration options and other functionality will be in a proper release.
author: LostRanger ([email protected])
game: GS
tags: utility
required: Lich >= 4.6.0.
version: 0.1.3 (2020-03-07)
changelog:
version: 0.1.3 (2020-03-07)
* Fix alignment issue in wide format.
* Now properly notes chrisms being applied (as opposed to only seeing them on appraise)
* Show some additional info when debugging is enabled
version: 0.1.2 (2020-02-04)
* No longer considered experimental.
version: 0.1.1 (2019-12-10)
* Fix some XML escapes being backwards, and handle them correctly in fake frontends
version: 0.1 (2019-12-10)
* Added TRIAGE command in-game. Documentation pending, see ;repo info triage for now.
* Experimental now expires on Jan 3rd 2020. We took too long to update this earlier, oops.
version: 0.0.9 (2019-12-02)
* First alpha release.
=end
=begin
Wide format -- fixed-width font
NO LK Deadbodyababcde BLEEDING
5m30s Deadbodyababcde <=> Linkedclericabc Injured
5m30s Deadbodyababcde <=> Linkedclericabc Healthy Chrism
(and)
Narrow format -- variable-width font
Deader (NO LK)
BLEEDING
Deader (5m30s)
-> Clericname
BLEEDING, Chrismed
Sort order: Linked to you first on top, then non-LK'd corpses, then LK'd corpses. Reverse room order (oldest first)?
Non-LK'd bodies are monsterbolded (entire line in wide, first line in bold in narrow)
=end
=begin
Updating lifekeep:
APPRAISE can get exact lifekeep duration.
If we see Symbol of Preservation, set to 11.5 minutes (rank 23 * 30 seconds) as worst-case and schedule for update
If we see 305 or white flask, set to 10 minutes as worst-case and schedule for update
If we see the player lifekeep, set to 10 minutes + (15s*BlessingsLore ranks) and schedule for update
If we see unlink messaging, clear
If we see expiration messaging, clear.
=end
=begin
You glance at <a exist="-10798327" noun="Jackke">Jackke</a> and immediately realize <a exist="-10798327" noun="Jackke">he</a> has 10 spirit levels out of a maximum of 10, and is currently preserved for 557 seconds.
You also notice that <a exist="-10798327" noun="Jackke">he</a> has snapped bones and serious bleeding from the neck, some minor cuts and bruises on his right leg, a completely severed left leg, minor cuts and bruises on his chest, deep gashes and serious bleeding from his abdominal area, and minor cuts and bruises on his back.
<a exist="-10798327" noun="Jackke">He</a> has a mangled left arm, old battle scars on his right leg, and an old battle scar across his back.
<a exist="-10798327" noun="Jackke">He</a> is bleeding from the left leg and profusely from the neck.
<a exist="-10798327" noun="Jackke">He</a> is also quite dead.
You glance at <a exist="-10798327" noun="Jackke">Jackke</a> and immediately realize <a exist="-10798327" noun="Jackke">he</a> has 10 spirit levels out of a maximum of 10, and is currently preserved for 450 seconds. Upon closer examination, you sense a translucent thread linking <a exist="-10798327" noun="Jackke">Jackke's</a> soul to you.
You also notice that <a exist="-10798327" noun="Jackke">he</a> has no apparent wounds.
<a exist="-10798327" noun="Jackke">He</a> has a mangled left arm.
<a exist="-10798327" noun="Jackke">He</a> is also quite dead.
<castTime value='1573413187'/>You gesture at <a exist="-10614020" noun="Anemegus">Anemegus</a>.
A luminescent web briefly forms around <a exist="-10614020" noun="Anemegus">Anemegus</a>, then fades into the body.
<!-- CLIENT --><c>unlink confirm<!-- ENDCLIENT -->
You break the bond established between your soul and <a exist="-10614020" noun="Anemegus">Anemegus's</a> spirit.
A silvery translucent thread extends from you encompassing <a exist="-10614020" noun="Anemegus">Anemegus's</a> corpse.
A web of glimmering light lifts out of <a exist="-10614020" noun="Anemegus">Anemegus's</a> dead body. Thread by thread, it unravels and dissolves into pale dust. As the dust blows away, nothing remains but a cold, still corpse.
#
TODO: Tend messaging?
=end
# EXPERIMENTAL_EXPIRES = Time.at(1578052800)
EXPERIMENTAL_EXPIRES = nil
module TriageScript
VERSION = '0.1.3 (2020-03-07)'
SHORT_VERSION = VERSION.split(' ', 2)[0]
PATTERNS = {
:appraise_start => /^You glance at <a exist="(?<exist>-\d+)" noun="(?<name>[^"]+).*has (?<spirit>\d+) spirit levels out of a maximum of (?<maxspirit>\d+)(?:, and is currently preserved for (?<time>\d+) seconds?)?(?<chrism>.*cobalt blue liquid\.)?(?:.*soul to ?(?:<[^>]+>)?(?<cleric>\w+))?/,
:appraise_injuries => /^You also notice that <a exist="-\d+" noun="[^"]+">s?he<\/a> (?:(?:has no apparent (?:injuries|wounds))|(?<injuries>.*))\./,
:appraise_bleeding => /^<a exist="-\d+" noun="[^"]+">(?:Sh|H)e<\/a> is bleeding (?<where>.*)\./,
:appraise_dead => /^<a exist="-\d+" noun="[^"]+">(?:Sh|H)e<\/a> is also quite dead\./,
:appraise_end => /<prompt/,
# :player_list_updated => /^<component id='room players'>/,
:lk_unlink => /^A web of glimmering light lifts out of <a exist="(?<exist>-\d+)" noun="(?<name>[^"]+)">/,
:lk_expired => /^<a exist="(?<exist>-\d+)" noun="(?<name>[^"]+)">.* seems slightly different. The stench of decay is growing more pervasive.$/,
:spell_casted => /^<castTime value=/,
:lk_cast => /^A luminescent web briefly forms around <a exist="(?<exist>-\d+)" noun="(?<name>[^"]+)">/,
:you_cast => /^(?:<.*>)?You gesture at <a exist="/,
:already_kept => /^You hear a gentle voice whisper to you, "The soul of <a exist="(?<exist>-\d+)" noun="(?<name>[^"]+).*PRESERVATION, my child\."$/,
:you_linked => /^A silvery translucent thread extends from you encompassing <a exist="(?<exist>-\d+)" noun="(?<name>[^"]+)/,
:spirit_linked => /^A silvery translucent thread extends from <a exist="-\d+" noun="(?<cleric>[^"]+).* encompassing <a exist="(?<exist>-\d+)" noun="(?<name>[^"]+)/,
:spirit_unlinked => /^(?:You break the bond established between your soul|The soul bond between you) and <a exist="(?<exist>-\d+)" noun="(?<name>[^"]+)/,
:herb_healed => /^<a exist="(?<exist>-\d+)" noun="(?<name>[^"]+)">.* looks better\.$/,
:empath_healed_maybe => /<a exist="-\d+" noun="(?<name1>[^"]+)">.*<a exist="-\d+" noun="(?<name2>[^"]+)">/,
:empath_heal_locations => /right eye|left eye|head|neck|chest|abdomen|back|right arm|right hand|right leg|left arm|left hand|left leg/,
:tend_expired => /The bandages on <a exist="(?<exist>-\d+)" noun="(?<name>[^"]+).* come loose\.$/,
:tended => /(?:You begin to do|<a.*> begins to do) (?<pronoun>his|her|your) best to bandage <a exist="(?<exist>-\d+)" noun="(?<name>[^"]+).*wound\.$/,
:chrism_applied => /^(?:You gingerly crack and wave|<a.*> gingerly cracks and waves) .* over <a exist="(?<exist>-\d+)" noun="(?<name>[^"]+)">.*body, and a mixture of oil and balsam/,
}
class Body
attr_accessor :exist, :name, :cleric, :roomorder, :chrism
attr_accessor :lifekept # Am I lifekept?
attr_accessor :lifekeep_expires # When does LK expire? Note: This can be in the past if we haven't seen it fall off.
attr_accessor :appraised # When was I last appraised?
attr_accessor :spirit # Current spirit
attr_accessor :maxspirit # Max spirit
attr_accessor :ttl # Time at which we consider this data 'old' and must refresh it.
attr_accessor :bleeding, :injuries
attr_accessor :queued # True if in the appraise queue.
def initialize(name, exist, roomorder=-1)
@exist = exist
@name = name
@roomorder = roomorder
end
def appraise
if @queued
TriageScript::debug "#{@name} already queued for appraise."
return
end
# return if @queued
@queued = true
maxttl(15)
TriageScript::debug "Queued #{@name} for appraise."
TriageScript::appq << self
end
def pc
return GameObj.pcs.find{|x| x.name == @name and x.status =~ /\bdead\b/}
end
def maxttl(n)
n = Time.now + n unless n.class == Time
@ttl = n if @ttl.nil? or @ttl > n
return @ttl
end
end
def self.run_worker(script)
hide_me
debug "Appraise worker reporting in."
meditate = Spell["Meditation"]
hook_name = "triage_appraise_hook"
before_dying { DownstreamHook.remove(hook_name) }
while (body = $triage_appraise_queue.pop)
waitrt?
# Wait for meditation to be finished, but no more than 5 seconds after it is interrupted
# 10+ minutes (600+ seconds) of meditate = we're meditating but haven't finished yet
sleep 5 while meditate.active? and meditate.secsleft > 590
pc = body.pc
next unless pc
success_line = /^You glance at <a exist="#{pc.id}".*spirit levels/
squelched = false
DownstreamHook.add(hook_name, proc do |xml|
if squelched
if xml.include?('<prompt')
squelched = false
DownstreamHook.remove(hook_name)
end
next nil
end
if xml =~ success_line
squelched = true
next nil
end
next xml
end)
script.want_downstream_xml = true
result = dothistimeout "appraise #{pc.noun}", 5, success_line
script.want_downstream_xml = false
script.downstream_buffer.clear
unless result
DownstreamHook.remove(hook_name)
body.queued = false # Normally the appraise result removes this, but if appraise fails there will be no result.
end
end
end
def self.die_together(script)
before_dying do
Script.list.each{|other|
other.kill if other.name == script.name and other != script
}
end
end
def self.appq
return @appq
end
def self.get_body(name, exist, ttl: nil, appraise: false)
body = @bodies[name]
return body if body
body = Body.new(name, exist)
@bodies[name] = body
body.ttl = Time.now + ttl if ttl
body.appraise if appraise
return body
end
def self.get_dead_pc(name)
return GameObj.pcs.find{|x| x.noun == name and x.status =~ /\bdead\b/}
end
def self.refresh_pcs
# Refresh our knowledge of dead PCs in the room.
dead_pcs = {}
GameObj.pcs.each do |pc|
next unless pc.status =~ /\bdead\b/
dead_pcs[pc.noun] = pc
end
@lock.synchronize do
# Delete bodies that are no longer dead.
@bodies.keep_if{|k, v| dead_pcs[k]}
ix = 0
# Make sure all bodies are in the list.
dead_pcs.each do|name, pc|
body = get_body(pc.noun, pc.id, ttl: 10, appraise: true)
body.roomorder == ix
ix += 1
end
if @bodies.length > 0
@dormant = false
refresh_window
else
unless @dormant
@dormant = true
refresh_window
end
end
end
end
def self.your_lifekeep_duration
return (
600 # Base duration
+ 15*(Skills.slblessings) # 15 seconds per rank of Blessings
)
end
def self.your_lifekeep_expires
return Time.now + your_lifekeep_duration
end
def self.debug(*what)
echo *what if @debugging
end
def self.healed(name)
# Call when someone is (possibly) healed. Returns the body, if there is one.
pc = get_dead_pc(name)
return unless pc
body = get_body(pc.noun, pc.id, appraise: true)
body.maxttl(5)
return body
end
def self.refresh_window
@window_thread.wakeup if @window_thread
end
def self.format_timedelta(delta)
return "*NOW*" if delta <= -2
m, s = delta.divmod(60)
return "#{m}m#{s.to_s.rjust(2,'0')}s"
end
def self.hook_commands
before_dying { UpstreamHook.remove("triage_command_hook") }
UpstreamHook.add("triage_command_hook", proc{|line|
next line unless line =~ /^(?:<c>)?\s*(?i:tria|triag|triage)\b(?:\s+(\S.*?))?\s*?$/
if $1
@script.downstream_buffer.unshift("<c>triage #{$1}")
else
@script.downstream_buffer.unshift("<c>triage")
end
next nil
})
end
def self.run(script)
script.want_downstream = false
die_together(script)
if script.vars[0] == '--worker'
return self.run_worker(script)
end
unless Char.prof == 'Cleric' || Char.prof == 'Paladin'
echo "This version of #{$lich_char}triage only supports clerics and paladins."
if script.vars.include?('--force')
echo "I'm starting up anyways because you asked nicely, but most likely things will not work properly."
else
echo "If you want to try using it anyways, use `#{$lich_char}triage --force`"
exit
end
end
script.want_downstream_xml = true
@script = script
@bodies = {}
@lock = Mutex.new
@appq = Queue.new
$triage_appraise_queue = @appq
buffer = []
@refresh_thread = nil
@window_thread = nil
@threads = []
before_dying do
@refresh_thread.kill if @refresh_thread
@window_thread.kill if @window_thread
@refresh_thread = nil
@window_thread = nil
_respond "<clearStream id='triageScriptWindow' /><pushStream id='triageScriptWindow' />Script not running.\n\nStart it with:\n<output class='mono' />#{$lich_char}#{@script.name}\n<output class='' /><popStream/>" if $frontend == 'stormfront'
end
@debugging = (CharSettings[:debugging] ||= false)
CharSettings[:window_format] = :tall if CharSettings[:window_format] != :wide
@window_format = CharSettings[:window_format]
Script.start(@script.name, {force: true, quiet: true, args: '--worker'})
buffer << "<streamWindow id='triageScriptWindow' title='Triage' subtitle=' #{SHORT_VERSION}' location='center' save='save' resident='true' />"
buffer << "<exposeStream id='triageScriptWindow' />"
buffer << "<clearStream id='triageScriptWindow' />"
buffer << "<pushStream id='triageScriptWindow' />"
buffer << "Welcome to #{$lich_char}#{@script.name}\n"
buffer << "Version #{VERSION}\n"
buffer << "One moment please...\n"
buffer << "<popStream/>"
send buffer.join
buffer.clear
@dormant = true # No window updates needed
refresh_pcs
refresh_window
@refresh_thread = Thread.new do
while true
sleep 5
now = Time.now
# debug "Sweeping @ #{now}"
@lock.synchronize do
@bodies.each do |name, body|
if body.ttl.nil? or body.ttl < now
debug("TTL expired: #{body.inspect}")
body.appraise
end
end
end
end
end
def self.format_output(mode=:tall, buffer: nil, interactive: true, now: nil)
buffer ||= []
now ||= Time.now
buffer << '<output class="mono" />' if mode == :wide
player = XMLData.name
bodies_sorted = @bodies.values
bodies_sorted.sort!{|a, b|
# Our linked body shows first.
next 1 if (b.cleric == player && a.cleric != player)
next -1 if (a.cleric == player && b.cleric != player)
# Bodies not lifekept sort before bodies that are. Unknown sort in the middle
unless a.lifekept == b.lifekept
next 1 if a.lifekept
next -1 if b.lifekept
next -1 if b.lifekept.nil?
next 1 if a.lifekept.nil?
end
# next 1 if (!b.lifekept && a.lifekept)
# next -1 if (!a.lifekept && b.lifekept)
# Room order
next (a.roomorder <=> b.roomorder) if a.roomorder != b.roomorder
# Name as a last resort
next a.name <=> b.name
}.each do |body|
case mode
when :tall
buffer << '<pushBold/>' if body.lifekept == false
buffer << "#{body.name} ("
if body.lifekept
if body.lifekeep_expires
buffer << format_timedelta((body.lifekeep_expires - now).to_i)
else
buffer << "kept?"
end
else
buffer << "<d cmd='triage lifekeep #{body.name}'>" if interactive
if body.lifekept.nil?
buffer << "???"
else
buffer << "NO LK"
end
buffer << "</d>" if interactive
end
buffer << ")\n"
buffer << '<popBold/>' if body.lifekept == false
if body.cleric
if body.cleric == player
buffer << "-> YOU\n"
elsif body.cleric
buffer << "-> #{body.cleric}\n"
end
end
status = []
if body.bleeding.nil?
status << '???'
elsif body.bleeding
status << 'BLEEDING'
elsif body.injuries
status << 'Injured'
else
status << 'Healthy'
end
status << 'Chrismed' if body.chrism
buffer << " #{status.join(', ')}\n"
if @debugging
n = (body.ttl - now).to_i
buffer << " TTL: #{n}s\n"
end
buffer << "\n"
when :wide
buffer << '<pushBold/>' if body.lifekept == false
if body.lifekept
if body.lifekeep_expires
lk = format_timedelta((body.lifekeep_expires - now).to_i)
else
lk = "kept?"
end
elsif body.lifekept.nil?
lk = '???'
else
lk = 'NO LK'
end
lk = lk.rjust(6)
lk = "<d cmd='triage lifekeep #{body.name}'>#{lk}</d>" if interactive and !body.lifekept
buffer << lk
buffer << " "
buffer << body.name.ljust(15)
buffer << " "
if body.cleric
if body.cleric == player
buffer << "<=> YOU".ljust(25)
else
buffer << "<=> #{body.cleric}".ljust(25)
end
else
buffer << ' '*19
end
buffer << ' '
if body.bleeding.nil?
health = '????????'
elsif body.bleeding
health = 'BLEEDING'
elsif body.injuries
health = 'Injured'
else
health = 'Healthy'
end
if body.chrism
buffer << "#{health.ljust(8)} Chrismed"
else
buffer << health
end
buffer << '<popBold/>' if body.lifekept == false
buffer << "\n"
if @debugging
n = (body.ttl - now).to_i
buffer << " TTL: #{n}s (#{body.ttl})\n"
end
end
end
buffer << '<output class="" />' if mode == :wide
return buffer
end
if $frontend == 'stormfront'
@window_thread = Thread.new do
begin
while true
now = Time.now
timestamp = now.strftime("%l:%M:%S %p").strip
buffer = []
buffer << "<clearStream id='triageScriptWindow' />"
buffer << "<pushStream id='triageScriptWindow' />"
@lock.synchronize do
if @bodies.length == 0
buffer << "Corpse-free since: \n#{timestamp}"
buffer << "\nDebugging is enabled.\n" if @debugging
else
format_output(@window_format, buffer: buffer, interactive: true, now: now)
buffer << "[#{timestamp}]\n"
end # Bodies
end # Lock
buffer << "<popStream/>"
_respond buffer.join
if @dormant
sleep
else
sleep 5
end
end # Main while look
rescue => ex
echo "Something broke in the window thread. Please report this issue to LostRanger."
echo "Details: #{ex.inspect}"
exit
end
end
else
@window_thread = nil
end
hook_commands
# Main tracking thread
while (xml = get)
if xml.include?("<component id='room players'>")
debug("Player list changed.")
# List of players in the room changed. See if there are new bodies.
refresh_pcs
elsif xml.include?("<castTime value=")
debug("Spellcast detected.")
# We cast a spell or entered cast RT
# See if we tried to LK a body.
xml = get
debug xml
if xml =~ PATTERNS[:lk_cast]
debug("Successful cast of LK.")
# We LK'd them. We know our own LK duration
@lock.synchronize do
body = get_body($~[:name], $~[:exist], appraise: true)
body.lifekept = true
body.lifekeep_expires = self.your_lifekeep_expires
debug body.inspect
end
@dormant = false
refresh_window
elsif xml =~ PATTERNS[:already_kept]
debug("Body already kept.")
@lock.synchronize do
body = get_body($~[:name], $~[:exist], appraise: true)
unless body.lifekept
body.lifekept = true
body.appraise
end
debug body.inspect
end
elsif xml =~ PATTERNS[:you_linked]
debug("Link established")
@lock.synchronize do
body = get_body($~[:name], $~[:exist], appraise: true)
body.cleric = XMLData.name
debug body.inspect
end
@dormant = false
refresh_window
end
elsif xml =~ PATTERNS[:chrism_applied]
@lock.synchronize do
body = get_body($~[:name], $~[:exist], appraise: true)
body.chrism = true
refresh_window
debug body.inspect
end
elsif xml =~ PATTERNS[:spirit_linked]
debug("Link established")
@lock.synchronize do
body = get_body($~[:name], $~[:exist], appraise: true)
body.cleric = $~[:cleric]
debug body.inspect
end
elsif xml =~ PATTERNS[:spirit_unlinked]
debug("Link between you and target broken")
@lock.synchronize do
body = get_body($~[:name], $~[:exist], appraise: true)
# Make sure they were actually linked to us, linking can get weird sometimes.
body.cleric = nil if body.cleric == XMLData.name
debug body.inspect
end
elsif xml =~ PATTERNS[:lk_cast]
@lock.synchronize do
body = get_body($~[:name], $~[:exist], appraise: true)
body.lifekept = true
body.lifekeep_expires = Time.now + 600
body.appraise
debug body.inspect
@dormant = false
refresh_window
end
elsif xml =~ PATTERNS[:lk_expired]
debug("Detected loss of lifekeep")
@lock.synchronize do
body = get_body($~[:name], $~[:exist], appraise: true)
body.lifekept = false
body.lifekeep_expires = nil
debug body.inspect
@dormant = false
refresh_window
end
elsif xml =~ PATTERNS[:lk_unlink]
debug("Detected intentional unlink loss of lifekeep")
@lock.synchronize do
body = get_body($~[:name], $~[:exist], appraise: true)
body.lifekept = false
body.lifekeep_expires = nil
debug body.inspect
@dormant = false
refresh_window
end
elsif xml =~ PATTERNS[:appraise_start]
debug xml.inspect
repeat = true
@lock.synchronize do
while repeat
repeat = false
t = {
:name => $~[:name],
:exist => $~[:exist],
:spirit => $~[:spirit],
:maxspirit => $~[:maxspirit],
:cleric => $~[:cleric], # May be nil
:chrism => $~[:chrism] && true || false,
:time => $~[:time],
:bleeding => false,
:injuries => nil,
:dead => false,
}
t[:cleric] = XMLData.name if t[:cleric] == 'you'
while (xml = get)
if xml =~ PATTERNS[:appraise_injuries]
t[:injuries] = $~[:injuries]
elsif xml =~ PATTERNS[:appraise_bleeding]
t[:bleeding] = true
elsif xml =~ PATTERNS[:appraise_dead]
t[:dead] = true
break
elsif xml =~ PATTERNS[:appraise_end]
break
elsif xml =~ PATTERNS[:appraise_start]
# Could happen, e.g, if APPRAISE GROUP
repeat = true
break
end
end
unless t[:dead]
if @bodies.delete(t[:name])
@dormant = true if @bodies.length == 0
refresh_window
end
next
end
body = get_body(t[:name], t[:exist])
body.queued = false
body.cleric = t[:cleric]
body.spirit = t[:spirit]
body.maxspirit = t[:maxspirit]
body.bleeding = t[:bleeding]
body.injuries = t[:injuries]
body.chrism = t[:chrism]
if t[:time]
ttl = t[:time].to_i
body.lifekept = true
body.lifekeep_expires = Time.now + ttl
ttl = 120 if ttl > 120
else
ttl = 30
body.lifekept = false
body.lifekeep_expires = nil
end
body.ttl = Time.now + ttl
debug body.inspect
@dormant = false
refresh_window
end
end
elsif xml =~ PATTERNS[:herb_healed]
# Tinctures!
self.healed($~[:name])
elsif xml =~ PATTERNS[:tended]
pronoun = $~[:pronoun]
debug("Detected tend #{xml}, pronoun: #{pronoun}")
# Tended
body = self.healed($~[:name])
body.appraise if pronoun == 'your'
elsif xml =~ PATTERNS[:tend_expired]
pc = get_dead_pc($~[:name])
next unless pc
body = get_body(pc.name, pc.id, appraise: true)
unless body.bleeding # If they were already bleeding, there's no need to schedule a refresh -- they're definitely still bleeding.
body.bleeding = true
body.maxttl(10)
@dormant = false
refresh_window
end
elsif xml =~ PATTERNS[:empath_heal_locations]
# TODO: This could be more efficient since it finds two PCs, not just one, but this is simpler for now.
next unless xml =~ PATTERNS[:empath_healed_maybe]
self.healed($~[:name1])
self.healed($~[:name2])
#
# GameObj.pcs.each do |pc|
# next unless pc.noun == match[:name1] or pc.noun == match[:name2]
# next unless pc.status =~ /\bdead\b/
# body = get_body(pc.noun, pc.id, appraise: true)
# body.maxttl(10) # Refresh soonish to get all the healing, but not immediately.
# end
elsif xml.start_with?("<c>triage")
_, command, args = xml.split(/\s+/, 3)
handle_command(command, args)
end
end
end
def self.handle_command(command, args)
command ||= 'status'
command.downcase!
case command
when 's', 'st', 'sta', 'stat', 'statu', 'status'
@lock.synchronize do
if @bodies.length == 0
echo "No dead bodies appear to be present."
else
if @bodies.length == 1
buffer = ["There appears to be one dead body here:\n\n"]
else
buffer = ["There appear to be #{@bodies.length} dead bodies here:\n\n"]
end
buffer << '<output class="mono" />'
# FIXME: Should probably be wide format.
format_output(:wide, interactive: true, buffer: buffer)
buffer << '<output class="" />'
send buffer.join
end # Bodies
end # Lock
when 'l', 'lk', 'li', 'lif', 'life', 'lifek' 'lifeke', 'lifekee', 'lifekeep'
unless args
echo "Lifekeep whom?"
return
end
Spell[305].cast(args)
fput "appraise #{args}"
when 'sh', 'sho', 'show'
unless $frontend == 'stormfront'
echo "This function requires Stormfront."
return
end
_respond "<exposeStream id='triageScriptWindow' />"
refresh_window
when 'w', 'wi', 'wid', 'wide'
unless $frontend == 'stormfront'
echo "This function requires Stormfront."
return
end
CharSettings[:window_format] = @window_format = :wide
echo "Switched to wide-format window."
refresh_window
when 't', 'ta', 'tal', 'tall', 'n', 'na', 'nar', 'narr', 'narro', 'narrow'
unless $frontend == 'stormfront'
echo "This function requires Stormfront."
return
end
CharSettings[:window_format] = @window_format = :tall
echo "Switched to tall-format window."
refresh_window
when 'debug'
CharSettings[:debugging] = @debugging = !@debugging
echo "Toggled debugging to #{@debugging.to_s}"
refresh_window
else
echo "Unrecognized command '#{command}'."
echo "If you were looking for help, that's not currently available -- but see `#{$lich_char}repo info #{@script.name}`"
end
end
def self.send(what)
if $fake_stormfront
what = what.gsub(/<.*?>/, '')
what.gsub!('>', '>')
what.gsub!('<', '<')
_respond what
else
_respond what
end
end
end
unless script.vars[0] == '--worker'
if EXPERIMENTAL_EXPIRES
if EXPERIMENTAL_EXPIRES > Time.now
echo "** This is an EXPERIMENTAL triage build. It should be updated by #{EXPERIMENTAL_EXPIRES}."
echo "** Get new versions automatically with #{$lich_char}repo set-updatable #{script.name}"
else
echo "** This is an OUTDATED EXPERIMENTAL triage build. It should probably have been updated by now. It expired at #{EXPERIMENTAL_EXPIRES}."
echo "** You can still use it, but you may encounter bugs and minor annoyances."
echo "** Get new versions automatically with #{$lich_char}repo set-updatable #{script.name}"
# sleep 10 # Minor annoyances.
end
end
end
TriageScript.run(script)