示例#1
0
文件: dungeon.py 项目: helgefmi/ohno
    def update(self):
        """
        1. Check if we're on a new level, and make on if we are.
        2. Set self.curlevel and self.curtile
        3. Update the current level.
        """
        # TODO: Branches. We need to know which branch we are in and which
        #       levels are in which branch.
        #       This should probably be done inside this function, while
        #       the detection code should be in Level.
        dlvl = self.ohno.hero.dlvl
        if dlvl not in self.levels:
            self.ohno.logger.dungeon('Found dlvl %d!' % dlvl)
            self.levels[dlvl] = Level(self.ohno, dlvl)

        newlevel = self.levels[dlvl]
        if self.curlevel != newlevel:
            self.ohno.logger.dungeon(
                'We have moved from level %s to level %s' % (
                    self.curlevel,
                    newlevel
                )
            )
            if self.curlevel:
                MessageEvent.unsubscribe(self.curlevel.on_message)
                FoundItems.unsubscribe(self.curlevel.on_founditems)
            MessageEvent.subscribe(newlevel.on_message)
            FoundItems.subscribe(newlevel.on_founditems)

        self.curlevel = newlevel

        idx = self.ohno.hero.position.idx()
        self.curtile = self.curlevel.tiles[idx]

        self.ohno.logger.dungeon(
            'curtile before updating level: %r' % self.curtile
        )
        self.curlevel.update()
        self.ohno.logger.dungeon(
            'curtile after updating level: %r' % self.curtile
        )

        # Some sanity checks
        assert self.curtile.idx == idx
        assert self.curtile.appearance == self.ohno.hero.appearance
        assert self.curtile.monster is None
示例#2
0
    def update(self):
        """
        This function initially gets called by Ohno.loop, and should not return 
        from that call untill the bot is in a state of needing an action (i.e.
        menus should be closed, no --More-- in topline, no "What do you want to
        wish for?" etc.
        """
        self.ohno.logger.framebuffer('Updating framebuffer..')

        messages = self._read_messages()
        
        if 'Discoveries' in messages:
            # We should only get this when there's no other messages.
            assert len(messages) == 1
            discoveries = self._parse_discoveries()
            for appearance, identity in discoveries:
                Discovery.fire(self.ohno, appearance, identity)

        if 'Things that are here:' in self.get_string():
            things = self._parse_things_that_are_here()
            FoundItems.fire(self.ohno, things)
            # Since we're not synchronized at this moment (there might be an
            # unparsed topline after calling _parse_things_that_are_here), we
            # must call _read_messages again.
            messages += self._read_messages(receive_first=False)

        self.ohno.logger.framebuffer('All messages: %r' % messages)

        for message in messages:
            if (message.startswith('Do you want your possessions ') or 
               message.startswith('Do you want to see what you had ') or
               message.startswith('You die.')):
                YouDie.fire(self.ohno, messages)
                assert False, "Some event should probably exit()"

            if message.startswith('Call a'):
                self.ohno.client.send('\n')
                return messages + self.update()

            if message.startswith('Hello stranger, who are you'):
                self.ohno.client.send('\n')
                return messages + self.update()

        return messages
示例#3
0
文件: ohno.py 项目: helgefmi/ohno
 def on_message(self, event):
     if event.msgtype == "you_see_here":
         thing = event.kwargs["item"]
         FoundItems.fire(self, [thing])