Exemple #1
0
    def load_from_db(self, _recursive=True):
        """ Fetch data from database, if _recursive is True fetch each steps too """
        db = Database()

        result = db.select_one(
            '''
                SELECT questNumber, questName
                FROM quest
                WHERE questId = ?
            ''', (self.m_id, ))
        if result:
            self.m_number = result[0]
            self.m_name = result[1]

        result = db.select_all(
            '''
                SELECT questId, stepNumber
                FROM step
                WHERE step.questId = ?
                ORDER BY stepNumber
            ''', (self.m_id, ))
        if result:
            for row in result:
                self.add_step(Step(
                    row[0],  # questId
                    row[1],  # stepNumber
                ))

        if _recursive:
            for step in self.m_steps:
                step.load_from_db()
Exemple #2
0
    def load_from_db(self, _recursive=True):
        """ Fetch data from database, if _recursive is True fetch each quest too """
        db = Database()
        result = db.select_all('''
                SELECT questId
                FROM quest
                ORDER BY questNumber
            ''')

        for row in result:
            self.add_quest(Quest(row[0]  # questId
                                 ))

        if _recursive:
            for quest in self.m_quests:
                quest.load_from_db()
Exemple #3
0
    def init_heroes(self):
        db = Database()
        result = db.select_all(  # _name, _lvl, _weapon, _armor, _passive
            '''
                SELECT nameOfTheHero, lvl, weapon, armor, passive
                FROM hero
                WHERE idUser = ?
            ''',
            (self.id,)
        )

        # print(f"result: {result}")
        if result is not None:
            for row in result:
                self.add_hero(Hero(
                    _name=row[0],   # nameOfTheHero
                    _lvl=row[1],   # lvl
                    _weapon=row["weapon"],   # weapon
                    _armor=row[3],   # armor
                    _passive=row[4],   # passive
                ))
        else:
            self.m_heroes = None