mirror of
https://github.com/PaiGramTeam/EnkaNetwork.py.git
synced 2024-11-16 03:45:28 +00:00
Add artifact rolls (Props)
This commit is contained in:
parent
c42f2dee04
commit
76bb277fe2
@ -132,6 +132,19 @@ class Assets:
|
||||
"banner": utils.IconAsset(filename=data["picPath"][1]),
|
||||
"navbar": utils.IconAsset(filename=data["picPath"][0]),
|
||||
})
|
||||
|
||||
@classmethod
|
||||
def artifact_props(cls, id: int):
|
||||
LOGGER.debug(f"Getting artifact props assets with id: {id}")
|
||||
data = cls.DATA["artifact_props"].get(str(id))
|
||||
if not data:
|
||||
LOGGER.error(f"Artifact props not found with id: {id}")
|
||||
return
|
||||
|
||||
return assets.AritfactProps.parse_obj({
|
||||
"id": id,
|
||||
**data
|
||||
})
|
||||
|
||||
@classmethod
|
||||
def get_hash_map(cls, hash_id: str) -> Optional[str]:
|
||||
|
2082
enkanetwork/assets/data/artifact_props.json
Normal file
2082
enkanetwork/assets/data/artifact_props.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -110,6 +110,12 @@ class CharacterCostume(BaseModel):
|
||||
id: int = 0
|
||||
images: CharacterIconAsset = None
|
||||
|
||||
class AritfactProps(BaseModel):
|
||||
id: int = 0
|
||||
type: str = Field('', alias='propType')
|
||||
digit: str = Field('DIGIT', alias='propDigit')
|
||||
value: int = Field(0, alias='propValue')
|
||||
|
||||
|
||||
class CharacterAsset(BaseModel):
|
||||
""" Character (Assets)
|
||||
|
@ -88,6 +88,23 @@ class EquipmentsDetail(BaseModel):
|
||||
class Config:
|
||||
use_enum_values = True
|
||||
|
||||
class EquipmentsProps(BaseModel):
|
||||
id: int = 0
|
||||
prop_id: str = ''
|
||||
name: str = ''
|
||||
digit: DigitType = DigitType.NUMBER
|
||||
value: int = 0
|
||||
|
||||
def __init__(self, **data: Any) -> None:
|
||||
super().__init__(**data)
|
||||
self.name = Assets.get_hash_map(self.prop_id)
|
||||
|
||||
def get_value_symbol(self):
|
||||
return f"{self.value}{'%' if self.digit == DigitType.PERCENT else ''}"
|
||||
|
||||
def get_full_name(self):
|
||||
raw = self.value
|
||||
return f"{self.name}{str(raw) if raw < 0 else '+'+str(raw)}{'%' if self.digit == DigitType.PERCENT else ''}"
|
||||
|
||||
class Equipments(BaseModel):
|
||||
"""
|
||||
@ -105,6 +122,7 @@ class Equipments(BaseModel):
|
||||
type: EquipmentsType = EquipmentsType.UNKNOWN
|
||||
refinement: int = 1 # Refinement of equipments (Weapon only)
|
||||
ascension: int = 0 # Ascension (Weapon only)
|
||||
props: List[EquipmentsProps] = []
|
||||
|
||||
class Config:
|
||||
use_enum_values = True
|
||||
@ -118,6 +136,17 @@ class Equipments(BaseModel):
|
||||
self.level = data["reliquary"]["level"] - 1
|
||||
self.max_level = 4 * data["flat"]["rankLevel"]
|
||||
|
||||
for props in data["reliquary"].get("appendPropIdList", []):
|
||||
props_info = Assets.artifact_props(props)
|
||||
if props_info:
|
||||
# print(props_info)
|
||||
self.props.append(EquipmentsProps(**{
|
||||
"id": props_info.id,
|
||||
"prop_id": props_info.type,
|
||||
"digit": DigitType.PERCENT if props_info.digit == 'PERCENT' else DigitType.NUMBER,
|
||||
"value": props_info.value
|
||||
}))
|
||||
|
||||
if data["flat"]["itemType"] == "ITEM_WEAPON": # AKA. Weapon
|
||||
self.type = EquipmentsType.WEAPON
|
||||
self.level = data["weapon"]["level"]
|
||||
@ -133,4 +162,4 @@ class Equipments(BaseModel):
|
||||
|
||||
if self.ascension >= 2:
|
||||
self.detail.icon = IconAsset(filename=self.detail.icon.filename + "_Awaken")
|
||||
|
||||
|
28
example/artifact_props.py
Normal file
28
example/artifact_props.py
Normal file
@ -0,0 +1,28 @@
|
||||
import asyncio
|
||||
|
||||
from enkanetwork import EnkaNetworkAPI
|
||||
from enkanetwork import EquipmentsType, DigitType
|
||||
|
||||
client = EnkaNetworkAPI(lang="th")
|
||||
|
||||
async def main():
|
||||
async with client:
|
||||
data = await client.fetch_user(843715177)
|
||||
for character in data.characters:
|
||||
print(f"=== Artifacts props of {character.name} ===")
|
||||
for artifact in filter(lambda x: x.type == EquipmentsType.ARTIFACT, character.equipments):
|
||||
print(f"ID: {artifact.id}")
|
||||
print(f"Name: {artifact.detail.name}")
|
||||
print(f"Type: {artifact.detail.artifact_type}")
|
||||
print("--- Props ---")
|
||||
for props in artifact.props:
|
||||
print(f"ID: {props.id}")
|
||||
print(f"Type: {props.prop_id}")
|
||||
print(f"Raw name: {props.name}")
|
||||
print(f"Full name: {props.get_full_name()}")
|
||||
print(f"Value (Formatted): {props.get_value_symbol()}")
|
||||
print("-"*18)
|
||||
|
||||
print("="*18)
|
||||
|
||||
asyncio.run(main())
|
Loading…
Reference in New Issue
Block a user