SetFlag.rb
RubyMud/Commands/SetFlag.rb · 1.9 KB
From the archive rbmud-0.1rc2.tar.gz
Download the archive « Back to the archive contents
require "Command.rb"
require "Commands.rb"
require "Player.rb"
module RubyMud
class SetFlag < Command
def words
return ["set","flag"]
end
def initialize()
super()
end
# Set a flag
def execute(clientConnection,string)
tokens = string.split(' ')
if (tokens.length > 2)
clientConnection.send(tokens[0]+" flagname\r\n")
return
end
player = clientConnection.player
# Print all the visible flags a player can switch
if (tokens.length == 1)
clientConnection.send("<bright white>Visible flags:\r\n")
flags = Flags.getFlags()
print "Num Flags:#{flags.length}\r\n"
# Loop through all the flags in the system
for flag in flags
# If the flag is visible
next if (!flag.visible?)
print "!\r\n"
# Does the player have this flag set ?
if (player.getFlagByClass(flag))
s = "*"+flag.to_s()+"\r\n"
else
s = " "+flag.to_s()+"\r\n"
end
# Print it
if flag.changeable?
clientConnection.send("<bright green>"+s)
else
clientConnection.send("<bright red>"+s)
end
end
return
end
# The player wants to change a flag on himself
# Find the flag
flags = Flags.getFlags()
# Loop through all the flags in the system
for flag in flags
if (flag.to_s() == tokens[1])
# If it isnt changeable return
if (!flag.changeable?)
clientConnection.send("<bright red>You cannot set that")
return
end
# If its set, remove it
f = player.getFlagByClass(flag)
if (f != nil)
player.removeFlagByClassName(f.class.name)
clientConnection.send("<bright red>"+f.class.name+" off\r\n")
else # Add it
#player.addFlag(flag.new(player))
flag.new(player)
clientConnection.send("<bright green>"+flag.to_s()+" on\r\n")
end
end
end
end
end
# Create the instance, it adds itself to the commands list
SetFlag.new()
end #module