From c2d6989e6efcb05fa702e3f4e290469cb768356c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C4=93lla=20Caerulea?= <69615283+StellaCaerulea@users.noreply.github.com> Date: Mon, 23 Oct 2023 21:51:24 +0800 Subject: [PATCH] :bug: Fixed `enka_parser` wrongly taking some percentages as decimals --- python_genshin_artifact/enka/enka_parser.py | 20 +++----------------- python_genshin_artifact/enka/fight.py | 13 ++++++++++++- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/python_genshin_artifact/enka/enka_parser.py b/python_genshin_artifact/enka/enka_parser.py index 37d7446..3025eff 100644 --- a/python_genshin_artifact/enka/enka_parser.py +++ b/python_genshin_artifact/enka/enka_parser.py @@ -4,7 +4,7 @@ from typing import Tuple, List, Optional from python_genshin_artifact.enka.artifacts import artifacts_name_map, equip_type_map from python_genshin_artifact.enka.assets import Assets from python_genshin_artifact.enka.characters import characters_map -from python_genshin_artifact.enka.fight import fight_map +from python_genshin_artifact.enka.fight import fight_map, toFloat from python_genshin_artifact.enka.weapon import weapon_name_map from python_genshin_artifact.models.artifact import ArtifactInfo from python_genshin_artifact.models.characterInfo import CharacterInfo @@ -82,26 +82,12 @@ def de_equip_list(equip_list: list[dict]) -> Tuple[WeaponInfo, List[ArtifactInfo _reliquary_main_stat = _flat["reliquaryMainstat"] _main_prop_id = _reliquary_main_stat["mainPropId"] stat_name = fight_map[_main_prop_id] - stat_value = _reliquary_main_stat["statValue"] - if "_PERCENT" in _main_prop_id: - stat_value /= 100 - elif "FIGHT_PROP_CRITICAL" in _main_prop_id: - stat_value /= 100 - elif "FIGHT_PROP_CRITICAL_HURT" in _main_prop_id: - stat_value /= 100 - elif "_ADD_HURT" in _main_prop_id: - stat_value /= 100 + stat_value = toFloat(_main_prop_id, _reliquary_main_stat["statValue"]) _main_stat = (stat_name, stat_value) for _reliquary_sub_stats in _flat["reliquarySubstats"]: _append_prop_id = _reliquary_sub_stats["appendPropId"] stat_name = fight_map[_append_prop_id] - stat_value = _reliquary_sub_stats["statValue"] - if "_PERCENT" in _append_prop_id: - stat_value /= 100 - elif "FIGHT_PROP_CRITICAL" in _append_prop_id: - stat_value /= 100 - elif "FIGHT_PROP_CRITICAL_HURT" in _append_prop_id: - stat_value /= 100 + stat_value = toFloat(_append_prop_id, _reliquary_sub_stats["statValue"]) _sub_stats = (stat_name, stat_value) sub_stats.append(_sub_stats) slot = equip_type_map[_flat["equipType"]] diff --git a/python_genshin_artifact/enka/fight.py b/python_genshin_artifact/enka/fight.py index c17393a..f0c5138 100644 --- a/python_genshin_artifact/enka/fight.py +++ b/python_genshin_artifact/enka/fight.py @@ -1,4 +1,4 @@ -from typing import Dict +from typing import Dict, List fight_map: Dict[str, str] = { "FIGHT_PROP_ATTACK": "ATKFixed", @@ -21,3 +21,14 @@ fight_map: Dict[str, str] = { "FIGHT_PROP_ROCK_ADD_HURT": "GeoBonus", "FIGHT_PROP_GRASS_ADD_HURT": "DendroBonus", } + +fixed: List[str] = { + "FIGHT_PROP_ATTACK", + "FIGHT_PROP_DEFENSE", + "FIGHT_PROP_HP", + "FIGHT_PROP_ELEMENT_MASTERY", +} + + +def toFloat(prop_id: str, pc: float) -> float: + return pc if prop_id in fixed else (pc / 100)