Class: Area
- Inherits:
-
Olib::Container
- Object
- Olib::Gameobj_Extender
- Olib::Container
- Area
- Defined in:
- lib/Olib/area.rb
Instance Attribute Summary collapse
-
#objects ⇒ Object
Returns the value of attribute objects.
-
#room ⇒ Object
Returns the value of attribute room.
Attributes inherited from Olib::Container
#containers, #nested, #ontop, #ref
Attributes inherited from Olib::Gameobj_Extender
Class Method Summary collapse
Instance Method Summary collapse
- #check_container(container) ⇒ Object
- #contents ⇒ Object
- #each ⇒ Object
-
#initialize ⇒ Area
constructor
A new instance of Area.
Methods inherited from Olib::Container
#[], #add, #at, #def, #find_by_tags, #full?, #in, #look, #method_missing, #nested?, #on, #rummage, #to_s, #where
Methods inherited from Olib::Gameobj_Extender
Constructor Details
#initialize ⇒ Area
Returns a new instance of Area.
29 30 31 32 33 34 35 36 37 |
# File 'lib/Olib/area.rb', line 29 def initialize @room = Room.current @objects = [ GameObj.loot, GameObj.room_desc ] .flatten .compact .map { |thing| thing.id } .uniq # sometimes objects exist in both loot & room_desc .map { |id| Olib::Container.new id } end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Olib::Container
Instance Attribute Details
#objects ⇒ Object
Returns the value of attribute objects.
27 28 29 |
# File 'lib/Olib/area.rb', line 27 def objects @objects end |
#room ⇒ Object
Returns the value of attribute room.
27 28 29 |
# File 'lib/Olib/area.rb', line 27 def room @room end |
Class Method Details
Instance Method Details
#check_container(container) ⇒ Object
64 65 66 67 68 |
# File 'lib/Olib/area.rb', line 64 def check_container(container) unless container.contents container.look.at.on end end |
#contents ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/Olib/area.rb', line 39 def contents items = [] @objects .reject { |container| container.name =~ /[A-Z][a-z]+ disk/ } .each { |container| check_container container item = Olib::Item.new container unless container.nested? container.contents.each { |item| item.container = container items << item } else container.containers.each do |nested| check_container nested nested.contents.each { |item| item.container = container items << item } end end } items.compact end |
#each ⇒ Object
6 7 8 9 10 |
# File 'lib/Olib/area.rb', line 6 def each self.contents.each { |item| yield item } end |