-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlich-lib.rb
More file actions
executable file
·3516 lines (3351 loc) · 93.2 KB
/
lich-lib.rb
File metadata and controls
executable file
·3516 lines (3351 loc) · 93.2 KB
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
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# The vast majority of script 'commands' are defined here. A lot of random garbage is tossed in because over the long months I've been writing Lich, I've been learning as I added to it. For now I'm too lazy to clean it up, so it's only real use is to serve as an example (if you really want to, go ahead and try to use this to extend your own project, but good luck, lol). If you want to peek at what happens when you use a command in a script, just do a search for 'def (command)' [replace (command) with the command you want to look at, of course].
at_exit { Process.waitall }
class NilClass
def dup
nil
end
def method_missing(*args)
nil
end
end
module Enumerable
def qfind(obj)
find { |el| el.match obj }
end
end
class String
def split_as_list
string = self
string.sub!(/^You (?:also see|notice) |^In the .+ you see /, ',')
string.sub('.','').sub(/ and (an?|some|the)/, ', \1').split(',').reject { |str|
str.strip.empty?
}.collect { |str| str.lstrip }
end
end
class Char
@@cha ||= nil
@@name ||= nil
private_class_method :new
def Char.init(name)
@@name == nil ? @@name = name.strip : @@name.dup
end
def Char.name
@@name or $_TAGHASH_['GSB'].slice(/[A-Z][a-z]+/)
end
def Char.health(*args)
checkhealth(*args)
end
def Char.mana(*args)
checkmana(*args)
end
def Char.spirit(*args)
checkspirit(*args)
end
def Char.maxhealth
Object.module_eval { maxhealth }
end
def Char.maxmana
Object.module_eval { maxmana }
end
def Char.maxspirit
Object.module_eval { maxspirit }
end
def Char.stamina(*args)
checkstamina(*args)
end
def Char.maxstamina
Object.module_eval { maxstamina }
end
def Char.cha(val=nil)
val == nil ? @@cha : @@cha = val
end
def Char.dump_info
save = Thread.critical
begin
Marshal.dump([
Spell.detailed?,
Spell.serialize,
Spellsong.serialize,
Stats.serialize,
Skills.serialize,
Spells.serialize,
Gift.serialize,
Society.serialize,
])
ensure
Thread.critical = save
end
end
def Char.load_info(string)
save = Char.dump_info
begin
Spell.load_detailed,
Spell.load_active,
Spellsong.load_serialized,
Stats.load_serialized,
Skills.load_serialized,
Spells.load_serialized,
Gift.load_serialized,
Society.load_serialized = Marshal.load(string)
rescue
raise $! if string == save
string = save
retry
end
end
def Char.method_missing(meth, *args)
[ Stats, Skills, Spellsong, Society ].each { |klass|
begin
result = klass.__send__(meth, *args)
return result
rescue
end
}
raise NoMethodError
end
end
class Society
@@status ||= String.new
@@rank ||= 0
def Society.serialize
[@@status,@@rank]
end
def Society.load_serialized=(val)
@@status,@@rank = val
end
def Society.status=(val)
@@status = val
end
def Society.status
@@status.dup
end
def Society.rank=(val)
if val =~ /Master/
if @@status =~ /Voln/ then @@rank = 26 elsif @@status =~ /Council of Light/ then @@rank = 20 else @@rank = val.to_i end
else
@@rank = val.slice(/[0-9]+/).to_i
end
end
def Society.step
@@rank
end
def Society.member
@@status.dup
end
def Society.rank
@@rank
end
end
class Spellsong
@@renewed ||= Time.at(Time.now.to_i - 1200)
def Spellsong.renewed
@@renewed = Time.now
end
def Spellsong.renewed=(val)
@@renewed = val
end
def Spellsong.renewed_at
@@renewed
end
def Spellsong.timeleft
if Time.now - @@renewed > Spellsong.duration
@@renewed = Time.now
end
(Spellsong.duration - (Time.now - @@renewed)) / 60.00
end
def Spellsong.serialize
Spellsong.timeleft
end
def Spellsong.load_serialized=(old)
Thread.new {
n = 0
while Stats.level == 0
sleep 0.25
n += 1
break if n >= 4
end
unless n >= 4
@@renewed = Time.at(Time.now.to_f - (Spellsong.duration - old * 60.00))
else
@@renewed = Time.now
end
}
nil
end
def Spellsong.duration
total = 120
1.upto(Stats.level.to_i) { |n|
if n < 26
total += 4
elsif n < 51
total += 3
elsif n < 76
total += 2
else
total += 1
end
}
(total + Stats.log[1].to_i + (Stats.inf[1].to_i * 3) + (Skills.mltelepathy.to_i * 2))
end
def Spellsong.tonisdodgebonus
thresholds = [1,2,3,5,8,10,14,17,21,26,31,36,42,49,55,63,70,78,87,96]
bonus = 20
thresholds.each { |val| if Skills.elair >= val then bonus += 1 end }
bonus
end
def Spellsong.tonishastebonus
bonus = -1
thresholds = [30,75]
thresholds.each { |val| if Skills.elair >= val then bonus -= 1 end }
bonus
end
def Spellsong.mirrorsdodgebonus
20 + ((Spells.bard - 19) / 2).round
end
def Spellsong.mirrorscost
[19 + ((Spells.bard - 19) / 5).truncate, 8 + ((Spells.bard - 19) / 10).truncate]
end
def Spellsong.depressionpushdown
20 + Skills.mltelepathy
end
def Spellsong.depressionslow
thresholds = [10,25,45,70,100]
bonus = -2
thresholds.each { |val| if Skills.mltelepathy >= val then bonus -= 1 end }
bonus
end
def Spellsong.sonicarmordurability
210 + (Stats.level / 2).round + Skills.to_bonus(Skills.elair)
end
def Spellsong.sonicbladedurability
160 + (Stats.level / 2).round + Skills.to_bonus(Skills.elair)
end
def Spellsong.sonicshielddurability
125 + (Stats.level / 2).round + Skills.to_bonus(Skills.elair)
end
def Spellsong.sonicbonus
(Spells.bard / 2).round
end
def Spellsong.sonicarmorbonus
Spellsong.sonicbonus + 15
end
def Spellsong.sonicbladebonus
Spellsong.sonicbonus + 10
end
def Spellsong.sonicshieldbonus
Spellsong.sonicbonus + 10
end
def Spellsong.valorbonus
10 + (Spells.bard / 2).round
end
def Spellsong.valorcost
[10 + (Spellsong.valorbonus / 2), 3 + (Spellsong.valorbonus / 5)]
end
def Spellsong.luckcost
[6 + ((Spells.bard - 6) / 4),(6 + ((Spells.bard - 6) / 4) / 2).round]
end
def Spellsong.holdingtargets
1 + ((Spells.bard - 1) / 7).truncate
end
end
class Skills
@@twoweaponcombat ||= 0
@@armoruse ||= 0
@@shielduse ||= 0
@@combatmaneuvers ||= 0
@@edgedweapons ||= 0
@@bluntweapons ||= 0
@@twohandedweapons ||= 0
@@rangedweapons ||= 0
@@thrownweapons ||= 0
@@polearmweapons ||= 0
@@brawling ||= 0
@@ambush ||= 0
@@multiopponentcombat ||= 0
@@combatleadership ||= 0
@@physicalfitness ||= 0
@@dodging ||= 0
@@arcanesymbols ||= 0
@@magicitemuse ||= 0
@@spellaiming ||= 0
@@harnesspower ||= 0
@@emc ||= 0
@@mmc ||= 0
@@smc ||= 0
@@elair ||= 0
@@elearth ||= 0
@@elfire ||= 0
@@elwater ||= 0
@@slblessings ||= 0
@@slreligion ||= 0
@@slsummoning ||= 0
@@sldemonology ||= 0
@@slnecromancy ||= 0
@@mldivination ||= 0
@@mlmanipulation ||= 0
@@mltelepathy ||= 0
@@mltransference ||= 0
@@mltransformation ||= 0
@@survival ||= 0
@@disarmingtraps ||= 0
@@pickinglocks ||= 0
@@stalkingandhiding ||= 0
@@perception ||= 0
@@climbing ||= 0
@@swimming ||= 0
@@firstaid ||= 0
@@trading ||= 0
@@pickpocketing ||= 0
def Skills.serialize
[@@twoweaponcombat, @@armoruse, @@shielduse, @@combatmaneuvers, @@edgedweapons, @@bluntweapons, @@twohandedweapons, @@rangedweapons, @@thrownweapons, @@polearmweapons, @@brawling, @@ambush, @@multiopponentcombat, @@combatleadership, @@physicalfitness, @@dodging, @@arcanesymbols, @@magicitemuse, @@spellaiming, @@harnesspower, @@emc, @@mmc, @@smc, @@elair, @@elearth, @@elfire, @@elwater, @@slblessings, @@slreligion, @@slsummoning, @@sldemonology, @@slnecromancy, @@mldivination, @@mlmanipulation, @@mltelepathy, @@mltransference, @@mltransformation, @@survival, @@disarmingtraps, @@pickinglocks, @@stalkingandhiding, @@perception, @@climbing, @@swimming, @@firstaid, @@trading, @@pickpocketing]
end
def Skills.load_serialized=(array)
@@twoweaponcombat, @@armoruse, @@shielduse, @@combatmaneuvers, @@edgedweapons, @@bluntweapons, @@twohandedweapons, @@rangedweapons, @@thrownweapons, @@polearmweapons, @@brawling, @@ambush, @@multiopponentcombat, @@combatleadership, @@physicalfitness, @@dodging, @@arcanesymbols, @@magicitemuse, @@spellaiming, @@harnesspower, @@emc, @@mmc, @@smc, @@elair, @@elearth, @@elfire, @@elwater, @@slblessings, @@slreligion, @@slsummoning, @@sldemonology, @@slnecromancy, @@mldivination, @@mlmanipulation, @@mltelepathy, @@mltransference, @@mltransformation, @@survival, @@disarmingtraps, @@pickinglocks, @@stalkingandhiding, @@perception, @@climbing, @@swimming, @@firstaid, @@trading, @@pickpocketing = array
end
def Skills.method_missing(arg1, arg2='')
instance_eval("@@#{arg1}#{arg2}", if Script.self then Script.self.name else "Lich" end)
end
def Skills.to_bonus(ranks)
bonus = 0
while ranks > 0
if ranks > 40
bonus += (ranks - 40)
ranks = 40
elsif ranks > 30
bonus += (ranks - 30) * 2
ranks = 30
elsif ranks > 20
bonus += (ranks - 20) * 3
ranks = 20
elsif ranks > 10
bonus += (ranks - 10) * 4
ranks = 10
else
bonus += (ranks * 5)
ranks = 0
end
end
bonus
end
end
class Spells
@@minorelemental ||= 0
@@majorelemental ||= 0
@@minorspiritual ||= 0
@@majorspiritual ||= 0
@@wizard ||= 0
@@sorcerer ||= 0
@@ranger ||= 0
@@paladin ||= 0
@@empath ||= 0
@@cleric ||= 0
@@bard ||= 0
def Spells.method_missing(arg1, arg2='')
instance_eval("@@#{arg1}#{arg2}")
end
def Spells.minorspirit
@@minorspiritual
end
def Spells.minorspirit=(val)
@@minorspiritual = val
end
def Spells.majorspirit
@@majorspiritual
end
def Spells.majorspirit=(val)
@@majorspiritual = val
end
def Spells.get_circle_name(num)
val = num.to_s
if val == "1" then "Minor Spirit"
elsif val == "2" then "Major Spirit"
elsif val == "3" then "Cleric"
elsif val == "4" then "Minor Elemental"
elsif val == "5" then "Major Elemental"
elsif val == "6" then "Ranger"
elsif val == "7" then "Sorcerer"
elsif val == "9" then "Wizard"
elsif val == "10" then "Bard"
elsif val == "11" then "Empath"
elsif val == "16" then "Paladin"
elsif val == "66" then "Death"
elsif val == "65" then "Imbedded Enchantment"
elsif val == "96" then "Combat Maneuvers"
elsif val == "98" then "Order of Voln"
elsif val == "99" then "Council of Light"
elsif val == "cm" then "Combat Maneuvers"
elsif val == "mi" then "Miscellaneous"
else 'Unknown Circle' end
end
def Spells.active
Spell.active
end
def Spells.known
ary = []
Spell.list.each { |sp_obj|
circlename = Spells.get_circle_name(sp_obj.circle)
sym = circlename.delete("\s").downcase
ranks = Spells.send(sym).to_i rescue()
next unless ranks.nonzero?
num = sp_obj.num.to_s[-2..-1].to_i
ary.push sp_obj if ranks >= num
}
ary
end
def Spells.serialize
[@@minorelemental,@@majorelemental,@@minorspiritual,@@majorspiritual,@@wizard,@@sorcerer,@@ranger,@@paladin,@@empath,@@cleric,@@bard]
end
def Spells.load_serialized=(val)
@@minorelemental,@@majorelemental,@@minorspiritual,@@majorspiritual,@@wizard,@@sorcerer,@@ranger,@@paladin,@@empath,@@cleric,@@bard = val
end
end
class Spell
@@active ||= Array.new
@@list ||= Array.new
@@active_loaded ||= false
@@detailed ||= true
attr_reader :timestamp, :num, :name, :duration, :timeleft, :msgup, :msgdn, :stacks, :circle, :circlename, :selfonly, :cost
def initialize(num,name,duration,cost,misc,msgup,msgdn)
@name,@duration,@cost,@msgup,@msgdn = name,duration,cost,msgup,msgdn
if num.to_i.nonzero? then @num = num.to_i else @num = num end
@timestamp = Time.now
@selfonly = misc.include?('1')
@stacks = misc.include?('~')
@active = false
@timeleft = 0
@msgup = msgup
@msgdn = msgdn
@circle = (num.to_s.length == 3 ? num.to_s[0..0] : num.to_s[0..1])
@circlename = Spells.get_circle_name(@circle)
@@list.push(self) unless @@list.find { |spell| spell.name == @name }
end
def Spell.serialize
spell = nil; @@active.each { |spell| spell.touch }
@@active
end
def Spell.load_active=(data)
data.each { |oldobject|
spell = @@list.find { |newobject| oldobject.name == newobject.name }
unless @@active.include?(spell)
spell.timeleft = oldobject.timeleft
spell.active = true
@@active.push(spell)
end
}
end
def Spell.load_detailed=(data)
@@detailed = data
end
def Spell.detailed?
@@detailed
end
def Spell.increment_detailed
@@detailed = !@@detailed
end
def active=(val)
@active = val
end
def Spell.active
@@active
end
def Spell.list
@@list
end
def Spell.upmsgs
@@list.collect { |spell| spell.msgup }
end
def Spell.dnmsgs
@@list.collect { |spell| spell.msgdn }
end
def timeleft=(val)
@timeleft = val
@timestamp = Time.now
end
def touch
if @duration.to_s == "Spellsong.timeleft"
@timeleft = Spellsong.timeleft
else
@timeleft = @timeleft - ((Time.now - @timestamp) / 60.00)
if @timeleft.to_f <= 0
self.putdown
return 0.0
end
end
@timestamp = Time.now
@timeleft
end
def Spell.[](val)
if val.class == Spell
val
elsif val.class == Fixnum
@@list.find { |spell| spell.num == val }
else
if ret = @@list.find { |spell| spell.name =~ /^#{val}$/i } then ret
elsif ret = @@list.find { |spell| spell.name =~ /^#{val}/i } then ret
else @@list.find { |spell| spell.msgup =~ /#{val}/i or spell.msgdn =~ /#{val}/i } end
end
end
def Spell.active?(val)
Spell[val].active?
end
def active?
touch
@active
end
def minsleft
touch
end
def secsleft
touch * 60
end
def to_s
@name.to_s
end
def putup
touch
@stacks ? @timeleft += eval(@duration).to_f : @timeleft = eval(@duration).to_f
if @timeleft > 240 then @timeleft = 239.983 end
@@active.push(self) unless @@active.include?(self)
@active = true
end
def putdown
@active = false
@timeleft = 0
@timestamp = Time.now
@@active.delete(self)
end
def remaining
self.touch.as_time
end
end
class Stats
@@race ||= 'unknown'
@@prof ||= 'unknown'
@@gender ||= 'unknown'
@@age ||= 0
@@exp ||= 0
@@level ||= 0
@@str ||= [0,0]
@@con ||= [0,0]
@@dex ||= [0,0]
@@agi ||= [0,0]
@@dis ||= [0,0]
@@aur ||= [0,0]
@@log ||= [0,0]
@@int ||= [0,0]
@@wis ||= [0,0]
@@inf ||= [0,0]
def Stats.method_missing(arg1, arg2='')
if arg2.class == Array
instance_eval("@@#{arg1}[#{arg2.join(',')}]", if Script.self then Script.self.name else "Lich" end)
elsif arg2.to_s =~ /^\d+$/
instance_eval("@@#{arg1}#{arg2}", if Script.self then Script.self.name else "Lich" end)
elsif arg2.empty?
instance_eval("@@#{arg1}", if Script.self then Script.self.name else "Lich" end)
else
instance_eval("@@#{arg1}'#{arg2}'", if Script.self then Script.self.name else "Lich" end)
end
end
def Stats.serialize
[@@race,@@prof,@@gender,@@age,@@exp,@@level,@@str,@@con,@@dex,@@agi,@@dis,@@aur,@@log,@@int,@@wis,@@inf]
end
def Stats.load_serialized=(array)
@@race,@@prof,@@gender,@@age,@@exp,@@level,@@str,@@con,@@dex,@@agi,@@dis,@@aur,@@log,@@int,@@wis,@@inf = array
end
end
class Gift
@@began ||= Time.now
@@timer ||= 0
@@running ||= false
@@stopwatch ||= Time.now
@@tracked ||= false
def Gift.serialize
[@@began,@@timer]
end
def Gift.load_serialized=(array)
@@tracked = true
@@began,@@timer = array
end
def Gift.touch
over = @@began + 604800
if Time.now > over
@@timer = 0
@@running = false
@@stopwatch = Time.now
end
Gift.stopwatch
end
def Gift.stopwatch
if $_TAGHASH_['GSr'] =~ /^A/
if @@running then @@timer += (Time.now.to_f - @@stopwatch.to_f) end
@@running = false
else
if @@running
@@timer += (Time.now.to_f - @@stopwatch.to_f)
end
@@running = true
@@stopwatch = Time.now
end
end
def Gift.remaining
Gift.touch
unless @@tracked then return 0 end
21600 - @@timer
end
def Gift.restarts_on
@@began + 604800
end
def Gift.ended
@@timer = 21601
end
def Gift.started
@@began = Time.now
@@timer = 0
@@stopwatch = Time.now
Gift.stopwatch
end
end
class Lich
def Lich.reload_settings
begin
if Char.name
file = File.open($lich_dir + "settings-#{Char.name}.txt")
else
file = File.open($lich_dir + "settings.txt")
end
file.readlines.collect { |line| line.strip }.find_all { |line| line !~ /^#/ and !line.empty? }.each { |line|
set, val = line.split(':').collect { |piece| piece.strip }
if val.include?(',')
Lich.module_eval("@@#{set} = ['#{val.gsub(/, |,/, "', '")}']", if Script.self then Script.self.name else "Lich" end)
else
Lich.module_eval("@@#{set} = '#{val}'", if Script.self then Script.self.name else "Lich" end)
end
}
rescue SystemCallError
file ? file.close : nil
if Char.name
file = File.open($lich_dir + "settings-#{Char.name}.txt", 'w')
else
file = File.open($lich_dir + "settings.txt", 'w')
end
file.write %[# These are your Lich settings. Note that each character will have their own file called "settings-(charname).txt" if you're using Lich with GemStone. If you're using it with another MUD, the template file (just plain "settings.txt") will be used globally since Lich has no clue what your char name is. You can access any of these from within a script with `Lich.(settingname)' exactly as though it were a variable. So for example, `Lich.lootsack' in a script would be replaced with whatever you put here. Note that as of v3.26+, you can make up any setting you want and just stick it in this file; once you reload the settings (see the `;help' menu or use settings.lic), it'll work like any of the previously available ones (e.g., `Lich.i_am_weirdly_named' would work if you put `i_am_weirdly_named: stuff' in here). These really aren't very convenient; the primary reason they exist is so that Wizard scripts that try to use the standard Wizard script variables can still be run properly by Lich, and also so that when you're writing a script that you think may be of use to others you have a way of making sure it will work for anybody who properly sets their Lich settings instead of only working if they manually change the script.\r\nlootsack:\r\nboxsack:\r\nscrollsack:\r\nwandsack:\r\nsheath:\r\ngemsack:\r\npuregemsack:\r\nherbsack:\r\nmagicsack:\r\nshield:\r\nweapon:\r\nuser0:\r\nuser1:\r\nuser2:\r\nuser3:\r\nuser4:\r\nuser5:\r\nuser6:\r\nuser7:\r\nuser8:\r\nuser9:\r\ntreasure:\r\nexcludeloot:\r\n]
file.close
retry
rescue SyntaxError
$stderr.puts($!)
rescue
$stderr.puts($!)
$stderr.puts($!.backtrace)
ensure
file ? file.close : nil
end
end
def Lich.method_missing(arg1, arg2='')
instance_eval("@@#{arg1}#{arg2}", if Script.self then Script.self.name else "Lich" end)
end
def Lich.fetchloot
if items = checkloot.find_all { |item| item =~ /#{@@treasure.join('|')}/ }
take(items)
else
return false
end
end
end
class Status
@@head = -2..-1
@@neck = -4..-3
@@rarm = -6..-5
@@larm = -8..-7
@@rleg = -10..-9
@@lleg = -12..-11
@@rhand = -14..-13
@@lhand = -16..-15
@@chest = -18..-17
@@abs = -20..-19
@@back = -22..-21
@@reye = -24..-23
@@leye = -26..-25
@@nerves = -28..-27
SFMAP = Hash[ 'nsys', 'nerves', 'leftArm', 'larm', 'rightArm', 'rarm', 'rightLeg', 'rleg', 'leftLeg', 'lleg',
'rightHand', 'rhand', 'leftHand', 'lhand', 'rightEye', 'reye', 'leftEye', 'leye', 'abdomen', 'abs',
]
def Status.method_missing(arg)
arg = arg.to_s
arg =~ /scar/ ? tag = "GSb" : tag = "GSa"
instance_eval("dec2bin($_TAGHASH_[tag].to_i).to_s[@@#{arg.slice(/head|neck|rarm|larm|rleg|lleg|rhand|lhand|chest|abs|back|reye|leye|nerves/)}]",
if Script.self then Script.self.name else "Lich" end)
end
def Status.rank(val)
bin2dec(val.to_i)
end
def Status.sf_update(area, rank)
range = Status.class_eval(sprintf("@@%s", SFMAP.fetch(area) { |query| query }))
if rank =~ /Injury/i
tag = [ 'GSa' ]
elsif rank =~ /Scar/i
tag = [ 'GSb' ]
else
tag = [ 'GSa', 'GSb' ]
end
tag.each { |t|
buf = sprintf("%028b", $_TAGHASH_[t].to_i)
buf[range] = dec2bin(rank.slice(/\d/).to_i).to_s[-2..-1]
$_TAGHASH_[t] = sprintf("%010d", sprintf("0b0%s", buf))
}
end
end
class Wounds
def Wounds.method_missing(arg)
bin2dec(Status.send("woundshift#{arg}").to_i)
end
def Wounds.arms
[Wounds.larm,Wounds.rarm,Wounds.lhand,Wounds.rhand].max
end
def Wounds.limbs
[Wounds.larm,Wounds.rarm,Wounds.lhand,Wounds.rhand,Wounds.rleg,Wounds.lleg].max
end
def Wounds.torso
[Wounds.reye,Wounds.leye,Wounds.chest,Wounds.abs,Wounds.back].max
end
end
class Scars
def Scars.method_missing(arg)
bin2dec(Status.send("scarshift#{arg}").to_i)
end
def Scars.arms
[Scars.larm,Scars.rarm,Scars.lhand,Scars.rhand].max
end
def Scars.limbs
[Scars.larm,Scars.rarm,Scars.lhand,Scars.rhand,Scars.lleg,Scars.rleg].max
end
def Scars.torso
[Scars.reye,Scars.leye,Scars.chest,Scars.abs,Scars.back].max
end
end
class Watchfor
def Watchfor.method_missing(*args)
nil
end
end
class Array
def method_missing(*usersave)
self
end
end
class NilClass
def split(*val)
Array.new
end
def to_s
""
end
def strip
""
end
end
class FalseClass
def method_missing(*usersave)
nil
end
end
class String
def method_missing(*usersave)
""
end
def silent
false
end
def to_s
self.dup
end
end
class TrueClass
def method_missing(*usersave)
true
end
end
class Script
@@wizard_save_last ||= String.new
@@Watchfors ||= Array.new
@@wizard_save ||= Hash.new
at_exit { Script.shutdown_reap }
@@wizard_cmds ||= Hash.new
attr_accessor :opts
=begin
@@finalizer_proc = proc { |script|
if $LICH_DEBUG
respond("#{$DEBUG_MESSAGE || "--- Debug: "}`#{script.to_s}' (object_id: #{script.object_id}) is being garbage collected.")
end
}
=end
def wizard_cmds_init
undef :wizard_cmds_init
@@wizard_cmds['counter'] ||= <<-'COUNTER'
if @lines[@stackptr] =~ /add/i
if (csub = @lines[@stackptr].slice(/-?\d+/).to_i).nonzero?
@wizard_counter += csub
else
@wizard_counter += 1
end
elsif @lines[@stackptr] =~ /subtract|sub/i
if (csub = @lines[@stackptr].slice(/-?\d+/).to_i).nonzero?
@wizard_counter -= csub
else
@wizard_counter -= 1
end
elsif @lines[@stackptr] =~ /divide/i
@wizard_counter = (@wizard_counter / @lines[@stackptr].split.last.chomp.to_i).truncate
elsif @lines[@stackptr] =~ /multiply/i
@wizard_counter = (@wizard_counter * @lines[@stackptr].split.last.chomp.to_i).truncate
elsif @lines[@stackptr] =~ /set/i
@wizard_counter = @lines[@stackptr].split.last.chomp.to_i
end
COUNTER
@@wizard_cmds['echo'] ||= <<-'ECHO'
respond(@lines[@stackptr].sub(/echo\s?/i, '').strip)
ECHO
@@wizard_cmds['save'] ||= <<-'SAVE'
@wizard_save = @lines[@stackptr].sub(/save /i, '').gsub('"','').gsub('_',"\s").strip
@@wizard_save[@name.to_s] = @wizard_save.dup; @@wizard_save_last = @wizard_save.dup
SAVE
@@wizard_cmds['put'] ||= <<-'PUT'
if @lines[@stackptr] =~ /^\s*put\s+\.([^\s]+)(\s.+)?/i
if start_wizard_script($1.dup,$2.split)
name = $1
wait_until { Script.find(name) }
exit
end
else
waitrt?
fput("#{@lines[@stackptr].sub(/put /i, '').strip}")
end
PUT
@@wizard_cmds['pause'] ||= <<-'PAUSE'
if @lines[@stackptr].split[1].to_f <= 0
ptime = 1
else
ptime = @lines[@stackptr].split[1].to_f
end
sleep(ptime)
waitrt?
PAUSE
@@wizard_cmds['goto'] ||= <<-'GOTO'
target = @lines[@stackptr].split[1]
target.delete!(":")
if (found_label = @labels[target]).nil?
if (found_label = @labels[@labels.keys.find { |val| val =~ /\b#{target}\b/i }]).nil?
if (found_label = @labels[@labels.keys.find { |val| val =~ /labelerror/i }]).nil?
echo("Fatal label error; '#{target}' not found, labelerror not found.")
exit
end
sleep 0.02
end
end
File.open($lich_dir + "lich_debug.txt", "a") { |f| f.puts "JUMP:%04s:%04s" % [ @stackptr, found_label ] } if $WIZARD_DEBUG
@stackptr = found_label
GOTO
@@wizard_cmds['waitforre'] ||= <<-'WAITFORRE'
regexp = eval(@lines[@stackptr].sub(/waitforre /i,'').strip); waitforre(regexp)
WAITFORRE
@@wizard_cmds['waitfor'] ||= <<-'WAITFOR'
waitfor(Regexp.escape(@lines[@stackptr].sub(/waitfor /i, '').strip))
WAITFOR
@@wizard_cmds['wait'] ||= <<-'WAIT'
clear
get
WAIT
@@wizard_cmds['setvariable'] ||= <<-'SETVARIABLE'
@setvars[@lines[@stackptr].split[1]] = @lines[@stackptr].sub(/^\s*setvariable\s+[^\s]+/i,'').strip
SETVARIABLE
@@wizard_cmds['deletevariable'] ||= <<-'DELETEVARIABLE'
@setvars[@lines[@stackptr].split[1]] = String.new
DELETEVARIABLE
@@wizard_cmds['matchre'] ||= @@wizard_cmds['match'] ||= <<-'MATCH'
@match_table_labels.push(@lines[@stackptr].split[1].strip)
if @lines[@stackptr] =~ /\bmatch\b/i
@match_table_strings.push(Regexp.escape(@lines[@stackptr].sub(/\s*match #{@match_table_labels.last} /i, '')))
else
@match_table_strings.push(@lines[@stackptr].sub(/\s*matchre #{@match_table_labels.last} /i, '').sub(/\/i$/,'').gsub('/',''))
end
MATCH
@@wizard_cmds['matchwait'] ||= <<-'MATCHWAIT'
the_match = waitfor(@match_table_strings.join('|'))
idx = @match_table_strings.index(@match_table_strings.find { |val| the_match =~ /#{val}/i })
if (found_label = @labels[@match_table_labels[idx]]).nil?
found_label = @labels[@labels.keys.find { |lbl| lbl =~ /\b#{@match_table_labels[idx]}\b/i }]
if found_label.nil?
if (found_label = @labels[@labels.keys.find { |lbl| lbl =~ /labelerror/i }]).nil?
echo("Fatal label error; '#{@match_table_labels[idx]}' not found, labelerror not found.")
exit
end
end
end
@stackptr = found_label
@match_table_labels.clear
@match_table_strings.clear
MATCHWAIT
@@wizard_cmds['move'] ||= <<-'MOVE'
if @rev == true
dir = @lines[@stackptr].sub(/move /i, '').strip
if dir =~ /\bu\b|\bup\b/i then move("down")
elsif dir =~ /\bd\b|\bdown\b/i then move("up")
elsif dir =~ /\bn\b|\bnorth\b/i then move("south")
elsif dir =~ /\bne\b|\bnortheast\b/i then move("southwest")
elsif dir =~ /\be\b|\beast\b/i then move("west")
elsif dir =~ /\bse\b|\bsoutheast\b/i then move("northwest")
elsif dir =~ /\bs\b|\bsouth\b/i then move("north")
elsif dir =~ /\bsw\b|\bsouthwest\b/i then move("northeast")
elsif dir =~ /\bw\b|\bwest\b/i then move("east")
elsif dir =~ /\bnw\b|\bnorthwest\b/i then move("southeast")
else move("#{dir}")
end
else
move("#{@lines[@stackptr].sub(/move /i, '').strip}")
end
MOVE
@@wizard_cmds['exit'] ||= <<-'EXIT'
exit unless @rev == true
EXIT
@@wizard_cmds['shift'] ||= <<-'SHIFT'
@vars.shift
SHIFT
@@wizard_cmds['nextroom'] ||= <<-'NEXTROOM'
roomcount = $room_count
waitfor('\[[^\]]+\]') while roomcount == $room_count
NEXTROOM
end
private :wizard_cmds_init
def Script.namescript_incoming_stable(string)
@@names.each { |script| script.io.push(string) }
@@wakeme.each { |thr|
begin
thr.wakeup
rescue
# @@wakeme.delete(thr)
end
}
nil
end
def Script.shutdown_reap
if Script.self
echo "Uh, this script is trying to shut Lich down (it's tried to execute the `cleanup' method Lich uses just before it quits). This is really of no use to scripts: the method call is being ignored."
sleep 1
return nil
end
Script.index.each { |script| script.kill }
Thread.list.each { |thr|
begin
thr.join(2) if (thr.alive? and thr != Thread.current and thr != Thread.main)
rescue
end
}
nil
end
def Script.wrap_script(fname, iname, cmdline)
Thread.new {
script = Script.new(fname)
catch(:reap) {
begin
pipe = IO.popen("\"#{iname}\" \"#{$script_dir + fname}\" #{cmdline}", "w+")
pipe.sync = true
script.instance_variable_set(:@pipe, pipe)
rescue SystemCallError
respond("--- Lich: #{$!}")
throw :reap
rescue Exception
respond("--- Lich: #{$!}")
throw :reap
rescue
respond("--- Lich: #{$!}")
throw :reap
end
script.set_as_good
script.instance_variable_get(:@dying_procs).push proc { pipe.close unless pipe.closed? }
while line = pipe.gets
if line =~ /^LICH:/
begin
if resp = eval(line.sub(/[^:]+:\s*/, ''), nil, script.name)
pipe.puts resp
end
rescue SyntaxError
respond("--- Lich: #{$!}")
throw :reap
rescue
respond("--- Lich: #{$!}")
throw :reap
end
next