Read.rb
RubyMud/Commands/Read.rb · 995 B
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 Read < Command
def words
return ["read"]
end
def initialize()
super()
end
# read bookname pagenum
def execute(clientConnection,string)
tokens = string.split(' ')
if (tokens.length != 2)
clientConnection.send("read <bookname>\r\n")
return
end
# Check if the book is in the player's inventory
player = clientConnection.player
book = player.getObjectByName(tokens[1])
if (book == nil)
clientConnection.send("You dont have that book\r\n")
return
end
# Check that the item is infact a book
if (!book.is_a?(Book))
clientConnection.send("uhh, you cant read a #{book.name}\r\n")
return
end
startpage = 0
if tokens.length == 3
startpage = tokens[2].to_i()
end
book.read(clientConnection,startpage)
end
end
# Create the instance, it adds itself to the commands list
Read.new()
end #module