Module: Lich::DragonRealms::DRCI

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

Overview

Low-level, stateless methods for manipulating items in the game world.

DRCI provides item operations: getting, putting, wearing, removing, counting, searching, and querying hand contents. This module is "bottom-level" and only depends on DRC (common). Higher-level item operations that combine item management with other concerns should live in separate modules.

Constant Summary collapse

ITEM_ID_REF_PATTERN =

A "#" item reference (the GameObj id syntax item_ref passes through). Captures the id.

/\A#(\d+)\z/.freeze
TRASH_STORAGE =

How to add new trash receptacles https://github.com/elanthia-online/dr-scripts/wiki/Adding-new-trash-receptacles Default trash-receptacle nouns. Players extend this at runtime via the custom_trash_storage setting; see trash_storage and CustomSubstitutions.

%w[arms barrel basin basket bin birdbath bucket chamberpot gloop hole log puddle statue stump tangle tree turtle urn gelapod].freeze
DROP_TRASH_SUCCESS_PATTERNS =

Patterns matching successful item disposal via DROP, PUT, or similar.

Includes messages when an item crumbles, is fed to a gelapod, or spreads on ground.

Examples:

Matches

"You drop the rock."
"You put the item on the ground."
"As you open your hand to release the moonblade, it crumbles to dust."

See Also:

[
  /^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/
].freeze
DROP_TRASH_FAILURE_PATTERNS =

Patterns matching failed item disposal attempts.

Includes messages when the item cannot be dropped due to game rules, permissions, container restrictions, or item state.

Examples:

Matches

"I could not find what you were referring to."
"No littering in the bank."
"You should empty it out, first." (full container)

See Also:

[
  /^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
].freeze
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/
].freeze
WORN_TRASHCAN_VERB_PATTERNS =

Patterns matching verb responses when activating a worn trashcan.

Used by dispose_trash after successfully putting an item in a worn trashcan container to verify activation.

Examples:

Matches

"You drum your fingers on the shroud."
"You pull a lever on the worn trashcan."
"You poke your finger around inside the bag."
[
  /^You drum your fingers/,
  /^You pull a lever/,
  /^You poke your finger around/
].freeze
GET_ITEM_SUCCESS_PATTERNS =

Patterns matching successful item retrieval via GET.

Includes messages when picking, drawing, plucking, slipping, or scooping items, as well as cases where the item is already held or carefully removed from bundles.

Examples:

Matches

"You get the sword."
"You draw your weapon."
"You are already holding that."
"With a flick of your wrist, you stealthily unsheath your blade."

See Also:

[
  /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/
].freeze
GET_ITEM_FAILURE_PATTERNS =

Patterns matching failed item retrieval attempts.

Includes messages when hands are full, injured, or item cannot be reached, as well as when the item doesn't exist, is cursed, or has exceeded item limits.

Examples:

Matches

"You need both hands free."
"Your left hand is too injured."
"I could not find what you were referring to."
"You can't reach that from here."

See Also:

[
  /^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/
].freeze
WEAR_ITEM_SUCCESS_PATTERNS =

Patterns matching successful item wearing via WEAR.

Includes messages when putting on, slinging, attaching, strapping, sliding, and other wear actions across different item types.

Examples:

Matches

"You put on the cloak."
"You sling the bow across your shoulder."
"You are already wearing that."
"A brisk chill rushes through you as you wear the ice-veined gloves."

See Also:

[
  /^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.
].freeze
WEAR_ITEM_FAILURE_PATTERNS =

Patterns matching failed item wearing attempts.

Includes messages when the item cannot be worn (not designed for wear, conflicts with current state, or invalid for you).

Examples:

Matches

"You can't wear that."
"You need to unload it first."
"Wear what?"

See Also:

[
  /^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/
].freeze
TIE_ITEM_ALREADY_TIED_PATTERN =

The game's reply when the item is already tied: counts as success, but tie_item_result reports it as :already_tied.

/has already been tied off/.freeze
TIE_ITEM_SUCCESS_PATTERNS =

Success replies: "You tie up the soft gem pouch.", "You carefully tie ...", "You attach to a strap on your ." The verb must come right after "You" (one -ly adverb allowed) and be the whole word, so lines that only contain "tie" ("You untie ...", "...tactical abilities...", "...tied with...") can't pass for the reply while bput waits for it.

[
  /^You (?:\w+ly )?tie\b/,
  /^You attach/,
  TIE_ITEM_ALREADY_TIED_PATTERN
].freeze
TIE_ITEM_EMPTY_PATTERN =

The game's reply when asked to tie off an empty container: nothing is tied (see tie_item_result).

/Tie it off when it's empty\?/.freeze
TIE_ITEM_FAILURE_PATTERNS =

Patterns matching failed item tying attempts.

Includes messages when the item has no remaining ties, cannot be tied, or tying is prevented by hand injury or item state.

Examples:

Matches

"There's no more free ties."
"Tie what?"
"Your wounds hinder your ability to do that."

See Also:

[
  /^There's no more free ties/,
  /^Tie what/,
  /^You are a little too busy/,
  /^You don't seem to be able to move/,
  /^You must be holding/,
  /^Your wounds hinder your ability to do that/,
  /close the fan/,
  /doesn't seem to fit/
].freeze
UNTIE_ITEM_SUCCESS_PATTERNS =

Patterns matching successful item untying via UNTIE.

Examples:

Matches

"You remove the tie."
"You untie the pouch."

See Also:

[
  /^You remove/,
  /You untie/i
].freeze
UNTIE_ITEM_FAILURE_PATTERNS =

Patterns matching failed item untying attempts.

Includes messages when you cannot move, fumble with ties, or item doesn't exist.

Examples:

Matches

"You don't seem to be able to move."
"You fumble with the ties."
"Untie what?"

See Also:

[
  /^You don't seem to be able to move/,
  /^You fumble with the ties/,
  /^You are a little too busy/,
  /^You are a bit too busy/,
  /^Untie what/,
  /^What were you referring/
].freeze
REMOVE_ITEM_SUCCESS_PATTERNS =

Patterns matching successful item removal via REMOVE.

Includes messages when pulling off, sliding off, detaching, loosening, unloosening, or managing removal of worn items.

Examples:

Matches

"You pull off the boots."
"You slide your ring off."
"You untie the belt."
"Grunting with momentary exertion, you grip each of your heavy combat boots..."

See Also:

[
  /^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/,
  /^You work your way out/,
  /^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.
  /^With masterful grace, you ready/,
  /^A brisk chill leaves you as you/ # cold-enchanted items (e.g., ice-veined leather gloves)
].freeze
REMOVE_ITEM_FAILURE_PATTERNS =

Patterns matching failed item removal attempts.

Includes messages when you are not wearing the item, hands are full, or you cannot move to remove it.

Examples:

Matches

"You aren't wearing that."
"You need a free hand."
"Remove what?"

See Also:

[
  /^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/,
  /^What were you/
].freeze
SHEATH_ITEM_SUCCESS_PATTERNS =

Success patterns for the SHEATH verb.

Matches game output when a weapon is successfully sheathed into a scabbard, sheath, or harness. Also splatted into PUT_AWAY_ITEM_SUCCESS_PATTERNS because STOW can trigger sheath responses when the default storage is a sheath.

Examples:

Matches

"Sheathing your sword, you put it away."
"You sheath your sword in your scabbard."
"With fluid and stealthy movements you slip the sabre into your harness."

See Also:

[
  /^Sheathing/,
  /^You sheath/,
  /^You secure your/,
  /^You slip/,
  /^You hang/,
  /^You (easily )?strap/,
  /^With a flick of your wrist,? you stealthily sheath/,
  /^With fluid and stealthy movements you slip/,
  /^The .* slides easily/
].freeze
SHEATH_ITEM_FAILURE_PATTERNS =

Failure patterns for the SHEATH verb.

Examples:

Matches

"Sheath your sword where?"
"There's no room for that."

See Also:

[
  /^Sheath your .* where/,
  /^There's no room/,
  /is too small to hold that/,
  /is too wide to fit/,
  /^Your (left|right) hand is too injured/
].freeze
PUT_AWAY_ITEM_SUCCESS_PATTERNS =

Success patterns for putting an item away via PUT or STOW.

Includes SHEATH_ITEM_SUCCESS_PATTERNS because STOW can trigger sheath responses when the default storage is a sheath/harness.

[
  /^You put your .* in/,
  /^You hold out/,
  /^You stuff/,
  /^You tuck/,
  /^You open your pouch and put/,
  /^You guide your/i, # puppy storage
  /^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 gently set/,
  # Sheath patterns included because STOW can trigger sheath responses.
  *SHEATH_ITEM_SUCCESS_PATTERNS,
  /^You toss .* into/ # You toss the alcohol into the bowl and mix it in thoroughly
].freeze
PUT_AWAY_ITEM_FAILURE_PATTERNS =

Patterns matching failed item storage via PUT or STOW.

Includes messages when no container exists, container is full, item is too heavy, or storage is prevented by permissions or container design.

Examples:

Matches

"There isn't any more room in that."
"Containers can't be placed in there."
"The item is too heavy to go in there."
"That doesn't belong in there!"

See Also:

[
  /^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/
].freeze
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/
].freeze
STOW_ITEM_SUCCESS_PATTERNS =

