class Olib::Container
Attributes
containers[RW]
nested[RW]
ontop[RW]
ref[RW]
Public Class Methods
new(id=nil)
click to toggle source
Calls superclass method
# File lib/Olib/core/container.rb, line 43 def initialize(id=nil) # extract the class name to attempt to lookup the item by your settings # ex: class Lootsack # ex: class Gemsack name = if self.class.name.include?("::") then self.class.name.downcase.split("::").last.strip else self.class.name.downcase end candidates = Inventory[Vars[name]] raise Olib::Errors::DoesntExist.new("#{name} could not be initialized are you sure you:\n ;var set #{name}=<something>") if candidates.empty? && id.nil? @id = id @ref = GameObj[id] || candidates.first @ontop = Array.new unless GameObj[@ref.id].contents tops = [ "table" ] action = tops.include?(@ref.noun) ? "look on ##{@ref.id}" : "look in ##{@ref.id}" fput action end super @ref end
Public Instance Methods
[](query)
click to toggle source
# File lib/Olib/core/container.rb, line 93 def [](query) return contents.select do |item| item if (item.type =~ query || item.noun =~ query || item.name =~ query) end end
add(*items)
click to toggle source
# File lib/Olib/core/container.rb, line 168 def add(*items) _id = @id items.each { |item| result = Olib.do "_drag ##{item.class == String ? item : item.id} ##{_id}", /#{[Olib::Dictionary.put[:success], Olib::Dictionary.put[:failure].values].flatten.join("|")}/ if result =~ /won"t fit in the/ tag "full" raise Errors::ContainerFull end } self end
at()
click to toggle source
# File lib/Olib/core/container.rb, line 112 def at Olib.wrap_stream("look at ##{@id}") { |line| if line =~ /You see nothing unusual|prompt time|You gaze through (.*?) and see...|written/ raise Olib::Errors::Mundane end 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::Mundane end } self end
contents()
click to toggle source
# File lib/Olib/core/container.rb, line 68 def contents [ @ontop, GameObj[@ref.id].contents.map do |item| Item.new(item, self) end ].flatten end
def(__verbs__)
click to toggle source
# File lib/Olib/core/container.rb, line 99 def def __verbs__ @verbs = "open close analyze inspect weigh".split(" ").map(&:to_sym) singleton = (class << self; self end) @verbs.each do |verb| singleton.send :define_method, verb do fput "#{verb.to_s} ##{@id}" self end end end
full?()
click to toggle source
# File lib/Olib/core/container.rb, line 164 def full? is? "full" end
in()
click to toggle source
# File lib/Olib/core/container.rb, line 151 def in fput "look in ##{@id}" self end
look()
click to toggle source
# File lib/Olib/core/container.rb, line 132 def look self end
method_missing(name, *args)
click to toggle source
# File lib/Olib/core/container.rb, line 181 def method_missing(name, *args) where(noun: name.to_s) end
nested?()
click to toggle source
# File lib/Olib/core/container.rb, line 160 def nested? @nested end
on()
click to toggle source
# File lib/Olib/core/container.rb, line 136 def on return self unless @id Olib.wrap_stream("look on ##{@id}") { |line| raise Olib::Errors::Mundane if line =~ /There is nothing on there|prompt time/ if line =~ /On the (.*?) you see/ @ontop << line.match(Dictionary.contents)[:items] .scan(Dictionary.tag) .map {|matches| Item.new GameObj.new *matches } raise Olib::Errors::Mundane end next } self end
rummage()
click to toggle source
# File lib/Olib/core/container.rb, line 156 def rummage Rummage.new(self) end
to_s()
click to toggle source
# File lib/Olib/core/container.rb, line 185 def to_s "<Container:#{@id} @name=#{@name} @contents=[#{contents}]>" end
where(conditions)
click to toggle source
# File lib/Olib/core/container.rb, line 74 def where(conditions) contents.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