Class: Lich::Common::GameObj
- Inherits:
-
Object
- Object
- Lich::Common::GameObj
- Defined in:
- lib/common/gameobj.rb
Overview
Represents a game object in the Lich game.
Direct Known Subclasses
Constant Summary collapse
- @@loot =
Array.new
- @@npcs =
Array.new
- @@npc_status =
Hash.new
- @@pcs =
Array.new
- @@pc_status =
Hash.new
- @@inv =
Array.new
- @@contents =
Hash.new
- @@right_hand =
nil
- @@left_hand =
nil
- @@room_desc =
Array.new
- @@fam_loot =
Array.new
- @@fam_npcs =
Array.new
- @@fam_pcs =
Array.new
- @@fam_room_desc =
Array.new
- @@type_data =
Hash.new
- @@type_cache =
Hash.new
- @@sellable_data =
Hash.new
Instance Attribute Summary collapse
-
#after_name ⇒ Object
Returns the value of attribute after_name.
-
#before_name ⇒ Object
Returns the value of attribute before_name.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#noun ⇒ Object
Returns the value of attribute noun.
Class Method Summary collapse
-
.[](val) ⇒ GameObj?
Retrieves a game object by its identifier, noun, or name.
Instance Method Summary collapse
-
#contents ⇒ Array
Retrieves the contents of the game object.
-
#empty? ⇒ Boolean
Checks if the game object is empty.
-
#full_name ⇒ String
Constructs the full name of the game object.
-
#GameObj ⇒ String
Returns the noun of the game object.
-
#initialize(id, noun, name, before = nil, after = nil) ⇒ GameObj
constructor
Initializes a new GameObj instance.
-
#sellable ⇒ String?
Checks if the game object is sellable.
-
#status ⇒ String?
Retrieves the status of the game object.
-
#status=(val) ⇒ nil
Sets the status of the game object.
-
#to_s ⇒ String
Returns the noun of the game object.
-
#type ⇒ String?
Determines the type of the game object based on its name and noun.
Constructor Details
#initialize(id, noun, name, before = nil, after = nil) ⇒ GameObj
Initializes a new GameObj instance.
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/common/gameobj.rb', line 33 def initialize(id, noun, name, before = nil, after = nil) @id = id @noun = noun @noun = 'lapis' if @noun == 'lapis lazuli' @noun = 'hammer' if @noun == "Hammer of Kai" @noun = 'ball' if @noun == "ball and chain" # DR item 'ball and chain' doesn't work. @noun = 'mother-of-pearl' if (@noun == 'pearl') and (@name =~ /mother\-of\-pearl/) @name = name @before_name = before @after_name = after end |
Instance Attribute Details
#after_name ⇒ Object
Returns the value of attribute after_name.
24 25 26 |
# File 'lib/common/gameobj.rb', line 24 def after_name @after_name end |
#before_name ⇒ Object
Returns the value of attribute before_name.
24 25 26 |
# File 'lib/common/gameobj.rb', line 24 def before_name @before_name end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
23 24 25 |
# File 'lib/common/gameobj.rb', line 23 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
24 25 26 |
# File 'lib/common/gameobj.rb', line 24 def name @name end |
#noun ⇒ Object
Returns the value of attribute noun.
24 25 26 |
# File 'lib/common/gameobj.rb', line 24 def noun @noun end |
Class Method Details
.[](val) ⇒ GameObj?
Retrieves a game object by its identifier, noun, or name.
144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/common/gameobj.rb', line 144 def GameObj.[](val) if val.class == String if val =~ /^\-?[0-9]+$/ @@inv.find { |o| o.id == val } || @@loot.find { |o| o.id == val } || @@npcs.find { |o| o.id == val } || @@pcs.find { |o| o.id == val } || [@@right_hand, @@left_hand].find { |o| o.id == val } || @@room_desc.find { |o| o.id == val } elsif val.split(' ').length == 1 @@inv.find { |o| o.noun == val } || @@loot.find { |o| o.noun == val } || @@npcs.find { |o| o.noun == val } || @@pcs.find { |o| o.noun == val } || [@@right_hand, @@left_hand].find { |o| o.noun == val } || @@room_desc.find { |o| o.noun == val } else @@inv.find { |o| o.name == val } || @@loot.find { |o| o.name == val } || @@npcs.find { |o| o.name == val } || @@pcs.find { |o| o.name == val } || [@@right_hand, @@left_hand].find { |o| o.name == val } || @@room_desc.find { |o| o.name == val } || @@inv.find { |o| o.name =~ /\b#{Regexp.escape(val.strip)}$/i } || @@loot.find { |o| o.name =~ /\b#{Regexp.escape(val.strip)}$/i } || @@npcs.find { |o| o.name =~ /\b#{Regexp.escape(val.strip)}$/i } || @@pcs.find { |o| o.name =~ /\b#{Regexp.escape(val.strip)}$/i } || [@@right_hand, @@left_hand].find { |o| o.name =~ /\b#{Regexp.escape(val.strip)}$/i } || @@room_desc.find { |o| o.name =~ /\b#{Regexp.escape(val.strip)}$/i } || @@inv.find { |o| o.name =~ /\b#{Regexp.escape(val).sub(' ', ' .*')}$/i } || @@loot.find { |o| o.name =~ /\b#{Regexp.escape(val).sub(' ', ' .*')}$/i } || @@npcs.find { |o| o.name =~ /\b#{Regexp.escape(val).sub(' ', ' .*')}$/i } || @@pcs.find { |o| o.name =~ /\b#{Regexp.escape(val).sub(' ', ' .*')}$/i } || [@@right_hand, @@left_hand].find { |o| o.name =~ /\b#{Regexp.escape(val).sub(' ', ' .*')}$/i } || @@room_desc.find { |o| o.name =~ /\b#{Regexp.escape(val).sub(' ', ' .*')}$/i } end elsif val.class == Regexp @@inv.find { |o| o.name =~ val } || @@loot.find { |o| o.name =~ val } || @@npcs.find { |o| o.name =~ val } || @@pcs.find { |o| o.name =~ val } || [@@right_hand, @@left_hand].find { |o| o.name =~ val } || @@room_desc.find { |o| o.name =~ val } end end |
Instance Method Details
#contents ⇒ Array
Retrieves the contents of the game object.
134 135 136 |
# File 'lib/common/gameobj.rb', line 134 def contents @@contents[@id].dup end |
#empty? ⇒ Boolean
Checks if the game object is empty.
125 126 127 |
# File 'lib/common/gameobj.rb', line 125 def empty? false end |
#full_name ⇒ String
Constructs the full name of the game object.
172 173 174 |
# File 'lib/common/gameobj.rb', line 172 def full_name "#{@before_name}#{' ' unless @before_name.nil? or @before_name.empty?}#{name}#{' ' unless @after_name.nil? or @after_name.empty?}#{@after_name}" end |
#GameObj ⇒ String
Returns the noun of the game object.
163 164 165 |
# File 'lib/common/gameobj.rb', line 163 def GameObj @noun end |
#sellable ⇒ String?
This method will load sellable data if it is empty.
Checks if the game object is sellable.
68 69 70 71 72 73 74 75 76 |
# File 'lib/common/gameobj.rb', line 68 def sellable GameObj.load_data if @@sellable_data.empty? list = @@sellable_data.keys.find_all { |t| (@name =~ @@sellable_data[t][:name] or @noun =~ @@sellable_data[t][:noun]) and (@@sellable_data[t][:exclude].nil? or @name !~ @@sellable_data[t][:exclude]) } if list.empty? nil else list.join(',') end end |
#status ⇒ String?
Retrieves the status of the game object.
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/common/gameobj.rb', line 83 def status if @@npc_status.keys.include?(@id) @@npc_status[@id] elsif @@pc_status.keys.include?(@id) @@pc_status[@id] elsif @@loot.find { |obj| obj.id == @id } or @@inv.find { |obj| obj.id == @id } or @@room_desc.find { |obj| obj.id == @id } or @@fam_loot.find { |obj| obj.id == @id } or @@fam_npcs.find { |obj| obj.id == @id } or @@fam_pcs.find { |obj| obj.id == @id } or @@fam_room_desc.find { |obj| obj.id == @id } or (@@right_hand.id == @id) or (@@left_hand.id == @id) or @@contents.values.find { |list| list.find { |obj| obj.id == @id } } nil else 'gone' end end |
#status=(val) ⇒ nil
Sets the status of the game object.
101 102 103 104 105 106 107 108 109 |
# File 'lib/common/gameobj.rb', line 101 def status=(val) if @@npcs.any? { |npc| npc.id == @id } @@npc_status[@id] = val elsif @@pcs.any? { |pc| pc.id == @id } @@pc_status[@id] = val else nil end end |
#to_s ⇒ String
Returns the noun of the game object.
116 117 118 |
# File 'lib/common/gameobj.rb', line 116 def to_s @noun end |
#type ⇒ String?
This method will load type data if it is empty.
Determines the type of the game object based on its name and noun.
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/common/gameobj.rb', line 51 def type GameObj.load_data if @@type_data.empty? return @@type_cache[@name] if @@type_cache.key?(@name) list = @@type_data.keys.find_all { |t| (@name =~ @@type_data[t][:name] or @noun =~ @@type_data[t][:noun]) and (@@type_data[t][:exclude].nil? or @name !~ @@type_data[t][:exclude]) } if list.empty? return @@type_cache[@name] = nil else return @@type_cache[@name] = list.join(',') end end |