Class: Shop::Playershop

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

Constant Summary collapse

@@noncontainers =
[ "wall", "ceiling", "permit", "floor", "helmet", "snowshoes",
"candelabrum", "flowerpot", "Hearthstone", "bear", "candelabra",
"sculpture", "anvil", "tapestry", "portrait", "Wehnimer", "spiderweb",
"rug", "fountain", "longsword", "ship", "panel", "painting", "armor",
"flowers", "head", "plate", "vase", "pillows", "mask", "skeleton", "fan",
"flag", "statue", "mat", "plaque", "mandolin", "plant", "sign" ]

Class Method Summary collapse

Class Method Details

.balanceObject



123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/Olib/shops.rb', line 123

def Playershop.balance
  balance = 0
  Olib.wrap_stream('shop withdraw') { |line|
    next if line =~ /^Usage: SHOP WITHDRAW <amount>/
    raise Errors::Prempt if line =~ /^You must be in your shop to do that.$/

    if line =~ /Your shop's bank account is currently ([\d]+)/
      balance = $1.to_i
      raise Errors::Prempt
    end

  }
  return balance
end

.containersObject



117
118
119
120
121
# File 'lib/Olib/shops.rb', line 117

def Playershop.containers
  Shop.containers.reject { |container|
    @@noncontainers.include? container.noun
  }
end

.find_by_tags(*tags) ⇒ Object



150
151
152
153
154
155
# File 'lib/Olib/shops.rb', line 150

def Playershop.find_by_tags(*tags)
  
  Playershop.items.select { |item|
    !tags.map {|tag| item.is?(tag) }.include? false
  }
end

.itemsObject



163
164
165
166
167
# File 'lib/Olib/shops.rb', line 163

def Playershop.items
  Playershop.containers.map { |container|
    container.contents
  }.flatten
end

.signObject



157
158
159
160
161
# File 'lib/Olib/shops.rb', line 157

def Playershop.sign
  Shop.containers.select { |container|
    container.noun == 'sign'
  }[0]
end

.where(conditions) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
# File 'lib/Olib/shops.rb', line 138

def Playershop.where(conditions)        
  Playershop.items.select { |item|
    !conditions.keys.map { |key|
      if conditions[key].class == Array
        item.props[key].class == Array && !conditions[key].map { |ele| item.props[key].include? ele }.include?(false)
      else
        item.props[key] == conditions[key]
      end
    }.include?(false)
  }
end