示例#1
0
文件: messages.py 项目: helgefmi/ohno
 def parse_message(self, msg):
     """
     Checks if we have a parser for this particular message, and fires a
     MessageEvent when we have a match.
     """
     self.ohno.logger.messages("Got message: %s" % repr(msg))
     for regexp, msgtype in self.compiled_parsers:
         match = regexp.match(msg)
         if match:
             self.ohno.logger.messages("Found match: msgtype=%r" % msgtype)
             MessageEvent.fire(self.ohno, msgtype, match.groupdict())
             break
     else:
         self.ohno.logger.messages("TODO: Unparsed message %r" % msg)
示例#2
0
文件: ohno.py 项目: helgefmi/ohno
    def __init__(self, root_dir):
        # Make sure __init__ doesn't do any crazy stuff.
        # Should always make sure initializing Ohno won't throw any exceptions.
        self.logger = LogLady(
            root_dir + "/logs",
            (
                "ohno",
                "client",
                "telnet",
                "framebuffer",
                "hero",
                "dungeon",
                "ui",
                "curses",
                "input",
                "pty",
                "strategy",
                "action",
                "tile",
                "level",
                "messages",
                "event",
                "monster",
                "spoilers",
                "item",
            ),
        )

        # Every submodule needs to be able to find other submodules, so they
        # all take an ohno instance as the first argument.
        self.client = Client(self)
        self.framebuffer = FrameBuffer(self)
        self.hero = Hero(self)
        self.dungeon = Dungeon(self)
        self.ai = AI(self)
        self.messages = Messages(self)
        self.spoilers = Spoilers(self)
        self.ui = UI(self)

        self.paused = self.running = None
        self.last_action = None
        self.tick = 0
        self.all_messages = []

        YouDie.subscribe(self.on_youdie)
        MessageEvent.subscribe(self.on_message)
示例#3
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