Patterns matching successful item stowing via STOW.

Combines GET_ITEM_SUCCESS_PATTERNS and PUT_AWAY_ITEM_SUCCESS_PATTERNS since STOW both retrieves and stores in a single command.

[
  *GET_ITEM_SUCCESS_PATTERNS,
  *PUT_AWAY_ITEM_SUCCESS_PATTERNS
].freeze
STOW_ITEM_FAILURE_PATTERNS =

Patterns matching failed item stowing via STOW.

Combines GET_ITEM_FAILURE_PATTERNS and PUT_AWAY_ITEM_FAILURE_PATTERNS to cover both retrieval and storage failures.

[
  *GET_ITEM_FAILURE_PATTERNS,
  *PUT_AWAY_ITEM_FAILURE_PATTERNS
].freeze
STOW_ITEM_RETRY_PATTERNS =

Patterns matching STOW responses that warrant automatic retry.

Includes messages when items appear to update upon stowing, requiring the command to be retried to complete the stow.

[
  *PUT_AWAY_ITEM_RETRY_PATTERNS
].freeze
WIELD_ITEM_SUCCESS_PATTERNS =

Success patterns for the WIELD verb.

Matches game output when a weapon is successfully drawn from a sheath, scabbard, or harness.

Examples:

Matches

"You draw your sword from your scabbard."
"You deftly remove a dagger from your thigh sheath."
"With a flick of your wrist, you stealthily unsheath your weapon."

See Also:

[
  /you draw (?!\w+'s wounds)/i,
  /^You deftly remove/,
  /^You slip/,
  /^With a flick of your wrist,? you stealthily unsheath/,
  /^With fluid and stealthy movements you draw/,
  /^The .* slides easily out/
].freeze
WIELD_ITEM_FAILURE_PATTERNS =

Failure patterns for the WIELD verb.

[
  /^Wield what/,
  /^Your (left|right) hand is too injured/
].freeze
SWAP_HANDS_SUCCESS_PATTERNS =

Success patterns for the SWAP verb (hand swap).

Matches game output when items are successfully swapped between left and right hands.

Examples:

Matches

"You move a steel sword to your left hand."

See Also:

[
  /^You move/
].freeze
SWAP_HANDS_FAILURE_PATTERNS =

Failure patterns for the SWAP verb (hand swap).

[
  /^Will alone cannot conquer the paralysis/
].freeze
UNLOAD_WEAPON_SUCCESS_PATTERNS =

Success patterns for the UNLOAD verb.

Matches game output when a ranged weapon is successfully unloaded. Includes both visible and hidden unloading messages, as well as the case where ammo falls to the ground (hands full).

The game may prepend an aim/firing timer tag to the unload line, e.g. " You unload the shortbow." The optional (?:<dialogData.*?<\/dialogData>)? prefix lets the patterns match whether or not the tag is present, without assuming its inner values.

Examples:

Matches

"You unload the crossbow."
"Your bolt falls from your crossbow to your feet."
"As you release the string, the arrow tumbles to the ground."
"You remain concealed by your surroundings, convinced that your unloading of the crossbow went unobserved."

See Also:

[
  /^(?:<dialogData.*?<\/dialogData>)?You unload/,
  /^Your .* fall.*to your feet\.$/,
  /As you release the string(.* fades and disappears)?/,
  /^(?:<dialogData.*?<\/dialogData>)?You .* unloading/
].freeze
UNLOAD_WEAPON_FAILURE_PATTERNS =

Failure patterns for the UNLOAD verb.

[
  /But your .* isn't loaded/,
  /You can't unload such a weapon/,
  /You don't have a ranged weapon to unload/,
  /You must be holding the weapon to do that/
].freeze
RUMMAGE_SUCCESS_PATTERNS =

Patterns matching successful container inspection via RUMMAGE.

Includes messages when contents are listed, or when the container is empty.

Examples:

Matches

"You rummage through the backpack and see a sword, a shield, some bandages."
"In the chest you see a key."
"There is nothing in that container."

See Also:

[
  /^You rummage through .* and see (.*)\./,
  /^In the .* you see (.*)\./,
  /there is nothing/i
].freeze
RUMMAGE_FAILURE_PATTERNS =

Patterns matching failed container inspection via RUMMAGE.

Includes messages when you cannot move, container doesn't exist, or container reference is invalid.

Examples:

Matches

"I could not find what you were referring to."
"You don't seem to be able to move."
"What were you referring to?"

See Also:

[
  /^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/
].freeze
TAP_SUCCESS_PATTERNS =

Patterns matching successful item inspection via TAP.

Includes messages indicating the item's location (worn, stowed, in hand) and special item behaviors (favor orbs, surveyors' cases).

Examples:

Matches

"You tap a longsword. It is currently worn."
"You tap a lockpick. It is inside your backpack."
"You tap a favor orb. The orb is delicate and should be handled with care."
"You tap Tharos on the shoulder."

See Also:

[
  /^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
].freeze
TAP_FAILURE_PATTERNS =

Patterns matching failed item inspection via TAP.

Includes messages when the item doesn't exist or cannot be tapped.

Examples:

Matches

"I could not find what you were referring to."
"What were you referring to?"

See Also:

[
  /^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/
].freeze
OPEN_CONTAINER_SUCCESS_PATTERNS =

Patterns matching successful container opening via OPEN.

Includes messages when the container opens or was already open.

Examples:

Matches

"You open the backpack."
"It's already open."
"You unbutton the pouch."

See Also:

