tmud-2.9.0/benchmark/
tmud-2.9.0/cmd/
tmud-2.9.0/cmd/objects/
tmud-2.9.0/cmd/tiny/
tmud-2.9.0/db/
tmud-2.9.0/doc/classes/Acceptor.src/
tmud-2.9.0/doc/classes/BoolExpParser.src/
tmud-2.9.0/doc/classes/CacheStats.src/
tmud-2.9.0/doc/classes/Character.src/
tmud-2.9.0/doc/classes/Client.src/
tmud-2.9.0/doc/classes/ColorFilter.src/
tmud-2.9.0/doc/classes/Command.src/
tmud-2.9.0/doc/classes/Configuration.src/
tmud-2.9.0/doc/classes/Connector.src/
tmud-2.9.0/doc/classes/ConsoleClient.src/
tmud-2.9.0/doc/classes/CursesClient.src/
tmud-2.9.0/doc/classes/DebugFilter.src/
tmud-2.9.0/doc/classes/Dumper.src/
tmud-2.9.0/doc/classes/Engine.src/
tmud-2.9.0/doc/classes/Event.src/
tmud-2.9.0/doc/classes/EventManager.src/
tmud-2.9.0/doc/classes/Farts/AttributeSyntaxNode.src/
tmud-2.9.0/doc/classes/Farts/CallSyntaxNode.src/
tmud-2.9.0/doc/classes/Farts/CommandSyntaxNode.src/
tmud-2.9.0/doc/classes/Farts/CommentSyntaxNode.src/
tmud-2.9.0/doc/classes/Farts/EndSyntaxNode.src/
tmud-2.9.0/doc/classes/Farts/IfSyntaxNode.src/
tmud-2.9.0/doc/classes/Farts/Interpreter.src/
tmud-2.9.0/doc/classes/Farts/Lexer.src/
tmud-2.9.0/doc/classes/Farts/Lib.src/
tmud-2.9.0/doc/classes/Farts/LiteralSyntaxNode.src/
tmud-2.9.0/doc/classes/Farts/LocalVarSyntaxNode.src/
tmud-2.9.0/doc/classes/Farts/Parser.src/
tmud-2.9.0/doc/classes/Farts/ProgramSyntaxNode.src/
tmud-2.9.0/doc/classes/Farts/SyntaxNode.src/
tmud-2.9.0/doc/classes/Filter.src/
tmud-2.9.0/doc/classes/LineIO.src/
tmud-2.9.0/doc/classes/Loader.src/
tmud-2.9.0/doc/classes/Log.src/
tmud-2.9.0/doc/classes/Module.src/
tmud-2.9.0/doc/classes/ObjCmd.src/
tmud-2.9.0/doc/classes/PacketIO.src/
tmud-2.9.0/doc/classes/ProtocolStack.src/
tmud-2.9.0/doc/classes/Publisher.src/
tmud-2.9.0/doc/classes/Reactor.src/
tmud-2.9.0/doc/classes/Room.src/
tmud-2.9.0/doc/classes/SQLite/
tmud-2.9.0/doc/classes/SQLite/Database.src/
tmud-2.9.0/doc/classes/SQLite3/
tmud-2.9.0/doc/classes/SQLite3/Database.src/
tmud-2.9.0/doc/classes/Script.src/
tmud-2.9.0/doc/classes/SockIO.src/
tmud-2.9.0/doc/classes/String.src/
tmud-2.9.0/doc/classes/TerminalFilter.src/
tmud-2.9.0/doc/classes/TernaryTrie.src/
tmud-2.9.0/doc/classes/TernaryTrie/
tmud-2.9.0/doc/classes/TernaryTrie/TNode.src/
tmud-2.9.0/doc/classes/Timer.src/
tmud-2.9.0/doc/classes/Utility.src/
tmud-2.9.0/doc/classes/XmlStore.src/
tmud-2.9.0/doc/classes/YamlStore.src/
tmud-2.9.0/doc/dot/
tmud-2.9.0/doc/files/cmd/objects/
tmud-2.9.0/doc/files/cmd/tiny/
tmud-2.9.0/doc/files/lib/
tmud-2.9.0/doc/files/lib/engine/
tmud-2.9.0/doc/files/lib/farts/
tmud-2.9.0/doc/files/tclient_rb.src/
tmud-2.9.0/doc/files/tmud_rb.src/
tmud-2.9.0/farts/
tmud-2.9.0/lib/
tmud-2.9.0/lib/core/
tmud-2.9.0/lib/engine/
tmud-2.9.0/lib/farts/
tmud-2.9.0/logs/
#
# file::    room.rb
# author::  Jon A. Lambert
# version:: 2.8.0
# date::    01/19/2006
#
# This source code copyright (C) 2005, 2006 by Jon A. Lambert
# All rights reserved.
#
# Released under the terms of the TeensyMUD Public License
# See LICENSE file for additional information.
#
$:.unshift "lib" if !$:.include? "lib"
$:.unshift "vendor" if !$:.include? "vendor"

require 'core/gameobject'

# The Room class is the mother of all rooms.
#
class Room < GameObject
  property :exits
  logger 'DEBUG'

  # Create a new Room object
  # [+name+]   The displayed name of the room
  # [+owner+]    The owner id of this room
  # [+return+] A handle to the new Room.
  def initialize(name, owner)
    super(name, owner)
    self.exits={}               # The hash of exits for this room, where the
                                # key is the displayed name of the exit and the
                                # value is the room id at the end of the exit.
  end

  # Event :describe
  # [+e+]      The event
  # [+return+] Undefined
  def describe(e)
    msg = "[COLOR Green](#{id.to_s}) #{name}[/COLOR]\n#{desc}\n"
    add_event(id,e.from,:show,msg)
  end

  # Event :describe_exits
  # [+e+]      The event
  # [+return+] Undefined
  def describe_exits(e)
    msg = "[COLOR Red]Exits:\n"
    s = exits.size
    if s == 0
      msg << "None.[/COLOR]"
    else
      i = 0
      exits.keys.each do |ex|
        msg << ex
        i += 1
        case s - i
        when 1 then s > 2 ? msg << ", and " : msg << " and "
        when 0 then msg << "."
        else
          msg << ", "
        end
      end
      msg << "[/COLOR]"
    end
    add_event(id,e.from,:show,msg)
  end

  # Event :leave
  # [+e+]      The event
  # [+return+] Undefined
  def leave(e)
    ch = get_object(e.from)
    characters(e.from).each do |x|
      add_event(id,x.id,:show, ch.name + " has left #{e.msg}.") if x.account
    end
    # remove character
    delete_contents(ch.id)
    ch.location = nil
    add_event(id,exits[e.msg],:arrive,ch.id)
  end

  # Event :arrive
  # [+e+]      The event
  # [+return+] Undefined
  def arrive(e)
    ch = get_object(e.msg)
    # add character
    add_contents(ch.id)
    ch.location = id
    characters(e.msg).each do |x|
      add_event(id,x.id,:show, ch.name+" has arrived.") if x.account
    end
    ch.parse('look')
  end

end