2022-07-05 08:46:47 +00:00
|
|
|
import logging
|
|
|
|
|
2022-07-05 06:41:29 +00:00
|
|
|
from pydantic import BaseModel, Field
|
2022-08-14 09:44:47 +00:00
|
|
|
from typing import Any, List, Union
|
|
|
|
|
|
|
|
from .utils import IconAsset
|
2022-07-05 06:41:29 +00:00
|
|
|
|
|
|
|
from ..enum import EquipmentsType, DigitType, EquipType
|
2022-07-16 19:36:26 +00:00
|
|
|
from ..assets import Assets
|
2022-07-05 06:41:29 +00:00
|
|
|
|
2022-07-05 08:46:47 +00:00
|
|
|
LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2022-08-17 04:54:16 +00:00
|
|
|
__all__ = (
|
|
|
|
'EquipmentsStats',
|
|
|
|
'EquipmentsDetail',
|
|
|
|
'Equipments'
|
|
|
|
)
|
|
|
|
|
2022-07-29 04:31:21 +00:00
|
|
|
|
2022-07-05 06:41:29 +00:00
|
|
|
class EquipmentsStats(BaseModel):
|
|
|
|
prop_id: str = ""
|
|
|
|
type: DigitType = DigitType.NUMBER
|
|
|
|
name: str = ""
|
2022-08-22 09:29:18 +00:00
|
|
|
value: Union[int, float] = Field(0, alias="statValue")
|
2022-07-05 06:41:29 +00:00
|
|
|
|
2022-08-17 04:54:16 +00:00
|
|
|
def __init__(self, **data: Any) -> None:
|
2022-07-05 06:41:29 +00:00
|
|
|
super().__init__(**data)
|
|
|
|
|
2022-07-29 04:31:21 +00:00
|
|
|
LOGGER.debug("=== Fight prop ===")
|
2022-07-05 08:46:47 +00:00
|
|
|
|
2022-07-05 06:41:29 +00:00
|
|
|
if "mainPropId" in data:
|
2022-08-17 04:54:16 +00:00
|
|
|
self.prop_id = str(data["mainPropId"])
|
2022-07-16 19:36:26 +00:00
|
|
|
fight_prop = Assets.get_hash_map(str(data["mainPropId"]))
|
2022-07-05 06:41:29 +00:00
|
|
|
else:
|
2022-08-17 04:54:16 +00:00
|
|
|
self.prop_id = str(data["appendPropId"])
|
2022-07-16 19:36:26 +00:00
|
|
|
fight_prop = Assets.get_hash_map(str(data["appendPropId"]))
|
2022-08-16 15:03:28 +00:00
|
|
|
|
2022-08-17 04:54:16 +00:00
|
|
|
prod_id = ["HURT", "CRITICAL", "EFFICIENCY", "PERCENT", "ADD"]
|
2022-08-16 15:03:28 +00:00
|
|
|
|
2022-08-22 09:29:18 +00:00
|
|
|
if self.prop_id.split("_")[-1] in prod_id:
|
|
|
|
self.value = float(data["statValue"])
|
2022-08-17 04:54:16 +00:00
|
|
|
self.type = DigitType.PERCENT
|
2022-07-05 06:41:29 +00:00
|
|
|
|
2022-07-05 08:46:47 +00:00
|
|
|
if not fight_prop:
|
|
|
|
return
|
2022-07-05 06:41:29 +00:00
|
|
|
|
2022-08-17 04:54:16 +00:00
|
|
|
self.name = fight_prop
|
2022-07-05 06:41:29 +00:00
|
|
|
|
2022-07-29 04:31:21 +00:00
|
|
|
|
2022-07-05 06:41:29 +00:00
|
|
|
class EquipmentsDetail(BaseModel):
|
|
|
|
"""
|
|
|
|
Custom data
|
|
|
|
"""
|
2022-07-29 04:31:21 +00:00
|
|
|
name: str = "" # Get from name hash map
|
|
|
|
artifact_name_set: str = "" # Name set artifacts
|
|
|
|
artifact_type: EquipType = EquipType.Unknown # Type of artifact
|
2022-11-19 05:36:12 +00:00
|
|
|
icon: IconAsset = None
|
2022-07-05 06:41:29 +00:00
|
|
|
rarity: int = Field(0, alias="rankLevel")
|
|
|
|
mainstats: EquipmentsStats = Field(None, alias="reliquaryMainstat")
|
|
|
|
substats: List[EquipmentsStats] = []
|
|
|
|
|
2022-08-17 04:54:16 +00:00
|
|
|
def __init__(self, **data: Any) -> None:
|
2022-07-05 06:41:29 +00:00
|
|
|
super().__init__(**data)
|
|
|
|
|
2022-07-29 04:31:21 +00:00
|
|
|
if data["itemType"] == "ITEM_RELIQUARY": # AKA. Artifact
|
|
|
|
LOGGER.debug("=== Artifact ===")
|
2022-08-17 04:54:16 +00:00
|
|
|
self.icon = IconAsset(filename=data["icon"])
|
|
|
|
self.artifact_type = EquipType(data["equipType"])
|
2022-07-05 08:46:47 +00:00
|
|
|
# Sub Stats
|
2022-08-17 04:54:16 +00:00
|
|
|
for stats in data["reliquarySubstats"] if "reliquarySubstats" in data else []:
|
|
|
|
self.substats.append(EquipmentsStats.parse_obj(stats))
|
2022-07-05 06:41:29 +00:00
|
|
|
|
2022-07-29 04:31:21 +00:00
|
|
|
if data["itemType"] == "ITEM_WEAPON": # AKA. Weapon
|
|
|
|
LOGGER.debug("=== Weapon ===")
|
2022-08-17 04:54:16 +00:00
|
|
|
self.icon = IconAsset(filename=data["icon"])
|
2022-07-05 08:46:47 +00:00
|
|
|
|
|
|
|
# Main and Sub Stats
|
2022-08-17 04:54:16 +00:00
|
|
|
self.mainstats = EquipmentsStats.parse_obj(
|
2022-07-29 04:31:21 +00:00
|
|
|
data["weaponStats"][0])
|
2022-07-05 06:41:29 +00:00
|
|
|
for stats in data["weaponStats"][1:]:
|
2022-08-17 04:54:16 +00:00
|
|
|
self.substats.append(EquipmentsStats.parse_obj(stats))
|
2022-07-05 08:46:47 +00:00
|
|
|
|
2022-07-16 19:36:26 +00:00
|
|
|
_name = Assets.get_hash_map(str(data["nameTextMapHash"]))
|
2022-07-18 19:07:53 +00:00
|
|
|
if "setNameTextMapHash" in data:
|
2022-08-16 15:03:28 +00:00
|
|
|
_artifact_name_set = Assets.get_hash_map(str(data["setNameTextMapHash"]))
|
2022-08-17 04:54:16 +00:00
|
|
|
self.artifact_name_set = _artifact_name_set or ""
|
2022-07-29 04:31:21 +00:00
|
|
|
|
2022-08-17 04:54:16 +00:00
|
|
|
self.name = _name if _name is not None else ""
|
2022-07-05 06:41:29 +00:00
|
|
|
|
|
|
|
class Config:
|
|
|
|
use_enum_values = True
|
|
|
|
|
2022-07-29 04:31:21 +00:00
|
|
|
|
2022-07-05 06:41:29 +00:00
|
|
|
class Equipments(BaseModel):
|
|
|
|
"""
|
|
|
|
API Response data
|
|
|
|
"""
|
|
|
|
id: int = Field(0, alias="itemId")
|
|
|
|
detail: EquipmentsDetail = Field({}, alias="flat")
|
|
|
|
|
|
|
|
"""
|
|
|
|
Custom data
|
|
|
|
"""
|
2022-07-29 04:31:21 +00:00
|
|
|
level: int = 0 # Get form key "reliquary" and "weapon"
|
2022-08-15 20:16:59 +00:00
|
|
|
max_level: int = 0
|
2022-07-29 04:31:21 +00:00
|
|
|
# Type of equipments (Ex. Artifact, Weapon)
|
|
|
|
type: EquipmentsType = EquipmentsType.UNKNOWN
|
2022-08-17 04:54:16 +00:00
|
|
|
refinement: int = 1 # Refinement of equipments (Weapon only)
|
2022-07-29 04:31:21 +00:00
|
|
|
ascension: int = 0 # Ascension (Weapon only)
|
2022-07-05 06:41:29 +00:00
|
|
|
|
|
|
|
class Config:
|
|
|
|
use_enum_values = True
|
|
|
|
|
2022-08-17 04:54:16 +00:00
|
|
|
def __init__(self, **data: Any) -> None:
|
2022-07-05 06:41:29 +00:00
|
|
|
super().__init__(**data)
|
|
|
|
|
2022-07-29 04:31:21 +00:00
|
|
|
if data["flat"]["itemType"] == "ITEM_RELIQUARY": # AKA. Artifact
|
2022-08-17 04:54:16 +00:00
|
|
|
self.type = EquipmentsType.ARTIFACT
|
|
|
|
self.level = data["reliquary"]["level"] - 1
|
|
|
|
self.max_level = 4 * data["flat"]["rankLevel"]
|
2022-07-29 04:31:21 +00:00
|
|
|
|
|
|
|
if data["flat"]["itemType"] == "ITEM_WEAPON": # AKA. Weapon
|
2022-08-17 04:54:16 +00:00
|
|
|
self.type = EquipmentsType.WEAPON
|
|
|
|
self.level = data["weapon"]["level"]
|
2022-08-15 20:16:59 +00:00
|
|
|
|
2022-07-17 06:07:40 +00:00
|
|
|
if "affixMap" in data["weapon"]:
|
2022-08-17 04:54:16 +00:00
|
|
|
self.refinement = data["weapon"]["affixMap"][
|
|
|
|
list(data["weapon"]["affixMap"].keys())[0]] + 1
|
2022-08-15 20:16:59 +00:00
|
|
|
|
2022-07-17 16:50:36 +00:00
|
|
|
if "promoteLevel" in data["weapon"]:
|
2022-08-17 04:54:16 +00:00
|
|
|
self.ascension = data["weapon"]["promoteLevel"]
|
|
|
|
self.max_level = (self.ascension * 10) + (
|
|
|
|
10 if self.ascension > 0 else 0) + 20
|