Class: Olib::Shop::Container

Inherits:
Gameobj_Extender show all
Defined in:
lib/Olib/shops.rb

Instance Attribute Summary collapse

Attributes inherited from Gameobj_Extender

#type

Instance Method Summary collapse

Methods inherited from Gameobj_Extender

#__extend__, #echo

Constructor Details

#initialize(obj) ⇒ Container

Returns a new instance of Container.


41
42
43
44
45
# File 'lib/Olib/shops.rb', line 41

def initialize(obj)
  @cache = Hash.new
  @props = Hash.new
  super(obj)
end

Instance Attribute Details

#cacheObject

Returns the value of attribute cache


30
31
32
# File 'lib/Olib/shops.rb', line 30

def cache
  @cache
end

#containersObject

Returns the value of attribute containers


30
31
32
# File 'lib/Olib/shops.rb', line 30

def containers
  @containers
end

#idObject

Returns the value of attribute id


30
31
32
# File 'lib/Olib/shops.rb', line 30

def id
  @id
end

#nestedObject

Returns the value of attribute nested


30
31
32
# File 'lib/Olib/shops.rb', line 30

def nested
  @nested
end

#propsObject

Returns the value of attribute props


30
31
32
# File 'lib/Olib/shops.rb', line 30

def props
  @props
end

#showObject

Returns the value of attribute show


30
31
32
# File 'lib/Olib/shops.rb', line 30

def show
  @show
end

Instance Method Details

#action(verb) ⇒ Object


47
48
49
# File 'lib/Olib/shops.rb', line 47

def action(verb)
  "#{verb} ##{@id}"
end

#atObject

detect nested containers


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/Olib/shops.rb', line 56

def at
  
  Olib.wrap_stream(action 'look at') { |line|
    
    raise Olib::Errors::Mundane if line =~ /You see nothing unusual/

    if line =~ /Looking at the (.*?), you see (?<nested>.*)/
      @nested     = true

      @containers = line.match(/Looking at the (.*?), you see (?<nested>.*)/)[:nested].scan(/<a exist="(?<id>.*?)" noun="(?<noun>.*?)">(?<name>.*?)<\/a>/).map {|matches| 
        Container.new GameObj.new *matches
      }
      raise Olib::Errors::Prempt
    end
    
  }

  self
end

#contentsObject


98
99
100
101
# File 'lib/Olib/shops.rb', line 98

def contents
  look.in.on unless GameObj[@id].contents
  GameObj[@id].contents.map {|i| Item.new(i).define('container', @id) }
end

#inObject


80
81
82
83
84
85
86
87
# File 'lib/Olib/shops.rb', line 80

def in
  return self unless @id
  Olib.wrap_stream(action 'look in') { |line|
    raise Olib::Errors::Mundane if line=~ /^There is nothing in there|^That is closed|filled with a variety of garbage|Total items:/
    raise Olib::Errors::Prempt  if line =~ /^In the (.*?) you see/
  }
  self
end

#lookObject


51
52
53
# File 'lib/Olib/shops.rb', line 51

def look
  self
end

#nested?Boolean

Returns:

  • (Boolean)

76
77
78
# File 'lib/Olib/shops.rb', line 76

def nested?
  @nested || false
end

#onObject


89
90
91
92
93
94
95
96
# File 'lib/Olib/shops.rb', line 89

def on
  return self unless @id
  Olib.wrap_stream(action 'look on') { |line|
    raise Olib::Errors::Mundane if line =~ /^There is nothing on there/
    raise Olib::Errors::Prempt  if line =~ /^On the (.*?) you see/
  }
  self
end

#to_sObject


32
33
34
35
36
37
38
39
# File 'lib/Olib/shops.rb', line 32

def to_s
  info = {}
  info[:name]     = @name
  info[:noun]     = @noun
  info[:props]    = @props
  info[:cache]    = @cache
  info.to_s
end