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)
Instance Attribute Summary collapse
-
#adjective ⇒ Object
readonly
Returns the value of attribute adjective.
-
#bound ⇒ Object
readonly
Returns the value of attribute bound.
-
#container ⇒ Object
readonly
Returns the value of attribute container.
-
#hinders_lockpicking ⇒ Object
readonly
Returns the value of attribute hinders_lockpicking.
-
#leather ⇒ Object
readonly
Returns the value of attribute leather.
-
#lodges ⇒ Object
readonly
Returns the value of attribute lodges.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#needs_unloading ⇒ Object
readonly
Returns the value of attribute needs_unloading.
-
#ranged ⇒ Object
readonly
Returns the value of attribute ranged.
-
#skip_repair ⇒ Object
readonly
Returns the value of attribute skip_repair.
-
#swappable ⇒ Object
readonly
Returns the value of attribute swappable.
-
#tie_to ⇒ Object
readonly
Returns the value of attribute tie_to.
-
#transform_text ⇒ Object
readonly
Returns the value of attribute transform_text.
-
#transform_verb ⇒ Object
readonly
Returns the value of attribute transform_verb.
-
#transforms_to ⇒ Object
readonly
Returns the value of attribute transforms_to.
-
#wield ⇒ Object
readonly
Returns the value of attribute wield.
-
#worn ⇒ Object
readonly
Returns the value of attribute worn.
Class Method Summary collapse
-
.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.
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 instance with equipment properties.
-
#ranged_weapon?(noun) ⇒ Boolean
Checks whether a noun represents a ranged weapon.
-
#short_name ⇒ String
Returns a short gettable name combining the adjective and noun.
-
#short_regex ⇒ Regexp
Returns a regex pattern matching the item in game output.
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.
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
#adjective ⇒ Object (readonly)
Returns the value of attribute adjective.
606 607 608 |
# File 'documented/dragonrealms/commons/common.rb', line 606 def adjective @adjective end |
#bound ⇒ Object (readonly)
Returns the value of attribute bound.
606 607 608 |
# File 'documented/dragonrealms/commons/common.rb', line 606 def bound @bound end |
#container ⇒ Object (readonly)
Returns the value of attribute container.
606 607 608 |
# File 'documented/dragonrealms/commons/common.rb', line 606 def container @container end |
#hinders_lockpicking ⇒ Object (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 |
#leather ⇒ Object (readonly)
Returns the value of attribute leather.
606 607 608 |
# File 'documented/dragonrealms/commons/common.rb', line 606 def leather @leather end |
#lodges ⇒ Object (readonly)
Returns the value of attribute lodges.
606 607 608 |
# File 'documented/dragonrealms/commons/common.rb', line 606 def lodges @lodges end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
606 607 608 |
# File 'documented/dragonrealms/commons/common.rb', line 606 def name @name end |
#needs_unloading ⇒ Object (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 |
#ranged ⇒ Object (readonly)
Returns the value of attribute ranged.
606 607 608 |
# File 'documented/dragonrealms/commons/common.rb', line 606 def ranged @ranged end |
#skip_repair ⇒ Object (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 |
#swappable ⇒ Object (readonly)
Returns the value of attribute swappable.
606 607 608 |
# File 'documented/dragonrealms/commons/common.rb', line 606 def swappable @swappable end |
#tie_to ⇒ Object (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_text ⇒ Object (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_verb ⇒ Object (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_to ⇒ Object (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 |
#wield ⇒ Object (readonly)
Returns the value of attribute wield.
606 607 608 |
# File 'documented/dragonrealms/commons/common.rb', line 606 def wield @wield end |
#worn ⇒ Object (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.
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_name ⇒ String
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.
661 662 663 |
# File 'documented/dragonrealms/commons/common.rb', line 661 def short_name @adjective ? "#{@adjective}.#{@name}" : @name end |
#short_regex ⇒ Regexp
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.
674 675 676 |
# File 'documented/dragonrealms/commons/common.rb', line 674 def short_regex @adjective ? /\b#{@adjective}.*\b#{@name}/i : /\b#{@name}/i end |