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

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

Overview

Represents an item in the game.

See Also:

  • to check if the item is a ranged weapon.

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

Returns a new instance of Item.



403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
# File 'documented/dragonrealms/commons/common.rb', line 403

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.



401
402
403
# File 'documented/dragonrealms/commons/common.rb', line 401

def adjective
  @adjective
end

#boundObject (readonly)

Returns the value of attribute bound.



401
402
403
# File 'documented/dragonrealms/commons/common.rb', line 401

def bound
  @bound
end

#containerObject (readonly)

Returns the value of attribute container.



401
402
403
# File 'documented/dragonrealms/commons/common.rb', line 401

def container
  @container
end

#hinders_lockpickingObject (readonly)

Returns the value of attribute hinders_lockpicking.



401
402
403
# File 'documented/dragonrealms/commons/common.rb', line 401

def hinders_lockpicking
  @hinders_lockpicking
end

#leatherObject (readonly)

Returns the value of attribute leather.



401
402
403
# File 'documented/dragonrealms/commons/common.rb', line 401

def leather
  @leather
end

#lodgesObject (readonly)

Returns the value of attribute lodges.



401
402
403
# File 'documented/dragonrealms/commons/common.rb', line 401

def lodges
  @lodges
end

#nameObject (readonly)

Returns the value of attribute name.



401
402
403
# File 'documented/dragonrealms/commons/common.rb', line 401

def name
  @name
end

#needs_unloadingObject (readonly)

Returns the value of attribute needs_unloading.



401
402
403
# File 'documented/dragonrealms/commons/common.rb', line 401

def needs_unloading
  @needs_unloading
end

#rangedObject (readonly)

Returns the value of attribute ranged.



401
402
403
# File 'documented/dragonrealms/commons/common.rb', line 401

def ranged
  @ranged
end

#skip_repairObject (readonly)

Returns the value of attribute skip_repair.



401
402
403
# File 'documented/dragonrealms/commons/common.rb', line 401

def skip_repair
  @skip_repair
end

#swappableObject (readonly)

Returns the value of attribute swappable.



401
402
403
# File 'documented/dragonrealms/commons/common.rb', line 401

def swappable
  @swappable
end

#tie_toObject (readonly)

Returns the value of attribute tie_to.



401
402
403
# File 'documented/dragonrealms/commons/common.rb', line 401

def tie_to
  @tie_to
end

#transform_textObject (readonly)

Returns the value of attribute transform_text.



401
402
403
# File 'documented/dragonrealms/commons/common.rb', line 401

def transform_text
  @transform_text
end

#transform_verbObject (readonly)

Returns the value of attribute transform_verb.



401
402
403
# File 'documented/dragonrealms/commons/common.rb', line 401

def transform_verb
  @transform_verb
end

#transforms_toObject (readonly)

Returns the value of attribute transforms_to.



401
402
403
# File 'documented/dragonrealms/commons/common.rb', line 401

def transforms_to
  @transforms_to
end

#wieldObject (readonly)

Returns the value of attribute wield.



401
402
403
# File 'documented/dragonrealms/commons/common.rb', line 401

def wield
  @wield
end

#wornObject (readonly)

Returns the value of attribute worn.



401
402
403
# File 'documented/dragonrealms/commons/common.rb', line 401

def worn
  @worn
end

Class Method Details

.from_text(text) ⇒ Object



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

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 if the given noun is a ranged weapon.

Parameters:

  • noun (String)

    the noun to check.

Returns:

  • (Boolean)

    true if the noun is a ranged weapon, false otherwise.



437
438
439
440
441
442
443
444
# File 'documented/dragonrealms/commons/common.rb', line 437

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 the short name of the item, including its adjective if present.

Returns:

  • (String)

    the short name of the item.



425
426
427
# File 'documented/dragonrealms/commons/common.rb', line 425

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

#short_regexObject



429
430
431
# File 'documented/dragonrealms/commons/common.rb', line 429

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