| Class | GameObject |
| In: |
lib/core/gameobject.rb
|
| Parent: | Root |
The GameObject class is no longer the mother of all objects.
Create a new Object
# File lib/core/gameobject.rb, line 30 def initialize(name, owner, location=nil) super(name, owner) self.location = location # The location of this object or nil if none self.contents = [] self.triggers = {} self.msgfail = '' self.msgsucc = '' end
Add an object to the contents of this object
# File lib/core/gameobject.rb, line 41 def add_contents(oid) if contents.include? oid log.error "Object #{oid} already in contents of #{id}" else contents << oid end end
Add a trigger script to this object
# File lib/core/gameobject.rb, line 67 def add_trigger(event, sid) event = event.intern if event.respond_to?(:to_str) triggers[event] = sid end
Finds all the characters contained in this object except the passed character.
# File lib/core/gameobject.rb, line 106 def characters(exempt=nil) ary = contents.collect do |oid| o = get_object(oid) (o.class == Character && oid != exempt && o.account) ? o : nil end ary.compact end
Deletes an object from the contents of this object
# File lib/core/gameobject.rb, line 51 def delete_contents(oid) d = contents.delete(oid) if d.nil? log.error "Object #{oid} not in contents of #{id}" end d end
Deletes a trigger script from this object
# File lib/core/gameobject.rb, line 74 def delete_trigger(event) event = event.intern if event.respond_to?(:to_str) triggers.delete(event) end
# File lib/core/gameobject.rb, line 163 def drop(e) plyr = get_object(e.from) place = get_object(plyr.location) # remove it plyr.delete_contents(id) # add it place.add_contents(id) self.location = place.id add_event(id,e.from,:show,"You drop the #{name}") end
Returns the contents of the object
# File lib/core/gameobject.rb, line 61 def get_contents contents || [] end
Returns a specific trigger script from the object
# File lib/core/gameobject.rb, line 82 def get_trigger(event) event = event.intern if event.respond_to?(:to_str) triggers[event] end
Returns the trigger scripts on the object
# File lib/core/gameobject.rb, line 89 def get_triggers triggers.values end
All command input routed through here and parsed.
# File lib/core/gameobject.rb, line 117 def parse(m) # match legal command m=~/([A-Za-z0-9_@?"'#!]+)(.*)/ cmd=$1 arg=$2 arg.strip! if arg # look for a command from our table for objects c = world.ocmds.find(cmd) # there are three possibilities here case c.size when 0 # no commands found false when 1 # command found return self.send(c[0].cmd, arg) else # ambiguous command - tell luser about them. false end end