-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbox.lic
1865 lines (1671 loc) · 73.2 KB
/
box.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
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
=begin
Various utilities for handling lockpicking, disarming and boxes -- for those who don't want to fully automate but
would still like some convenience functions. Also has some utility for those getting boxes picked.
Usage:
;box HELP Shows this help text.
;box EMPTY [<container>] Open the currently held box, gather the coins, and empty it into the specified
container (or your default lootsack)
;box GRAB [<container>] Attempts to grab a closed (and presumably locked) box from the specified
inventory container(s), or any inventory container if none are specified.
Separate multiple container names with commas or semicolons.
;box LIST [<container>] List known boxes in the specifed containers(s), or all containers if no
container is specified.
;box STATUS Shows your current lootsack and most recent customer.
;box LOOTSACK [<cont>] Sets/shows your current lootsack. Note that this affects ALL Lich scripts.
;box SCAN LOOKs in all of your containers to attempt to force inventory information
to refresh. Use this if GRAB or LIST are acting up. Will not examine
closed containers, or containers that are in other containers.
;box ACCEPT [WAIT] ACCEPT an offer and remember who offered it. If 'WAIT' is specified, will
wait for an offer if one is not currently pending. Items that do not look
like boxes will not be automatically accepted.
Puts ;box in 'customer mode'
;box JOB Ask the box pool worker for a job.
Puts ;box in 'job mode'
;box RETURN [<player>] Customer mode: Return the box you recently accepted to whoever offered it to you,
or to <player>.
Job mode: Asks the worker to check your work.
;box NEXT [<player>] Customer mode: Does ';box RETURN <player>' and ';box ACCEPT wait', in
that order.
Job mode: Does ';box RETURN' and ';box JOB', in that order.
;box DISARM or DETECT Disarm the currently held box, whatever it happens to be named -- or detect
traps without attempting to disarm.
;box SCARABS [<opts>] Configures the automatic scarab disarming that can happen as part of ;box disarm
Type `;box SCARABS` by itself for more details.
;box UNLOCK [<lockpick>] Unlock the currently held box using the specified lockpick. If <lockpick>
consists of multiple words, this will try to find any matching lockpick,
even if the adjectives do not match the game's adjectives. For instance,
';box vaalin lockpick' will 'a/dark vaalin/lockpick', even though you
would normally need to type 'get my dark lockpick'
If no lockpick is specified, whatever item you are holding (other than the
box) is assumed to be the lockpick you want to use.
;box COMMAND Shows or changes the current command used to pick boxes. Useful for using
lock mastery. Type ;box COMMAND by itself to see more details on this
option.
;box WINDOW [<option>] Configures the lockpicking results window, where <option> is one of:
OFF, ON, SAVE, CLEAR, or SHOW. WINDOW by itself will show the current
configuration. Only available in StormFront. EXPERIMENTAL.
This script is oblivious to items that are in closed containers.
author: LostRanger (thisgenericname@gmail.com)
game: GemStone
tags: lockpicking
required: Lich >= 4.6.0.
version: 0.17 (2020-03-06)
changelog:
version 0.17 (2020-03-06)
* Should no longer stall on open rolls.
version 0.16 (2020-03-03)
* Disarm/detect captures should no longer be confused by something else referencing the box, such as a LOOK ON TABLE in-flight.
* Disarm/detect messaging no longer stalls ;box if the box is already open.
* NPC dialog when acquiring a job with ;box job is now copied to the lockpicking window
* Who you accepted a box from using ;box accept is now copied to the lockpicking window.
version 0.15 (2020-03-02)
* ;box should properly work again when there is no lockpicking window.
version 0.14 (2020-03-02)
* Calipers can now be calibrated with no box target. This will fail if you don't have at least 40 ranks of LM.
* Fix a hang when attempting to calibrate already-calibrated calipers.
* Fix a bug when looking for a box on a nonexistant table.
* `;box empty` and `;box drop will` properly fail out if you aren't holding a box but have one from the pool.
* Added an option to automatically disarm and optionally pick up or loot scarabs, configurable via `;box scarabs`
NOTE: AUTOMATIC LOOTING IS EXPERIMENTAL. IT MAY KILL YOU (but shouldn't.)
version 0.13 (2020-03-01)
* ;box now remembers whether it's working with traditional customer boxes or boxes from the job pool.
`;box job` asks the worker for a job and puts ;box in 'job mode'
`;box accept` puts ;box back in 'customer mode'
`;box next` and `;box return` now interact with the box pool while in job mode:
;box return does ASK <npc> ABOUT CHECK, and ;box next follows that up with ASK <npc> ABOUT JOB.
version 0.12 (2020-03-01)
* Added preliminary support for the box pool. To work, you *may* occasionally need to manually LOOK ON TABLE.
Improved support to come in a later release.
version 0.11 (2019-07-11)
* Fix accidental garbage that breaks the script in Ruby 2.6
version 0.10 (2017-07-21)
* Significantly refactored internal stuff behind the scenes
* `;box measure` now injects the lock difficulty numbers into the measuring output.
* Now supports wearable lockpicks and other tools.
version 0.9 (2017-07-01)
* Added ;box trick <trick> as a convenience shortcut for setting your lockpicking command to use the specified LM trick.
* Added ;box unlock [<lockpick]> which uses the specified lockpick to relock a box (with Lock Mastery)
* Added ;box ignore <container>, which prevents ;box for searching from lockpicks and other tools in that container.
version 0.8.1 (2017-06-23)
* Improved performance of ;box empty so that it should no longer fail the second part while in RT.
version 0.8 (2017-06-21)
* ;box disarm can now accept an item to hold while disarming (like a lockpick or knife)
* ;box return now stores the last used tool like other commands do.
version 0.7 (2017-05-13)
* Possible fix to an issue where lockpick messaging would not always end up in the lockpicking window, and would
be duplicated in the story window instead (Stormfront Only)
* Fix HELP being broken for non-rogues (introduced in 0.6)
version 0.6 (2017-05-12)
* (StormFront only) add experimental support for copying all lockpicking results to a custom window.
* add support for DETECT instead of DISARM
version 0.5 (2017-05-09)
* add support for calipers using ;box measure (to measure) and ;box calipers (to specify is your calipers)
version 0.4 (2017-05-06)
* figure out which lockpick to use before storing the one you were previously holding. Prevents an issue where
the container would be updating as ;box searched for the new lockpick, thus causing it to not finding it.
version 0.3 (2017-05-01)
* now attempts to return your lockpick from whence it came when emptying a box and prior to accepting a new box.
* hides locksmith-specific help from non-locksmiths unless they ask for HELP FULL
* preemptively waitrt in some places to avoid attempting commands that will always fail in roundtime
* improve ;box scan to use INV CONTAINERS
version 0.2 (2017-04-27)
* can now change command used for lockpicking (for use with lockmastery); see ;box COMMAND
version 0.1 (2017-04-22)
* initial release
=end
# Messaging for the future
# You carefully begin to examine...
#
# class XMLFilter
# def initialize(whitelist = ['a'])
# @whitelist = Set.new(whitelist)
# @blacklist_depth = 0
# end
#
#
#
# @output = []
# include REXML::StreamListener
# end
#
# We changed BoxScript from a Class to a Module, but that'll fail if the script was already run once this session
# Fix that.
[Object, Scripting].each{|ns| ns.send(:remove_const, :BoxScript) if ns.constants.include?(:BoxScript) } if defined?(BoxScript)
if CharSettings['command'] and CharSettings[:command].nil?
echo "Migrating settings from an ancient version of box."
CharSettings[:command] = CharSettings['lockpick_command']
CharSettings[:calipers] = CharSettings['calipers']
CharSettings[:window] = CharSettings['window']
CharSettings[:ignored] = CharSettings['ignored']
CharSettings[:customer] = {}
CharSettings['customer'].each{|k, v| CharSettings[:customer][k.intern] = v} if CharSettings['customer']
end
CharSettings[:command] = 'pick $B with $L' unless CharSettings[:command]
CharSettings[:calipers] = 'calipers' unless CharSettings[:calipers]
CharSettings[:window] = 'on' if CharSettings[:window].nil?
CharSettings[:ignored] = Set.new unless CharSettings[:ignored]
CharSettings[:worn] = :first unless CharSettings[:worn]
# We don't want to store this in the DB since it's only relevant for the current session.
#
unless $_box_script_status
$_box_script_status = {
:scanned => false,
:last_tool => nil,
:last_box => nil,
:windowcreated => false,
}
end
module BoxScript
attr_accessor :last_tool, :last_box
VERSION = '0.16 (2020-03-03)'
BOX_NOUNS = %w(box strongbox chest coffer trunk).to_set
unless defined?(LOCK_DIFFICULTIES)
LOCK_DIFFICULTIES = {}
[
'primitive', 'rudimentary', 'extremely easy', 'very easy', 'easy', 'very basic', 'fairly easy', 'simple',
'fairly simple', 'fairly plain', 'moderately well-crafted', 'well-crafted', 'tricky', 'somewhat difficult',
'moderately difficult', 'very well-crafted', 'difficult', 'extremely well-crafted', 'very difficult',
'fairly complicated', 'intricate', 'amazingly well-crafted', 'very complex', 'impressively complicated',
'amazingly intricate', 'extremely difficult', 'extremely complex', 'masterfully well-crafted',
'amazingly complicated', 'astoundingly complex', 'incredibly intricate', 'absurdly well-crafted',
'exceedingly complex', 'absurdly difficult', 'masterfully intricate', 'unbelievably complicated',
'masterfully intricate', 'absurdly complex', 'impossibly complex'
].each_with_index{|k, v|
LOCK_DIFFICULTIES[k] = v
}
end
#echo LOCK_DIFFICULTIES.inspect
class RingBuffer
# Only partially implemented -- just what we use.
def initialize(maxlength)
@maxlength = maxlength
@contents = []
@pos = 0
end
def to_a
# At position 0, or if not full yet, we can return the entire array as-is.
return @contents.dup if @contents.length < @maxlength or @pos == 0
return @contents[@pos..-1] + @contents[0..@pos-1]
end
def push(what)
@contents[@pos] = what
@pos = 0 if (@pos += 1) >= @maxlength
end
end
class ItemResult
attr_reader :item, :container, :ignored, :worn, :held
def initialize(item, container: nil, ignored: false, worn: false, held: false)
@item = item
@container = container
@ignored = ignored
@held = held
@worn = worn
end
def fetch(wait=false)
@item.inspect
return false unless @item
return nil if @held
return nil if BoxScript.hands.find{|x| x.id == @item.id}
waitrt?
if @worn
fput "remove ##{@item.id}"
elsif @container
fput "get ##{@item.id}"
end
wait_until_held if wait
return true
end
def wait_until_held #
while true
return if GameObj.right_hand.id == @item.id or GameObj.left_hand.id == @item.id
waitfor '<right', '<left'
end
end
def wait_until_stored
while true
return unless GameObj.right_hand.id == @item.id or GameObj.left_hand.id == @item.id
waitfor '<right', '<left'
end
end
def store(wait=false)
return false unless @item
return nil if @held
return nil unless BoxScript.hands.find{|x| x.id == @item.id}
waitrt?
if @worn
fput "wear ##{@item.id}"
elsif @container
return false unless GameObj.inv.find{|x| x.id == @container}
fput "put ##{@item.id} in ##{@container}"
end
wait_until_stored if wait
return true
end
end
class StreamWindowBase
def initialize(id)
@buffer = []
@id = id
@exposed = false
end
def created?
false
end
def create(save: false)
# noop
end
def expose
@buffer << "<exposeStream id='#{@id}' />"
end
def write(contents, expose: true)
contents = contents.join('') if contents.is_a?(Array)
end
end
class CustomStreamWindow
def initialize
super('boxresults')
@buffer = []
@id = id
end
def created?
$_box_script_status[:window_created]
end
def create(save: false)
return if created?
window = REXML::Element.new('streamWindow')
window.attributes['id'] = @id
window.attributes['title'] = 'Lockpicking'
window.attributes['ifclosed'] = ''
window.attributes['scroll'] = 'auto'
window.attributes['resident'] = 'true'
window.attributes['save'] = 'save' if save
@buffer << window.to_s
$_box_script_status[:window_created] = true
end
end
def self.get_item_patterns(name, strip_my=true)
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
def self.find_item(what, haystack, strip_my=true, **result_args)
if what.is_a?(String)
what = get_item_patterns(what)
elsif what.is_a?(Regexp)
what = [what]
end
# echo what.inspect
what.each{|pattern|
result = haystack.find{|x| x.name =~ pattern}
return ItemResult.new(result, **result_args) if result
}
return nil
end
def self.find_item_anywhere(name, strip_my=true)
patterns = get_item_patterns(name, strip_my)
result = find_item(patterns, @holding, strip_my, held: true)
return result if result
ignored_result = nil
patterns.each{|pattern|
pattern = [pattern]
if CharSettings[:worn] == :first
result = find_item(pattern, GameObj.inv, strip_my, worn: true)
return result if result
end
GameObj.inv.each{|container|
next unless container.contents and container.contents.length > 0
#echo CharSettings[:ignored].inspect
#echo container.name
if CharSettings[:ignored].include?(container.name)
next if ignored_result
ignored_result = find_item(pattern, container.contents, container: container.id, ignored: true)
next
else
result = find_item(pattern, container.contents, strip_my, container: container.id)
return result if result
end
}
if CharSettings[:worn] == :last
result = find_item(pattern, GameObj.inv, strip_my, worn: true)
return result if result
end
}
# If we're still here, we either haven't found anything (in which case ignored_result is nil)
# Or we've only found something in an ignored container. Return that.
return ignored_result
end
def self.hands
return @holding
end
def self.wait_until_holding(id)
wait_until { GameObj.right_hand.id == id or GameObj.left_hand.id == id }
end
def self.condense
result = @buffer.join('')
@buffer = []
result
end
def self.flush
result = condense
unless result == ''
puts result
end
result
end
def self.find_boxes(contents, want_closed = nil)
return [] unless contents
contents.select {|box|
next(false) unless BOX_NOUNS.include?(box.noun)
next(true) if want_closed == nil
# echo box.contents.inspect
(box.contents == nil) == want_closed
}
end
def self.find_target_box(pool: true, hands: true)
@holding.each{|item| return item if item.id and BOX_NOUNS.include?(item.noun) } if hands
return unless pool
# Options if we're not holding a box, for the box pool system:
# - Check all GameObj.loot for something with the character name ("Akamu's box")
# - Check all GameObj.loot CONTENTS for something with the character name ("Akamu's box")
# - Parse REGET
# - Try looking on things if an NPC is present.
# Bonus: Use mapdb tags?
pattern = /\b#{Char.name}'s (?:.* )?(?:box|strongbox|chest|trunk|coffer)$/
# echo pattern.inspect
if GameObj.loot
GameObj.loot.each do |container|
# echo container.name
return container if container.name =~ pattern
if container.contents
container.contents.each do |item|
# echo ">> #{item.name}"
return item if item.name =~ pattern
end
end
end
end
id = nil
noun = nil
table = nil
reget.each do |xml|
if xml =~ /The <a exist="(\d+)" noun="([^"]+)">[^<]+<\/a> is setup .*? <a exist="(\d+)".*for you.*<d cmd='ASK .* ABOUT CHECK/
id = $1
noun = $2
table = $3
end
end
if id
put "look on ##{table}"
return GameObj.new(id, noun, "#{Char.name}'s #{noun}")
end
# Last-ditch effort using metadata.
table = find_table
return nil unless table
fput "look on ##{table.id}"
return unless table.contents
return table.contents.find{|item| item.name =~ pattern}
return nil
end
def self.get_meta_tag(tag)
rm = Room.current
return nil unless rm and rm.id and rm.tags
if rm.tags.find{|x| x =~ /meta:boxpool:#{tag}:(.+)/}
return $1
elsif rm.tags.find{|x| x == "locksmith pool"}
echo "This room is tagged as being a locksmith pool, but does not have meta:boxpool:#{tag}:<name> set. Please ask someone familiar with the mapdb to fix this."
end
return nil
end
def self.find_table
name = get_meta_tag('table')
return nil unless name
table = GameObj.loot.find{|x| x.name == name}
return table if table
echo "mapdb error: This room is tagged as having '#{table}' as the box pool table, but it does not appear to be present?"
return nil
end
def self.find_npc
name = get_meta_tag('npc')
return nil unless name
npc = GameObj.npcs.find{|x| x.name == name}
return npc if npc
echo "mapdb error: This room is tagged as having '#{npc}' as the box pool NPC, but it does not appear to be present?"
return nil
end
def self.filter_items(items, filters)
unless filters
return items
end
# Convert filter to a list of strings split out by word.
filters = filters.strip.downcase.split(/\s*[,;]\s*/).map! {|text|
text_to_words(text)
}
filters.map {|filter|
item = find_matching_item(items, filter)
unless item
echo "I could not find your '#{filter.join(" ")}'."
return nil
end
item
}
end
def self.cmd_window(args = nil)
unless $frontend == 'stormfront'
echo 'This command is only available in the StormFront FE'
return
end
args = args.downcase.strip if args
case args
when 'on', 'true'
CharSettings[:window] = @window_option = true
echo 'The locksmithing window is now enabled.'
when 'off', 'false'
CharSettings[:window] = @window_option = false
echo 'The locksmithing window is now disabled.'
when 'save'
CharSettings[:window] = @window_option = 'save'
echo 'The locksmithing window is now enabled, and its window location should now persist across sessions.'
when 'show'
unless @window_option
echo 'The locksmithing window is currently disabled, and cannot be shown.'
return
end
expose_window
when 'clear'
unless @created_window
echo "Cannot clear the locksmithing window because it hasn't yet been created."
return
end
@buffer << '<clearStream id="boxresults" />'
when nil
if @window_option
echo 'The locksmithing window is currently enabled.'
if @window_option == 'save'
echo "The locksmithing window's position will hypothetically be saved in Stormfront across sesssions."
end
else
echo 'The locksmithing window is currently disabled.'
end
else
echo 'Subcommand not recognized, expected one of ON, OFF, SAVE, SHOW, or CLEAR.'
end
flush
end
def self.is_locksmith?
Stats.prof == 'Rogue' or Skills.disarmingtraps > 0 or Skills.pickinglocks > 0
end
def self.cmd_help(args = nil)
script = "#{$lich_char}#{@script.name}"
spacer = ''.ljust(script.length, ' ')
msg = []
msg << "#{script} version #{VERSION}"
msg << "Usage:"
msg << ''
msg << " #{script} HELP Shows this help text."
msg << ''
msg << " #{script} EMPTY [<container>] Open the currently held box, gather the coins, and empty it into the specified"
msg << " #{spacer} container (or your default lootsack)"
msg << ''
msg << " #{script} GRAB [<container>] Attempts to grab a closed (and presumably locked) box from the specified "
msg << " #{spacer} inventory container(s), or any inventory container if none are specified."
msg << " #{spacer} Separate multiple container names with commas or semicolons."
msg << ''
msg << " #{script} LIST [<container>] List known boxes in the specifed containers(s), or all containers if no"
msg << " #{spacer} container is specified."
msg << ''
msg << " #{script} STATUS Shows your current lootsack and most recent customer."
msg << ''
msg << " #{script} LOOTSACK [<cont>] Sets/shows your current lootsack. Note that this affects ALL Lich scripts."
msg << ''
msg << " #{script} SCAN LOOKs in all of your containers to attempt to force inventory information"
msg << " #{spacer} to refresh. Use this if GRAB or LIST are acting up. Will not examine"
msg << " #{spacer} closed containers, or containers that are in other containers."
msg << ''
if is_locksmith? or args.downcase == 'full'
msg << " #{script} ACCEPT [WAIT] ACCEPT an offer and remember who offered it. If 'WAIT' is specified, will"
msg << " #{spacer} wait for an offer if one is not currently pending. Items that do not look"
msg << " #{spacer} like boxes will not be automatically accepted."
msg << " #{spacer} Puts ;box in 'customer mode'"
msg << ''
msg << " #{script} JOB Ask the box pool worker for a job."
msg << " #{spacer} Puts ;box in 'job mode'"
msg << ''
msg << " #{script} RETURN [<player>] Customer mode: Return the box you recently accepted to whoever offered it to you,"
msg << " #{spacer} or to <player>."
msg << " #{spacer} Job mode: Asks the worker to check your work."
msg << ''
msg << " #{script} NEXT [<player>] Customer mode: Does '#{script} RETURN <player>' and '#{script} ACCEPT wait', in"
msg << " #{spacer} that order."
msg << " #{spacer} Job mode: Does '#{script} RETURN' and '#{script} JOB', in that order."
msg << ''
msg << " #{script} DETECT Detect traps on the currently held box. Does not attempt to disarm."
msg << ''
msg << " #{script} DISARM [<tool>] Detect or attempt to disarm the current box, optionally using the specified"
msg << " #{spacer} tool. (Specify a tool for traps that require a lockpick or knife to disarm.)"
msg << ''
msg << " #{script} SCARABS [<opts>] Configures the automatic scarab disarming that can happen as part of ;box disarm"
msg << " #{spacer} Type `#{script} SCARABS` by itself for more details."
msg << ''
msg << " #{script} UNLOCK [<lockpick>] Unlock the currently held box using the specified lockpick (or the lockpick"
msg << " #{spacer} currently in your hands). If <lockpick> consists of multiple words, this "
msg << " #{spacer} will try to find any lockpick with the same noun and any matching adjectives,"
msg << " #{spacer} even if those adjectives do not match what the game expects. For instance, "
msg << " #{spacer} '#{script} vaalin lockpick' will grab 'a/dark vaalin/lockpick', even though"
msg << " #{spacer} you would normally need to type 'get my dark lockpick'."
msg << ''
msg << " #{script} RELOCK [<lockpick>] Like UNLOCK, but relocks the box instead using Lock Mastery."
msg << ''
msg << " #{script} FETCH <tool> Fetches the specified tool using the same matching logic as in UNLOCK."
msg << " #{spacer} The tool in question will be remembered and returned stored as normal."
msg << ''
msg << " #{script} STORE Store the tool that was last fetched by returning it to its original location,"
msg << " #{spacer} if known."
msg << ''
msg << " #{script} CHART [<search>] Shows a table of lock difficulties, possibly only those matching <search>."
msg << ''
msg << " #{script} RELOCK [<lockpick>] Like UNLOCK, but relocks the box instead using Lock Mastery."
msg << ''
msg << " #{script} CALIPERS [<item>] Set or show which calipers you are currently using."
msg << ''
msg << " #{script} MEASURE Measure the box you are holding with your calipers."
msg << ''
msg << " #{script} CALIBRATE Calibrate your calipers."
msg << ''
msg << " #{script} DROP Drop your box and return your current tool to where it came from."
msg << ''
msg << " #{script} COMMAND Shows or changes the current command used to pick boxes. Useful for using"
msg << " #{spacer} lock mastery. Type #{script} COMMAND by itself to see more details on this"
msg << " #{spacer} option."
msg << ''
msg << " #{script} TRICK <trick> Sets your lockpicking command to use the specified Lock Mastery trick."
msg << " #{spacer} Type '#{script} TRICK NONE' to reset to 'normal' lockpicking."
msg << ''
msg << " #{script} WINDOW [<option>] Configures the lockpicking results window, where <option> is one of:"
msg << " #{spacer} OFF, ON, SAVE, CLEAR, or SHOW. WINDOW by itself will show the current "
msg << " #{spacer} configuration. Only available in StormFront. EXPERIMENTAL."
msg << ''
msg << " #{script} IGNORE [<what>] Ignore the specified container when searching for lockpicks. Useful"
msg << " #{spacer} for storing your broken lockpicks. Use '#{script} IGNORE' by itself"
msg << " #{spacer} to view the current list."
msg << ''
msg << " #{script} UNIGNORE [<what>] Stop ignoring the specified container when searching for lockpicks."
msg << ''
msg << " #{script} WINDOW [<option>] Configures the lockpicking results window, where <option> is one of:"
msg << " #{spacer} OFF, ON, SAVE, CLEAR, or SHOW. WINDOW by itself will show the current "
msg << " #{spacer} configuration. Only available in StormFront. EXPERIMENTAL."
msg << ''
msg << "#{script} remembers the last tool (lockpick or calipers) that it grabbed and the container that it came from."
msg << "ACCEPT, NEXT, EMPTY, UNLOCK (if specifying a lockpick) and MEASURE will all return the tool to that same"
msg << "container if you are still holding the tool and still wearing the container."
else
msg << "The above options are most useful for all characters. For commands primarily of interest to those who"
msg << "are opening boxes, see #{script} HELP FULL."
msg << "[Rogues and characters with at least one rank of Lockpicking or Disarming will always see the full help]"
end
msg << ''
msg << "This script is oblivious to items that are in closed containers."
msg << ''
respond msg.join("\n")
cmd_status
end
def self.inject_info(line)
line.gsub!(/Measuring carefully, it looks to be an? (.+) lock\./){|match|
n = LOCK_DIFFICULTIES[$1]
next(line) unless n
n *= 40
"#{$&} (Between -#{n == 0 ? 5 : n} and -#{n+35}.)"
}
return line
end
def self.time_delta(timestamp)
diff = (DateTime.now - timestamp)
if diff < 0 # ???
return "at some point in the wibbly-wobbly timey-wimey future"
elsif (diff * 86400) < 5
return "moments ago"
elsif (diff * 86400) < 90
return "#{(diff * 86400).to_i} seconds ago"
elsif (diff * 1440) < 2
return "about a minute ago"
elsif (diff * 1440) < 90
return "about #{(diff * 1440).to_i} minutes ago"
end
return "at #{timestamp}"
end
def self.cmd_status(args = nil)
cmd_lootsack(nil)
cmd_scarab('status')
if CharSettings[:mode] == :customer
cust = CharSettings[:customer]
if cust
ago = time_delta(cust[:when])
respond "Currently in CUSTOMER mode. Your most recent customer was #{cust[:name]}, who offered you #{cust[:box]} #{ago}."
else
respond "Currently in CUSTOMER mode. You have no recorded recent customers."
end
elsif CharSettings[:mode] == :job
if CharSettings[:job_started]
ago = time_delta(CharSettings[:job_started])
respond "Currently in JOB mode. You started this job #{ago}."
else
respond "Currently in JOB mode. You started this job at an unknown time."
end
end
end
def self.cmd_command(args)
unless args
respond "Your current lockpicking command is: #{CharSettings[:command]}"
respond
respond "To change it, use '#{$lich_char}#{@script.name} COMMAND command to send', using '$L' in place of your"
respond "lockpick and '$B' in place of your box. Some examples:"
respond
respond "#{$lich_char}#{@script.name} COMMAND pick $B with $L"
respond "#{$lich_char}#{@script.name} COMMAND lmas ptrick spin $B"
respond
respond "Note: do not use MY in these commands, as an exact reference to the target box and pick is already supplied";
else
respond "Your lockpicking command has been changed to: #{args}."
CharSettings[:command] = args
end
end
def self.cmd_ptrick(args)
unless args
respond "Your current lockpicking command is: #{CharSettings[:command]}"
respond
respond "To configure #{$lich_char}#{@script.name} to use a particular trick, type:"
respond " #{$lich_char}#{@script.name} TRICK <trick>"
respond "Where <trick> is the name of a lockmastery trick. Use 'none' to revert to 'standard' lockpicking."
respond
respond "For more advanced options regarding your lockpicking command, see #{$lich_char}#{@script.name} COMMAND"
else
if args.strip.downcase =~ /^(?:none|clear)$/
cmd_command('pick $B with $L')
else
cmd_command("lmaster ptrick #{args} $B")
end
end
end
def self.cmd_accept(args, store=true)
$_box_script_status[:last_tool].store
unless CharSettings[:mode] == :customer
CharSettings[:mode] = :customer
echo "Switching to CUSTOMER mode."
end
wait = false
waiting = false
if args
if args.downcase == "wait"
wait = true
else
echo "Use #{$lich_char}#{@script.name} ACCEPT to accept an offer, or #{$lich_char}#{@script.name} ACCEPT WAIT to wait for an offer if needed."
return
end
end
waitrt?
fput 'accept'
loop {
line = get
if line == 'You have no offers to accept.'
if wait
waiting = true
else
echo "Use #{$lich_char}#{@script.name} ACCEPT WAIT to wait for an offer before accepting."
return
end
end
if line =~ /(You accept <a exist="-?\d+" noun="([^"]+)">.+<\/a> offer and are now holding (?:(.*) )?<a exist="(-?\d+)" noun="([^"]+)">(?:(.*) )?(?:box|strongbox|coffer|chest|trunk)<\/a>\.)/
message = $1
customer = $2
article = $3
exist = $4
noun = $5
adjective = $6
box_name = [article, adjective, noun].find_all{|x| x}.join(' ')
CharSettings[:customer] = {
:name => customer,
:article => article,
:adjective => adjective,
:noun => noun,
:when => DateTime.now,
:box => box_name
}
box = GameObj.new(exist, noun, "#{adjective} #{noun}".strip)
echo "Accepted #{box_name} from #{$2}."
return unless window_allowed?
checknewbox(box)
write_window($1)
write_window("\n")
_respond condense
return
end
if waiting and line =~ /^<a.*\/a> offers you .* (?:box|strongbox|coffer|chest|trunk)<\/a>.* The offer will expire in 30 seconds.$/
waitrt?
fput 'accept'
end
}
end
def self.cmd_job(args=nil, store=true)
$_box_script_status[:last_tool].store
npc = find_npc
unless npc
echo "I can't find the NPC to talk to. Either you're in the wrong room or map metadata may need to be updated."
return false
end
unless CharSettings[:mode] == :job
CharSettings[:mode] = :job
echo "Switching to JOB mode."
end
fput "ask ##{npc.id} about job"
return unless window_allowed?
nil until get =~ /(?:(<pushBold\/>.*<a exist="#{npc.id}".*says, "(?:.*The <a exist="(\d+)" noun="(.*)"|^\s*|.*))|ASK {entity} ABOUT\/FOR\/TO {subject})/
return unless $2
fput "look on table"
box = find_target_box(hands: false)
return unless box
checknewbox(box)
write_window($1)
write_window("\n")
_respond condense
CharSettings[:job_started] = DateTime.now
end
def self.window_allowed?
$frontend == 'stormfront' and @window_option
end
def self.checknewbox(box)
return unless window_allowed?
if box.id != $_box_script_status[:last_box].id
write_window("\n<style id=\"roomName\" />[#{box.name}]\n<style id=\"\" />")
$_box_script_status[:last_box] = box
end
end
def self.resolve_containers(args)
if args
items = filter_items(GameObj.inv, args)
return unless items
else
items = GameObj.inv
end
containers = {}
items.each {|x|
containers[x.id] = x.contents if x.contents != nil
}
return containers
#
# return GameObj.containers
end
def self.cmd_return(name = nil)
$_box_script_status[:last_tool].store
case CharSettings[:mode]
when :customer
unless CharSettings[:customer]
echo "I don't have anybody to return something to."
return false
end
# echo CharSettings['customer'].inspect
c = CharSettings[:customer]
name = c[:name] unless name
waitrt?
fput "give my #{c[:noun]} to #{name}" #FIXME
when :job
npc = find_npc
unless npc
echo "I can't find the NPC to talk to. Either you're in the wrong room or map metadata may need to be updated."
return false
end
fput "ask ##{npc.id} about check"
else
echo "Unknown mode #{CharSettings[:mode]}"
return false
end
return true
end
def self.cmd_next(name = nil)
return unless cmd_return(name)
case CharSettings[:mode]
when :customer
cmd_accept('wait', false)
when :job
cmd_job
else
echo "Unknown mode #{CharSettings[:mode]}"
return false
end
#
# unless CharSettings[:customer] or CharSettings[:mode] == :job
# echo "I don't have anybody to return something to."
# return
# end
# return_command(name)
end
def self.cmd_list(args)
containers = resolve_containers(args)
return unless containers
boxes = {true => {}, false => {}}
containers.each {|id, contents|
find_boxes(contents).each {|box|
closed = (box.contents == nil)
if boxes[closed][id] == nil
boxes[closed][id] = []
end
boxes[closed][id].push(box)
}
}
count = boxes[true].reduce(0) {|memo, (exist, contents)| memo + contents.length}
if count > 0
if count > 1
respond "Found #{count} apparently closed (and presumably locked) boxes:"
else
respond "Found #{count} apparently closed (and presumably locked) box:"
end
GameObj.inv.each {|container|
next unless boxes[true][container.id]
writelink("In your ", container, ":")