Class: Olib::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


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

def Playershop.balance
  balance = 0
  Olib.wrap_stream('shop withdraw') { |line|
    next if line =~ /^Usage: SHOP WITHDRAW <amount>/
    raise Olib::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 Olib::Errors::Prempt
    end

  }
  return balance
end

.containersObject


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

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

.find_by_tags(*tags) ⇒ Object


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

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

.itemsObject


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

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

.signObject


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

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

.where(conditions) ⇒ Object


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

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