Пример #1
0
    def load_database(self,
                      skip_skills=False,
                      skip_bonus=False,
                      skip_extra=False):
        base_dir = self.base_dir
        raw_cards = card.load_card_data(data_dir=base_dir)
        self.dungeons = dungeon.load_dungeon_data(data_dir=base_dir)

        if not skip_bonus:
            self.bonus_sets = {
                g.value: bonus.load_bonus_data(data_dir=base_dir,
                                               server=self.server,
                                               data_group=g.value)
                for g in StarterGroup
            }

        if not skip_skills:
            self.skills = skill.load_skill_data(data_dir=base_dir)
            parser = SkillParser()
            parser.parse(self.skills)
            self.leader_skills = parser.leader_skills
            self.active_skills = parser.active_skills
            self.skill_id_to_leader_skill = {
                s.skill_id: s
                for s in self.leader_skills
            }
            self.skill_id_to_active_skill = {
                s.skill_id: s
                for s in self.active_skills
            }

        self.raw_enemy_skills = enemy_skill.load_enemy_skill_data(
            data_dir=base_dir)
        es_parser = BehaviorParser()
        es_parser.parse(self.raw_enemy_skills)
        self.enemy_skills = es_parser.enemy_behaviors

        if not skip_extra:
            self.exchange = exchange.load_data(data_dir=base_dir,
                                               server=self.server)
            self.egg_machines = extra_egg_machine.load_data(data_dir=base_dir,
                                                            server=self.server)

        self.bonuses = _clean_bonuses(self.server, self.bonus_sets,
                                      self.dungeons)
        self.enemies = _clean_enemy(raw_cards, self.enemy_skills)
        self.cards = _clean_cards(self.server, raw_cards, self.enemies, self)

        self.dungeon_id_to_dungeon = {d.dungeon_id: d for d in self.dungeons}
        self.monster_no_to_card = {c.monster_no: c for c in self.cards}
        if self.server == Server.jp:
            self.monster_id_to_card = self.monster_no_to_card
        else:
            self.monster_id_to_card = {
                nakr_no_to_monster_id(c.monster_no): c
                for c in self.cards
            }

        self.enemy_id_to_enemy = {e.enemy_id: e for e in self.enemies}
Пример #2
0
def main(args):
    def download_json(filename: str) -> Any:
        if args.filepath is not None:
            with open(
                    f"{args.filepath.rstrip('/')}/{args.server.lower()}/{filename}"
            ) as file:
                return json.load(file)
        else:
            with urllib.request.urlopen(
                    f"{args.url.rstrip('/')}/{args.server.lower()}/{filename}"
            ) as resp:
                return json.load(resp)

    def print_translations(skill) -> None:
        if isinstance(skill, ActiveSkill):
            if args.show_en:
                print("EN:", skill.text(EnASTextConverter()))
            if args.show_ja:
                print("JA:", skill.text(JaASTextConverter()))
            if args.show_ko:
                print("KO:", skill.text(KoASTextConverter()))
        elif isinstance(skill, LeaderSkill):
            if args.show_en:
                print("EN:", skill.text(EnLSTextConverter()))
            if args.show_ja:
                print("JA:", skill.text(JaLSTextConverter()))
            if args.show_ko:
                print("KO:", skill.text(KoLSTextConverter()))

    if len([
            o for o in (args.skill_type, args.skill_id, args.monster_id)
            if o is not None
    ]) != 1:
        raise Exception(
            'you must supply exactly one of skill_type, skill_id, or monster_id'
        )

    if args.server not in ("NA", "JP", "KR"):
        raise Exception('unexpected server:' + args.server)

    if not any((args.show_en, args.show_ja, args.show_ko)):
        args.show_en = True

    all_skills = [
        MonsterSkill(sid, raw) for sid, raw in enumerate(
            download_json('download_skill_data.json')['skill'])
    ]

    skill_class = skills = None
    if args.skill_type is not None or args.skill_id is not None:
        skills = skill_class = None
        if args.skill_type is not None:
            skill_class = next((s
                                for s in ALL_ACTIVE_SKILLS + ALL_LEADER_SKILLS
                                if s.skill_type == args.skill_type), None)

            if skill_class is None:
                raise Exception(
                    f'no creator for skill type: {args.skill_type}')

            skills = [
                skill_class(skill) for skill in all_skills
                if skill.skill_type == args.skill_type
            ]
        elif args.skill_id is not None:
            try:
                skill = all_skills[args.skill_id]
            except IndexError:
                raise Exception(f"invalid skill id: {args.skill_id}")

            skill_class = next((s
                                for s in ALL_ACTIVE_SKILLS + ALL_LEADER_SKILLS
                                if s.skill_type == skill.skill_type), None)
            if skill_class is None:
                if skill.skill_type == 0:
                    raise Exception(
                        f'invalid skill type. maybe this skill isn\'t out in this server?'
                    )
                else:
                    raise Exception(
                        f'no creator for skill type: {skill.skill_type}')
            skills = [skill_class(skill)]

        for c, skill in enumerate(skills):
            if skill.raw_description or args.showall:
                if c != 0:
                    print()
                if skill.name:
                    print(f"Skill #{skill.skill_id}: {skill.name}")
                else:
                    print(f"Skill #{skill.skill_id}")
                print("Raw:", skill.raw_data)
                print_translations(skill)
                if skill.raw_description and args.showofficial:
                    print("Official:", skill.raw_description)

    elif args.monster_id is not None:
        raw = next((c for c in download_json('download_card_data.json')['card']
                    if c[0] == args.monster_id), None)
        if raw is None:
            raise Exception(f"Invalid monster id: {args.monster_id}")

        monster = Card(raw)
        skill_parser = SkillParser().parse(all_skills)

        active_skill = skill_parser.active(monster.active_skill_id)
        leader_skill = skill_parser.leader(monster.leader_skill_id)

        print(f"[{monster.monster_no}] {monster.name}\n")
        if active_skill is not None:
            print(
                f"Active Skill: {active_skill.name}"
                f" (ID {active_skill.skill_id}, Type {active_skill.skill_type}, Raw {active_skill.raw_data})\n"
                f"Translations:")
            print_translations(active_skill)
            if args.showofficial:
                print(f"(Official: {active_skill.raw_description})\n")
            else:
                print()
        else:
            print("Active Skill: None\n")
        if leader_skill is not None:
            print(
                f"Leader Skill: {leader_skill.name}"
                f" (ID {leader_skill.skill_id}, Type {leader_skill.skill_type}, Raw {leader_skill.raw_data})"
            )
            print_translations(leader_skill)
            if args.showofficial:
                print(f"(Official: {leader_skill.raw_description})")
        else:
            print("Leader Skill: None")