Class: Lich::DragonRealms::DRC::Item
- Inherits:
-
Object
- Object
- Lich::DragonRealms::DRC::Item
- 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.
Instance Attribute Summary collapse
-
#adjective ⇒ Object
Returns the value of attribute adjective.
-
#bound ⇒ Object
Returns the value of attribute bound.
-
#container ⇒ Object
Returns the value of attribute container.
-
#hinders_lockpicking ⇒ Object
Returns the value of attribute hinders_lockpicking.
-
#leather ⇒ Object
Returns the value of attribute leather.
-
#lodges ⇒ Object
Returns the value of attribute lodges.
-
#name ⇒ Object
Returns the value of attribute name.
-
#needs_unloading ⇒ Object
Returns the value of attribute needs_unloading.
-
#ranged ⇒ Object
Returns the value of attribute ranged.
-
#skip_repair ⇒ Object
Returns the value of attribute skip_repair.
-
#swappable ⇒ Object
Returns the value of attribute swappable.
-
#tie_to ⇒ Object
Returns the value of attribute tie_to.
-
#transform_text ⇒ Object
Returns the value of attribute transform_text.
-
#transform_verb ⇒ Object
Returns the value of attribute transform_verb.
-
#transforms_to ⇒ Object
Returns the value of attribute transforms_to.
-
#wield ⇒ Object
Returns the value of attribute wield.
-
#worn ⇒ Object
Returns the value of attribute worn.
Class Method Summary collapse
-
.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.
Instance Method Summary collapse
-
#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
constructor
Initializes a new item.
-
#ranged_weapon?(noun) ⇒ Boolean
Checks if the given noun is a ranged weapon.
-
#short_name ⇒ String
Returns the short name of the item, including the adjective if present.
-
#short_regex ⇒ Regexp
Returns a regex pattern for matching the short name of the item.
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.
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
#adjective ⇒ Object
Returns the value of attribute adjective.
386 387 388 |
# File 'documented/dragonrealms/commons/common.rb', line 386 def adjective @adjective end |
#bound ⇒ Object
Returns the value of attribute bound.
386 387 388 |
# File 'documented/dragonrealms/commons/common.rb', line 386 def bound @bound end |
#container ⇒ Object
Returns the value of attribute container.
386 387 388 |
# File 'documented/dragonrealms/commons/common.rb', line 386 def container @container end |
#hinders_lockpicking ⇒ Object
Returns the value of attribute hinders_lockpicking.
386 387 388 |
# File 'documented/dragonrealms/commons/common.rb', line 386 def hinders_lockpicking @hinders_lockpicking end |
#leather ⇒ Object
Returns the value of attribute leather.
386 387 388 |
# File 'documented/dragonrealms/commons/common.rb', line 386 def leather @leather end |
#lodges ⇒ Object
Returns the value of attribute lodges.
386 387 388 |
# File 'documented/dragonrealms/commons/common.rb', line 386 def lodges @lodges end |
#name ⇒ Object
Returns the value of attribute name.
386 387 388 |
# File 'documented/dragonrealms/commons/common.rb', line 386 def name @name end |
#needs_unloading ⇒ Object
Returns the value of attribute needs_unloading.
386 387 388 |
# File 'documented/dragonrealms/commons/common.rb', line 386 def needs_unloading @needs_unloading end |
#ranged ⇒ Object
Returns the value of attribute ranged.
386 387 388 |
# File 'documented/dragonrealms/commons/common.rb', line 386 def ranged @ranged end |
#skip_repair ⇒ Object
Returns the value of attribute skip_repair.
386 387 388 |
# File 'documented/dragonrealms/commons/common.rb', line 386 def skip_repair @skip_repair end |
#swappable ⇒ Object
Returns the value of attribute swappable.
386 387 388 |
# File 'documented/dragonrealms/commons/common.rb', line 386 def swappable @swappable end |
#tie_to ⇒ Object
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_text ⇒ Object
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_verb ⇒ Object
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_to ⇒ Object
Returns the value of attribute transforms_to.
386 387 388 |
# File 'documented/dragonrealms/commons/common.rb', line 386 def transforms_to @transforms_to end |
#wield ⇒ Object
Returns the value of attribute wield.
386 387 388 |
# File 'documented/dragonrealms/commons/common.rb', line 386 def wield @wield end |
#worn ⇒ Object
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.
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.
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_name ⇒ String
Returns the short name of the item, including the adjective if present.
431 432 433 |
# File 'documented/dragonrealms/commons/common.rb', line 431 def short_name @adjective ? "#{@adjective}.#{@name}" : @name end |
#short_regex ⇒ Regexp
Returns a regex pattern for matching the short name of 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 |