Class: Area

Inherits:
Olib::Container show all
Defined in:
lib/Olib/area.rb

Instance Attribute Summary collapse

Attributes inherited from Olib::Container

#containers, #nested, #ontop, #ref

Attributes inherited from Olib::Gameobj_Extender

#type

Class Method Summary collapse

Instance Method Summary collapse

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

#__extend__, #at, #echo

Constructor Details

#initializeArea

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

#objectsObject

Returns the value of attribute objects.



27
28
29
# File 'lib/Olib/area.rb', line 27

def objects
  @objects
end

#roomObject

Returns the value of attribute room.



27
28
29
# File 'lib/Olib/area.rb', line 27

def room
  @room
end

Class Method Details

.contentsObject



2
3
4
# File 'lib/Olib/area.rb', line 2

def self.contents
  GameObj.loot.map { |obj| Olib::Item.new(obj) }
end

.deepObject



23
24
25
# File 'lib/Olib/area.rb', line 23

def Area.deep
  Area.new
end

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

#contentsObject



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

#eachObject



6
7
8
9
10
# File 'lib/Olib/area.rb', line 6

def each
  self.contents.each { |item|
    yield item
  }
end