Class: Olib::Jar

Inherits:
Item show all
Defined in:
lib/Olib/objects/jar.rb

Constant Summary

Constants inherited from Item

Item::SOLD, Item::TYPES, Item::WORTHLESS, Item::WRONG_SHOP

Instance Attribute Summary collapse

Attributes inherited from Item

#container, #props

Attributes inherited from Gameobj_Extender

#type

Instance Method Summary collapse

Methods inherited from Item

#==, #_drag, #_inspect, #acquire_from_shop, #action, #affordable?, #analyze, #buy, #buyable?, #cost, #crawl, #define, #drop, #exists?, #give, #has?, #in, #is?, #missing?, #price, #pull, #read, #remove, #sell, #shop_sell, #tag, #tags, #take, #tap, #to_s, #turn, type_methods, #untag, #use, #wear, #worn?

Methods inherited from Gameobj_Extender

#__extend__, #at, #echo

Constructor Details

#initialize(item) ⇒ Jar

Returns a new instance of Jar.


5
6
7
8
9
10
11
12
# File 'lib/Olib/objects/jar.rb', line 5

def initialize(item)
  super(item)
  @count = 0 # for empty jars
  @full  = false
  @empty = false
  _extract
  self
end

Instance Attribute Details

#countObject

Returns the value of attribute count


3
4
5
# File 'lib/Olib/objects/jar.rb', line 3

def count
  @count
end

#emptyObject

Returns the value of attribute empty


3
4
5
# File 'lib/Olib/objects/jar.rb', line 3

def empty
  @empty
end

#fullObject

Returns the value of attribute full


3
4
5
# File 'lib/Olib/objects/jar.rb', line 3

def full
  @full
end

#gemObject

Returns the value of attribute gem


3
4
5
# File 'lib/Olib/objects/jar.rb', line 3

def gem
  @gem
end

#initial_countObject

Returns the value of attribute initial_count


3
4
5
# File 'lib/Olib/objects/jar.rb', line 3

def initial_count
  @initial_count
end

#pullableObject

Returns the value of attribute pullable


3
4
5
# File 'lib/Olib/objects/jar.rb', line 3

def pullable
  @pullable
end

#stackedObject

Returns the value of attribute stacked


3
4
5
# File 'lib/Olib/objects/jar.rb', line 3

def stacked
  @stacked
end

Instance Method Details

#_extractObject


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/Olib/objects/jar.rb', line 14

def _extract
  jem = @after_name.gsub('containing', '').strip
  if jem != ''
    @gem = Gemstone_Regex.gems[:singularize].call(jem)
    look_result      = self.look
    if look_result   =~ /^Inside .*? you see ([0-9]+) portion/
      @count         = $1.to_i
      @initial_count = @count
      @full          = look_result.include?('It is full') ? true : false
    else
      respond "[0lib] Oddity detected in extracting Jar data"
    end
  else
    @empty = true
  end
  self
end

#acquireObject


52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/Olib/objects/jar.rb', line 52

def acquire
  if pullable?
    result    = Library.do "pull ##{@id}", /^You pull/
    @stacked  = true if result =~ /([0-9]+) left/
  else
    result = Library.do "buy ##{@id}", /You hand over/
    unless result =~ /^You hand over/
      Client.end "[FATAL] Logic flaw, not enough coins to acquire #{@name}"
    end
  end
  self
end

#add(g) ⇒ Object


88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/Olib/objects/jar.rb', line 88

def add(g)
  result = Library.do "_drag ##{g.id} ##{@id}", /^You add|^You put|is full|does not appear to be a suitable container for|^You can't do that/
  result = Library.do "put ##{g.id} in my #{@noun}", /^You add|^You put|is full|does not appear to be a suitable container for/ if result =~ /^You can't do that/
  case result
    when /^You add .* filling it/                         then inc.fill
    when /^You add|^You put/                              then inc
    when /does not appear to be a suitable container for/ then return false
    when /is full/                                        then fill; return false
    else                                                       return false
  end
  return true
end

#empty?Boolean

Returns:

  • (Boolean)

43
44
45
# File 'lib/Olib/objects/jar.rb', line 43

def empty?
  @empty
end

#fillObject


83
84
85
86
# File 'lib/Olib/objects/jar.rb', line 83

def fill
  @full = true
  return self
end

#full?Boolean

Returns:

  • (Boolean)

39
40
41
# File 'lib/Olib/objects/jar.rb', line 39

def full?
  @full
end

#incObject


78
79
80
81
# File 'lib/Olib/objects/jar.rb', line 78

def inc
  @count = @count+1
  return self
end

#lookObject


65
66
67
# File 'lib/Olib/objects/jar.rb', line 65

def look
  Library.do "look in ##{@id}", /^Inside .*? you see [0-9]+ portion|The .*? is empty./
end

#pullable?Boolean

Returns:

  • (Boolean)

69
70
71
72
73
74
75
76
# File 'lib/Olib/objects/jar.rb', line 69

def pullable?
  unless @pullable
    Library.do "get ##{@id}", /^Looking closely/
    result = Library.timeoutfor "You can PULL", "You'll have to buy it if you want it"
    if result =~ /^You can PULL/ then @pullable = true else @pullable = false end
  end
  @pullable
end

#shakeObject


32
33
34
35
36
37
# File 'lib/Olib/objects/jar.rb', line 32

def shake
  result = Library.do "shake ##{@id}", /^You give your #{@noun} a hard shake|before you realize that it is empty/
  @empty = true if result =~ /realize that it is empty/
  return Gem_O.new(GameObj.left_hand)  if GameObj.right_hand.id == @id
  return Gem_O.new(GameObj.right_hand) if GameObj.left_hand.id == @id
end

#stashObject


47
48
49
50
# File 'lib/Olib/objects/jar.rb', line 47

def stash
  take unless GameObj.right_hand.id == @id or GameObj.left_hand == @id
  Library.do "shop sell 1", /^You place your/
end