Example #1
0
 def test_mouseCanSqueak(self):
     events.runEventTransaction(self.store, self.mousehood.squeak)
     self.assertEquals(len(self.playerIntelligence.concepts), 1)
     event = self.playerIntelligence.concepts[0]
     self.assertEquals(
         commandutils.flatten(event.otherMessage.plaintext(self.player)),
         u"SQUEAK!")
Example #2
0
 def test_mouseCanSqueak(self):
     events.runEventTransaction(self.store, self.mousehood.squeak)
     self.assertEquals(len(self.playerIntelligence.concepts), 1)
     event = self.playerIntelligence.concepts[0]
     self.assertEquals(
         commandutils.flatten(event.otherMessage.plaintext(self.player)),
         u"SQUEAK!")
Example #3
0
 def test_randomHiragana(self):
     """
     When explicitly told to challenge without specifying a syllable, the
     mouse should say a random one.
     """
     events.runEventTransaction(self.store, self.mousehood.challenge)
     self.assertEquals(len(self.playerIntelligence.concepts), 1)
     event = self.playerIntelligence.concepts[0]
     self.assertChallenge(event)
Example #4
0
 def test_randomHiragana(self):
     """
     When explicitly told to challenge without specifying a syllable, the
     mouse should say a random one.
     """
     events.runEventTransaction(self.store, self.mousehood.challenge)
     self.assertEquals(len(self.playerIntelligence.concepts), 1)
     event = self.playerIntelligence.concepts[0]
     self.assertChallenge(event)
Example #5
0
    def runEventTransaction(self, player, line, match):
        """
        Take a player, line, and dictionary of parse results and execute the
        actual Action implementation.

        @param player: A provider of C{self.actorInterface}
        @param line: A unicode string containing the original input
        @param match: A dictionary containing some parse results to pass
        through to the C{run} method.

        """
        events.runEventTransaction(player.store, self.run, player, line,
                                   **match)
Example #6
0
    def runEventTransaction(self, player, line, match):
        """
        Take a player, line, and dictionary of parse results and execute the
        actual Action implementation.

        @param player: A provider of C{self.actorInterface}
        @param line: A unicode string containing the original input
        @param match: A dictionary containing some parse results to pass
        through to the C{run} method.

        """
        events.runEventTransaction(
            player.store, self.run, player, line, **match)
Example #7
0
    def test_mouseCanSqueak(self):
        """
        When explicitly told to challenge with a given romaji syllable, the
        mouse should say a hiragana letter.
        """
        events.runEventTransaction(self.store,
                                   self.mousehood.challenge,
                                   character=u"\N{HIRAGANA LETTER A}")

        self.assertEquals(len(self.playerIntelligence.concepts), 1)
        event = self.playerIntelligence.concepts[0]
        self.assertEquals(
            commandutils.flatten(event.otherMessage.plaintext(self.player)),
            u"A %s says, '\N{HIRAGANA LETTER A}'" % (self.mouseName, ))
Example #8
0
    def test_mouseCanSqueak(self):
        """
        When explicitly told to challenge with a given romaji syllable, the
        mouse should say a hiragana letter.
        """
        events.runEventTransaction(
            self.store,
            self.mousehood.challenge,
            character=u"\N{HIRAGANA LETTER A}")

        self.assertEquals(len(self.playerIntelligence.concepts), 1)
        event = self.playerIntelligence.concepts[0]
        self.assertEquals(
            commandutils.flatten(event.otherMessage.plaintext(self.player)),
            u"A %s says, '\N{HIRAGANA LETTER A}'" % (self.mouseName,))
Example #9
0
    def runEventTransaction(self, player, line, match):
        """
        Take a player, input, and dictionary of parse results, resolve those
        parse results into implementations of appropriate interfaces in the
        game world, and execute the actual Action implementation (contained in
        the 'do' method) in an event transaction.

        This is the top level of action invocation.

        @param player: A L{Thing} representing the actor's body.

        @param line: A unicode string containing the original input

        @param match: A dictionary containing some parse results to pass
            through to this L{Action}'s C{do} method as keyword arguments.

        @raise eimaginary.AmbiguousArgument: if multiple valid targets are
            found for an argument.
        """
        def thunk():
            begin = time.time()
            try:
                actor = self.actorInterface(player)
                for (k, v) in match.items():
                    try:
                        objs = self.resolve(player, k, v)
                    except NotImplementedError:
                        pass
                    else:
                        if len(objs) == 1:
                            match[k] = objs[0]
                        elif len(objs) == 0:
                            self.cantFind(player, actor, k, v)
                        else:
                            raise eimaginary.AmbiguousArgument(
                                self, k, v, objs)
                return self.do(actor, line, **match)
            finally:
                end = time.time()
                log.msg(interface=iaxiom.IStatEvent,
                        stat_actionDuration=end - begin,
                        stat_actionExecuted=1)

        events.runEventTransaction(player.store, thunk)
Example #10
0
    def runEventTransaction(self, player, line, match):
        """
        Take a player, input, and dictionary of parse results, resolve those
        parse results into implementations of appropriate interfaces in the
        game world, and execute the actual Action implementation (contained in
        the 'do' method) in an event transaction.

        This is the top level of action invocation.

        @param player: A L{Thing} representing the actor's body.

        @param line: A unicode string containing the original input

        @param match: A dictionary containing some parse results to pass
            through to this L{Action}'s C{do} method as keyword arguments.

        @raise eimaginary.AmbiguousArgument: if multiple valid targets are
            found for an argument.
        """
        def thunk():
            begin = time.time()
            try:
                actor = self.actorInterface(player)
                for (k, v) in match.items():
                    try:
                        objs = self.resolve(player, k, v)
                    except NotImplementedError:
                        pass
                    else:
                        if len(objs) == 1:
                            match[k] = objs[0]
                        elif len(objs) == 0:
                            self.cantFind(player, actor, k, v)
                        else:
                            raise eimaginary.AmbiguousArgument(self, k, v, objs)
                return self.do(actor, line, **match)
            finally:
                end = time.time()
                log.msg(interface=iaxiom.IStatEvent,
                        stat_actionDuration=end - begin,
                        stat_actionExecuted=1)
        events.runEventTransaction(player.store, thunk)