room.rb
rbmud-0.2/lib/room.rb · 1.5 KB
From the archive RbMUD-0.2.tar.bz2
Download the archive « Back to the archive contents
#!/usr/bin/env ruby
# $Revision: 1.20 $
# $Date: 2003/12/06 18:12:08 $
# $Author: jefus, mikeman2 $
class Room < Base
attr_accessor :exits, :rid
def initMobiles
@config['@mobiles'].each{|cfile|
mob = Mobile.new(CFile.new(cfile))
@contents << mob
mob.location = $system.rooms.fetch(@rid)
mob.enterGame
#Logger.log("initialized mobile:")
#p mob
$system.mobiles << mob
} if @config['@mobiles']
end
def initialize(rid)
begin
@rid = rid
super(CFile.new("system:rooms:#{rid}"))
@exits = Array.new
@config['@exits'].each{|cfile|
@exits << Exit.new(cfile)
} if @config['@exits'] #Gotcha
rescue
Logger.log("Error loading room #{rid}: #{$!})\n\n*******TRACE**********\n\n#{$@}")
end
end
def save
super
end
def puts(line, doer = self)
@contents.each{|obj|
if obj.kind_of?(Mobile)
obj.puts(line) if obj.name != doer.name && obj.connection
end
}
end
def has_exit?(direction)
@exits.each {|exit| return true if exit.direction == direction }
return false
end
def exit(direction)
@exits.each {|exit| return exit if exit.direction == direction }
return nil
end
end
class Exit
attr_accessor :config, :filename, :direction, :name, :rid, :locked, :door
def initialize(cfile)
@filename = cfile
@config = CFile.new(cfile)
@config.attributes.each{|key, value|
eval("#{key} = value")
}
end
def to_s
return @filename
end
def dir
return @direction
end
end
Logger.log("Room code initialized.")