Module: Lich::DragonRealms::DRCI

Defined in:
documented/dragonrealms/commons/common-items.rb

Constant Summary collapse

TRASH_STORAGE =

How to add new trash receptacles github.com/elanthia-online/dr-scripts/wiki/Adding-new-trash-receptacles List of trash receptacles This constant holds the various types of trash receptacles available in the game.

%w[arms barrel basin basket bin birdbath bucket chamberpot gloop hole log puddle statue stump tangle tree turtle urn gelapod]
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 leaves your hand, like a moonblade.
  /^As you open your hand to release the/,
  /^You toss .* at the domesticated gelapod/,
  /^You feed .* a bit warily to the domesticated gelapod/
]
DROP_TRASH_FAILURE_PATTERNS =
[
  /^What were you referring to/,
  /^I could not find/,
  /^But you aren't holding that/,
  /^Perhaps you should be holding that first/,
  /^You're kidding, right/,
  /^You can't do that/,
  /No littering/, # A guard steps over to you and says, "No littering in the bank."
  /^Where do you want to put that/,
  /^You really shouldn't be loitering/,
  /^You don't seem to be able to move/,
  # 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/,
  /^You need something in your right hand/,
  /^You can't put that there/,
  /^The domesticated gelapod glances warily at/, # deeds
  /^You should empty it out, first./ # container with items
]
DROP_TRASH_RETRY_PATTERNS =

Messages that when trying to drop an item you’re warned. To continue you must retry the command.

