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) Represents an item in the game.

Examples:

Creating an item

item = DRC::Item.new(name: 'gloves', leather: true, worn: 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.

Parameters:

  • name (String) (defaults to: nil)

    The name of the item.

  • leather (Boolean) (defaults to: nil)

    Whether the item is made of leather.

  • worn (Boolean) (defaults to: false)

    Whether the item is worn (default is false).

  • hinders_locks (Boolean) (defaults to: nil)

    Whether the item hinders lockpicking (default is nil).

  • container (String) (defaults to: nil)

    The container type (default is nil).

  • swappable (Boolean) (defaults to: false)

    Whether the item is swappable (default is false).

  • tie_to (String) (defaults to: nil)

    The item it is tied to (default is nil).

  • adjective (String) (defaults to: nil)

    An adjective for the item (default is nil).

  • bound (Boolean) (defaults to: false)

    Whether the item is bound (default is false).

  • wield (Boolean) (defaults to: false)

    Whether the item can be wielded (default is false).

  • transforms_to (String) (defaults to: nil)

    The item it transforms to (default is nil).

  • transform_text (String) (defaults to: nil)

    The text shown when transforming (default is nil).

  • transform_verb (String) (defaults to: nil)

    The verb used for transformation (default is nil).

  • lodges (Boolean) (defaults to: true)

    Whether the item lodges (default is true).

  • skip_repair (Boolean) (defaults to: false)

    Whether to skip repair (default is false).

  • ranged (Boolean) (defaults to: nil)

    Whether the item is ranged (default is nil).

  • needs_unloading (Boolean) (defaults to: nil)

    Whether the item needs unloading (default is nil).



407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
# File 'documented/dragonrealms/commons/common.rb', line 407

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

Returns the value of attribute adjective.



386
387
388
# File 'documented/dragonrealms/commons/common.rb', line 386

def adjective
  @adjective
end

#boundObject

Returns the value of attribute bound.



386
387
388
# File 'documented/dragonrealms/commons/common.rb', line 386

def bound
  @bound
end

#containerObject

Returns the value of attribute container.



386
387
388
# File 'documented/dragonrealms/commons/common.rb', line 386

def container
  @container
end

#hinders_lockpickingObject

Returns the value of attribute hinders_lockpicking.



386
387
388
# File 'documented/dragonrealms/commons/common.rb', line 386

def hinders_lockpicking
  @hinders_lockpicking
end

#leatherObject

Returns the value of attribute leather.



386
387
388
# File 'documented/dragonrealms/commons/common.rb', line 386

def leather
  @leather
end

#lodgesObject

Returns the value of attribute lodges.



386
387
388
# File 'documented/dragonrealms/commons/common.rb', line 386

def lodges
  @lodges
end

#nameObject

Returns the value of attribute name.



386
387
388
# File 'documented/dragonrealms/commons/common.rb', line 386

def name
  @name
end

#needs_unloadingObject

Returns the value of attribute needs_unloading.



386
387
388
# File 'documented/dragonrealms/commons/common.rb', line 386

def needs_unloading
  @needs_unloading
end

#rangedObject

Returns the value of attribute ranged.



386
387
388
# File 'documented/dragonrealms/commons/common.rb', line 386

def ranged
  @ranged
end

#skip_repairObject

Returns the value of attribute skip_repair.



386
387
388
# File 'documented/dragonrealms/commons/common.rb', line 386

def skip_repair
  @skip_repair
end

#swappableObject

Returns the value of attribute swappable.



386
387
388
# File 'documented/dragonrealms/commons/common.rb', line 386

def swappable
  @swappable
end

#tie_toObject

Returns the value of attribute tie_to.



386
387
388
# File 'documented/dragonrealms/commons/common.rb', line 386

def tie_to
  @tie_to
end

#transform_textObject

Returns the value of attribute transform_text.



386
387
388
# File 'documented/dragonrealms/commons/common.rb', line 386

def transform_text
  @transform_text
end

#transform_verbObject

Returns the value of attribute transform_verb.



386
387
388
# File 'documented/dragonrealms/commons/common.rb', line 386

def transform_verb
  @transform_verb
end

#transforms_toObject

Returns the value of attribute transforms_to.



386
387
388
# File 'documented/dragonrealms/commons/common.rb', line 386

def transforms_to
  @transforms_to
end

#wieldObject

Returns the value of attribute wield.



386
387
388
# File 'documented/dragonrealms/commons/common.rb', line 386

def wield
  @wield
end

#wornObject

Returns the value of attribute worn.



386
387
388
# File 'documented/dragonrealms/commons/common.rb', line 386

def worn
  @worn
end

Class Method Details

.from_text(text) ⇒ Item?

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. Parses the text of an item into an Item instance.

Examples:

item = DRC::Item.from_text("a shiny sword")

Parameters:

  • text (String)

    The text representation of the item.

Returns:

  • (Item, nil)

    The created Item instance or nil if parsing fails.



467
468
469
470
471
472
473
474
475
476
477
478
479
480
# File 'documented/dragonrealms/commons/common.rb', line 467

def self.from_text(text)
  text = 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 = text.split
  if text.nil? || text.empty?
    nil
  elsif parts.size > 1
    DRC::Item.new(adjective: parts.first, name: parts.last)
  else
    DRC::Item.new(name: text)
  end
end

Instance Method Details

#ranged_weapon?(noun) ⇒ Boolean

Checks if the given noun is a ranged weapon.

Examples:

is_ranged = item.ranged_weapon?("bow")

Parameters:

  • noun (String)

    The noun to check.

Returns:

  • (Boolean)

    True if it is a ranged weapon, false otherwise.



448
449
450
451
452
453
454
455
456
457
458
# File 'documented/dragonrealms/commons/common.rb', line 448

def ranged_weapon?(noun)
  # Common ranged weapon names
  return true if noun =~ /^(bow|shortbow|longbow|crossbow|stonebow|latchbow|slurbow|lockbow|pelletbow|arbalest|sling|slingshot|blowgun)$/i
  # Gamgweth or racial ranged weapon names
  # https://elanthipedia.play.net/Genie_racial_language_item_subs
  # https://elanthipedia.play.net/Category:Language_Book
  return true if noun =~ /^(jranoki|uku'uan|uku'uanstaho|chunenguti|hhr'ibu|guti|mahil|taisgwelduan|chyeb|sverfil|tangara|alaer|kari|wami|usus|srigos|href|vrope|falocisana|stof|dzelt)$/i

  # Not a ranged weapon we're aware of
  return false
end

#short_nameString

Returns the short name of the item, including the adjective if present.

Examples:

item.short_name

Returns:

  • (String)

    The short name of the item.



431
432
433
# File 'documented/dragonrealms/commons/common.rb', line 431

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

#short_regexRegexp

Returns a regex pattern for matching the short name of the item.

Examples:

regex = item.short_regex

Returns:

  • (Regexp)

    The regex pattern for the item.



439
440
441
# File 'documented/dragonrealms/commons/common.rb', line 439

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