require "Command.rb" require "Commands.rb" require "Room.rb" module RubyMud class Dig < Command def words return ["dig"] end def initialize() super() end def execute(clientConnection,string) tokens = string.split(' ') if (tokens.length < 2) clientConnection.send("dig out1,out1,out1.. in1,in2,in3...\r\n") return true end outTokens = tokens[1].split(',') inTokens = [] if tokens.length > 2 inTokens = tokens[2].split(',') end currentRoom = clientConnection.player.parent # Check if there isnt already a room with that name here # Loop through exits in current toom for exit in currentRoom.exits # Loop through names in the exit that leads out of this room for exitName in exit.rooms[currentRoom] for out in outTokens next if out.downcase != exitName.downcase clientConnection.send("There is already an exit with the name #{out}\r\n") return end end end otherRoom = Room.new("room","Description") newExit = Exit.new(currentRoom,outTokens,otherRoom,inTokens) currentRoom.exits.push(newExit) otherRoom.exits.push(newExit) clientConnection.send("<bright green>Created a new room(##{otherRoom.num})\r\n") return true end end # Create the instance, it adds itself to the commands list Dig.new() end # module