require "Command.rb" require "Commands.rb" require "Player.rb" module RubyMud class AddFlag < Command def words return ["+f"] end def canUse?(object) #return true if object.getFlagByClass(Admin) != nil or object.getFlagByClass(Builder) != nil #return false return true end def initialize() super() end # Adds a flag def execute(clientConnection,string) tokens = string.split(' ') currentRoom = clientConnection.player.parent if (tokens.length != 3) clientConnection.send(tokens[0]+" objectname flagclass \r\n") return end begin flagclass = eval(tokens[2]) rescue clientConnection.send("Could not find that flag\r\n") return end # Check if the flag is infact a flag if !flagclass.ancestors.include?(Flag) clientConnection.send("Whoops #{tokens[2]} is not a flag\r\n") return end # find the object obj = currentRoom.getObjectByName(tokens[1]) if obj == nil clientConnection.send("Could not find that object\r\n") return true end # Check if the flag already is on the object if obj.getFlagByClass(flagclass) and !flagclass.moreThanOne? clientConnection.send("That flag is aleady on the object and only one is permited\r\n") return end # Add the flag to the object flagclass.new(obj) clientConnection.send("Added #{tokens[2]} to #{tokens[1]}\r\n") end end # Create the instance, it adds itself to the commands list AddFlag.new() end #module