Class: Lich::DragonRealms::DRC::Item

Inherits:
Object
  • Object
show all
Defined in:
documented/dragonrealms/commons/common.rb

Overview

Items class. Name is the noun of the object. Leather/metal boolean. Is the item worn (defaults to true). Does it hinder lockpicking? (false) Item.new(name:'gloves', leather:true, worn:true, hinders_locks:true, adjective:'ring', bound:true)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: nil, leather: nil, worn: false, hinders_locks: nil, container: nil, swappable: false, tie_to: nil, adjective: nil, bound: false, wield: false, transforms_to: nil, transform_text: nil, transform_verb: nil, lodges: true, skip_repair: false, ranged: nil, needs_unloading: nil) ⇒ Item

Creates an Item instance to describe equipment for outfit management.

Examples:

DRC::Item.new(name: 'sword', worn: true, adjective: 'broadsword')
DRC::Item.new(name: 'backpack', container: true)

Parameters:

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

    the item noun used for get/stow commands

  • leather (Boolean, nil) (defaults to: nil) —

    whether the item is leather (vs metal)

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

    whether the item is worn on the body (default false)

  • hinders_locks (Boolean, nil) (defaults to: nil) —

    whether wearing this item blocks lockpicking

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

    container noun if this item is a container (e.g. "backpack")

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

    whether this item can be freely swapped in/out during actions (default false)

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

    another item noun this should be tied to (e.g. "bag" for a cord)

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

    the descriptive adjective used in get commands (e.g. "ring" in "ring.sword")

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

    whether this item is bound and cannot be dropped (default false)

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

    whether the item should be wielded in hand (default false)

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

    noun of the item after a transform (e.g. "rope" -> "coil")

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

    text to look for to trigger the transform (e.g. "coil it")

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

    the verb to trigger the transform (e.g. "coil")

  • lodges (Boolean) (defaults to: true) —

    whether the item can lodge/stick in targets (default true)

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

    whether to skip repairing this item (default false)

  • ranged (Boolean, nil) (defaults to: nil) —

    whether this is a ranged weapon; auto-detected from name if nil

  • needs_unloading (Boolean, nil) (defaults to: nil) —

    whether the item needs unloading; defaults to ranged value if nil

See Also:



629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
# File 'documented/dragonrealms/commons/common.rb', line 629

def initialize(name: nil, leather: nil, worn: false, hinders_locks: nil, container: nil, swappable: false, tie_to: nil, adjective: nil, bound: false, wield: false, transforms_to: nil, transform_text: nil, transform_verb: nil, lodges: true, skip_repair: false, ranged: nil, needs_unloading: nil)
  @name = name
  @leather = leather
  @worn = worn
  @hinders_lockpicking = hinders_locks
  @container = container
  @swappable = swappable
  @tie_to = tie_to
  @adjective = adjective
  @bound = bound
  @wield = wield
  @transforms_to = transforms_to
  @transform_verb = transform_verb
  @transform_text = transform_text
  @lodges = lodges.nil? ? true : lodges
  @skip_repair = skip_repair
  @ranged = ranged.nil? ? ranged_weapon?(name) : ranged
  @needs_unloading = needs_unloading.nil? ? @ranged : needs_unloading
end

Instance Attribute Details

#adjective ⇒ Object (readonly)

Returns the value of attribute adjective.



604
605
606
# File 'documented/dragonrealms/commons/common.rb', line 604

def adjective
  @adjective
end

#bound ⇒ Object (readonly)

Returns the value of attribute bound.



604
605
606
# File 'documented/dragonrealms/commons/common.rb', line 604

def bound
  @bound
end

#container ⇒ Object (readonly)

Returns the value of attribute container.



604
605
606
# File 'documented/dragonrealms/commons/common.rb', line 604

def container
  @container
end

#hinders_lockpicking ⇒ Object (readonly)

Returns the value of attribute hinders_lockpicking.



604
605
606
# File 'documented/dragonrealms/commons/common.rb', line 604

def hinders_lockpicking
  @hinders_lockpicking
end

#leather ⇒ Object (readonly)

Returns the value of attribute leather.



604
605
606
# File 'documented/dragonrealms/commons/common.rb', line 604

def leather
  @leather
end

#lodges ⇒ Object (readonly)

Returns the value of attribute lodges.



604
605
606
# File 'documented/dragonrealms/commons/common.rb', line 604

def lodges
  @lodges
end

#name ⇒ Object (readonly)

Returns the value of attribute name.



604
605
606
# File 'documented/dragonrealms/commons/common.rb', line 604

def name
  @name
end

#needs_unloading ⇒ Object (readonly)

Returns the value of attribute needs_unloading.



604
605
606
# File 'documented/dragonrealms/commons/common.rb', line 604

