forked from elanthia-online/dr-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common-items.lic
838 lines (742 loc) · 27.9 KB
/
common-items.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
# quiet
=begin
Documentation: https://elanthipedia.play.net/Lich_script_development#common-items
=end
# This module should be 'bottom-level' and only depend on common.
# Any modules that deal with items and <something> should be somewhere else
custom_require.call(%w[common])
module DRCI
module_function
@@trash_storage = %w[basket bin gloop barrel bucket urn log arms stump tree statue chamberpot birdbath turtle]
@@drop_trash_success_patterns = [
/^You drop/,
/^You put/,
/^You spread .* on the ground/,
/smashing it to bits/,
# The next message is when item crumbles when dropped, like a moonblade.
/^As you open your hand to release the/
]
@@drop_trash_failure_patterns = [
/What were you referring to/,
/I could not find/,
/But you aren't holding that/,
/You're kidding, right/,
/You can't do that/,
/No littering/,
/You really shouldn't be loitering/,
# You may get the next message if you've been cursed and unable to let go of items.
# Find a Cleric to uncurse you.
/Oddly, when you attempt to stash it away safely/
]
# Messages that when trying to drop an item you're warned.
# To continue you must retry the command.
@@drop_trash_retry_patterns = [
# You may get the next message if the item would be damaged upon dropping.
/If you still wish to drop it/,
/would damage it/,
# You may get the next messages when an outdated item is updated upon use.
# "Something appears different about the <item>, perhaps try doing that again."
# Example: https://elanthipedia.play.net/Item:Leather_lotion
/Something appears different about/,
/perhaps try doing that again/
]
@@worn_trashcan_verb_patterns = [
/You drum your fingers/,
/You pull a lever/,
/You poke your finger around/
]
@@get_item_success_patterns = [
/You get/,
/You pick/,
/You pluck/,
/You slip/,
/You deftly remove/,
/You are already holding/,
/You fade in for a moment as you/
]
@@get_item_failure_patterns = [
/already in your inventory/,
/You need a free hand/,
/needs to be tended to be removed/,
/You can't pick that up with your hand that damaged/,
/Your (left|right) hand is too injured/,
/You just can't/,
/push you over the item limit/,
/You stop as you realize the .* is not yours/,
/Get what/,
/I could not/,
/What were you/,
/rapidly decays away/,
/cracks and rots away/
]
@@wear_item_success_patterns = [
/You put/,
/You pull/,
/You sling/,
/You attach/,
/You strap/,
/You slide/,
/You spin/,
/You slip/,
/You place/,
/You hang/,
/You tug/,
/You toss one strap/,
/You carefully loop/,
/You work your way into/,
/slide effortlessly onto your/,
/You are already wearing/
]
@@wear_item_failure_patterns = [
/You can't wear/,
/You (need to|should) unload/,
/close the fan/,
/You don't seem to be able to move/,
/Wear what/,
/I could not/,
/What were you/
]
@@remove_item_success_patterns = [
/You remove/,
/You detach/,
/You sling/,
/You slide/,
/You take off/,
/You loosen/,
/You tug/,
/as you remove/,
/Dropping your shoulder/,
/The leather gauntlets slide/,
/Without any effort/,
/you manage to loosen/,
/slide themselves off of your/
]
@@remove_item_failure_patterns = [
/You need a free hand/,
/You aren't wearing/,
/You don't seem to be able to move/,
/Remove what/,
/I could not/,
/What were you/
]
@@put_away_item_success_patterns = [
/^You put your .* in/,
/^You hold out/,
/^You tuck/,
/^You open your pouch and put/,
# The next message is when item crumbles when stowed, like a moonblade.
/^As you open your hand to release the/,
# You're a thief and you binned a stolen item.
/nods toward you as your .* falls into the .* bin/
]
@@put_away_item_failure_patterns = [
/^Stow what/,
/^Please rephrase that command/,
/^What were you referring to/,
/^I could not find what you were referring to/,
/even after stuffing it/,
/is too .* to (fit|hold)/,
/close the fan/,
/no matter how you arrange it/,
/There isn't any more room in/,
/There's no room/,
/to fit in the/,
/too heavy to go in there/,
/You (need to|should) unload/,
/You can't do that/,
/You just can't get/,
/You can't put items/,
/You can only take items out/,
/Perhaps you should be holding that first/,
/Containers can't be placed in/,
/The .* is not designed to carry anything/,
# You may get the next message if you've been cursed and unable to let go of items.
# Find a Cleric to uncurse you.
/Oddly, when you attempt to stash it away safely/
]
# Messages that when trying to put away an item you're warned.
# To continue you must retry the command.
@@put_away_item_retry_patterns = [
# You may get the next messages when an outdated item is updated upon use.
# "Something appears different about the <item>, perhaps try doing that again."
# Example: https://elanthipedia.play.net/Item:Leather_lotion
/Something appears different about/,
/perhaps try doing that again/
]
@@stow_item_success_patterns = [
*@@get_item_success_patterns,
*@@put_away_item_success_patterns
]
@@stow_item_failure_patterns = [
*@@get_item_failure_patterns,
*@@put_away_item_failure_patterns,
]
@@stow_item_retry_patterns = [
*@@put_away_item_retry_patterns
]
@@rummage_success_patterns = [
/You rummage through .* and see (.*)\./,
/In the .* you see (.*)\./,
/there is nothing/i
]
@@rummage_failure_patterns = [
/I could not find/,
/I don't know what you are referring to/,
/What were you referring to/
]
@@open_container_success_patterns = [
/^You open/,
/^You slowly open/,
/^You unbutton/,
/is already open/,
/^You spread your arms, carefully holding your bag well away from your body/
]
@@open_container_failure_patterns = [
/^Please rephrase that command/,
/^What were you referring to/,
/^I could not find what you were referring to/,
/^You don't want to ruin your spell just for that do you/,
/^It would be a shame to disturb the silence of this place for that/,
/^This is probably not the time nor place for that/,
/^There is no way to do that/,
/^You can't do that/
]
@@close_container_success_patterns = [
/^You close/,
/^You quickly close/,
/^You pull/,
/is already closed/
]
@@close_container_failure_patterns = [
/^Please rephrase that command/,
/^What were you referring to/,
/^I could not find what you were referring to/,
/^You don't want to ruin your spell just for that do you/,
/^It would be a shame to disturb the silence of this place for that/,
/^This is probably not the time nor place for that/,
/^There is no way to do that/,
/^You can't do that/
]
@@container_is_closed_patterns = [
/^But that's closed/,
/^That is closed/,
/^While it's closed/
]
#########################################
# TRASH ITEM
#########################################
def dispose_trash(item, worn_trashcan = nil, worn_trashcan_verb = nil)
return if item.nil?
if worn_trashcan
case DRC.bput("put my #{item} in my #{worn_trashcan}", @@drop_trash_retry_patterns, @@drop_trash_success_patterns, @@drop_trash_failure_patterns)
when *@@drop_trash_retry_patterns
return true if dispose_trash(item, worn_trashcan, worn_trashcan_verb)
when *@@drop_trash_success_patterns
DRC.bput("#{worn_trashcan_verb} my #{worn_trashcan}", *@@worn_trashcan_verb_patterns)
DRC.bput("#{worn_trashcan_verb} my #{worn_trashcan}", *@@worn_trashcan_verb_patterns)
return true
end
end
trashcans = DRRoom.room_objs
.reject { |obj| obj =~ /azure \w+ tree/ }
.map { |long_name| DRC.get_noun(long_name) }
.select { |obj| @@trash_storage.include?(obj) }
trashcans.each do |trashcan|
if trashcan == 'gloop'
trashcan = 'bucket' if DRRoom.room_objs.include?('bucket of viscous gloop')
trashcan = 'cauldron' if DRRoom.room_objs.include?('small bubbling cauldron of viscous gloop')
elsif trashcan == 'bucket'
trashcan = 'sturdy bucket' if DRRoom.room_objs.include?('sturdy bucket')
elsif trashcan == 'basket'
trashcan = 'waste basket' if DRRoom.room_objs.include?('waste basket')
elsif trashcan == 'bin'
trashcan = 'waste bin' if DRRoom.room_objs.include?('waste bin')
elsif trashcan == 'arms'
trashcan = 'statue'
elsif trashcan == 'birdbath'
trashcan = 'alabaster birdbath'
elsif trashcan == 'turtle'
trashcan = 'stone turtle'
elsif trashcan == 'tree'
trashcan = 'hollow' if DRRoom.room_objs.include?('dead tree with a darkened hollow near its base')
elsif XMLData.room_title == '[[A Junk Yard]]'
trashcan = 'bin'
end
case DRC.bput("put my #{item} in #{trashcan}", @@drop_trash_success_patterns, @@drop_trash_failure_patterns, @@drop_trash_retry_patterns)
when *@@drop_trash_retry_patterns
# If still didn't dispose of trash after retry
# then don't return yet, will try to drop it later.
return true if dispose_trash(item)
when *@@drop_trash_success_patterns
return true
end
end
# No trash bins or not able to put item in a bin, just drop it.
case DRC.bput("drop my #{item}", @@drop_trash_success_patterns, @@drop_trash_failure_patterns, @@drop_trash_retry_patterns)
when *@@drop_trash_retry_patterns
return dispose_trash(item)
when *@@drop_trash_success_patterns
return true
else
return false
end
end
#########################################
# SEARCH FOR ITEM
#########################################
def search?(item)
/Your .* is in/ =~ DRC.bput("inv search #{item}", 'You can\'t seem to find anything that looks like that', 'Your .* is in')
end
# Taps items to check if you're wearing it.
def wearing?(item)
tap(item) =~ /wearing/
end
# Taps item to determine if it's in the given container.
def inside?(item, container = nil)
tap(item, container) =~ /inside/
end
# Taps an item to confirm it exists.
def exists?(item)
tap(item) =~ /You tap|You (thump|drum) your fingers|The orb is delicate/
end
# Taps an item and returns the match string.
# If no container specified then generically taps whatever's in your immediate inventory.
def tap(item, container = nil)
from = container
from = "from #{container}" if container && !(container =~ /^(in|on|under|behind|from) /i)
DRC.bput("tap my #{item} #{from}", 'You tap .*', 'atop your', 'I could not find', 'on the shoulder', '^You (thump|drum) your fingers', 'The orb is delicate')
end
def in_hands?(item)
in_hand?(item, 'either')
end
def in_left_hand?(item)
in_hand?(item, 'left')
end
def in_right_hand?(item)
in_hand?(item, 'right')
end
# Checks if the item is in one or more hands.
# Hand options are: left, right, either, both.
def in_hand?(item, which_hand = 'either')
return false unless item
if item.is_a?(String)
if item.split.size > 1
item = DRC::Item.new(adjective: item.split.first, name: item.split.last)
else
item = DRC::Item.new(name: item)
end
end
case which_hand.downcase
when 'left'
DRC.left_hand =~ item.short_regex
when 'right'
DRC.right_hand =~ item.short_regex
when 'either'
in_left_hand?(item) || in_right_hand?(item)
when 'both'
in_left_hand?(item) && in_right_hand?(item)
else
DRC.message("Unknown hand: #{which_hand}. Valid options are: left, right, either, both")
false
end
end
def have_item_by_look?(item, container)
return false unless item
item = item.delete_prefix('my ')
preposition = 'in my' if container && !(container =~ /^((in|on|under|behind|from) )?my /i)
case DRC.bput("look at my #{item} #{preposition} #{container}", "#{item}", 'You see nothing unusual', 'I could not find', 'What were you referring to')
when 'You see nothing unusual', "#{item}"
true
else
false
end
end
#########################################
# COUNT ITEMS
#########################################
def count_item_parts(item)
match_messages = [
/and see there (?:is|are) (.+) left\./,
/There (?:is|are) (?:only )?(.+) parts? left/,
/There's (?:only )?(.+) parts? left/,
/There are enough left to create (.+) more/
]
count = 0
$ORDINALS.each do |ordinal|
case DRC.bput("count my #{ordinal} #{item}",
'I could not find what you were referring to.',
'tell you much of anything.',
*match_messages)
when 'I could not find what you were referring to.'
break
when 'tell you much of anything.'
echo "ERROR: count_item_parts called on non-stackable item: #{item}"
count = count_items(item)
break
when *match_messages
count += DRC.text2num(Regexp.last_match(1).tr('-', ' '))
end
waitrt?
end
count
end
def count_items(item)
/inside your (.*).|I could not find/ =~ DRC.bput("tap my #{item}", 'inside your (.*).', 'atop your', 'I could not find')
container = Regexp.last_match(1)
return 0 if container.nil?
count_items_in_container(item, container)
end
def count_items_in_container(item, container)
contents = DRC.bput("rummage /C #{item.split.last} IN MY #{container}", '^You rummage .*', 'That would accomplish nothing')
# This regexp avoids counting the quoted item name in the message, as
# well as avoiding finding the item as a substring of other items.
contents.scan(/ #{item}\W/).size
end
def count_lockpick_container(container)
count = DRC.bput("app my #{container}", 'and it appears to be full', 'and it might hold an additional \d+', '\d+ lockpicks would probably fit').scan(/\d+/).first.to_i
waitrt?
count
end
def get_box_list_in_container(container)
DRC.rummage('B', container)
end
def count_all_boxes(settings)
current_box_count = 0
containers = [
settings.picking_box_source,
settings.pick['picking_box_sources'],
settings.pick['blacklist_container'],
settings.pick['too_hard_container']
].flatten.uniq.reject { |container|
container.to_s.empty?
}.each { |container|
current_box_count += get_box_list_in_container(container).size
}
current_box_count
end
#########################################
# STOW ITEM
#########################################
def stow_hands
(!DRC.left_hand || stow_hand('left')) &&
(!DRC.right_hand || stow_hand('right'))
end
def stow_hand(hand)
braid_regex = /The braided (.+) is too long/
case DRC.bput("stow #{hand}", braid_regex, @@container_is_closed_patterns, @@stow_item_success_patterns, @@stow_item_failure_patterns, @@stow_item_retry_patterns)
when braid_regex
dispose_trash(DRC.get_noun(Regexp.last_match(1)))
when *@@stow_item_retry_patterns
stow_hand(hand)
when *@@stow_item_success_patterns
true
else
false
end
end
#########################################
# GET ITEM
#########################################
# Gets an item unless you are already hold it.
# Use this method to avoid having two of an item
# in your hands when you only want one.
#
# Returns true if the item is in your hand
# or we were able to get it to your hand.
def get_item_if_not_held?(item, container = nil)
return false unless item
return true if in_hands?(item)
return get_item(item, container)
end
# Provide a predicate-named method to follow convention.
def get_item?(item, container = nil)
get_item(item, container)
end
# Gets an item, optionally from a specific container.
# If no container specified then generically grabs from the room/your person.
# Can provide an array of containers to try, too, in case some might be empty.
def get_item(item, container = nil)
if container.is_a?(Array)
container.each do |c|
return true if get_item_safe(item, c)
end
return false
end
get_item_safe(item, container)
end
# Same as 'get_item_unsafe' but ensures that
# the container argument is prefixed with 'my' qualifier.
def get_item_safe?(item, container = nil)
item = "my #{item}" if item && !(item =~ /^my /i)
container = "my #{container}" if container && !(container =~ /^((in|on|under|behind|from) )?my /i)
get_item_unsafe(item, container)
end
def get_item_safe(item, container = nil)
get_item_safe?(item, container)
end
# Gets an item, optionally from a specific container.
# If no container specified then generically grabs from the room/your person.
def get_item_unsafe(item, container = nil)
from = container
from = "from #{container}" if container && !(container =~ /^(in|on|under|behind|from) /i)
case DRC.bput("get #{item} #{from}", @@get_item_success_patterns, @@get_item_failure_patterns)
when *@@get_item_success_patterns
return true
else
return false
end
end
#########################################
# WEAR ITEM
#########################################
# Wears an item from your hands.
def wear_item?(item)
wear_item_safe?(item)
end
# Same as 'wear_item_unsafe?' but ensures that
# the item name is prefixed with 'my' qualifier.
def wear_item_safe?(item)
item = "my #{item}" if item && !(item =~ /^my /i)
wear_item_unsafe?(item)
end
# Wears an item from your hands.
def wear_item_unsafe?(item)
case DRC.bput("wear #{item}", @@wear_item_success_patterns, @@wear_item_failure_patterns)
when *@@wear_item_success_patterns
return true
else
return false
end
end
#########################################
# REMOVE ITEM
#########################################
# Removes an item you're wearing.
def remove_item?(item)
remove_item_safe?(item)
end
# Same as 'remove_item_unsafe?' but ensures that
# the item name is prefixed with 'my' qualifier.
def remove_item_safe?(item)
item = "my #{item}" if item && !(item =~ /^my /i)
remove_item_unsafe?(item)
end
# Removes an item you're wearing.
def remove_item_unsafe?(item)
case DRC.bput("remove #{item}", /You .*#{item}/i, @@remove_item_success_patterns, @@remove_item_failure_patterns)
when /You .*#{item}/i, *@@remove_item_success_patterns
return true
else
return false
end
end
#########################################
# STOW ITEM
#########################################
# Stows an item into its default container. See STORE HELP for details.
# Same as 'stow_item_safe?'.
def stow_item?(item)
stow_item_safe?(item)
end
# Stows an item into its default container. See STORE HELP for details.
# Same as 'stow_item_unsafe?' but ensures that
# the item argument is prefixed with 'my '.
def stow_item_safe?(item)
item = "my #{item}" if item && !(item =~ /^my /i)
stow_item_unsafe?(item)
end
# Stows an item into its default container. See STORE HELP for details.
# Unless you include the 'my ' prefix in the item then this may
# try to stow an item on the ground rather than something in your inventory.
def stow_item_unsafe?(item)
case DRC.bput("stow #{item}", @@container_is_closed_patterns, @@stow_item_success_patterns, @@stow_item_failure_patterns, @@stow_item_retry_patterns)
when *@@stow_item_retry_patterns
return stow_item_unsafe?(item)
when *@@stow_item_success_patterns
return true
else
return false
end
end
#########################################
# LOWER ITEM
#########################################
# Lowers the item to the ground.
# Determines which hand is holding the item then lowers it to your feet slot.
def lower_item?(item)
return false unless in_hands?(item)
item_regex = /\b#{item}\b/
hand = (DRC.left_hand =~ item_regex) ? 'left' : 'right'
DRC.bput("lower ground #{hand}", "You lower", "But you aren't holding anything") =~ /You lower/
end
#########################################
# CHECK CONTAINER CONTENTS
#########################################
# Checks if the container is empty.
# Returns true if certain the container is empty.
# Returns false if certain the container is not empty.
# Returns nil if unable to determine either way (e.g. can't open container or look in it).
def container_is_empty?(container)
look_in_container(container).empty?
end
# Returns a list of item descriptions from the `INVENTORY <type|slot>` verb output.
# Where <type> can be armor, weapon, fluff, container, or combat.
# Where <slot> can be any phrase from INV SLOTS LIST command.
def get_inventory_by_type(type = 'combat', line_count = 40)
case DRC.bput("inventory #{type}", "Use INVENTORY HELP for more options.", "The INVENTORY command is the best way")
when "The INVENTORY command is the best way"
DRC.message("Unrecognized inventory type: #{type}. Valid options are ARMOR, WEAPON, FLUFF, CONTAINER, COMBAT, or any slot from INVENTORY SLOTS LIST.")
return []
end
# Multiple lines may have been printed to the game window,
# grab the last several lines for analysis.
snapshot = reget(line_count)
# Unless you're looking for items at your feet, this is noise.
items_at_feet = snapshot.grep(/(^Lying at your feet)/).any?
# If the snapshot found all the inventory then begin processing.
if snapshot.grep(/^All of your (#{type}|items)|^You aren't wearing anything like that|Both of your hands are empty/).any? && snapshot.grep(/Use INVENTORY HELP/).any?
snapshot
.map(&:strip)
.reverse
.take_while { |line| [/^All of your (#{type}|items)/, /^You aren't wearing anything like that/, /Both of your hands are empty/].none? { |phrase| phrase =~ line } }
.drop_while { |line| !line.start_with?('[Use INVENTORY HELP for more options.]') }
.drop(1)
.reverse
.take_while { |line| !items_at_feet || !line.start_with?('Lying at your feet') }
.map { |item| item.gsub(/^(a|an|some)\s+/, '').gsub(/\s+\(closed\)/, '') }
else
# Otherwise, retry the command. Other actions may have flooded the game window.
get_inventory_by_type(type, line_count + 40)
end
end
# Gets a list of items found in a container via RUMMAGE or LOOK.
# Default is 'rummage' which returns the full item tap descriptions (e.g. some grey ice skates with black laces)
# You can pass in 'LOOK' to get back the short item names, which is easier to parse to know the adjective and noun (e.g. some grey ice skates)
def get_item_list(container, verb = 'rummage')
case verb
when /^(r|rummage)$/i
rummage_container(container)
when /^(l|look)$/i
look_in_container(container)
end
end
# Gets a list of items by RUMMAGE the container.
# Returns a list (empty or otherwise) if able to rummage the container.
# Returns nil if unable to determine if container's contents (e.g. can't open it or rummage it).
def rummage_container(container)
container = "my #{container}" unless container.nil? || container =~ /^my /i
contents = DRC.bput("rummage #{container}", @@container_is_closed_patterns, @@rummage_success_patterns, @@rummage_failure_patterns)
case contents
when *@@rummage_failure_patterns
return nil
when *@@container_is_closed_patterns
return nil unless open_container?(container)
rummage_container(container)
else
contents
.match(/You rummage through .* and see (?:a|an|some) (?<items>.*)\./)[:items]
.split(/(?:, | and )?(?:a|an|some) /)
end
end
# Gets a list of items by LOOK in the container.
# Returns a list (empty or otherwise) if able to look in the container.
# Returns nil if unable to determine if container's contents (e.g. can't open it or look in it).
def look_in_container(container)
container = "my #{container}" unless container.nil? || container =~ /^my /i
contents = DRC.bput("look in #{container}", @@container_is_closed_patterns, @@rummage_success_patterns, @@rummage_failure_patterns)
case contents
when *@@rummage_failure_patterns
return nil
when *@@container_is_closed_patterns
return nil unless open_container?(container)
look_in_container(container)
else
contents
.match(/In the .* you see (?:some|an|a) (?<items>.*)\./)[:items]
.split(/(?:,|and) (?:some|an|a)/)
.map(&:strip)
end
end
#########################################
# PUT AWAY ITEM
#########################################
# Puts away an item, optionally into a specific container.
# If no container specified then uses the default stow location.
# Can provide an array of containers to try, too, in case some might be full.
def put_away_item?(item, container = nil)
if container.is_a?(Array)
container.each do |c|
return true if put_away_item_safe?(item, c)
end
return false
end
put_away_item_safe?(item, container)
end
# Same as 'put_away_item_unsafe?' but ensures that
# the container argument is prefixed with 'my' qualifier.
def put_away_item_safe?(item, container = nil)
item = "my #{item}" if item && !(item =~ /^my /i)
container = "my #{container}" unless container.nil? || container =~ /^my /i
put_away_item_unsafe?(item, container)
end
# Puts away an item, optionally into a specific container.
# If no container specified then uses the default stow location.
def put_away_item_unsafe?(item, container = nil)
command = "put #{item} in #{container}" if container
command = "stow #{item}" unless container
result = DRC.bput(command, @@container_is_closed_patterns, @@put_away_item_success_patterns, @@put_away_item_failure_patterns, @@put_away_item_retry_patterns)
case result
when *@@container_is_closed_patterns
return false unless open_container?(container)
return put_away_item_unsafe?(item, container)
when *@@put_away_item_retry_patterns
return put_away_item_unsafe?(item, container)
when *@@put_away_item_success_patterns
return true
when *@@put_away_item_failure_patterns
return false
else
return false
end
end
#########################################
# OPEN/CLOSE CONTAINERS
#########################################
def open_container?(container)
case DRC.bput("open #{container}", @@open_container_success_patterns, @@open_container_failure_patterns)
when *@@open_container_success_patterns
return true
end
return false
end
def close_container?(container)
case DRC.bput("close #{container}", @@close_container_success_patterns, @@close_container_failure_patterns)
when *@@close_container_success_patterns
return true
end
return false
end
#########################################
# GIVE/ACCEPT ITEM
#########################################
def give_item?(target, item)
# An offer expires after 30 seconds.
# The timeout is set to 35 to give some buffer for clock skew.
case DRC.bput("give my #{item} to #{target}", { 'timeout' => 35 }, "has accepted your offer", "has declined the offer", "Your offer to .* has expired", "You may only have one outstanding offer at a time", "What is it you're trying to give", "There's nothing in your right hand to give away")
when "has accepted your offer"
true
else
false
end
end
# If you accept then returns the name of the person whose offer you accepted. This serves as a "truthy" value, too.
# If you don't, or aren't able to, accept then returns false.
def accept_item?
case DRC.bput("accept", "You accept .* offer and are now holding", "You have no offers", "Both of your hands are full", "would push you over your item limit")
when /You accept (?<name>\w+)'s offer and are now holding/
Regexp.last_match[:name]
else
false
end
end
end