[
  /^You open/,
  /^You slowly open/,
  /^The .* opens/,
  /^You unbutton/,
  /([Ii]t's|is) already open/,
  /^You spread your arms, carefully holding your bag well away from your body/
].freeze
OPEN_CONTAINER_FAILURE_PATTERNS =

Patterns matching failed container opening attempts.

Includes messages when you cannot open (due to spells, location, or game rules) or the container doesn't exist.

Examples:

Matches

"You don't want to ruin your spell just for that."
"Open what?"
"There is no way to do that."

See Also:

[
  /^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/
].freeze
CLOSE_CONTAINER_SUCCESS_PATTERNS =

Patterns matching successful container closing via CLOSE.

Includes messages when the container closes or was already closed.

Examples:

Matches

"You close the backpack."
"It is already closed."
"You quickly close the chest."

See Also:

[
  /^You close/,
  /^You quickly close/,
  /^You pull/,
  /is already closed/
].freeze
CLOSE_CONTAINER_FAILURE_PATTERNS =

Patterns matching failed container closing attempts.

Includes messages when you cannot close due to spells, location, or the container doesn't exist.

Examples:

Matches

"You don't want to ruin your spell just for that."
"There is no way to do that."

See Also:

[
  /^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/
].freeze
CONTAINER_IS_CLOSED_PATTERNS =

Patterns matching when a container is closed and cannot be accessed.

Used when attempting to interact with a closed container, triggering a recovery attempt to open it first.

Examples:

Matches

"But that's closed."
"While it's closed, you can't do that."
[
  /^But that's closed/,
  /^That is closed/,
  /^While it's closed/
].freeze
LOWER_SUCCESS_PATTERNS =

Patterns matching successful item lowering via LOWER.

Includes messages when the item is placed on the ground (feet slot), or when a cursed item crumbles upon release.

Examples:

Matches

"You lower the sword to the ground."
"As you open your hand to release the moonblade, it crumbles to dust."

See Also:

[
  /^You lower/,
  # The next message is when item crumbles when leaves your hand, like a moonblade.
  /^As you open your hand to release the/
].freeze
LOWER_FAILURE_PATTERNS =

Patterns matching failed item lowering attempts.

Includes messages when you are not holding anything, cannot move, or the item reference is invalid.

Examples:

Matches

"But you aren't holding anything."
"You don't seem to be able to move."

See Also:

[
  /^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/
].freeze
LIFT_SUCCESS_PATTERNS =

Patterns matching successful item lifting via LIFT.

Examples:

Matches

"You pick up the sword from the ground."

See Also:

[
  /^You pick up/
].freeze
LIFT_FAILURE_PATTERNS =

Patterns matching failed item lifting attempts.

Includes messages when there are no items at your feet, you lack strength, or the item reference is invalid.

Examples:

Matches

"There are no items lying at your feet."
"You are not strong enough to pick that up."

See Also:

[
  /^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/
].freeze
GIVE_ITEM_SUCCESS_PATTERNS =

Patterns matching successful item transfer to an NPC or player via GIVE.

Includes messages when an offer is accepted, repair tickets are exchanged, or the recipient confirms receipt.

Examples:

Matches

"Ragge has accepted your offer."
"Your sword and are handed back a repair ticket."
"Please don't lose this ticket!"

See Also:

[
  /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/
].freeze
GIVE_ITEM_FAILURE_PATTERNS =

Patterns matching failed item giving attempts.

Includes messages when the recipient declines, offer expires, item is not repairable, or conditions prevent the transfer.

Examples:

Matches

"has declined the offer."
"Your offer to Ragge has expired."
"I don't repair those here."
"Lucky for you! That isn't damaged!"

See Also:

[
  /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!/
].freeze
FILL_POUCH_SUCCESS_PATTERNS =

Patterns matching successful gem pouch filling via FILL.

Includes messages when the pouch opens, gems are added, or pouch is already empty.

Examples:

Matches

"You open your black gem pouch."
"You fill your gem pouch with gems from the container."
"There aren't any gems in that."

See Also:

[
  /^You open/,
  /^You fill your/,
  /^There aren't any gems/
].freeze
FILL_POUCH_NEEDS_TIE_PATTERNS =

Patterns matching when a gem pouch must be tied before filling continues.

Examples:

Matches

"You'd better tie it up before putting more gems in."
"You'll need to tie it up before you can put anything else in it."

See Also:

[
  /^You'd better tie it up before putting/,
  /^You'll need to tie it up before/
].freeze
FILL_POUCH_FULL_PATTERN =

Pattern matching when a gem pouch is completely full and cannot accept more gems.

Examples:

Matches

"Your black gem pouch is too full to fit any more gems in."

See Also:

/is too full to fit/.freeze
FILL_POUCH_FAILURE_PATTERNS =

Patterns matching failed gem pouch filling attempts.

Includes messages when the pouch or source container doesn't exist.

Examples:

Matches

"What were you referring to?"
"Please rephrase that command."

See Also:

[
  /^Please rephrase that command/,
  /^What were you referring to/
].freeze
INV_BELT_START_PATTERN =

Pattern matching the start of INVENTORY BELT output.

Used to delimit the beginning of belt inventory listing.

/^All of your items worn attached to the belt:/.freeze
INV_BELT_END_PATTERN =

Pattern matching the end of INVENTORY BELT output.

Used to delimit the end of belt inventory listing.

/^\[Use INVENTORY HELP/.freeze
COUNT_PART_PATTERNS =

Patterns extracting the count of remaining parts/uses from stackable items.

Captures the count value in a named group (:count) from APPRAISE, COUNT, and similar inspection commands.

Examples:

Matches with count capture

"There are 45 leather left." => 45
"The item has 10 uses remaining." => 10
"You count out 32 pieces of material there." => 32
[
  /and see there (?:is|are) (?<count>.+) left\./,
  /There (?:is|are) (?:only )?(?<count>.+) parts? left/,
  /There's (?:only )?(?<count>.+) parts? left/,
  /The (?:.+) has (?<count>.+) uses remaining./,
  /There are enough left to create (?<count>.+) more/,
  /You count out (?<count>.+) pieces? of material there/,
  /There (?:is|are) (?<count>.+) scrolls? left for use with crafting/
].freeze
BRAID_TOO_LONG_PATTERN =

Pattern matching when a braided item is too long to stow and must be disposed.

Captures the braid name in the :braid_name group. Used by stow_hand to recover from braid overflow by disposing the item as trash.

Examples:

Matches

"The braided leather cord is too long for your container."
"The braided hemp rope is too long to stow."
/The braided (?<braid_name>.+) is too long/.freeze
ACCEPT_SUCCESS_PATTERN =

Pattern matching successful item acceptance from another player via ACCEPT.

Captures the offering player's name in the :name group.

Examples:

Matches

"You accept Tharos's offer and are now holding a steel sword."

See Also:

/You accept (?<name>\w+)'s offer and are now holding/.freeze

Class Method Summary collapse

Class Method Details

.accept_item? ⇒ String, false

Accepts a pending item offer from another player.

Returns:

  • (String, false) —

    name of the person whose offer was accepted, or false if no offer pending or hands full

See Also:



2380
2381
2382
2383
2384
# File 'documented/dragonrealms/commons/common-items.rb', line 2380

def accept_item?
  result = DRC.bput("accept", ACCEPT_SUCCESS_PATTERN, "You have no offers", "Both of your hands are full", "would push you over your item limit")
  match = result&.match(ACCEPT_SUCCESS_PATTERN)
  match ? match[:name] : false
end

.check_belt_for_pouch?(gem_pouch_adjective, gem_pouch_noun) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Checks if a gem pouch is already attached to the belt.

Uses INV BELT to inspect belt contents and matches against the pouch adjective and noun.

Parameters:

  • gem_pouch_adjective (String) —

    pouch adjective (e.g., "black")

  • gem_pouch_noun (String) —

    pouch noun (e.g., "pouch")

Returns:

  • (Boolean) —

    true if a matching pouch is found on the belt



2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
# File 'documented/dragonrealms/commons/common-items.rb', line 2399

def check_belt_for_pouch?(gem_pouch_adjective, gem_pouch_noun)
  belt_contents = Lich::Util.issue_command(
    "inv belt",
    INV_BELT_START_PATTERN,
    INV_BELT_END_PATTERN,
    timeout: 3,
    silent: true,
    quiet: true,
    usexml: false,
    include_end: false
  )

  return false if belt_contents.nil? || belt_contents.empty?

  pouch_pattern = /#{gem_pouch_adjective}.*gem.*#{gem_pouch_noun}/i
  belt_contents.any? { |line| line.match?(pouch_pattern) }
end

.close_container?(container) ⇒ Boolean

Closes a container.

Parameters:

  • container (String) —

    container noun to close

Returns:

  • (Boolean) —

    true if container was closed (or already closed)

See Also:



2301
2302
2303
2304
2305
2306
2307
# File 'documented/dragonrealms/commons/common-items.rb', line 2301

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 container is empty by looking inside it.

Parameters:

  • container (String) —

    container noun to check

Returns:

  • (Boolean, nil) —

    true if empty, false if not empty, nil if unable to determine (e.g., cannot open or look in container)



2055
2056
2057
# File 'documented/dragonrealms/commons/common-items.rb', line 2055

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

.count_all_boxes(settings) ⇒ Integer

Counts all lockpick boxes across configured containers.

Checks the picking_box_source, picking_box_sources, blacklist, and too_hard containers from settings.

Parameters:

  • settings (OpenStruct) —

    user settings from get_settings

Returns:

  • (Integer) —

    total number of boxes across all containers



1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
# File 'documented/dragonrealms/commons/common-items.rb', line 1552

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 remaining parts/uses of a stackable item.

Iterates through ordinals (first, second, ...) to count across multiple stacks. Falls back to count_items if the item is not stackable.

Examples:

DRCI.count_item_parts("leather")  #=> 45

Parameters:

  • item (String) —

    item noun to count

Returns:

  • (Integer) —

    total number of parts across all stacks



1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
# File 'documented/dragonrealms/commons/common-items.rb', line 1442

def count_item_parts(item)
  count = 0
  # Item IDs (starting with #) are unique, so we count once without ordinals
  items_to_count = item&.start_with?('#') ? [item] : $ORDINALS.map { |ord| "#{ord} #{item}" }

  items_to_count.each do |item_with_ordinal|
    result = DRC.bput("count #{item_ref(item_with_ordinal)}",
                      'I could not find what you were referring to.',
                      'tell you much of anything.',
                      *COUNT_PART_PATTERNS)
    if result == 'I could not find what you were referring to.'
      break
    elsif result == 'tell you much of anything.'
      Lich::Messaging.msg("bold", "DRCI: count_item_parts called on non-stackable item: #{item}")
      count = count_items(item)
      break
    else
      # Try to match against our count patterns
      match = COUNT_PART_PATTERNS.lazy.filter_map { |pat| result.match(pat) }.first
      if match
        countval = match[:count].tr('-', ' ')
        if countval.match?(/\A\d+\z/)
          count += Integer(countval)
        else
          count += DRC.text2num(countval)
        end
      end
    end
    waitrt?
  end
  count
end

.count_items(item) ⇒ Integer

Counts matching items in the container inferred by tapping the item.

Taps the item to determine which container it is in, then delegates to count_items_in_container.

Parameters:

  • item (String) —

    item noun to count

Returns:

  • (Integer) —

    number of matching items in the inferred container

See Also:



1484
1485
1486
1487
1488
1489
1490
# File 'documented/dragonrealms/commons/common-items.rb', line 1484

def count_items(item)
  tap_result = tap(item)
  match = tap_result&.match(/inside your (?<container>.*)/)
  return 0 unless match

  count_items_in_container(item, match[:container])
end

.count_items_in_container(item, container) ⇒ Integer

Counts matching items in a specific container via RUMMAGE.

Parameters:

  • item (String) —

    item noun to count

  • container (String) —

    container noun to rummage

Returns:

  • (Integer) —

    number of matching items found

See Also:



1499
1500
1501
1502
1503
1504
# File 'documented/dragonrealms/commons/common-items.rb', line 1499

def count_items_in_container(item, container)
  contents = DRC.bput("rummage /C #{item.split.last} in #{item_ref(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 how many more lockpicks a lockpick stacker can hold.

Uses APPRAISE QUICK to determine remaining capacity.

Parameters:

  • container (String) —

    lockpick ring/stacker noun

Returns:

  • (Integer) —

    number of additional lockpicks that can fit

See Also:



1514
1515
1516
1517
1518
# File 'documented/dragonrealms/commons/common-items.rb', line 1514

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

.count_necro_stacker(necro_stacker) ⇒ Integer

Counts items in a Necromancer material stacker via STUDY.

Parameters:

  • necro_stacker (String) —

    stacker noun

Returns:

  • (Integer) —

    number of items currently held



1540
1541
1542
1543
# File 'documented/dragonrealms/commons/common-items.rb', line 1540

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

.dispose_hand_state(hand) ⇒ Array

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns [id, name] of what the hand holds.

Returns:

  • (Array) —

    [id, name] of what the hand holds



1210
1211
1212
1213
# File 'documented/dragonrealms/commons/common-items.rb', line 1210

def dispose_hand_state(hand)
  obj = hand == 'left' ? GameObj.left_hand : GameObj.right_hand
  [obj&.id, obj&.name]
end

.dispose_held_trash(item, worn_trashcan = nil, worn_trashcan_verb = nil, retries:) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Disposes of an item already in hand. Never GETs: see dispose_trash.

Returns:

  • (Boolean) —

    true if disposed, false if not



1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
# File 'documented/dragonrealms/commons/common-items.rb', line 1060

def dispose_held_trash(item, worn_trashcan = nil, worn_trashcan_verb = nil, retries:)
  return false if dispose_retries_exhausted?(retries)

  if worn_trashcan
    result = execute_dispose_command("put #{item_ref(item)} in #{item_ref(worn_trashcan)}", item, retries, worn_trashcan, worn_trashcan_verb)
    if result == :success
      if worn_trashcan_verb
        DRC.bput("#{worn_trashcan_verb} #{item_ref(worn_trashcan)}", *WORN_TRASHCAN_VERB_PATTERNS)
        DRC.bput("#{worn_trashcan_verb} #{item_ref(worn_trashcan)}", *WORN_TRASHCAN_VERB_PATTERNS)
      end
      return true
    end
    return result unless result == :failure
  end

  # Check for meta:trashcan tag on the room to identify a specific trashcan to use.
  metatag_match = Room.current.tags.find { |t| t =~ /meta:trashcan:(?<trashcan>.*)/ }&.match(/meta:trashcan:(?<trashcan>.*)/)
  if metatag_match
    metatag_trashcan = metatag_match[:trashcan]

    # 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 #{item_ref(item)} to gelapod" if DRRoom.room_objs.include?('gelapod')
    else
      metatag_trash_command = "put #{item_ref(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?
      result = execute_dispose_command(metatag_trash_command, item, retries)
      return true if result == :success
      return result unless result == :failure
    end
  end

  recognized_trash = trash_storage
  trashcans = DRRoom.room_objs
                    .reject { |obj| obj =~ /azure \w+ tree/ }
                    .map { |long_name| DRC.get_noun(long_name) }
                    .select { |obj| recognized_trash.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 #{item_ref(item)} to gelapod"
    end

    trash_command = "put #{item_ref(item)} in #{trashcan}" unless trashcan == 'gelapod'

    result = execute_dispose_command(trash_command, item, retries)
    return true if result == :success
    return result unless result == :failure
  end

  # No trash bins or not able to put item in a bin, just drop it.
  result = execute_dispose_command("drop #{item_ref(item)}", item, retries)
  case result
  when :success
    true
  when :failure
    Lich::Messaging.msg("bold", "DRCI: Failed to dispose of '#{item}'.")
    false
  else
    result
  end
end

.dispose_item_hands(item) ⇒ Hash{String => Array}

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The hands holding the item, each with what it holds (id and name).

Returns:



1204
1205
1206
# File 'documented/dragonrealms/commons/common-items.rb', line 1204

def dispose_item_hands(item)
  %w[left right].select { |hand| in_hand?(item, hand) }.to_h { |hand| [hand, dispose_hand_state(hand)] }
end

.dispose_item_not_held(item) ⇒ false

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (false)


1217
1218
1219
1220
# File 'documented/dragonrealms/commons/common-items.rb', line 1217

def dispose_item_not_held(item)
  Lich::Messaging.msg("bold", "DRCI: '#{item}' is no longer in your hands (it may already have been disposed of). Not getting another to dispose of.")
  false
end

.dispose_retries_exhausted?(retries) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns true (after saying so) when no retries remain.

Returns:

  • (Boolean) —

    true (after saying so) when no retries remain



1153
1154
1155
1156
1157
1158
# File 'documented/dragonrealms/commons/common-items.rb', line 1153

def dispose_retries_exhausted?(retries)
  return false if retries.positive?

  Lich::Messaging.msg("bold", "DRCI: dispose_trash exceeded max retries")
  true
end

.dispose_trash(item, worn_trashcan = nil, worn_trashcan_verb = nil, retries: 3) ⇒ Boolean?

Disposes of an item by putting it in a trash receptacle.

Tries multiple disposal strategies in order: worn trashcan, room meta-tagged trashcan, room objects matching known trash receptacles, and finally drops the item on the ground.

The item is fetched only here, before the first command. Once it is in hand, no later step GETs it again: get my <noun> would take a same-named item from inventory and trash that instead. If a command goes unanswered, the hands decide: the item left the hand (the reply was lost) counts as disposed, and an item still in hand moves on to the next way of disposing of it.

Examples:

Dispose using room trash bins

DRCI.dispose_trash("rock")

Dispose into a worn trashcan

DRCI.dispose_trash("rock", "shroud", "tap")

Parameters:

  • item (String) —

    item noun to dispose of

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

    worn container for trash (e.g., "shroud")

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

    verb to activate the worn trashcan after use

  • retries (Integer) (defaults to: 3) —

    remaining retry attempts before giving up (default 3)

Returns:

  • (Boolean, nil) —

    true if disposed, false if failed, nil if item is nil or not held



1048
1049
1050
1051
1052
1053
1054
# File 'documented/dragonrealms/commons/common-items.rb', line 1048

def dispose_trash(item, worn_trashcan = nil, worn_trashcan_verb = nil, retries: 3)
  return unless item
  return false if dispose_retries_exhausted?(retries)
  return unless DRCI.get_item_if_not_held?(item)

  dispose_held_trash(item, worn_trashcan, worn_trashcan_verb, retries: retries)
end

.execute_dispose_command(command, item, retries, *retry_args) ⇒ Symbol, Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Executes a dispose command and handles common retry/recovery patterns.

The item is in hand when this runs, and it never GETs the item again: see dispose_trash.

Parameters:

  • command (String) —

    game command to execute

  • item (String) —

    item being disposed

  • retries (Integer) —

    remaining retry attempts

  • retry_args (Array) —

    extra args to pass to dispose_held_trash on retry

Returns:

  • (Symbol, Boolean) —

    :success, :failure (try the next way), or a final boolean for dispose_trash to return



1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
# File 'documented/dragonrealms/commons/common-items.rb', line 1173

def execute_dispose_command(command, item, retries, *retry_args)
  hands_before = dispose_item_hands(item)
  case DRC.bput(command, 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
    :success
  when /^Perhaps you should be holding that first/, /^But you aren't holding that/
    in_hands?(item) ? :failure : dispose_item_not_held(item)
  when *DROP_TRASH_FAILURE_PATTERNS
    :failure
  when *DROP_TRASH_RETRY_PATTERNS
    return dispose_item_not_held(item) unless in_hands?(item)

    dispose_held_trash(item, *retry_args, retries: retries - 1)
  else
    # No reply matched before bput's timeout. If a hand that held the
    # item now holds something else, count it as disposed. That only
    # says the item left the hand, for any reason (the command took
    # effect, or it decayed, was stolen or dissipated), not that it
    # reached the receptacle. Either way it is gone, and getting
    # another to dispose of is the one thing to avoid.
    return :failure if hands_before.all? { |hand, held| dispose_hand_state(hand) == held }

    Lich::Messaging.msg("bold", "DRCI: No reply to '#{command}', but '#{item}' has left your hands; treating it as disposed.")
    :success
  end
end

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

Checks if an item exists in inventory or a container by tapping it.

Examples:

DRCI.exists?("deed")
DRCI.exists?("sword", "backpack")

Parameters:

  • item (String) —

    item noun to check

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

    container to check in, or nil for general inventory

Returns:

  • (Boolean) —

    true if the item exists



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

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, retries: 10) ⇒ void

This method returns an undefined value.

Fills a gem pouch from a source container.

Handles full pouches by swapping them out for spares via swap_out_full_gempouch?. Handles untied pouches by tying them when requested.

Examples:

DRCI.fill_gem_pouch_with_container("black", "pouch", "lootbag",
  "backpack", "trunk", true)

Parameters:

  • gem_pouch_adjective (String) —

    pouch adjective (e.g., "black")

  • gem_pouch_noun (String) —

    pouch noun (e.g., "pouch")

  • source_container (String) —

    container holding gems to transfer

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

    container for full pouches

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

    container holding spare pouches

  • should_tie_gem_pouches (Boolean) (defaults to: false) —

    whether to tie pouches after filling

  • retries (Integer) (defaults to: 10) —

    remaining retry attempts before giving up (default 10)



2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
# File 'documented/dragonrealms/commons/common-items.rb', line 2522

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, retries: 10)
  if retries <= 0
    Lich::Messaging.msg("bold", "DRCI: fill_gem_pouch_with_container exceeded max retries")
    return
  end

  Flags.add("pouch-full", FILL_POUCH_FULL_PATTERN)
  begin
    pouch = "#{gem_pouch_adjective} #{gem_pouch_noun}"
    result = DRC.bput(
      "fill #{item_ref(pouch)} with #{item_ref(source_container)}",
      *FILL_POUCH_SUCCESS_PATTERNS,
      FILL_POUCH_FULL_PATTERN,
      *FILL_POUCH_NEEDS_TIE_PATTERNS,
      *FILL_POUCH_FAILURE_PATTERNS
    )

    case result
    when *FILL_POUCH_FAILURE_PATTERNS
      Lich::Messaging.msg("bold", "DRCI: Fill failed - #{result}")
      return
    when *FILL_POUCH_NEEDS_TIE_PATTERNS
      # Pouch needs to be tied before more gems can be added
      if should_tie_gem_pouches
        # Tie the pouch and retry
        unless tie_gem_pouch?(gem_pouch_adjective, gem_pouch_noun)
          Lich::Messaging.msg("bold", "DRCI: Could not tie #{gem_pouch_adjective} #{gem_pouch_noun}.")
          return
        end
        return fill_gem_pouch_with_container(gem_pouch_adjective, gem_pouch_noun, source_container, full_pouch_container, spare_gem_pouch_container, should_tie_gem_pouches, retries: retries - 1)
      else
        # Treat as full - swap out the pouch
        unless swap_out_full_gempouch?(gem_pouch_adjective, gem_pouch_noun, full_pouch_container, spare_gem_pouch_container, should_tie_gem_pouches)
          Lich::Messaging.msg("bold", "DRCI: Could not swap gem pouches.")
          return
        end
        return fill_gem_pouch_with_container(gem_pouch_adjective, gem_pouch_noun, source_container, full_pouch_container, spare_gem_pouch_container, should_tie_gem_pouches, retries: retries - 1)
      end
    when FILL_POUCH_FULL_PATTERN
      # Pouch is full, swap it out
      unless swap_out_full_gempouch?(gem_pouch_adjective, gem_pouch_noun, full_pouch_container, spare_gem_pouch_container, should_tie_gem_pouches)
        Lich::Messaging.msg("bold", "DRCI: Could not swap gem pouches.")
        return
      end
      return fill_gem_pouch_with_container(gem_pouch_adjective, gem_pouch_noun, source_container, full_pouch_container, spare_gem_pouch_container, should_tie_gem_pouches, retries: retries - 1)
    end

    # Check flag for mid-fill full pouch (when pouch fills up during the fill operation)
    if Flags["pouch-full"]
      Flags.reset("pouch-full")
      unless swap_out_full_gempouch?(gem_pouch_adjective, gem_pouch_noun, full_pouch_container, spare_gem_pouch_container, should_tie_gem_pouches)
        Lich::Messaging.msg("bold", "DRCI: Could not swap gem pouches.")
        return
      end
      return fill_gem_pouch_with_container(gem_pouch_adjective, gem_pouch_noun, source_container, full_pouch_container, spare_gem_pouch_container, should_tie_gem_pouches, retries: retries - 1)
    end

    # Optionally tie the pouch after successful fill
    tie_gem_pouch?(gem_pouch_adjective, gem_pouch_noun) if should_tie_gem_pouches
  ensure
    Flags.delete("pouch-full")
  end
end

.get_box_list_in_container(container) ⇒ Array<String>

Lists boxes in a container via RUMMAGE /B.

Parameters:

  • container (String) —

    container noun to rummage

Returns:

  • (Array<String>) —

    list of box descriptions



1524
1525
1526
# File 'documented/dragonrealms/commons/common-items.rb', line 1524

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

.get_inventory_by_type(type = 'combat') ⇒ Array<String>

Returns a list of item descriptions from the INVENTORY <type|slot> verb output.

Examples:

DRCI.get_inventory_by_type('combat')
#=> ["steel plate helm", "dark leather jerkin with reinforced seams"]

Parameters:

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

    inventory type: armor, weapon, fluff, container, combat, or any slot from INVENTORY SLOTS LIST

Returns:

  • (Array<String>) —

    item descriptions with articles stripped

See Also:



2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
# File 'documented/dragonrealms/commons/common-items.rb', line 2070

def get_inventory_by_type(type = 'combat')
  start_pattern = /^All of your |^You aren't wearing anything like that|^Both of your hands are empty/
  end_pattern = /^\[Use INVENTORY HELP/

  snapshot = Lich::Util.issue_command(
    "inventory #{type}",
    start_pattern,
    end_pattern,
    timeout: 5,
    usexml: false,
    include_end: false
  )

  if snapshot.nil? || snapshot.empty?
    Lich::Messaging.msg("bold", "DRCI: No inventory data for type '#{type}'. Valid options: ARMOR, WEAPON, FLUFF, CONTAINER, COMBAT, or any slot from INVENTORY SLOTS LIST.")
    return []
  end

  items_at_feet = snapshot.any? { |line| line.strip.start_with?('Lying at your feet') }

  snapshot
    .map(&:strip)
    .reject { |line| start_pattern.match?(line) || line.empty? }
    .take_while { |line| !items_at_feet || !line.start_with?('Lying at your feet') }
    .map { |item| item.gsub(/^(a|an|some)\s+/, '').gsub(/\s+\(closed\)/, '') }
end

.get_item(item, container = nil) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Gets an item, optionally from a specific container.

Accepts a single container or an array of containers to try in order. Delegates to get_item_safe with "my " prefix qualification.

Parameters:

  • item (String) —

    item noun to get

  • container (String, Array<String>, nil) (defaults to: nil) —

    container(s) to try, or nil for default

Returns:

  • (Boolean) —

    true if item was retrieved successfully



1677
1678
1679
1680
1681
1682
1683
1684
1685
# File 'documented/dragonrealms/commons/common-items.rb', line 1677

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

Gets an item, optionally from a specific container.

Predicate-named convenience wrapper for get_item.

Examples:

Get from default storage

DRCI.get_item?("sword")

Get from specific container

DRCI.get_item?("bandages", "backpack")

Parameters:

  • item (String) —

    item noun to get

  • container (String, Array<String>, nil) (defaults to: nil) —

    container noun, array of containers to try, or nil

Returns:

  • (Boolean) —

    true if item was retrieved successfully

See Also:



1664
1665
1666
# File 'documented/dragonrealms/commons/common-items.rb', line 1664

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

.get_item_from_eddy_portal?(item, container) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Gets an item from an eddy portal after forcing a content refresh.

Workaround for a game change where you must LOOK in the portal before its contents are available for retrieval.

Parameters:

  • item (String) —

    item name to get

  • container (String) —

    portal container reference

Returns:

  • (Boolean) —

    true if item was retrieved successfully

See Also:



1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
# File 'documented/dragonrealms/commons/common-items.rb', line 1771

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

Gets an item only if not already held in either hand.

Avoids getting a duplicate when you already have the item. Returns true if the item is already in hand or was successfully retrieved.

Examples:

DRCI.get_item_if_not_held?("almanac")
DRCI.get_item_if_not_held?("sword", "backpack")

Parameters:

  • item (String) —

    item noun to get

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

    container to get from, or nil for default

Returns:

  • (Boolean) —

    true if item is now in hand

See Also:



1642
1643
1644
1645
1646
1647
# File 'documented/dragonrealms/commons/common-items.rb', line 1642

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<String>?

Lists items in a container using RUMMAGE or LOOK.

RUMMAGE returns full tap descriptions (e.g., "grey ice skates with black laces"). LOOK returns short names (e.g., "grey ice skates"), which is easier to parse.

Examples:

DRCI.get_item_list("backpack", "look")

Parameters:

  • container (String) —

    container noun to inspect

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

    "rummage" or "look"

Returns:

  • (Array<String>, nil) —

    list of item descriptions, or nil on failure

See Also:



2111
2112
2113
2114
2115
2116
2117
2118
# File 'documented/dragonrealms/commons/common-items.rb', line 2111

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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Gets an item with "my " prefix on item and container names.

Wrapper for get_item_safe? with identical behavior.

Parameters:

  • item (String) —

    item noun to get

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

    container noun, or nil for default

Returns:

  • (Boolean) —

    true if item was retrieved successfully



1707
1708
1709
# File 'documented/dragonrealms/commons/common-items.rb', line 1707

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

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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Gets an item with "my " prefix on item and container names.

Parameters:

  • item (String) —

    item noun to get

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

    container noun, or nil for default

Returns:

  • (Boolean) —

    true if item was retrieved successfully



1693
1694
1695
1696
1697
# File 'documented/dragonrealms/commons/common-items.rb', line 1693

def get_item_safe?(item, container = nil)
  item = item_ref(item)
  container = item_ref(container) if container && !(container =~ /^(in|on|under|behind|from) /i)
  get_item_unsafe(item, container)
end

.get_item_unsafe(item, container = nil) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Gets an item without "my " prefix qualification.

Issues the GET command, then verifies success by checking whether the item's noun appears in either hand via the XML game-object feed (+in_hands?+) rather than relying on text-pattern matching of the game response. This avoids false positives from combat messages (e.g. "You get a startling sensation" matching /^You get/).

The success and failure patterns are still passed to bput so it returns promptly once the game has responded, but the return value of bput is not used to determine success.

A short polling loop (up to 1 second) accommodates XML feed lag between the text response and the GameObj update.

A "#<id>" reference has no noun (Lich::DragonRealms::DRC.get_noun returns nil), so it is verified by that exact id being in hand (see in_hand?).

Examples:

Basic retrieval

get_item_unsafe("backpack")  #=> true (if backpack is now in hand)

With container

get_item_unsafe("sword", "chest")  #=> true

Parameters:

  • item (String) —

    item name (unqualified) or "#"

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

    container name (unqualified), or nil

Returns:

  • (Boolean) —

    true if item was retrieved successfully

See Also:



1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
# File 'documented/dragonrealms/commons/common-items.rb', line 1742

def get_item_unsafe(item, container = nil)
  from = container
  from = "from #{container}" if container && !(container =~ /^(in|on|under|behind|from) /i)

  target = item.to_s.match?(ITEM_ID_REF_PATTERN) ? item : DRC.get_noun(item)
  DRC.bput("get #{item} #{from}", GET_ITEM_FAILURE_PATTERNS, GET_ITEM_SUCCESS_PATTERNS)

  10.times do
    break if in_hands?(target)
    sleep 0.1
  end

  return true if in_hands?(target)
  return get_item_from_eddy_portal?(item, container) if container =~ /\bportal\b/i

  false
end

.get_scroll_list_in_container(container) ⇒ Array<String>

Lists scrolls in a container via RUMMAGE /SC.

Parameters:

  • container (String) —

    container noun to rummage

Returns:

  • (Array<String>) —

    list of scroll descriptions



1532
1533
1534
# File 'documented/dragonrealms/commons/common-items.rb', line 1532

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

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

Gives a held item to a target (player or NPC).

Handles retry prompts, expired offers, and hand-swap scenarios. Uses a 35-second timeout to allow the target time to accept.

Examples:

Give to NPC for repair

DRCI.give_item?("Ragge", "sword")

Parameters:

  • target (String) —

    player name or NPC noun to give to

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

    item noun, or nil to give whatever is held

  • retries (Integer) (defaults to: 5) —

    remaining retry attempts before giving up (default 5)

Returns:

  • (Boolean, nil) —

    true if accepted, false if declined/failed, nil on edge cases

See Also:



2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
# File 'documented/dragonrealms/commons/common-items.rb', line 2327

def give_item?(target, item = nil, retries: 5)
  if retries <= 0
    Lich::Messaging.msg("bold", "DRCI: give_item? exceeded max retries")
    return false
  end

  command = item ? "give #{item_ref(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, retries: retries - 1)
  when /already has an outstanding offer/
    pause 5
    give_item?(target, item, retries: retries - 1)
  when /GIVE it again/
    waitrt
    give_item?(target, item, retries: retries - 1)
  when /You don't need to specify the object/
    if in_right_hand?(item)
      give_item?(target, retries: retries - 1)
    elsif in_left_hand?(item)
      case DRC.bput('swap', *SWAP_HANDS_SUCCESS_PATTERNS, *SWAP_HANDS_FAILURE_PATTERNS)
      when *SWAP_HANDS_SUCCESS_PATTERNS
        give_item?(target, retries: retries - 1)
      else
        false
      end
    else
      Lich::Messaging.msg("bold", "DRCI: give_item? could not find '#{item}' in either hand")
      false
    end
  end
end

.have_item_by_look?(item, container) ⇒ Boolean

Checks if an item exists in a container by LOOKing at it.

Unlike exists? which uses TAP, this uses LOOK AT which can find items inside containers that TAP cannot reach.

Parameters:

  • item (String) —

    item noun to look for

  • container (String) —

    container noun to look in

Returns:

  • (Boolean) —

    true if item is found in the container



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

def have_item_by_look?(item, container)
  return false unless item

  item = item.delete_prefix('my ')
  # For item IDs, don't add preposition with 'my' - just use 'in' for the container
  if container&.start_with?('#')
    preposition = 'in' if container && !(container =~ /^(in|on|under|behind|from) /i)
  else
    preposition = 'in my' if container && !(container =~ /^((in|on|under|behind|from) )?my /i)
  end

  case DRC.bput("look at #{item_ref(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

.id_in_hand?(id, which_hand) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Whether the item with this GameObj id is in the given hand(s). An empty hand is a placeholder with a nil id, so it never matches.

Parameters:

  • id (String) —

    item id, without the leading "#"

  • which_hand (String) —

    "left", "right", "either", or "both"

Returns:

  • (Boolean)


1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
# File 'documented/dragonrealms/commons/common-items.rb', line 1367

def id_in_hand?(id, which_hand)
  left = GameObj.left_hand&.id.to_s == id
  right = GameObj.right_hand&.id.to_s == id
  case which_hand.downcase
  when 'left' then left
  when 'right' then right
  when 'either' then left || right
  when 'both' then left && right
  else
    Lich::Messaging.msg("bold", "DRCI: Unknown hand: #{which_hand}. Valid options are: left, right, either, both")
    false
  end
end

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

Checks if an item is in one or more hands.

Accepts a string noun, a "#<id>" reference, or a Lich::DragonRealms::DRC::Item object. Strings are converted to Item objects for regex matching against hand contents; a "#<id>" reference has no noun to match, so it is compared with the GameObj hand ids instead (exact item only).

Examples:

Check either hand

DRCI.in_hand?("sword")

Check specific hand

DRCI.in_hand?("shield", "left")

Check for one exact item by id

DRCI.in_hand?("#41234567")

Parameters:

  • item (String, DRC::Item) —

    item noun, "#", or Item object

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

    "left", "right", "either", or "both"

Returns:

  • (Boolean) —

    true if item is in the specified hand(s)



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 1337

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

  if item.is_a?(String) && (id = item[ITEM_ID_REF_PATTERN, 1])
    return id_in_hand?(id, which_hand)
  end

  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
    Lich::Messaging.msg("bold", "DRCI: Unknown hand: #{which_hand}. Valid options are: left, right, either, both")
    false
  end
end

.in_hands?(item) ⇒ Boolean

Checks if the item is in either hand.

Parameters:

Returns:

  • (Boolean) —

    true if item is in either hand

See Also:



1294
1295
1296
# File 'documented/dragonrealms/commons/common-items.rb', line 1294

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

.in_left_hand?(item) ⇒ Boolean

Checks if the item is in the left hand.

Parameters:

Returns:

  • (Boolean) —

    true if item is in the left hand

See Also:



1304
1305
1306
# File 'documented/dragonrealms/commons/common-items.rb', line 1304

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

.in_right_hand?(item) ⇒ Boolean

Checks if the item is in the right hand.

Parameters:

Returns:

  • (Boolean) —

    true if item is in the right hand

See Also:



1314
1315
1316
# File 'documented/dragonrealms/commons/common-items.rb', line 1314

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

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

Checks if an item is inside a container by tapping it.

Parameters:

  • item (String) —

    item noun to check

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

    container noun to check, or nil for any

Returns:

  • (Boolean) —

    true if item is inside a container



1250
1251
1252
# File 'documented/dragonrealms/commons/common-items.rb', line 1250

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

.item_ref(value) ⇒ String?

Prepends "my " to an item or container name for ownership qualification.

Skips the prefix when the value is nil, already starts with "my ", or uses item ID syntax (starts with "#").

Examples:

DRCI.item_ref("sword")       #=> "my sword"
DRCI.item_ref("my sword")    #=> "my sword"
DRCI.item_ref("#12345")       #=> "#12345"
DRCI.item_ref(nil)            #=> nil

Parameters:

  • value (String, nil) —

    item or container noun

Returns:

  • (String, nil) —

    qualified name, or nil if value was nil



58
59
60
61
62
# File 'documented/dragonrealms/commons/common-items.rb', line 58

def item_ref(value)
  return value if value.nil? || value =~ /^(my |#)/i

  "my #{value}"
end

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

Lifts an item from the ground, optionally stowing it afterward.

Examples:

Lift only

DRCI.lift?("sword")

Lift and stow to default

DRCI.lift?("sword", true)

Lift and put in specific container

DRCI.lift?("sword", "backpack")

Parameters:

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

    item noun to lift (uses last word only)

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

    if a String, puts item in that container; if true, stows to default container; if nil/false, just lifts

Returns:

  • (Boolean) —

    true if lifted (and optionally stowed) successfully



2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
# File 'documented/dragonrealms/commons/common-items.rb', line 2028

def lift?(item = nil, stow = nil)
  return false unless item

  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

.list_container_contents(verb, container, retries: 2) {|String| ... } ⇒ Array<String>?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Shared implementation for listing container contents with retry and closed-container recovery. Callers provide a block to parse the game response into an item list.

Parameters:

  • verb (String) —

    command verb ("rummage" or "look in")

  • container (String) —

    container noun

  • retries (Integer) (defaults to: 2) —

    remaining retry attempts

Yields:

  • (String) —

    game response text for parsing

Yield Returns:

  • (Array<String>) —

    parsed item list

Returns:

  • (Array<String>, nil) —

    parsed items, empty array if empty, nil on failure



2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
# File 'documented/dragonrealms/commons/common-items.rb', line 2170

def list_container_contents(verb, container, retries: 2, &parse_block)
  container = item_ref(container)

  if retries <= 0
    Lich::Messaging.msg("bold", "DRCI: #{verb} exceeded max retries")
    return nil
  end

  contents = DRC.bput("#{verb} #{container}", CONTAINER_IS_CLOSED_PATTERNS, RUMMAGE_SUCCESS_PATTERNS, RUMMAGE_FAILURE_PATTERNS)
  case contents
  when *RUMMAGE_FAILURE_PATTERNS
    Lich::Messaging.msg("bold", "DRCI: Unable to #{verb} '#{container}'.")
    nil
  when *CONTAINER_IS_CLOSED_PATTERNS
    unless open_container?(container)
      Lich::Messaging.msg("bold", "DRCI: Unable to open '#{container}' for #{verb}.")
      return nil
    end

    list_container_contents(verb, container, retries: retries - 1, &parse_block)
  when /there is nothing/i
    []
  else
    parse_block.call(contents)
  end
end

.look_in_container(container, retries: 2) ⇒ Array<String>?

Lists items in a container via LOOK IN.

Returns short item names. Automatically opens closed containers before looking.

Parameters:

  • container (String) —

    container noun to look in

  • retries (Integer) (defaults to: 2) —

    remaining retry attempts before giving up (default 2)

Returns:

  • (Array<String>, nil) —

    list of item descriptions, or nil if cannot access container



2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
# File 'documented/dragonrealms/commons/common-items.rb', line 2147

def look_in_container(container, retries: 2)
  list_container_contents("look in", container, retries: retries) do |contents|
    match = contents.match(/In the .* you see (?:some|an|a) (?<items>.*)\./)
    next [] unless match

    match[:items]
      .split(/(?:,|and) (?:some|an|a)/)
      .map(&:strip)
  end
end

.lower_item?(item) ⇒ Boolean

Lowers a held item to the ground (feet slot).

Determines which hand holds the item, then issues LOWER GROUND.

Examples:

DRCI.lower_item?("sword")

Parameters:

  • item (String) —

    item noun or "#" to lower

Returns:

  • (Boolean) —

    true if item was lowered successfully, false if not held or failed



2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
# File 'documented/dragonrealms/commons/common-items.rb', line 2001

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

  hand = in_left_hand?(item) ? '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 container.

Parameters:

  • container (String) —

    container noun to open

Returns:

  • (Boolean) —

    true if container was opened (or already open)

See Also:



2287
2288
2289
2290
2291
2292
2293
# File 'documented/dragonrealms/commons/common-items.rb', line 2287

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 held item, optionally into a specific container.

If no container is specified, uses the default stow location. Accepts an array of containers to try in order (useful when some may be full).

Examples:

Stow to default location

DRCI.put_away_item?("sword")

Put in specific container

DRCI.put_away_item?("sword", "backpack")

Try multiple containers

DRCI.put_away_item?("gem", ["pouch", "sack", "backpack"])

Parameters:

  • item (String) —

    item noun to put away

  • container (String, Array<String>, nil) (defaults to: nil) —

    container noun, array of containers, or nil

Returns:

  • (Boolean) —

    true if item was put away successfully

See Also:



2221
2222
2223
2224
2225
2226
2227
2228
2229
# File 'documented/dragonrealms/commons/common-items.rb', line 2221

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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Puts away an item with "my " prefix on item and container names.

Parameters:

  • item (String) —

    item noun to put away

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

    container noun, or nil for default

Returns:

  • (Boolean) —

    true if item was put away successfully



2237
2238
2239
# File 'documented/dragonrealms/commons/common-items.rb', line 2237

def put_away_item_safe?(item, container = nil)
  put_away_item_unsafe?(item_ref(item), item_ref(container))
end

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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Puts away an item without "my " prefix qualification.

Supports custom prepositions (e.g., "on", "under") and retries on closed containers or retry-pattern responses.

Parameters:

  • item (String) —

    item name (unqualified)

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

    container name (unqualified), or nil for default stow

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

    container preposition ("in", "on", "under", etc.)

  • retries (Integer) (defaults to: 3) —

    remaining retry attempts before giving up (default 3)

Returns:

  • (Boolean) —

    true if item was put away successfully



2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
# File 'documented/dragonrealms/commons/common-items.rb', line 2252

def put_away_item_unsafe?(item, container = nil, preposition = "in", retries: 3)
  if retries <= 0
    Lich::Messaging.msg("bold", "DRCI: put_away_item_unsafe? exceeded max retries")
    return false
  end

  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, preposition, retries: retries - 1)
  when *PUT_AWAY_ITEM_RETRY_PATTERNS
    return put_away_item_unsafe?(item, container, preposition, retries: retries - 1)
  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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Removes the current gem pouch and stows it in a container.

Parameters:

  • gem_pouch_adjective (String) —

    pouch adjective (e.g., "black")

  • gem_pouch_noun (String) —

    pouch noun (e.g., "pouch")

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

    container for the full pouch, or nil for default

Returns:

  • (Boolean) —

    true if removed and stowed successfully



2444
2445
2446
2447
2448
2449
2450
2451
# File 'documented/dragonrealms/commons/common-items.rb', line 2444

def remove_and_stow_pouch?(gem_pouch_adjective, gem_pouch_noun, full_pouch_container = nil)
  pouch = "#{gem_pouch_adjective} #{gem_pouch_noun}"
  unless remove_item?(pouch)
    Lich::Messaging.msg("bold", "DRCI: Unable to remove existing pouch.")
    return false
  end
  put_away_item?(pouch, full_pouch_container) || stow_item?(pouch)
end

.remove_item?(item) ⇒ Boolean

Removes a worn item into your hands.

Issues the REMOVE command with "my " prefix qualification.

Examples:

DRCI.remove_item?("cloak")

Parameters:

  • item (String) —

    item noun to remove

Returns:

  • (Boolean) —

    true if item was removed successfully

See Also:



1907
1908
1909
# File 'documented/dragonrealms/commons/common-items.rb', line 1907

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

.remove_item_safe?(item) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Removes a worn item with "my " prefix qualification.

Parameters:

  • item (String) —

    item noun to remove

Returns:

  • (Boolean) —

    true if item was removed successfully



1916
1917
1918
# File 'documented/dragonrealms/commons/common-items.rb', line 1916

def remove_item_safe?(item)
  remove_item_unsafe?(item_ref(item))
end

.remove_item_unsafe?(item) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Removes a worn item without "my " prefix qualification.

Parameters:

  • item (String) —

    item name (unqualified)

Returns:

  • (Boolean) —

    true if item was removed successfully



1925
1926
1927
1928
1929
1930
1931
1932
# File 'documented/dragonrealms/commons/common-items.rb', line 1925

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, retries: 2) ⇒ Array<String>?

Lists items in a container via RUMMAGE.

Returns full tap descriptions. Automatically opens closed containers before rummaging.

Parameters:

  • container (String) —

    container noun to rummage

  • retries (Integer) (defaults to: 2) —

    remaining retry attempts before giving up (default 2)

Returns:

  • (Array<String>, nil) —

    list of item descriptions, or nil if cannot access container



2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
# File 'documented/dragonrealms/commons/common-items.rb', line 2128

def rummage_container(container, retries: 2)
  list_container_contents("rummage", container, retries: retries) do |contents|
    match = contents.match(/You rummage through .* and see (?:a|an|some) (?<items>.*)\./)
    next [] unless match

    match[: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

Searches inventory for an item using the INV SEARCH command.

Examples:

DRCI.search?("deed")  #=> true if found

Parameters:

  • item (String) —

    item noun to search for

Returns:

  • (Boolean) —

    true if item is found in inventory



1233
1234
1235
# File 'documented/dragonrealms/commons/common-items.rb', line 1233

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

.stow_hand(hand, retries: 3) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Stows whatever is in the specified hand.

Handles braids that are too long by disposing them as trash.

Parameters:

  • hand (String) —

    "right" or "left"

  • retries (Integer) (defaults to: 3) —

    remaining retry attempts before giving up (default 3)

Returns:

  • (Boolean) —

    true if the hand is now empty



1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
# File 'documented/dragonrealms/commons/common-items.rb', line 1604

def stow_hand(hand, retries: 3)
  if retries <= 0
    Lich::Messaging.msg("bold", "DRCI: stow_hand exceeded max retries")
    return false
  end

  result = DRC.bput("stow #{hand}", BRAID_TOO_LONG_PATTERN, CONTAINER_IS_CLOSED_PATTERNS, STOW_ITEM_SUCCESS_PATTERNS, STOW_ITEM_FAILURE_PATTERNS, STOW_ITEM_RETRY_PATTERNS)
  braid_match = result&.match(BRAID_TOO_LONG_PATTERN)
  if braid_match
    dispose_trash(DRC.get_noun(braid_match[:braid_name]))
  elsif STOW_ITEM_RETRY_PATTERNS.any? { |pat| pat.match?(result) }
    stow_hand(hand, retries: retries - 1)
  elsif STOW_ITEM_SUCCESS_PATTERNS.any? { |pat| pat.match?(result) }
    true
  else
    false
  end
end

.stow_hands ⇒ Boolean

Stows whatever is held in both hands.

Skips empty hands. Returns true only if both hands are empty or successfully stowed.

Returns:

  • (Boolean) —

    true if both hands are now empty

See Also:



1581
1582
1583
1584
# File 'documented/dragonrealms/commons/common-items.rb', line 1581

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

.stow_item?(item) ⇒ Boolean

Stows an item into its default container (per STORE HELP settings).

Issues the STOW command with "my " prefix qualification. Retries automatically on retry-pattern responses.

Examples:

DRCI.stow_item?("sword")

Parameters:

  • item (String) —

    item noun to stow

Returns:

  • (Boolean) —

    true if item was stowed successfully

See Also:



1950
1951
1952
# File 'documented/dragonrealms/commons/common-items.rb', line 1950

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

.stow_item_safe?(item) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Stows an item with "my " prefix qualification.

Parameters:

  • item (String) —

    item noun to stow

Returns:

  • (Boolean) —

    true if item was stowed successfully



1959
1960
1961
# File 'documented/dragonrealms/commons/common-items.rb', line 1959

def stow_item_safe?(item)
  stow_item_unsafe?(item_ref(item))
end

.stow_item_unsafe?(item, retries: 3) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Note:

Without "my " prefix, may attempt to stow an item on the ground rather than one in your inventory.

Stows an item without "my " prefix qualification.

Parameters:

  • item (String) —

    item name (unqualified)

  • retries (Integer) (defaults to: 3) —

    remaining retry attempts before giving up (default 3)

Returns:

  • (Boolean) —

    true if item was stowed successfully



1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
# File 'documented/dragonrealms/commons/common-items.rb', line 1972

def stow_item_unsafe?(item, retries: 3)
  if retries <= 0
    Lich::Messaging.msg("bold", "DRCI: stow_item_unsafe? exceeded max retries")
    return false
  end

  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, retries: retries - 1)
  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 a full gem pouch for a spare one.

Removes and stows the current pouch, then checks the belt for an existing spare before getting one from the spare container.

Parameters:

  • gem_pouch_adjective (String) —

    pouch adjective (e.g., "black")

  • gem_pouch_noun (String) —

    pouch noun (e.g., "pouch")

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

    container for the full pouch

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

    container holding spare pouches

  • should_tie_gem_pouches (Boolean) (defaults to: false) —

    whether to tie the new pouch

Returns:

  • (Boolean) —

    true if swap completed successfully



2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
# File 'documented/dragonrealms/commons/common-items.rb', line 2464

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?
    Lich::Messaging.msg("bold", "DRCI: No free hand. Not swapping pouches now.")
    return false
  end

  unless remove_and_stow_pouch?(gem_pouch_adjective, gem_pouch_noun, full_pouch_container)
    Lich::Messaging.msg("bold", "DRCI: Remove and stow pouch routine failed.")
    return false
  end

  pouch = "#{gem_pouch_adjective} #{gem_pouch_noun}"

  # Check if there's already another pouch on the belt before getting from spare container
  if check_belt_for_pouch?(gem_pouch_adjective, gem_pouch_noun)
    Lich::Messaging.msg("plain", "DRCI: Found existing #{pouch} on belt, using that.")
    unless untie_item?(pouch)
      Lich::Messaging.msg("bold", "DRCI: Could not untie existing pouch on belt.")
      return false
    end
  elsif !get_item?(pouch, spare_gem_pouch_container)
    Lich::Messaging.msg("bold", "DRCI: No spare pouch found in #{spare_gem_pouch_container || 'default container'}.")
    return false
  end

  unless wear_item?(pouch)
    Lich::Messaging.msg("bold", "DRCI: Could not wear new pouch.")
    return false
  end

  # A fresh pouch is usually empty, and an empty pouch can't be tied off
  # yet -- that is expected, not a failure.
  if should_tie_gem_pouches && tie_item_result(pouch) == :failed
    Lich::Messaging.msg("bold", "DRCI: Could not tie new pouch.")
    # Not a fatal error - pouch is worn, just not tied
  end

  true
end

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

Taps an item and returns the game response string.

The tap response indicates whether the item is worn, inside a container, etc. Used by wearing?, inside?, and exists?.

Parameters:

  • item (String) —

    item noun to tap

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

    container to qualify the tap, or nil for general inventory

Returns:

  • (String, nil) —

    game response text, or nil if item is nil



1280
1281
1282
1283
1284
1285
1286
# File 'documented/dragonrealms/commons/common-items.rb', line 1280

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

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

.tie_gem_pouch(gem_pouch_adjective, gem_pouch_noun) ⇒ Object

Deprecated.

Use tie_gem_pouch? instead for boolean return value.

Warns only on a real failure: an empty pouch can't be tied off, and stays silent as it always has.



2431
2432
2433
2434
2435
# File 'documented/dragonrealms/commons/common-items.rb', line 2431

def tie_gem_pouch(gem_pouch_adjective, gem_pouch_noun)
  if tie_item_result("#{gem_pouch_adjective} #{gem_pouch_noun}") == :failed
    Lich::Messaging.msg("bold", "DRCI: Failed to tie #{gem_pouch_adjective} #{gem_pouch_noun}.")
  end
end

.tie_gem_pouch?(gem_pouch_adjective, gem_pouch_noun) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Ties a gem pouch.

Parameters:

  • gem_pouch_adjective (String) —

    pouch adjective (e.g., "black")

  • gem_pouch_noun (String) —

    pouch noun (e.g., "pouch")

Returns:

  • (Boolean) —

    true if tied successfully or already tied



2423
2424
2425
# File 'documented/dragonrealms/commons/common-items.rb', line 2423

def tie_gem_pouch?(gem_pouch_adjective, gem_pouch_noun)
  tie_item?("#{gem_pouch_adjective} #{gem_pouch_noun}")
end

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

Ties an item, optionally to a specific container.

True only when the item is tied afterwards (tied now, or already tied). An empty container can't be tied off, so that reply is false; use tie_item_result to tell it apart from a failure.

Examples:

Tie to belt

DRCI.tie_item?("pouch", "belt")

Parameters:

  • item (String) —

    item noun to tie

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

    container to tie to, or nil for default

Returns:

  • (Boolean) —

    true if item is tied

See Also:



1804
1805
1806
# File 'documented/dragonrealms/commons/common-items.rb', line 1804

def tie_item?(item, container = nil)
  %i[tied already_tied].include?(tie_item_result(item, container))
end

.tie_item_result(item, container = nil) ⇒ Symbol

Ties an item and reports what happened.

Examples:

DRCI.tie_item_result("pouch") #=> :empty

Parameters:

  • item (String) —

    item noun to tie

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

    container to tie to, or nil for default

Returns:

  • (Symbol) —

    :tied, :already_tied, :empty (an empty container can't be tied off -- nothing was tied), or :failed (including no reply)

See Also:



1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
# File 'documented/dragonrealms/commons/common-items.rb', line 1819

def tie_item_result(item, container = nil)
  place = container ? "to #{item_ref(container)}" : nil
  case DRC.bput("tie #{item_ref(item)} #{place}", TIE_ITEM_SUCCESS_PATTERNS, TIE_ITEM_EMPTY_PATTERN, TIE_ITEM_FAILURE_PATTERNS)
  when TIE_ITEM_ALREADY_TIED_PATTERN
    :already_tied
  when *TIE_ITEM_SUCCESS_PATTERNS
    :tied
  when TIE_ITEM_EMPTY_PATTERN
    :empty
  else
    :failed
  end
end

.trash_storage ⇒ Array<String>

Recognized trash-receptacle nouns: the built-in TRASH_STORAGE defaults merged with the player's custom_trash_storage additions. Lets a player teach dispose_trash about a receptacle their town has that Lich does not yet know, without a Lich release.

Returns:

  • (Array<String>) —

    recognized trash-receptacle nouns

See Also:



81
82
83
# File 'documented/dragonrealms/commons/common-items.rb', line 81

def trash_storage
  CustomSubstitutions.resolve(:custom_trash_storage, TRASH_STORAGE, type: :names)
end

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

Unties an item, optionally from a specific container.

Parameters:

  • item (String) —

    item noun to untie

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

    container to untie from, or nil for default

Returns:

  • (Boolean) —

    true if item was untied successfully

See Also:



1840
1841
1842
1843
1844
1845
1846
1847
1848
# File 'documented/dragonrealms/commons/common-items.rb', line 1840

def untie_item?(item, container = nil)
  place = container ? "from #{item_ref(container)}" : nil
  case DRC.bput("untie #{item_ref(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 an item from your hands.

Issues the WEAR command with "my " prefix qualification.

Examples:

DRCI.wear_item?("cloak")

Parameters:

  • item (String) —

    item noun to wear

Returns:

  • (Boolean) —

    true if item was worn successfully

See Also:



1865
1866
1867
# File 'documented/dragonrealms/commons/common-items.rb', line 1865

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

.wear_item_safe?(item) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Wears an item with "my " prefix qualification.

Parameters:

  • item (String) —

    item noun to wear

Returns:

  • (Boolean) —

    true if item was worn successfully



1874
1875
1876
# File 'documented/dragonrealms/commons/common-items.rb', line 1874

def wear_item_safe?(item)
  wear_item_unsafe?(item_ref(item))
end

.wear_item_unsafe?(item) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Wears an item without "my " prefix qualification.

Parameters:

  • item (String) —

    item name (unqualified)

Returns:

  • (Boolean) —

    true if item was worn successfully



1883
1884
1885
1886
1887
1888
1889
1890
# File 'documented/dragonrealms/commons/common-items.rb', line 1883

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 an item is currently worn by tapping it.

Parameters:

  • item (String) —

    item noun to check

Returns:

  • (Boolean) —

    true if item is currently worn



1241
1242
1243
# File 'documented/dragonrealms/commons/common-items.rb', line 1241

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