[
  # 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 draw (?!\w+'s wounds)/i,
  /^You get/,
  /^You pick/,
  /^You pluck/,
  /^You slip/,
  /^You scoop/,
  /^You deftly remove/,
  /^You are already holding/,
  /^You fade in for a moment as you/,
  /^You carefully lift/,
  /^You carefully remove .* from the bundle/,
  /^With a flick of your wrist, you stealthily unsheath/
]
GET_ITEM_FAILURE_PATTERNS =
[
  /^A magical force keeps you from grasping/,
  /^You'll need both hands free/,
  /^You need both hands free/,
  /^You need a free hand/,
  /^You can't pick that up with your hand that damaged/,
  /^Your (left|right) hand is too injured/,
  /^You just can't/,
  /^You stop as you realize the .* is not yours/,
  /^You can't reach that from here/, # on a mount like a flying carpet
  /^You don't seem to be able to move/,
  /^You should untie/,
  /^You can't do that/,
  /^Get what/,
  /^I could not/,
  /^What were you/,
  /already in your inventory/, # wearing it
  /needs to be tended to be removed/, # ammo lodged in you
  /push you over the item limit/, # you're at item capacity
  /rapidly decays away/, # item disappears when try to get it
  /cracks and rots away/, # item disappears when try to get it
  /^You should stop practicing your Athletics skill before you do that/
]
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 struggle/,
  /^You squeeze/,
  /^You manage/,
  /^You gently place/,
  /^You toss one strap/,
  /^You carefully loop/,
  /^You work your way into/,
  /^You are already wearing/,
  /^Gritting your teeth, you grip/,
  /^You expertly sling the/,
  /put it on/, # weird clerical collar thing, trying to make it a bit generic
  /slide effortlessly onto your/,
  /^You carefully arrange/,
  /^A brisk chill rushes through you as you wear/, # some hiro bearskin gloves interlaced with strips of ice-veined leather
  /^You drape/,
  /You lean over and slip your feet into the boots./, # a pair of weathered barkcloth boots lined in flannel,
  /^You reach down and step into/, # pair of enaada boots clasped by asharsh'dai
  /Gritting your teeth/ # Gritting your teeth, you grip each of your heavy combat boots in turn by the straps, and drive your feet into them for a secure fit.
]
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/
]
TIE_ITEM_SUCCESS_PATTERNS =
[
  /^You .* tie/,
  /^You attach/
]
TIE_ITEM_FAILURE_PATTERNS =
[
  /^You don't seem to be able to move/,
  /^There's no more free ties/,
  /^You must be holding/,
  /doesn't seem to fit/,
  /close the fan/,
  /^You are a little too busy/,
  /^Your wounds hinder your ability to do that/,
  /^Tie what/
]
UNTIE_ITEM_SUCCESS_PATTERNS =
[
  /^You remove/,
  /You untie/i
]
UNTIE_ITEM_FAILURE_PATTERNS =
[
  /^You don't seem to be able to move/,
  /^You fumble with the ties/,
  /^Untie what/,
  /^What were you referring/
]
REMOVE_ITEM_SUCCESS_PATTERNS =
[
  /^Dropping your shoulder/,
  /^The .* slide/,
  /^Without any effort/,
  /^You .* slide/,
  /^You detach/,
  /^You loosen/,
  /^You pull/,
  /^You.*remove/,
  /^You slide/,
  /^You sling/,
  /^You slip/,
  /^You struggle/,
  /^You take/,
  /you tug/i,
  /^You untie/,
  /as you remove/,
  /slide themselves off of your/,
  /you manage to loosen/,
  /you unlace/,
  /^You slam the heels/,
  /^With masterful grace, you ready/
]
REMOVE_ITEM_FAILURE_PATTERNS =
[
  /^You'll need both hands free/,
  /^You need a free hand/,
  /^You aren't wearing/,
  /^You don't seem to be able to move/,
  /^Remove what/,
  /^I could not/,
  /^Grunting with momentary exertion/, # Grunting with momentary exertion, you grip each of your heavy combat boots in turn by the heel, and pull them off.
  /^What were you/
]
PUT_AWAY_ITEM_SUCCESS_PATTERNS =
[
  /^You put your .* in/,
  /^You hold out/,
  /^You stuff/,
  /^You tuck/,
  /^You open your pouch and put/,
  /^You guide your/i, # puppy storage
  /^You hang/, # frog belt
  /^You nudge your/i, # monkey storage
  # 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/,
  /^You add/,
  /^You rearrange/,
  /^You combine the stacks/,
  /^You secure/,
  # The following are success messages for putting an item in a container OFF your person.
  /^You drop/i,
  /^You set/i,
  /You put/i,
  /^You carefully fit .* into your bundle/,
  /^You slip/,
  /^You easily strap/,
  /^You gently set/,
  /^With a flick of your wrist, you stealthily sheath/,
  /^You strap your .* to your harness/,
  /^You toss .* into/ # You toss the alcohol into the bowl and mix it in thoroughly
]
PUT_AWAY_ITEM_FAILURE_PATTERNS =
[
  /^Stow what/,
  /^I can't find your container for stowing things in/,
  /^Please rephrase that command/,
  /^What were you referring to/,
  /^I could not find what you were referring to/,
  /^There isn't any more room in/,
  /^There's no room/,
  /^(The|That).* 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/,
  /^You don't seem to be able to move/,
  /^Perhaps you should be holding that first/,
  /^Containers can't be placed in/,
  /^The .* is not designed to carry anything/,
  /^You can't put that.*there/,
  /^Weirdly, you can't manage .* to fit/,
  /^\[Containers can't be placed in/,
  /even after stuffing it/,
  /is too .* to (fit|hold)/,
  /no matter how you arrange it/,
  /close the fan/,
  /to fit in the/,
  /doesn't seem to want to leave you/, # trying to put a pet in a home within a container
  # 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/,
  /completely full/,
  /That doesn't belong in there!/,
  /exerts a steady force preventing/
]
PUT_AWAY_ITEM_RETRY_PATTERNS =

Messages that when trying to put away an item you’re warned. To continue you must retry the command.

[
  # 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 =
[
  /^You don't seem to be able to move/,
  /^I could not find/,
  /^I don't know what you are referring to/,
  /^What were you referring to/
]
TAP_SUCCESS_PATTERNS =
[
  /^You tap\s(?!into).*/, # The `.*` is needed to capture entire phrase. Methods parse it to know if an item is worn, stowed, etc.
  /^You (thump|drum) your finger/, # You tapped an item with fancy verbiage, ohh la la!
  /^As you tap/, # As you tap a large ice-veined leather and flamewood surveyor's case
  /^The orb is delicate/, # You tapped a favor orb
  /^You .* on the shoulder/, # You tapped someone
  /^You suddenly forget what you were doing/ # "tap my tessera" messaging when hands are full
]
TAP_FAILURE_PATTERNS =
[
  /^You don't seem to be able to move/,
  /^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/,
  /^The .* opens/,
  /^You unbutton/,
  /(It's|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/,
  /^You don't seem to be able to move/,
  /^There is no way to do that/,
  /^You can't do that/,
  /^Open what/
]
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/,
  /^You don't seem to be able to move/,
  /^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/
]
LOWER_SUCCESS_PATTERNS =
[
  /^You lower/,
  # The next message is when item crumbles when leaves your hand, like a moonblade.
  /^As you open your hand to release the/
]
LOWER_FAILURE_PATTERNS =
[
  /^You don't seem to be able to move/,
  /^But you aren't holding anything/,
  /^Please rephrase that command/,
  /^What were you referring to/,
  /^I could not find what you were referring to/
]
LIFT_SUCCESS_PATTERNS =
[
  /^You pick up/
]
LIFT_FAILURE_PATTERNS =
[
  /^There are no items lying at your feet/,
  /^What did you want to try and lift/,
  /can't quite lift it/,
  /^You are not strong enough to pick that up/
]
GIVE_ITEM_SUCCESS_PATTERNS =
[
  /has accepted your offer/,
  /your ticket and are handed back/,
  /Please don't lose this ticket!/,
  /^You hand .* gives you back a repair ticket/,
  /^You hand .* your ticket and are handed back/
]
GIVE_ITEM_FAILURE_PATTERNS =
[
  /I don't repair those here/,
  /There isn't a scratch on that/,
  /give me a few more moments/,
  /I will not repair something that isn't broken/,
  /I can't fix those/,
  /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/,
  /Lucky for you!  That isn't damaged!/
]

Class Method Summary collapse

Class Method Details

.accept_item?String, false

Accepts an item offer from a target.

Examples:

accept_item?

Returns:

  • (String, false)

    Returns the name of the item accepted or false if no offer was accepted.



1364
1365
1366
1367
1368
1369
1370
1371
# File 'documented/dragonrealms/commons/common-items.rb', line 1364

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

.close_container?(container) ⇒ Boolean

Closes a specified container.

Examples:

close_container?("chest")

Parameters:

  • container (String)

    The container to close.

Returns:

  • (Boolean)

    Returns true if the container was closed successfully, false otherwise.



1318
1319
1320
1321
1322
1323
1324
# File 'documented/dragonrealms/commons/common-items.rb', line 1318

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

.container_is_empty?(container) ⇒ Boolean

Checks if a specified container is empty.

Examples:

container_is_empty?("chest")

Parameters:

  • container (String)

    The container to check.

Returns:

  • (Boolean)

    Returns true if the container is empty, false otherwise.



1140
1141
1142
# File 'documented/dragonrealms/commons/common-items.rb', line 1140

def container_is_empty?(container)
  look_in_container(container).empty?
end

.count_all_boxes(settings) ⇒ Integer

Counts all boxes across various specified sources.

Examples:

count_all_boxes(settings)

Parameters:

  • settings (Object)

    The settings object containing box sources.

Returns:

  • (Integer)

    Returns the total count of boxes found.



787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
# File 'documented/dragonrealms/commons/common-items.rb', line 787

def count_all_boxes(settings)
  current_box_count = 0

  [
    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

.count_item_parts(item) ⇒ Integer

Counts the number of parts left of a specified item.

Examples:

count_item_parts("wood")

Parameters:

  • item (String)

    The item to count parts of.

Returns:

  • (Integer)

    Returns the number of parts left.



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
# File 'documented/dragonrealms/commons/common-items.rb', line 683

def count_item_parts(item)
  match_messages = [
    /and see there (?:is|are) (.+) left\./,
    /There (?:is|are) (?:only )?(.+) parts? left/,
    /There's (?:only )?(.+) parts? left/,
    /The (?:.+) has (.+) uses remaining./,
    /There are enough left to create (.+) more/,
    /You count out (.+) pieces? of material there/,
    /There (?:is|are) (.+) scrolls? left for use with crafting/
  ]
  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
      countval = Regexp.last_match(1).tr('-', ' ')
      if countval.match?(/\A\d+\z/)
        count += Integer(countval)
      else
        count += DRC.text2num(countval)
      end
    end
    waitrt?
  end
  count
end

.count_items(item) ⇒ Integer

Counts the number of specified items in the inventory.

Examples:

count_items("arrows")

Parameters:

  • item (String)

    The item to count.

Returns:

  • (Integer)

    Returns the count of items found.



723
724
725
726
727
728
729
# File 'documented/dragonrealms/commons/common-items.rb', line 723

def count_items(item)
  /inside your (.*)/ =~ tap(item)
  container = Regexp.last_match(1)
  return 0 if container.nil?

  count_items_in_container(item, container)
end

.count_items_in_container(item, container) ⇒ Integer

Counts the number of specified items in a given container.

Examples:

count_items_in_container("gems", "pouch")

Parameters:

  • item (String)

    The item to count.

  • container (String)

    The container to check.

Returns:

  • (Integer)

    Returns the count of items found in the container.



737
738
739
740
741
742
# File 'documented/dragonrealms/commons/common-items.rb', line 737

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

.count_lockpick_container(container) ⇒ Integer

Counts the number of lockpicks that can fit in a specified container.

Examples:

count_lockpick_container("lockpick box")

Parameters:

  • container (String)

    The container to check.

Returns:

  • (Integer)

    Returns the number of lockpicks that can fit in the container.



749
750
751
752
753
# File 'documented/dragonrealms/commons/common-items.rb', line 749

def count_lockpick_container(container)
  count = DRC.bput("appraise my #{container} quick", /it appears to be full/, /it might hold an additional \d+/, /\d+ lockpicks would probably fit/).scan(/\d+/).first.to_i
  waitrt?
  count
end

.count_necro_stacker(necro_stacker) ⇒ Integer

Counts the number of items in a necromancer’s stacker.

Examples:

count_necro_stacker("necro stacker")

Parameters:

  • necro_stacker (String)

    The necromancer’s stacker to check.

Returns:

  • (Integer)

    Returns the number of items in the stacker.



778
779
780
# File 'documented/dragonrealms/commons/common-items.rb', line 778

def count_necro_stacker(necro_stacker)
  DRC.bput("study my #{necro_stacker}", /currently holds \d+ items/).scan(/\d+/).first.to_i
end

.dispose_trash(item, worn_trashcan = nil, worn_trashcan_verb = nil) ⇒ Boolean

Disposes of a specified trash item into a trash receptacle.

Examples:

dispose_trash("old newspaper")

Parameters:

  • item (String)

    The item to be disposed of.

  • worn_trashcan (String, nil) (defaults to: nil)

    The name of the worn trashcan, if any.

  • worn_trashcan_verb (String, nil) (defaults to: nil)

    The verb associated with the worn trashcan.

Returns:

  • (Boolean)

    Returns true if the item was successfully disposed of, false otherwise.



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
# File 'documented/dragonrealms/commons/common-items.rb', line 427

def dispose_trash(item, worn_trashcan = nil, worn_trashcan_verb = nil)
  return unless item
  return unless DRCI.get_item_if_not_held?(item)

  if worn_trashcan
    case DRC.bput("put my #{item} in my #{worn_trashcan}", DROP_TRASH_SUCCESS_PATTERNS, DROP_TRASH_FAILURE_PATTERNS, DROP_TRASH_RETRY_PATTERNS, /^Perhaps you should be holding that first/)
    when *DROP_TRASH_SUCCESS_PATTERNS
      if worn_trashcan_verb
        DRC.bput("#{worn_trashcan_verb} my #{worn_trashcan}", *WORN_TRASHCAN_VERB_PATTERNS)
        DRC.bput("#{worn_trashcan_verb} my #{worn_trashcan}", *WORN_TRASHCAN_VERB_PATTERNS)
      end
      return true
    when *DROP_TRASH_FAILURE_PATTERNS
      # NOOP, try next trashcan option
    when *DROP_TRASH_RETRY_PATTERNS
      return DRCI.dispose_trash(item, worn_trashcan, worn_trashcan_verb)
    when /^Perhaps you should be holding that first/
      return (DRCI.get_item?(item) && DRCI.dispose_trash(item, worn_trashcan, worn_trashcan_verb))
    end
  end

  # Check for meta:trashcan tag on the room to identify a specific trashcan to use.
  if Room.current.tags.find { |t| t =~ /meta:trashcan:(.*)/ }
    metatag_trashcan = Regexp.last_match(1)

    # Gelapod needs special handling since you feed it, and it disappears in winter
    metatag_trash_command = nil
    if metatag_trashcan == 'gelapod'
      metatag_trash_command = "feed my #{item} to gelapod" if DRRoom.room_objs.include?('gelapod')
    else
      metatag_trash_command = "put my #{item} in #{metatag_trashcan}"
    end

    # gelapod is not here - probably winter move on to next attempt to get rid of
    unless metatag_trash_command.nil?
      case DRC.bput(metatag_trash_command, DROP_TRASH_SUCCESS_PATTERNS, DROP_TRASH_FAILURE_PATTERNS, DROP_TRASH_RETRY_PATTERNS, /^Perhaps you should be holding that first/)
      when *DROP_TRASH_SUCCESS_PATTERNS
        return true
      when *DROP_TRASH_FAILURE_PATTERNS
        # NOOP, try next trashcan option
      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 dispose_trash(item)
      when /^Perhaps you should be holding that first/
        return (DRCI.get_item?(item) && DRCI.dispose_trash(item))
      end
    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')
      trashcan = 'small bin' if DRRoom.room_objs.include?('small bin concealed with some nearby brush')
    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 trashcan == 'basin'
      trashcan = 'stone basin' if DRRoom.room_objs.include?('hollow stone basin')
    elsif trashcan == 'tangle'
      trashcan = 'dark gap' if DRRoom.room_objs.include?('tangle of thick roots forming a dark gap')
    elsif XMLData.room_title == '[[A Junk Yard]]'
      trashcan = 'bin'
    elsif trashcan == 'gelapod'
      trash_command = "feed my #{item} to gelapod"
    end

    trash_command = "put my #{item} in #{trashcan}" unless trashcan == 'gelapod'

    case DRC.bput(trash_command, DROP_TRASH_SUCCESS_PATTERNS, DROP_TRASH_FAILURE_PATTERNS, DROP_TRASH_RETRY_PATTERNS, /^Perhaps you should be holding that first/)
    when *DROP_TRASH_SUCCESS_PATTERNS
      return true
    when *DROP_TRASH_FAILURE_PATTERNS
      # NOOP, try next trashcan option
    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 /^Perhaps you should be holding that first/
      return (DRCI.get_item?(item) && DRCI.dispose_trash(item))
    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, /^Perhaps you should be holding that first/, /^But you aren't holding that/)
  when *DROP_TRASH_SUCCESS_PATTERNS
    return true
  when *DROP_TRASH_FAILURE_PATTERNS
    return false
  when *DROP_TRASH_RETRY_PATTERNS
    return dispose_trash(item)
  when /^Perhaps you should be holding that first/, /^But you aren't holding that/
    return (DRCI.get_item?(item) && DRCI.dispose_trash(item))
  else
    # failure of match patterns in the bput, but still need to return a value
    return false
  end
end

.exists?(item, container = nil) ⇒ Boolean

Checks if a specified item exists in the inventory or container.

Examples:

exists?("potion")

Parameters:

  • item (String)

    The item to check for.

  • container (String, nil) (defaults to: nil)

    The container to check inside.

Returns:

  • (Boolean)

    Returns true if the item exists, false otherwise.



580
581
582
583
584
585
586
587
# File 'documented/dragonrealms/commons/common-items.rb', line 580

def exists?(item, container = nil)
  case tap(item, container)
  when *TAP_SUCCESS_PATTERNS
    true
  else
    false
  end
end

.fill_gem_pouch_with_container(gem_pouch_adjective, gem_pouch_noun, source_container, full_pouch_container = nil, spare_gem_pouch_container = nil, should_tie_gem_pouches = false) ⇒ void

This method returns an undefined value.

Fills a specified gem pouch with items from a container.

Examples:

fill_gem_pouch_with_container("yellow", "gem pouch", "bag")

Parameters:

  • gem_pouch_adjective (String)

    The adjective describing the gem pouch.

  • gem_pouch_noun (String)

    The noun describing the gem pouch.

  • source_container (String)

    The container to fill the pouch from.

  • full_pouch_container (String, nil) (defaults to: nil)

    The container holding the full pouch.

  • spare_gem_pouch_container (String, nil) (defaults to: nil)

    The container holding the spare pouch.

  • should_tie_gem_pouches (Boolean) (defaults to: false)

    Whether to tie the gem pouches.



1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
# File 'documented/dragonrealms/commons/common-items.rb', line 1451

def fill_gem_pouch_with_container(gem_pouch_adjective, gem_pouch_noun, source_container, full_pouch_container = nil, spare_gem_pouch_container = nil, should_tie_gem_pouches = false)
  Flags.add("pouch-full", /is too full to fit any more/)
  case DRC.bput("fill my #{gem_pouch_adjective} #{gem_pouch_noun} with my #{source_container}",
                /^You open/,
                /is too full to fit/,
                /^You'd better tie it up before putting/,
                /You'll need to tie it up before/,
                /Please rephrase that command/,
                'What were you referring to',
                "There aren't any gems",
                'You fill your')
  when /Please rephrase that command/
    DRC.message("Container #{source_container} not found. Skipping fill")
    return
  when /^You'd better tie it up before putting/, /You'll need to tie it up before/
    # This is equivalent to a full pouch, unless we should tie pouches, in which case we tie and retry
    unless should_tie_gem_pouches
      unless swap_out_full_gempouch?(gem_pouch_adjective, gem_pouch_noun, full_pouch_container, spare_gem_pouch_container, should_tie_gem_pouches)
        DRC.message("Could not swap gem pouches.")
        return
      end
      fill_gem_pouch_with_container(gem_pouch_adjective, gem_pouch_noun, source_container, full_pouch_container, spare_gem_pouch_container, should_tie_gem_pouches)
    end
    tie_gem_pouch(gem_pouch_adjective, gem_pouch_noun) if should_tie_gem_pouches
    fill_gem_pouch_with_container(gem_pouch_adjective, gem_pouch_noun, source_container, full_pouch_container, spare_gem_pouch_container, should_tie_gem_pouches)
  end
  if Flags["pouch-full"]
    unless swap_out_full_gempouch?(gem_pouch_adjective, gem_pouch_noun, full_pouch_container, spare_gem_pouch_container, should_tie_gem_pouches)
      DRC.message("Could not swap gem pouches.")
      return
    end
    fill_gem_pouch_with_container(gem_pouch_adjective, gem_pouch_noun, source_container, full_pouch_container, spare_gem_pouch_container, should_tie_gem_pouches)
    tie_gem_pouch(gem_pouch_adjective, gem_pouch_noun) if should_tie_gem_pouches
    Flags.reset("pouch-full")
  end
end

.get_box_list_in_container(container) ⇒ Array

Retrieves a list of boxes in a specified container.

Examples:

get_box_list_in_container("chest")

Parameters:

  • container (String)

    The container to check.

Returns:

  • (Array)

    Returns an array of box names found in the container.



760
761
762
# File 'documented/dragonrealms/commons/common-items.rb', line 760

def get_box_list_in_container(container)
  DRC.rummage('B', container)
end

.get_inventory_by_type(type = 'combat', line_count = 40) ⇒ Array

Retrieves the inventory of a specified type.

Examples:

get_inventory_by_type("combat")

Parameters:

  • type (String) (defaults to: 'combat')

    The type of inventory to retrieve (e.g., ‘combat’).

  • line_count (Integer) (defaults to: 40)

    The number of lines to retrieve from the inventory.

Returns:

  • (Array)

    Returns an array of items in the specified inventory type.



1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
# File 'documented/dragonrealms/commons/common-items.rb', line 1150

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/, /You can't do that/)
  when /The INVENTORY command is the best way/, /You can't do that/
    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

.get_item(item, container = nil) ⇒ Boolean

Retrieves a specified item from a container or inventory.

Examples:

get_item("gem", "pouch")

Parameters:

  • item (String)

    The item to retrieve.

  • container (String, nil) (defaults to: nil)

    The container to retrieve the item from.

Returns:

  • (Boolean)

    Returns true if the item was retrieved, false otherwise.



867
868
869
870
871
872
873
874
875
# File 'documented/dragonrealms/commons/common-items.rb', line 867

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

.get_item?(item, container = nil) ⇒ Boolean

Retrieves a specified item from a container.

Examples:

get_item?("potion", "bag")

Parameters:

  • item (String)

    The item to retrieve.

  • container (String, nil) (defaults to: nil)

    The container to retrieve the item from.

Returns:

  • (Boolean)

    Returns true if the item was retrieved, false otherwise.



857
858
859
# File 'documented/dragonrealms/commons/common-items.rb', line 857

def get_item?(item, container = nil)
  get_item(item, container)
end

.get_item_from_eddy_portal?(item, container) ⇒ Boolean

Retrieves an item from an eddy portal.

Examples:

get_item_from_eddy_portal?("gem", "portal")

Parameters:

  • item (String)

    The item to retrieve.

  • container (String)

    The container to retrieve the item from.

Returns:

  • (Boolean)

    Returns true if the item was retrieved from the portal, false otherwise.



926
927
928
929
930
931
932
933
934
935
936
937
938
# File 'documented/dragonrealms/commons/common-items.rb', line 926

def get_item_from_eddy_portal?(item, container)
  # Ensure the eddy is open then look in it to force the contents to be loaded.
  return false unless DRCI.open_container?('my eddy') && DRCI.look_in_container('portal in my eddy')

  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

.get_item_if_not_held?(item, container = nil) ⇒ Boolean

Retrieves an item if it is not currently held.

Examples:

get_item_if_not_held?("sword")

Parameters:

  • item (String)

    The item to retrieve.

  • container (String, nil) (defaults to: nil)

    The container to retrieve the item from, if applicable.

Returns:

  • (Boolean)

    Returns true if the item was retrieved, false otherwise.



844
845
846
847
848
849
# File 'documented/dragonrealms/commons/common-items.rb', line 844

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

.get_item_list(container, verb = 'rummage') ⇒ Array

Retrieves a list of items from a specified container using a verb.

Examples:

get_item_list("bag", "rummage")

Parameters:

  • container (String)

    The container to retrieve items from.

  • verb (String) (defaults to: 'rummage')

    The verb to use for retrieval (e.g., ‘rummage’ or ‘look’).

Returns:

  • (Array)

    Returns an array of item names found in the container.



1184
1185
1186
1187
1188
1189
1190
1191
# File 'documented/dragonrealms/commons/common-items.rb', line 1184

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

.get_item_safe(item, container = nil) ⇒ Boolean

Safely retrieves a specified item from a container.

Examples:

get_item_safe("amulet", "pouch")

Parameters:

  • item (String)

    The item to retrieve.

  • container (String, nil) (defaults to: nil)

    The container to retrieve the item from.

Returns:

  • (Boolean)

    Returns true if the item was retrieved safely, false otherwise.



895
896
897
# File 'documented/dragonrealms/commons/common-items.rb', line 895

def get_item_safe(item, container = nil)
  get_item_safe?(item, container)
end

.get_item_safe?(item, container = nil) ⇒ Boolean

Safely retrieves a specified item from a container.

Examples:

get_item_safe?("ring", "box")

Parameters:

  • item (String)

    The item to retrieve.

  • container (String, nil) (defaults to: nil)

    The container to retrieve the item from.

Returns:

  • (Boolean)

    Returns true if the item was retrieved safely, false otherwise.



883
884
885
886
887
# File 'documented/dragonrealms/commons/common-items.rb', line 883

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

.get_item_unsafe(item, container = nil) ⇒ Boolean

Retrieves a specified item from a container without safety checks.

Examples:

get_item_unsafe("scroll", "chest")

Parameters:

  • item (String)

    The item to retrieve.

  • container (String, nil) (defaults to: nil)

    The container to retrieve the item from.

Returns:

  • (Boolean)

    Returns true if the item was retrieved, false otherwise.



905
906
907
908
909
910
911
912
913
914
915
916
917
918
# File 'documented/dragonrealms/commons/common-items.rb', line 905

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
    if container =~ /\bportal\b/i
      return get_item_from_eddy_portal?(item, container)
    else
      return false
    end
  end
end

.get_scroll_list_in_container(container) ⇒ Array

Retrieves a list of scrolls in a specified container.

Examples:

get_scroll_list_in_container("bookcase")

Parameters:

  • container (String)

    The container to check.

Returns:

  • (Array)

    Returns an array of scroll names found in the container.



769
770
771
# File 'documented/dragonrealms/commons/common-items.rb', line 769

def get_scroll_list_in_container(container)
  DRC.rummage('SC', container)
end

.give_item?(target, item = nil) ⇒ Boolean

Gives a specified item to a target.

Examples:

give_item?("merchant", "gem")

Parameters:

  • target (String)

    The target to give the item to.

  • item (String, nil) (defaults to: nil)

    The item to give.

Returns:

  • (Boolean)

    Returns true if the item was given successfully, false otherwise.



1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
# File 'documented/dragonrealms/commons/common-items.rb', line 1335

def give_item?(target, item = nil)
  command = item ? "give my #{item} to #{target}" : "give #{target}"
  case DRC.bput(command, { 'timeout' => 35 }, /GIVE it again/, /give it to me again/, /^You don't need to specify the object/, /already has an outstanding offer/, GIVE_ITEM_SUCCESS_PATTERNS, GIVE_ITEM_FAILURE_PATTERNS)
  when *GIVE_ITEM_SUCCESS_PATTERNS
    true
  when *GIVE_ITEM_FAILURE_PATTERNS
    false
  when /give it to me again/
    give_item?(target, item)
  when /already has an outstanding offer/
    pause 5
    give_item?(target, item)
  when /GIVE it again/
    waitrt
    give_item?(target, item)
  when /You don't need to specify the object/
    if DRC.right_hand.include?(item)
      give_item?(target)
    elsif DRC.left_hand.include?(item)
      fput("swap")
      give_item?(target)
    end
  end
end

.have_item_by_look?(item, container) ⇒ Boolean

Checks if a specified item is present by looking at it in a container.

Examples:

have_item_by_look?("scroll", "bag")

Parameters:

  • item (String)

    The item to check.

  • container (String)

    The container to look in.

Returns:

  • (Boolean)

    Returns true if the item is found, false otherwise.



661
662
663
664
665
666
667
668
669
670
671
672
673
# File 'documented/dragonrealms/commons/common-items.rb', line 661

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

.in_hand?(item, which_hand = 'either') ⇒ Boolean

Checks if a specified item is in a specified hand.

Examples:

in_hand?("axe", "left")

Parameters:

  • item (String)

    The item to check.

  • which_hand (String) (defaults to: 'either')

    The hand to check (‘left’, ‘right’, ‘either’, ‘both’).

Returns:

  • (Boolean)

    Returns true if the item is in the specified hand, false otherwise.



636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
# File 'documented/dragonrealms/commons/common-items.rb', line 636

def in_hand?(item, which_hand = 'either')
  return false unless item

  item = DRC::Item.from_text(item) if item.is_a?(String)
  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

.in_hands?(item) ⇒ Boolean

Checks if a specified item is in either hand.

Examples:

in_hands?("sword")

Parameters:

  • item (String)

    The item to check.

Returns:

  • (Boolean)

    Returns true if the item is in either hand, false otherwise.



608
609
610
# File 'documented/dragonrealms/commons/common-items.rb', line 608

def in_hands?(item)
  in_hand?(item, 'either')
end

.in_left_hand?(item) ⇒ Boolean

Checks if a specified item is in the left hand.

Examples:

in_left_hand?("shield")

Parameters:

  • item (String)

    The item to check.

Returns:

  • (Boolean)

    Returns true if the item is in the left hand, false otherwise.



617
618
619
# File 'documented/dragonrealms/commons/common-items.rb', line 617

def in_left_hand?(item)
  in_hand?(item, 'left')
end

.in_right_hand?(item) ⇒ Boolean

Checks if a specified item is in the right hand.

Examples:

in_right_hand?("dagger")

Parameters:

  • item (String)

    The item to check.

Returns:

  • (Boolean)

    Returns true if the item is in the right hand, false otherwise.



626
627
628
# File 'documented/dragonrealms/commons/common-items.rb', line 626

def in_right_hand?(item)
  in_hand?(item, 'right')
end

.inside?(item, container = nil) ⇒ Boolean

Checks if a specified item is inside a container.

Examples:

inside?("key", "box")

Parameters:

  • item (String)

    The item to check.

  • container (String, nil) (defaults to: nil)

    The container to check inside.

Returns:

  • (Boolean)

    Returns true if the item is inside the container, false otherwise.



570
571
572
# File 'documented/dragonrealms/commons/common-items.rb', line 570

def inside?(item, container = nil)
  tap(item, container) =~ /inside/
end

.lift?(item = nil, stow = nil) ⇒ Boolean

Implementing a suggestion by Gildaren for a simple predicate method You can pass this only an item and it will attempt to lift that item and return true/false You can pass this both an item and true and it will lift that item and return the result of stow_item? on that item You can pass this both an item and the name of a container and return the result of put_away_item? on that item and that container Lifts a specified item and optionally stows it.

Examples:

lift?("box", true)

Parameters:

  • item (String, nil) (defaults to: nil)

    The item to lift.

  • stow (Boolean, nil) (defaults to: nil)

    Whether to stow the item after lifting.

Returns:

  • (Boolean)

    Returns true if the item was lifted successfully, false otherwise.



1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
# File 'documented/dragonrealms/commons/common-items.rb', line 1116

def lift?(item = nil, stow = nil)
  item = item.split.last # Necessary until adjectives are implemented for lift
  case DRC.bput("lift #{item}", LIFT_SUCCESS_PATTERNS, LIFT_FAILURE_PATTERNS)
  when *LIFT_SUCCESS_PATTERNS
    if stow.is_a?(String)
      put_away_item?(item, stow)
    elsif stow
      stow_item?(item)
    else
      true
    end
  else
    false
  end
end

.look_in_container(container) ⇒ Array?

Looks inside a specified container to find items.

Examples:

look_in_container("box")

Parameters:

  • container (String)

    The container to look in.

Returns:

  • (Array, nil)

    Returns an array of items found or nil if unsuccessful.



1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
# File 'documented/dragonrealms/commons/common-items.rb', line 1221

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

.lower_item?(item) ⇒ Boolean

Lowers a specified item to the ground.

Examples:

lower_item?("spear")

Parameters:

  • item (String)

    The item to lower.

Returns:

  • (Boolean)

    Returns true if the item was lowered successfully, false otherwise.



1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
# File 'documented/dragonrealms/commons/common-items.rb', line 1093

def lower_item?(item)
  return false unless in_hands?(item)

  item_regex = /\b#{item}\b/
  hand = (DRC.left_hand =~ item_regex) ? 'left' : 'right'
  case DRC.bput("lower ground #{hand}", *LOWER_SUCCESS_PATTERNS, *LOWER_FAILURE_PATTERNS)
  when *LOWER_SUCCESS_PATTERNS
    true
  else
    false
  end
end

.open_container?(container) ⇒ Boolean

Opens a specified container.

Examples:

open_container?("chest")

Parameters:

  • container (String)

    The container to open.

Returns:

  • (Boolean)

    Returns true if the container was opened successfully, false otherwise.



1305
1306
1307
1308
1309
1310
1311
# File 'documented/dragonrealms/commons/common-items.rb', line 1305

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

.put_away_item?(item, container = nil) ⇒ Boolean

Puts away a specified item into a container.

Examples:

put_away_item?("gem", "pouch")

Parameters:

  • item (String)

    The item to put away.

  • container (String, nil) (defaults to: nil)

    The container to put the item into.

Returns:

  • (Boolean)

    Returns true if the item was put away successfully, false otherwise.



1248
1249
1250
1251
1252
1253
1254
1255
1256
# File 'documented/dragonrealms/commons/common-items.rb', line 1248

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

.put_away_item_safe?(item, container = nil) ⇒ Boolean

Safely puts away a specified item into a container.

Examples:

put_away_item_safe?("ring", "box")

Parameters:

  • item (String)

    The item to put away.

  • container (String, nil) (defaults to: nil)

    The container to put the item into.

Returns:

  • (Boolean)

    Returns true if the item was put away successfully, false otherwise.



1264
1265
1266
1267
1268
# File 'documented/dragonrealms/commons/common-items.rb', line 1264

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

.put_away_item_unsafe?(item, container = nil, preposition = "in") ⇒ Boolean

Puts away a specified item into a container without safety checks.

Examples:

put_away_item_unsafe?("scroll", "bag")

Parameters:

  • item (String)

    The item to put away.

  • container (String, nil) (defaults to: nil)

    The container to put the item into.

  • preposition (String) (defaults to: "in")

    The preposition to use (default is ‘in’).

Returns:

  • (Boolean)

    Returns true if the item was put away, false otherwise.



1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
# File 'documented/dragonrealms/commons/common-items.rb', line 1277

def put_away_item_unsafe?(item, container = nil, preposition = "in")
  command = "put #{item} #{preposition} #{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 container && 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

.remove_and_stow_pouch?(gem_pouch_adjective, gem_pouch_noun, full_pouch_container = nil) ⇒ Boolean

Removes and stows a specified gem pouch.

Examples:

remove_and_stow_pouch?("blue", "gem pouch")

Parameters:

  • gem_pouch_adjective (String)

    The adjective describing the gem pouch.

  • gem_pouch_noun (String)

    The noun describing the gem pouch.

  • full_pouch_container (String, nil) (defaults to: nil)

    The container holding the full pouch.

Returns:

  • (Boolean)

    Returns true if the pouch was removed and stowed successfully, false otherwise.



1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
# File 'documented/dragonrealms/commons/common-items.rb', line 1417

def remove_and_stow_pouch?(gem_pouch_adjective, gem_pouch_noun, full_pouch_container = nil)
  unless remove_item?("#{gem_pouch_adjective} #{gem_pouch_noun}")
    DRC.message("Unable to remove existing pouch.")
    return false
  end
  if put_away_item?("#{gem_pouch_adjective} #{gem_pouch_noun}", full_pouch_container)
    return true
  elsif stow_item?("#{gem_pouch_adjective} #{gem_pouch_noun}")
    return true
  else
    return false
  end
end

.remove_item?(item) ⇒ Boolean

Removes a specified item.

Examples:

remove_item?("ring")

Parameters:

  • item (String)

    The item to remove.

Returns:

  • (Boolean)

    Returns true if the item was removed successfully, false otherwise.



1019
1020
1021
# File 'documented/dragonrealms/commons/common-items.rb', line 1019

def remove_item?(item)
  remove_item_safe?(item)
end

.remove_item_safe?(item) ⇒ Boolean

Safely removes a specified item.

Examples:

remove_item_safe?("amulet")

Parameters:

  • item (String)

    The item to remove.

Returns:

  • (Boolean)

    Returns true if the item was removed successfully, false otherwise.



1028
1029
1030
1031
# File 'documented/dragonrealms/commons/common-items.rb', line 1028

def remove_item_safe?(item)
  item = "my #{item}" if item && !(item =~ /^my /i)
  remove_item_unsafe?(item)
end

.remove_item_unsafe?(item) ⇒ Boolean

Removes a specified item without safety checks.

Examples:

remove_item_unsafe?("belt")

Parameters:

  • item (String)

    The item to remove.

Returns:

  • (Boolean)

    Returns true if the item was removed, false otherwise.



1038
1039
1040
1041
1042
1043
1044
1045
# File 'documented/dragonrealms/commons/common-items.rb', line 1038

def remove_item_unsafe?(item)
  case DRC.bput("remove #{item}", REMOVE_ITEM_SUCCESS_PATTERNS, REMOVE_ITEM_FAILURE_PATTERNS)
  when *REMOVE_ITEM_SUCCESS_PATTERNS
    return true
  else
    return false
  end
end

.rummage_container(container) ⇒ Array?

Rummages through a specified container to find items.

Examples:

rummage_container("chest")

Parameters:

  • container (String)

    The container to rummage through.

Returns:

  • (Array, nil)

    Returns an array of items found or nil if unsuccessful.



1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
# File 'documented/dragonrealms/commons/common-items.rb', line 1198

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] # Get string of just the comma separated item list
      .sub(/ and (?=a|an|some)/, ", ") # replace " and " for the last item into " , "
      .split(/, (?:a|an|some) /) # Split at a, an, or some, but only when it follows a comma
  end
end

.search?(item) ⇒ Boolean

Checks if a specified item is present in the inventory.

Examples:

search?("sword")

Parameters:

  • item (String)

    The item to search for.

Returns:

  • (Boolean)

    Returns true if the item is found, false otherwise.



551
552
553
# File 'documented/dragonrealms/commons/common-items.rb', line 551

def search?(item)
  /(?:An?|Some) .+ is (?:in|being)/ =~ DRC.bput("inv search #{item}", /^You can't seem to find anything/, /(?:An?|Some) .+ is (?:in|being)/)
end

.stow_hand(hand) ⇒ Boolean

Stows an item from a specified hand.

Examples:

stow_hand("left")

Parameters:

  • hand (String)

    The hand to stow from (‘left’ or ‘right’).

Returns:

  • (Boolean)

    Returns true if the item was stowed successfully, false otherwise.



821
822
823
824
825
826
827
828
829
830
831
832
833
# File 'documented/dragonrealms/commons/common-items.rb', line 821

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

.stow_handsBoolean

Stows items in both hands if possible.

Examples:

stow_hands

Returns:

  • (Boolean)

    Returns true if both hands were stowed successfully, false otherwise.



811
812
813
814
# File 'documented/dragonrealms/commons/common-items.rb', line 811

def stow_hands
  (!DRC.left_hand || stow_hand('left')) &&
    (!DRC.right_hand || stow_hand('right'))
end

.stow_item?(item) ⇒ Boolean

Stows a specified item.

Examples:

stow_item?("sword")

Parameters:

  • item (String)

    The item to stow.

Returns:

  • (Boolean)

    Returns true if the item was stowed successfully, false otherwise.



1055
1056
1057
# File 'documented/dragonrealms/commons/common-items.rb', line 1055

def stow_item?(item)
  stow_item_safe?(item)
end

.stow_item_safe?(item) ⇒ Boolean

Safely stows a specified item.

Examples:

stow_item_safe?("shield")

Parameters:

  • item (String)

    The item to stow.

Returns:

  • (Boolean)

    Returns true if the item was stowed successfully, false otherwise.



1064
1065
1066
1067
# File 'documented/dragonrealms/commons/common-items.rb', line 1064

def stow_item_safe?(item)
  item = "my #{item}" if item && !(item =~ /^my /i)
  stow_item_unsafe?(item)
end

.stow_item_unsafe?(item) ⇒ Boolean

Stows a specified item without safety checks.

Examples:

stow_item_unsafe?("dagger")

Parameters:

  • item (String)

    The item to stow.

Returns:

  • (Boolean)

    Returns true if the item was stowed, false otherwise.



1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
# File 'documented/dragonrealms/commons/common-items.rb', line 1074

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

.swap_out_full_gempouch?(gem_pouch_adjective, gem_pouch_noun, full_pouch_container = nil, spare_gem_pouch_container = nil, should_tie_gem_pouches = false) ⇒ Boolean

Swaps out a full gem pouch for a spare one.

Examples:

swap_out_full_gempouch?("red", "gem pouch")

Parameters:

  • gem_pouch_adjective (String)

    The adjective describing the gem pouch.

  • gem_pouch_noun (String)

    The noun describing the gem pouch.

  • full_pouch_container (String, nil) (defaults to: nil)

    The container holding the full pouch.

  • spare_gem_pouch_container (String, nil) (defaults to: nil)

    The container holding the spare pouch.

  • should_tie_gem_pouches (Boolean) (defaults to: false)

    Whether to tie the gem pouches.

Returns:

  • (Boolean)

    Returns true if the swap was successful, false otherwise.



1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
# File 'documented/dragonrealms/commons/common-items.rb', line 1384

def swap_out_full_gempouch?(gem_pouch_adjective, gem_pouch_noun, full_pouch_container = nil, spare_gem_pouch_container = nil, should_tie_gem_pouches = false)
  unless DRC.left_hand.nil? || DRC.right_hand.nil?
    DRC.message("No free hand. Not swapping pouches now.")
    return false
  end

  unless remove_and_stow_pouch?(gem_pouch_adjective, gem_pouch_noun, full_pouch_container)
    DRC.message("Remove and stow pouch routine failed.")
    return false
  end

  unless get_item?("#{gem_pouch_adjective} #{gem_pouch_noun}", spare_gem_pouch_container)
    DRC.message("No spare pouch found.")
    return false
  end

  unless wear_item?("#{gem_pouch_adjective} #{gem_pouch_noun}")
    DRC.message("Could not wear new pouch.")
    return false
  end

  tie_gem_pouch(gem_pouch_adjective, gem_pouch_noun) if should_tie_gem_pouches

  return true
end

.tap(item, container = nil) ⇒ String?

Taps a specified item, optionally from a container.

Examples:

tap("gem", "pouch")

Parameters:

  • item (String)

    The item to tap.

  • container (String, nil) (defaults to: nil)

    The container to tap the item from.

Returns:

  • (String, nil)

    Returns the result of the tap action or nil if unsuccessful.



595
596
597
598
599
600
601
# File 'documented/dragonrealms/commons/common-items.rb', line 595

def tap(item, container = nil)
  return nil unless item

  from = container
  from = "from #{container}" if container && !(container =~ /^(in|on|under|behind|from) /i)
  DRC.bput("tap my #{item} #{from}", *TAP_SUCCESS_PATTERNS, *TAP_FAILURE_PATTERNS)
end

.tie_gem_pouch(gem_pouch_adjective, gem_pouch_noun) ⇒ Boolean

Ties a specified gem pouch.

Examples:

tie_gem_pouch("green", "gem pouch")

Parameters:

  • gem_pouch_adjective (String)

    The adjective describing the gem pouch.

  • gem_pouch_noun (String)

    The noun describing the gem pouch.

Returns:

  • (Boolean)

    Returns true if the pouch was tied successfully, false otherwise.



1437
1438
1439
# File 'documented/dragonrealms/commons/common-items.rb', line 1437

def tie_gem_pouch(gem_pouch_adjective, gem_pouch_noun)
  DRC.bput("tie my #{gem_pouch_adjective} #{gem_pouch_noun}", 'you tie', "it's empty?", 'has already been tied off')
end

.tie_item?(item, container = nil) ⇒ Boolean

Ties a specified item to a container.

Examples:

tie_item?("rope", "tree")

Parameters:

  • item (String)

    The item to tie.

  • container (String, nil) (defaults to: nil)

    The container to tie the item to.

Returns:

  • (Boolean)

    Returns true if the item was tied successfully, false otherwise.



949
950
951
952
953
954
955
956
957
# File 'documented/dragonrealms/commons/common-items.rb', line 949

def tie_item?(item, container = nil)
  place = container ? "to my #{container}" : nil
  case DRC.bput("tie my #{item} #{place}", TIE_ITEM_SUCCESS_PATTERNS, TIE_ITEM_FAILURE_PATTERNS)
  when *TIE_ITEM_SUCCESS_PATTERNS
    true
  else
    false
  end
end

.untie_item?(item, container = nil) ⇒ Boolean

Unties a specified item from a container.

Examples:

untie_item?("rope", "tree")

Parameters:

  • item (String)

    The item to untie.

  • container (String, nil) (defaults to: nil)

    The container to untie the item from.

Returns:

  • (Boolean)

    Returns true if the item was untied successfully, false otherwise.



965
966
967
968
969
970
971
972
973
# File 'documented/dragonrealms/commons/common-items.rb', line 965

def untie_item?(item, container = nil)
  place = container ? "from my #{container}" : nil
  case DRC.bput("untie my #{item} #{place}", UNTIE_ITEM_SUCCESS_PATTERNS, UNTIE_ITEM_FAILURE_PATTERNS)
  when *UNTIE_ITEM_SUCCESS_PATTERNS
    true
  else
    false
  end
end

.wear_item?(item) ⇒ Boolean

Wears a specified item.

Examples:

wear_item?("armor")

Parameters:

  • item (String)

    The item to wear.

Returns:

  • (Boolean)

    Returns true if the item was worn successfully, false otherwise.



983
984
985
# File 'documented/dragonrealms/commons/common-items.rb', line 983

def wear_item?(item)
  wear_item_safe?(item)
end

.wear_item_safe?(item) ⇒ Boolean

Safely wears a specified item.

Examples:

wear_item_safe?("helmet")

Parameters:

  • item (String)

    The item to wear.

Returns:

  • (Boolean)

    Returns true if the item was worn successfully, false otherwise.



992
993
994
995
# File 'documented/dragonrealms/commons/common-items.rb', line 992

def wear_item_safe?(item)
  item = "my #{item}" if item && !(item =~ /^my /i)
  wear_item_unsafe?(item)
end

.wear_item_unsafe?(item) ⇒ Boolean

Wears a specified item without safety checks.

Examples:

wear_item_unsafe?("cloak")

Parameters:

  • item (String)

    The item to wear.

Returns:

  • (Boolean)

    Returns true if the item was worn, false otherwise.



1002
1003
1004
1005
1006
1007
1008
1009
# File 'documented/dragonrealms/commons/common-items.rb', line 1002

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

.wearing?(item) ⇒ Boolean

Checks if a specified item is currently being worn.

Examples:

wearing?("armor")

Parameters:

  • item (String)

    The item to check.

Returns:

  • (Boolean)

    Returns true if the item is being worn, false otherwise.



560
561
562
# File 'documented/dragonrealms/commons/common-items.rb', line 560

def wearing?(item)
  tap(item) =~ /wearing/
end