class GameObject

The GameObject class is no longer the mother of all objects.

Public Class Methods

new(name, owner, location=nil) click to toggle source

Create a new Object

name

Every object needs a name

owner

The owner id of this object

location

The object id containing this object or nil.

return

A handle to the 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

Public Instance Methods

add_contents(oid) click to toggle source

Add an object to the contents of this object

oid

The object id to add

# 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_trigger(event, sid) click to toggle source

Add a trigger script to this object

s

The script to add

# 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
characters(exempt=nil) click to toggle source

Finds all the characters contained in this object except the passed character.

exempt

The character id exempted from the list.

return

Handle to a list of the Character objects.

# 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
delete_contents(oid) click to toggle source

Deletes an object from the contents of this object

oid

The object id to delete

# 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
delete_trigger(event) click to toggle source

Deletes a trigger script from this object

event

The trigger event type to delete

# File lib/core/gameobject.rb, line 74
def delete_trigger(event)
  event = event.intern if event.respond_to?(:to_str)
  triggers.delete(event)
end
describe(e) click to toggle source

Event :describe

e

The event

return

Undefined

# File lib/core/gameobject.rb, line 141
def describe(e)
  msg = "[COLOR Yellow]A #{name} is here[/COLOR]"
  add_event(id,e.from,:show,msg)
end
drop(e) click to toggle source

Event :drop

e

The event

return

Undefined

# 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
get(e) click to toggle source

Event :get

e

The event

return

Undefined

# File lib/core/gameobject.rb, line 149
def get(e)
  plyr = get_object(e.from)
  place = get_object(location)
  # remove it
  place.delete_contents(id)
  # add it
  plyr.add_contents(id)
  self.location = plyr.id
  add_event(id,e.from,:show,"You get the #{name}")
end
get_contents() click to toggle source

Returns the contents of the object

return

An array of object ids

# File lib/core/gameobject.rb, line 61
def get_contents
  contents || []
end
get_trigger(event) click to toggle source

Returns a specific trigger script from the object

event

The trigger event type to retrieve

return

A trigger or nil

# File lib/core/gameobject.rb, line 82
def get_trigger(event)
  event = event.intern if event.respond_to?(:to_str)
  triggers[event]
end
get_triggers() click to toggle source

Returns the trigger scripts on the object

return

An array of trigger scripts

# File lib/core/gameobject.rb, line 89
def get_triggers
  triggers.values
end
objects() click to toggle source

Finds all objects contained in this object

return

Handle to a array of the objects.

# File lib/core/gameobject.rb, line 95
def objects
  ary = contents.collect do |oid|
    o = get_object(oid)
    o.class == GameObject ? o : nil
  end
  ary.compact
end
parse(m) click to toggle source

All command input routed through here and parsed.

m

The input message to be parsed

return

false or true depending on whether command succeeded.

# File lib/core/gameobject.rb, line 117
def parse(m)
  # match legal command
  m=~%r([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
timer(e) click to toggle source

Event :timer

e

The event

return

Undefined

# File lib/core/gameobject.rb, line 177
def timer(e)
end