require "BaseObject.rb" require "Room.rb" module RubyMud class Mobile < BaseObject # ######################## # Overloadable Room events # ######################## # Is called when THIS mobile enters the room # Mobiles are self sufficient, THEY should proclaim # to the room when they enter it. # Note that the mobile has already been moved into the # room when this is called def onEnterRoom(exit) fromRoom = exit.otherRoom(@parent) return if exit.rooms[fromRoom].length == 0 @parent.roomTalk(self,"<magenta>"+@name+" entered the room from the #{exit.rooms[fromRoom][0]}\r\n") end # Is called before the mobile leaves the room, # they also tell the room themselves about this fact def onBeforeLeavingRoom(exit) return if exit.rooms[@parent].length == 0 @parent.roomTalk(self,"<magenta>"+@name+" left "+ exit.rooms[@parent][0]+"\r\n") end # Is called when a mobile drops something in the room def onItemDroppedInRoom(mobile,item) end # Is called for every mobile in the room when some mobile enters the room # This will most likely be used by aggy mobs, this way they know that # some poor soul entered on their domain def onMobileEnteredRoom(mobile) end # Is called for every mobile in the room when some mobile leaves the room # This could be used by mobs to say something like "gee, I'm glad x left, # he smelt funny" def onMobileLeftRoom(mobile) end # Is called for every mobile in the room when some mobile says something in the room def onMobileSaidSomethingInRoom(mobile,something) end # Is called whenever a mobile talks to this mobile def onMobileTalk(mobile,something) end # Text that origionates from the room itself ... # Each mobile can overload this method and do something with it # Eg. A player mobile will most likely just get sent 'something' # to his/her(bhahaah) clientConnection def onRoomTalk(mobile,something) end # ####### # Methods # ####### def moveThroughExit(exit) newRoom = exit.otherRoom(@parent) # Call the OnBeforeLeavingRoom event onBeforeLeavingRoom(exit) # Remove the player from his current room @parent.removeItem(self) # Set the new room @parent = newRoom # Insert into the new room newRoom.container.push(self) # Tell the others that the mobile has arrived onEnterRoom(exit) end # ########### # Constructor # ############ def initialize(room,name,description) super(room,name,description) end end end #module