Ejemplo n.º 1
0
 def get_dungeons_from_nickname(self, name: str, *,
                                server: Server) -> List[DungeonModel]:
     if name not in DUNGEON_NICKNAMES:
         return []
     sub_id = DUNGEON_NICKNAMES.get(name)
     mega = self.database.query_many(
         format_with_suffix(NICKNAME_QUERY, server), (sub_id, ))
     ems = []
     for enc in mega:
         data = self.database.query_one(
             format_with_suffix(ENEMY_DATA_QUERY, server),
             (enc["enemy_id"], ))
         if data is not None:
             edm = EnemyDataModel(**data)
         else:
             edm = None
         ems.append(EncounterModel(edm, **enc))
     sm = SubDungeonModel(ems,
                          sub_dungeon_id=mega[0]['sub_dungeon_id'],
                          dungeon_id=mega[0]['dungeon_id'],
                          name_ja=mega[0]['sub_name_ja'],
                          name_en=mega[0]['sub_name_en'],
                          name_ko=mega[0]['sub_name_ko'],
                          technical=mega[0]['technical'])
     return [DungeonModel([sm], **mega[0])]
Ejemplo n.º 2
0
    def get_dungeons_from_name(self, name: str, *,
                               server: Server) -> List[DungeonModel]:
        dungeons_result = self.database.query_many(
            format_with_suffix(DUNGEON_QUERY, server), (name + "%", ))
        dungeons = []
        for d in dungeons_result:
            dungeons.append(DungeonModel([], **d))

        for dm in dungeons:
            subs = self.database.query_many(
                format_with_suffix(SUB_DUNGEON_QUERY, server),
                (dm.dungeon_id, ))
            for s in subs:
                encounters = self.database.query_many(
                    format_with_suffix(ENCOUNTER_QUERY, server),
                    (s['sub_dungeon_id'], ))
                ems = []
                for e in encounters:
                    data = self.database.query_one(
                        format_with_suffix(ENEMY_DATA_QUERY, server),
                        (e["enemy_id"], ))
                    if data is not None:
                        edm = EnemyDataModel(**data)
                    else:
                        edm = None
                    ems.append(EncounterModel(edm, **e))
                dm.sub_dungeons.append(SubDungeonModel(ems, **s))
        return dungeons
Ejemplo n.º 3
0
    def get_all_sub_dungeons(self, server: Server = DEFAULT_SERVER) -> List[SubDungeonModel]:
        if server not in self._encounters_by_sub_dungeon_id:
            self._encounters_by_sub_dungeon_id[server] = defaultdict(set)
            for encounter in self.get_all_encounters(server=server):
                self._encounters_by_sub_dungeon_id[server][encounter.sub_dungeon_id].add(encounter)

        suffix = ""
        if server == Server.NA:
            suffix = '_na'

        result = self.database.query_many(f"SELECT * FROM sub_dungeons{suffix}")
        return [SubDungeonModel(sorted(self._encounters_by_sub_dungeon_id[server][r.sub_dungeon_id],
                                       key=lambda e: e.encounter_id),
                                **r) for r in result]