require "Command.rb" require "Commands.rb" module RubyMud class Take < Command def words return ["take","get","pickup"] end def initialize() super() end def execute(clientConnection,string) tokens = string.split(' ') if (tokens.length < 2) clientConnection.send(tokens[0]+" <object>\r\n") return end # Look for the object in the room currentRoom = clientConnection.player.parent tokens.delete_at(0) itemName = tokens.join(" ").downcase for i in 0...currentRoom.container.length item = currentRoom.container[i] # Only items can be picked up if (!item.is_a?(Item)) next end print("Evaluating: "+item.name.downcase+":"+itemName) if (item.name.downcase == itemName) # Remove it from the room currentRoom.removeItem(item) # Put it into the player clientConnection.player.container.push(item) # Notify the player that he has it clientConnection.send("You picked up the "+item.name+"\r\n") return end end clientConnection.send(itemName+" isnt an item, or isnt here\r\n") end end # Create the instance, it adds itself to the commands list Take.new() end #module