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

Initializes a new Item instance with equipment properties.

Auto-detects ranged weapons by noun if ranged is not explicitly set, checking against COMMON_RANGED_WEAPONS_PATTERN and RACIAL_RANGED_WEAPONS_PATTERN. If ranged is auto-detected as true, needs_unloading defaults to true unless explicitly set.

Parameters:

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

    the gettable noun of the item

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

    whether the item is made of leather

  • worn (Boolean) (defaults to: false)

    whether the item should be worn by default (default: false)

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

    whether the item hinders lockpicking

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

    the name of a container this item is stored in

  • swappable (Boolean) (defaults to: false)

    whether the item can be swapped with another in hand (default: false)

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

    an item to tie this item to

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

    optional adjective to disambiguate the noun

  • bound (Boolean) (defaults to: false)

    whether the item is bound to the character (default: false)

  • wield (Boolean) (defaults to: false)

    whether to wield the item instead of wearing it (default: false)

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

    noun the item becomes after transformation

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

    game output confirming the transformation

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

    verb to trigger the transformation

  • lodges (Boolean) (defaults to: true)

    whether the item can lodge in the character (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 if nil

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

    whether the item needs to be unloaded; defaults to ranged if nil



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

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

#adjectiveObject (readonly)

Returns the value of attribute adjective.



606
607
608
# File 'documented/dragonrealms/commons/common.rb', line 606

def adjective
  @adjective
end

#boundObject (readonly)

Returns the value of attribute bound.



606
607
608
# File 'documented/dragonrealms/commons/common.rb', line 606

def bound
  @bound
end

#containerObject (readonly)

Returns the value of attribute container.



606
607
608
# File 'documented/dragonrealms/commons/common.rb', line 606

def container
  @container
end

#hinders_lockpickingObject (readonly)

Returns the value of attribute hinders_lockpicking.



606
607
608
# File 'documented/dragonrealms/commons/common.rb', line 606

def hinders_lockpicking
  @hinders_lockpicking
end

#leatherObject (readonly)

Returns the value of attribute leather.



606
607
608
# File 'documented/dragonrealms/commons/common.rb', line 606

def leather
  @leather
end

#lodgesObject (readonly)

Returns the value of attribute lodges.



606
607
608
# File 'documented/dragonrealms/commons/common.rb', line 606

def lodges
  @lodges
end

#nameObject (readonly)

Returns the value of attribute name.



606
607
608
# File 'documented/dragonrealms/commons/common.rb', line 606

def name
  @name
end

#needs_unloadingObject (readonly)

Returns the value of attribute needs_unloading.



606
607
608
# File 'documented/dragonrealms/commons/common.rb', line 606

def needs_unloading
  @needs_unloading
end

#rangedObject (readonly)

Returns the value of attribute ranged.



606
607
608
# File 'documented/dragonrealms/commons/common.rb', line 606

def ranged
  @ranged
end

#skip_repairObject (readonly)

Returns the value of attribute skip_repair.



606
607
608
# File 'documented/dragonrealms/commons/common.rb', line 606

def skip_repair
  @skip_repair
end

#swappableObject (readonly)

Returns the value of attribute swappable.



606
607
608
# File 'documented/dragonrealms/commons/common.rb', line 606

def swappable
  @swappable
end

#tie_toObject (readonly)

Returns the value of attribute tie_to.



606
607
608
# File 'documented/dragonrealms/commons/common.rb', line 606

def tie_to
  @tie_to
end

#transform_textObject (readonly)

Returns the value of attribute transform_text.



606
607
608
# File 'documented/dragonrealms/commons/common.rb', line 606

def transform_text
  @transform_text
end

#transform_verbObject (readonly)

Returns the value of attribute transform_verb.



606
607
608
# File 'documented/dragonrealms/commons/common.rb', line 606

def transform_verb
  @transform_verb
end

#transforms_toObject (readonly)

Returns the value of attribute transforms_to.



606
607
608
# File 'documented/dragonrealms/commons/common.rb', line 606

def transforms_to
  @transforms_to
end

#wieldObject (readonly)

Returns the value of attribute wield.



606
607
608
# File 'documented/dragonrealms/commons/common.rb', line 606

def wield
  @wield
end

#wornObject (readonly)

Returns the value of attribute worn.



606
607
608
# File 'documented/dragonrealms/commons/common.rb', line 606

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.



701
702
703
704
705
706
707
708
709
710
711
712
713
714
# File 'documented/dragonrealms/commons/common.rb', line 701

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

Checks whether a noun represents a ranged weapon.

Returns true if the noun matches COMMON_RANGED_WEAPONS_PATTERN (bow, crossbow, sling, etc.) or RACIAL_RANGED_WEAPONS_PATTERN (Gamgweth names like jranoki, uku'uan). Case-insensitive. Returns false if noun is nil.

Examples:

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

Parameters:

  • noun (String, nil)

    the item noun

Returns:

  • (Boolean)

    true if the noun is a known ranged weapon



690
691
692
693
694
695
696
697
# File 'documented/dragonrealms/commons/common.rb', line 690

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_nameString

Returns a short gettable name combining the adjective and noun.

If an adjective is set, returns "adjective.noun"; otherwise returns the noun alone. Used for unambiguous item targeting in game commands.

Examples:

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

Returns:

  • (String)

    the short item name



661
662
663
# File 'documented/dragonrealms/commons/common.rb', line 661

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

#short_regexRegexp

Returns a regex pattern matching the item in game output.

If an adjective is set, matches "adjective...noun" (word boundary, any chars, word-boundary noun); otherwise matches just the noun. Case-insensitive.

Examples:

item = DRC::Item.new(name: 'sword', adjective: 'blue')
item.short_regex.match?("the blue ornate sword") #=> true

Returns:

  • (Regexp)

    a pattern to match the item in text



674
675
676
# File 'documented/dragonrealms/commons/common.rb', line 674

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