Пример #1
0
    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)
Пример #2
0
    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