Exemple #1
0
    def active_skill(self) -> Union[models.Gem, models.GrantedAbility]:
        """Get a character's main skill.

        :return: Main skill.
        :rtype: :data:`~typing.Union`\\[:class:`~pobapi.models.Gem`,
            :class:`~pobapi.models.GrantedAbility`]"""
        index = self.active_skill_group.active - 1
        # Short-circuited for the most common case
        if not index:
            return self.active_skill_group.abilities[index]
        # For base skills on Vaal skill gems,
        # the offset is as if the base skill gems would also be present.
        # Simulating this is easier than calculating the adjusted offset.
        active = [
            gem for gem in self.active_skill_group.abilities if not gem.support
        ]
        duplicate = []
        for gem in active:
            if gem.name.startswith("Vaal"):
                duplicate.append(gem)
            duplicate.append(gem)
        if len(duplicate) > 1 and duplicate[index] == duplicate[index - 1]:
            gem = duplicate[index - 1]
            name = constants.VAAL_SKILL_MAP.get(
                gem.name,
                gem.name.rpartition("Vaal ")[2])
            return models.Gem(name, gem.enabled, gem.quality, gem.level,
                              gem.support)
        return self.active_skill_group.abilities[index]
Exemple #2
0
 def _gems(cls, skill) -> List[models.Gem]:
     for gem in skill:
         name = gem.get("nameSpec")
         enabled_ = True if gem.get("enabled") == "true" else False
         level = int(gem.get("level"))
         quality = int(gem.get("quality"))
         yield models.Gem(name, enabled_, level, quality)
Exemple #3
0
    def _abilities(cls,
                   skill) -> List[Union[models.Gem, models.GrantedAbility]]:
        """Get a list of abilities, whether they are granted by gems or by items.

        :return: Abilities.
        :rtype: :class:`~typing.List`\\
            [:data:`~typing.Union`\\[:class:`~pobapi.models.Gem`,
            :class:`~pobapi.models.GrantedAbility`]]"""
        for ability in skill:
            gem_id = ability.get("gemId")
            name = ability.get("nameSpec")
            enabled = ability.get("enabled") == "true"
            level = int(ability.get("level"))
            if gem_id:
                quality = int(ability.get("quality"))
                support = ability.get("skillId").startswith("Support")
                yield models.Gem(name, enabled, level, quality, support)
            else:
                name = name or constants.SKILL_MAP.get(ability.get("skillId"))
                yield models.GrantedAbility(name, enabled, level)