Class GameObject
In: lib/core/gameobject.rb
Parent: Root
GameObject
Root
dot/f_12.png

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

Methods

Public Class methods

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

[Source]

# 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 an object to the contents of this object

oid
The object id to add

[Source]

# 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

s
The script to add

[Source]

# 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.

exempt
The character id exempted from the list.
return
Handle to a list of the Character objects.

[Source]

# 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

oid
The object id to delete

[Source]

# 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

event
The trigger event type to delete

[Source]

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

Event :describe

e
The event
return
Undefined

[Source]

# 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

Event :drop

e
The event
return
Undefined

[Source]

# 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

Event :get

e
The event
return
Undefined

[Source]

# 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

Returns the contents of the object

return
An array of object ids

[Source]

# File lib/core/gameobject.rb, line 61
  def get_contents
    contents || []
  end

Returns a specific trigger script from the object

event
The trigger event type to retrieve
return
A trigger or nil

[Source]

# 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

return
An array of trigger scripts

[Source]

# File lib/core/gameobject.rb, line 89
  def get_triggers
    triggers.values
  end

Finds all objects contained in this object

return
Handle to a array of the objects.

[Source]

# 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

All command input routed through here and parsed.

m
The input message to be parsed
return
false or true depending on whether command succeeded.

[Source]

# 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

Event :timer

e
The event
return
Undefined

[Source]

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

[Validate]