def needs_unloading
  @needs_unloading
end

#ranged ⇒ Object (readonly)

Returns the value of attribute ranged.



604
605
606
# File 'documented/dragonrealms/commons/common.rb', line 604

def ranged
  @ranged
end

#skip_repair ⇒ Object (readonly)

Returns the value of attribute skip_repair.



604
605
606
# File 'documented/dragonrealms/commons/common.rb', line 604

def skip_repair
  @skip_repair
end

#swappable ⇒ Object (readonly)

Returns the value of attribute swappable.



604
605
606
# File 'documented/dragonrealms/commons/common.rb', line 604

def swappable
  @swappable
end

#tie_to ⇒ Object (readonly)

Returns the value of attribute tie_to.



604
605
606
# File 'documented/dragonrealms/commons/common.rb', line 604

def tie_to
  @tie_to
end

#transform_text ⇒ Object (readonly)

Returns the value of attribute transform_text.



604
605
606
# File 'documented/dragonrealms/commons/common.rb', line 604

def transform_text
  @transform_text
end

#transform_verb ⇒ Object (readonly)

Returns the value of attribute transform_verb.



604
605
606
# File 'documented/dragonrealms/commons/common.rb', line 604

def transform_verb
  @transform_verb
end

#transforms_to ⇒ Object (readonly)

Returns the value of attribute transforms_to.



604
605
606
# File 'documented/dragonrealms/commons/common.rb', line 604

def transforms_to
  @transforms_to
end

#wield ⇒ Object (readonly)

Returns the value of attribute wield.



604
605
606
# File 'documented/dragonrealms/commons/common.rb', line 604

def wield
  @wield
end

#worn ⇒ Object (readonly)

Returns the value of attribute worn.



604
605
606
# File 'documented/dragonrealms/commons/common.rb', line 604

def worn
  @worn
end

Class Method Details

.from_text(text) ⇒ Object

Convenience method to parse the text of an item as shown when in your hands, with or without an adjective, into an Item class instance. Originally designed to support DRCI and equipmanager methods.



694
695
696
697
698
699
700
701
702
703
704
705
706
707
# File 'documented/dragonrealms/commons/common.rb', line 694

def self.from_text(text)
  return nil if text.nil? || text.to_s.strip.empty?

  normalized = text
               .sub('.', ' ') # convert 'foo.bar' => 'foo bar' so more easily split into adjective and noun
               .squeeze(' ') # condense repeated runs of whitespace with a single space
               .strip # remove leading/trailing whitespace
  parts = normalized.split
  if parts.size > 1
    DRC::Item.new(adjective: parts.first, name: parts.last)
  else
    DRC::Item.new(name: normalized)
  end
end

Instance Method Details

#ranged_weapon?(noun) ⇒ Boolean

Determines if a noun is a ranged weapon by matching against known patterns. Checks both common ranged weapons (bow, crossbow, sling, etc.) and racial ranged weapons (Gamgweth weapons like jranoki, uku'uan).

Examples:

item = Item.new(name: 'bow')
item.ranged_weapon?('bow') #=> true
item.ranged_weapon?('sword') #=> false

Parameters:

  • noun (String, nil) —

    the weapon noun to test

Returns:

  • (Boolean) —

    true if the noun matches a ranged weapon pattern, false otherwise

See Also:



683
684
685
686
687
688
689
690
# File 'documented/dragonrealms/commons/common.rb', line 683

def ranged_weapon?(noun)
  return false if noun.nil?

  return true if COMMON_RANGED_WEAPONS_PATTERN.match?(noun)
  return true if RACIAL_RANGED_WEAPONS_PATTERN.match?(noun)

  false
end

#short_name ⇒ String

Returns a compact get-friendly name combining adjective and noun. Used by outfit/equipment scripts as the basis for get/stow commands.

Examples:

Item.new(name: 'sword', adjective: 'broadsword').short_name #=> "broadsword.sword"
Item.new(name: 'sword').short_name #=> "sword"

Returns:

  • (String) —

    the adjective + '.' + name if adjective is set, else just name



656
657
658
# File 'documented/dragonrealms/commons/common.rb', line 656

def short_name
  @adjective ? "#{@adjective}.#{@name}" : @name
end

#short_regex ⇒ Regexp

Returns a case-insensitive regex for matching this item in game output. Matches the adjective (if present) followed by the noun as word boundaries.

Examples:

Item.new(name: 'sword', adjective: 'broadsword').short_regex
# => /\bbroadsword.*\bsword/i

Returns:



667
668
669
# File 'documented/dragonrealms/commons/common.rb', line 667

def short_regex
  @adjective ? /\b#{@adjective}.*\b#{@name}/i : /\b#{@name}/i
end