From 38d684831327b3f0e15a37e79175b32e53bee8f3 Mon Sep 17 00:00:00 2001 From: qwerdvd <2450899274@qq.com> Date: Fri, 12 May 2023 20:05:39 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=E5=AE=8C=E6=88=90=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../starrailuid_charinfo/draw_char_img.py | 5 +- .../starrailuid_charinfo/mono/Character.py | 73 +++++++++++++++---- StarRailUID/utils/map/SR_MAP_PATH.py | 4 + .../map/data/RelicSetSkill_mapping_1.0.5.json | 1 + 4 files changed, 67 insertions(+), 16 deletions(-) create mode 100644 StarRailUID/utils/map/data/RelicSetSkill_mapping_1.0.5.json diff --git a/StarRailUID/starrailuid_charinfo/draw_char_img.py b/StarRailUID/starrailuid_charinfo/draw_char_img.py index e10a1fb..af3492b 100644 --- a/StarRailUID/starrailuid_charinfo/draw_char_img.py +++ b/StarRailUID/starrailuid_charinfo/draw_char_img.py @@ -19,7 +19,10 @@ async def draw_char_info_img(raw_mes: str, sr_uid: str, url: Optional[str]): async def cal_char_info(char_data: dict): - await Character(char_data).get_equipment_info() + char = Character(char_data) + await char.get_equipment_info() + await char.get_char_attribute_bonus() + await char.get_relic_info() async def get_char_data( diff --git a/StarRailUID/starrailuid_charinfo/mono/Character.py b/StarRailUID/starrailuid_charinfo/mono/Character.py index 06839b0..1aa3273 100644 --- a/StarRailUID/starrailuid_charinfo/mono/Character.py +++ b/StarRailUID/starrailuid_charinfo/mono/Character.py @@ -1,8 +1,10 @@ +import json from typing import Dict, Tuple +from collections import Counter from mpmath import mp -from ...utils.map.SR_MAP_PATH import EquipmentID2AbilityProperty +from ...utils.map.SR_MAP_PATH import RelicSetSkill, EquipmentID2AbilityProperty mp.dps = 14 @@ -62,6 +64,61 @@ class Character: self.add_attr[property_type] += value else: self.add_attr[property_type] = value + + async def get_char_attribute_bonus(self): + attribute_bonus = self.attribute_bonus + for bonus in attribute_bonus: + status_add = bonus['statusAdd'] + bonus_property = status_add['property'] + value = status_add['value'] + if bonus_property in self.add_attr: + self.add_attr[bonus_property] += value + else: + self.add_attr[bonus_property] = value + + async def get_relic_info(self): + # 计算圣遗物效果 + set_id_list = [] + for relic in self.char_relic: + print(json.dumps(relic, ensure_ascii=False)) + set_id_list.append(relic['SetId']) + # 处理主属性 + relic_property = relic['MainAffix']['Property'] + property_value = mp.mpf(relic['MainAffix']['Value']) + if relic_property in self.add_attr: + self.add_attr[relic_property] = str( + mp.mpf(self.add_attr[relic_property]) + property_value + ) + else: + self.add_attr[relic_property] = str(property_value) + # 处理副词条 + for sub in relic['SubAffixList']: + sub_property = sub['Property'] + sub_value = mp.mpf(sub['Value']) + if sub_property in self.add_attr: + self.add_attr[sub_property] = str( + mp.mpf(self.add_attr[sub_property]) + sub_value + ) + else: + self.add_attr[sub_property] = str(sub_value) + # 处理套装属性 + set_id_dict = dict(Counter(set_id_list)) + for set_id, count in set_id_dict.items(): + set_property = '' + if 2 <= count < 4: + set_property = RelicSetSkill[str(set_id)]['2']['Property'] + set_value = mp.mpf(RelicSetSkill[str(set_id)]['2']['Value']) + if count == 4 and RelicSetSkill[str(set_id)]['4'] != {}: + set_property = RelicSetSkill[str(set_id)]['4']['Property'] + set_value = mp.mpf(RelicSetSkill[str(set_id)]['4']['Value']) + if set_property != '': + if set_property in self.add_attr: + self.add_attr[set_property] = str( + mp.mpf(self.add_attr[set_property]) + set_value + ) + else: + self.add_attr[set_property] = str(set_value) + print(self.base_attributes) print(self.add_attr) @@ -91,17 +148,3 @@ async def p2v(power: str, power_plus: int) -> Tuple[float, float]: power_value = float(power) return power_percent, power_value - - -# async def get_artifacts_value(raw_data: Dict) -> List[str]: -# # 计算圣遗物效果 -# all_effects = [] -# for equip in raw_data['equipList']: -# statNmae = equip['reliquaryMainstat']['statName'] -# statValue = equip['reliquaryMainstat']['statValue'] -# all_effects.append(await text_to_effect(statNmae, statValue)) -# for sub in equip['reliquarySubstats']: -# sub_name = sub['statName'] -# sub_value = sub['statValue'] -# all_effects.append(await text_to_effect(sub_name, sub_value)) -# return all_effects diff --git a/StarRailUID/utils/map/SR_MAP_PATH.py b/StarRailUID/utils/map/SR_MAP_PATH.py index 4bec31f..80cde92 100644 --- a/StarRailUID/utils/map/SR_MAP_PATH.py +++ b/StarRailUID/utils/map/SR_MAP_PATH.py @@ -25,6 +25,7 @@ avatarId2Rarity_fileName = f'avatarId2Rarity_mapping_{version}.json' EquipmentID2AbilityProperty_fileName = ( f'EquipmentID2AbilityProperty_mapping_{version}.json' ) +RelicSetSkill_fileName = f'RelicSetSkill_mapping_{version}.json' class TS(TypedDict): @@ -80,3 +81,6 @@ with open( EquipmentID2AbilityProperty = msgjson.decode( f.read(), type=Dict[str, Dict[str, List]] ) + +with open(MAP / RelicSetSkill_fileName, 'r', encoding='UTF-8') as f: + RelicSetSkill = msgjson.decode(f.read(), type=Dict[str, dict]) diff --git a/StarRailUID/utils/map/data/RelicSetSkill_mapping_1.0.5.json b/StarRailUID/utils/map/data/RelicSetSkill_mapping_1.0.5.json new file mode 100644 index 0000000..edcb79b --- /dev/null +++ b/StarRailUID/utils/map/data/RelicSetSkill_mapping_1.0.5.json @@ -0,0 +1 @@ +{"101": {"2": {"Property": "HealRatioBase", "Value": 0.0999999985238072}, "4": {}}, "102": {"2": {"Property": "AttackAddedRatio", "Value": 0.11999999822856863}, "4": {"Property": "SpeedAddedRatio", "Value": 0.059999999114284316}}, "103": {"2": {"Property": "DefenceAddedRatio", "Value": 0.1499999977857108}, "4": {}}, "104": {"2": {"Property": "IceAddedRatio", "Value": 0.0999999985238072}, "4": {}}, "105": {"2": {"Property": "PhysicalAddedRatio", "Value": 0.0999999985238072}, "4": {}}, "106": {"2": {}, "4": {}}, "107": {"2": {"Property": "FireAddedRatio", "Value": 0.0999999985238072}, "4": {}}, "108": {"2": {"Property": "QuantumAddedRatio", "Value": 0.0999999985238072}, "4": {}}, "109": {"2": {"Property": "ThunderAddedRatio", "Value": 0.0999999985238072}, "4": {}}, "110": {"2": {"Property": "WindAddedRatio", "Value": 0.0999999985238072}, "4": {}}, "111": {"2": {"Property": "BreakDamageAddedRatioBase", "Value": 0.15999999763809153}, "4": {"Property": "BreakDamageAddedRatioBase", "Value": 0.15999999763809153}}, "112": {"2": {"Property": "ImaginaryAddedRatio", "Value": 0.0999999985238072}, "4": {}}, "301": {"2": {"Property": "AttackAddedRatio", "Value": 0.11999999822856863}}, "302": {"2": {"Property": "HPAddedRatio", "Value": 0.11999999822856863}}, "303": {"2": {"Property": "StatusProbabilityBase", "Value": 0.0999999985238072}}, "304": {"2": {"Property": "DefenceAddedRatio", "Value": 0.1499999977857108}}, "305": {"2": {"Property": "CriticalDamageBase", "Value": 0.15999999763809153}}, "306": {"2": {"Property": "CriticalChanceBase", "Value": 0.07999999881904576}}, "307": {"2": {"Property": "BreakDamageAddedRatioBase", "Value": 0.15999999763809153}}, "308": {"2": {"Property": "SPRatioBase", "Value": 0.0499999992619036}}}