Exemplo n.º 1
0
 def __init__(self):
     self.clients.append(self)
     self.id = None
     makeTemporary(self)
     self.d = None
     self.doing = ""
     self.channel = Mud.getInstance().channel
     self.channel.addListener(self)
     self.character = Character()
     self.character.addListener(self)
     persist.persist(self.character)
Exemplo n.º 2
0
class MudProtocol(basic.LineReceiver):

    clients = []

    def __init__(self):
        self.clients.append(self)
        self.id = None
        makeTemporary(self)
        self.d = None
        self.doing = ""
        self.channel = Mud.getInstance().channel
        self.channel.addListener(self)
        self.character = Character()
        self.character.addListener(self)
        persist.persist(self.character)

    def command_help(self,*args):
        self.sendLine("No help yet.")
        self.prompt()

    def command_quit(self,*args):
        self.sendLine("Goodbye.")
        self.transport.loseConnection()

    def lineReceived(self, line):
        self.execute_command(line)

    def execute_command(self,line):
        command,_, rest = line.partition(" ")
        command_fn = "command_{0}".format(command)
        args = rest.split(" ")
        if hasattr(self,command_fn):
            return getattr(self,command_fn)(*args)
        elif hasattr(self.character,command_fn):
            return getattr(self.character,command_fn)(*args)
        else:
            return self.character.command_say(*[command] + args)

    def receiveMessage(self,message):
        self.sendMessage(message.dict['message'])

    def sendMessage(self,string):
        self.sendLine(string)
        self.prompt()

    def sendString(self,string):
        self.transport.write(string)

    def prompt(self):
        if self.character.task:
            self.sendString("({0})>".format(self.character.task))
        else:
            self.sendString(">")
Exemplo n.º 3
0
 def testSingle(self):
     c = Container()
     c.id = "container"
     m = Character(id='mob')
     m.name = "mob"
     c.add(m)
     self.assertEquals(c.id,"container")
     self.assertEquals(m.id,"mob")
     self.assert_( m in c.contains)
     self.assertEquals(c.get(id='mob'),m)
     self.assertEquals(c.get(attribute='mob'),[m])
     self.assert_(m.location)
     c.remove(m)
     self.assertFalse('mob' in c.contains)
     self.assertFalse(m.location)
     pass
Exemplo n.º 4
0
 def testMultiple(self):
     c = Container()
     c.id = "container"
     m1 = Character(id='mob1')
     m1.name = "mob1"
     m2 = Character(id='mob2')
     m2.name = "mob2"
     c.add(m1)
     c.add(m2)
     self.assert_(m1 in c.contains)
     self.assertEquals(c.get(id='mob1'),m1)
     self.assertEquals(c.get(id='mob2'),m2)
     self.assertEquals(c.get(attribute='character'),[m1])
     c.remove(m1)
     self.assert_(m2 in c.contains)
     self.assertEquals(c.get(id='mob2'),m2)
     self.assertEquals(c.get(attribute='character'),[m2])
     c.remove(m2)
     self.assertFalse(m2 in c.contains)
     self.assertRaises(GameException,c.get,attribute='xcvc')
     self.assertRaises(GameException,c.get,attribute='mob')