Class: Shop::Container

Inherits:
Exist
  • Object
show all
Defined in:
lib/Olib/shops.rb

Constant Summary

Constants inherited from Exist

Exist::GETTER, Exist::PATTERN

Instance Attribute Summary collapse

Attributes inherited from Exist

#gameobj

Instance Method Summary collapse

Methods inherited from Exist

#==, #deconstruct_keys, #effects, #exists?, #fetch, fetch, #gone?, #method_missing, normalize_type_data, #respond_to_missing?, scan, #tags, #to_h

Constructor Details

#initialize(obj) ⇒ Container

Returns a new instance of Container.



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

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Exist

Instance Attribute Details

#cacheObject

Returns the value of attribute cache.



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

def cache
  @cache
end

#containersObject

Returns the value of attribute containers.



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

def containers
  @containers
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#nestedObject

Returns the value of attribute nested.



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

def nested
  @nested
end

#propsObject

Returns the value of attribute props.



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

def props
  @props
end

#showObject

Returns the value of attribute show.



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

def show
  @show
end

Instance Method Details

#action(verb) ⇒ Object



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

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

#atObject

detect nested containers



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

def at
  
  Olib.wrap_stream(action 'look at') { |line|
    
    raise 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 Errors::Prempt
    end
    
  }

  self
end

#contentsObject



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

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

#inObject



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

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

#lookObject



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

def look
  self
end

#nested?Boolean

Returns:

  • (Boolean)


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

def nested?
  @nested || false
end

#onObject



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

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

#to_sObject



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

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