class Character

The Character class is the mother of all characters. Who’s their daddy?

Attributes

account[RW]

Public Class Methods

new(name,acctid) click to toggle source

Create a new Character object IMPORTANT :Character objects must be marked nonswappable while connected!!!

Otherwise we risk losing the contants of @account
name

The displayed name of the character.

acctid

The account id this character belongs to.

return

A handle to the new Character.

# File lib/core/character.rb, line 34
def initialize(name,acctid)
  super(name, nil, options['home'] || 1)
  self.acctid = acctid
  @account = nil              # reference to the Account.  If nil this
                              # character is not logged in.
                              # We could use get_object(acctid) but
                              # holding the reference is faster
end

Public Instance Methods

describe(e) click to toggle source

Event :describe

e

The event

return

Undefined

# File lib/core/character.rb, line 112
def describe(e)
  msg = "[COLOR Cyan]#{name} is here.[/COLOR]"
  add_event(id,e.from,:show,msg)
end
parse(m) click to toggle source

All command input routed through here and parsed.

m

The input message to be parsed

return

Undefined.

# File lib/core/character.rb, line 53
def parse(m)
  @account.prompt
  # handle edit mode
  if @mode == :edit
    edit_parser m
    return
  end

  # match legal command
  m=~%r([A-Za-z0-9_@?"'#!\]\[]+)(.*)/
  cmd=$1
  arg=$2
  arg.strip! if arg
  if !cmd
    sendto("Huh?")
    return
  end

  # look for a command in our spanking new table
  c = world.cmds.find(cmd)


  # add any exits to our command list
  # escape certain characters in cmd
  check = cmd.gsub(%r\?/,"\\?")
  check.gsub!(%r\#/,"\\#")
  check.gsub!(%r\[/,"\\[")
  check.gsub!(%r\]/,"\\]")
  get_object(location).exits.each do |exid|
    ext = get_object(exid)
    ext.name.split(%r;/).grep(%r^#{check}/).each do |ex|
      c << Command.new(:cmd_go,"go #{ex}",nil)
      arg = ex
    end
  end
  log.debug "parse commands - '#{c.inspect}', arguments - '#{arg}', check - '#{check}'"

  # there are three possibilities here
  case c.size
  when 0   # no commands found
    sendto("Huh?")
  when 1   # command found
    self.send(c[0].cmd, arg)
  else     # ambiguous command - tell luser about them.
    ln = "Which did you mean, "
    c.each do |x|
      ln += "\'" + x.name + "\'"
      x.name == c.last.name ? ln += "?" : ln += " or "
    end
    sendto(ln)
  end
rescue Exception
  # keep character alive after exceptions
  log.fatal $!
end
sendto(s) click to toggle source

Sends a message to the character if they are connected.

s

The message string

return

Undefined.

# File lib/core/character.rb, line 46
def sendto(s)
  @account.sendmsg(s+"\n") if @account
end
show(e) click to toggle source

Event :show

e

The event

return

Undefined

# File lib/core/character.rb, line 120
def show(e)
  sendto(e.msg)
end