diff --git a/StarRailUID/starrailuid_charinfo/draw_char_img.py b/StarRailUID/starrailuid_charinfo/draw_char_img.py index f25ee41..9b94c2c 100644 --- a/StarRailUID/starrailuid_charinfo/draw_char_img.py +++ b/StarRailUID/starrailuid_charinfo/draw_char_img.py @@ -10,6 +10,7 @@ from gsuid_core.logger import logger from gsuid_core.utils.image.convert import convert_img from gsuid_core.utils.image.image_tools import draw_text_by_line from starrail_damage_cal.cal_damage import cal_char_info, cal_info +from starrail_damage_cal.model import MihomoCharacter from starrail_damage_cal.to_data import api_to_dict from ..utils.error_reply import CHAR_HINT @@ -95,7 +96,9 @@ RELIC_CNT = { } -async def draw_char_img(char_data: Dict, sr_uid: str, msg: str) -> Union[bytes, str]: +async def draw_char_img( + char_data: MihomoCharacter, sr_uid: str, msg: str +) -> Union[bytes, str]: if isinstance(char_data, str): return char_data char = await cal_char_info(char_data) @@ -175,7 +178,7 @@ async def draw_char_img(char_data: Dict, sr_uid: str, msg: str) -> Union[bytes, attr_bg = Image.open(TEXT_PATH / "attr_bg.png") attr_bg_draw = ImageDraw.Draw(attr_bg) # 生命值 - hp = int(char.base_attributes.get("hp")) + hp = int(char.base_attributes.hp) add_hp = int( char.add_attr.get("HPDelta", 0) + hp @@ -193,7 +196,7 @@ async def draw_char_img(char_data: Dict, sr_uid: str, msg: str) -> Union[bytes, anchor="lm", ) # 攻击力 - attack = int(char.base_attributes["attack"]) + attack = int(char.base_attributes.attack) add_attack = int( char.add_attr.get("AttackDelta", 0) + attack * char.add_attr.get("AttackAddedRatio", 0) @@ -213,7 +216,7 @@ async def draw_char_img(char_data: Dict, sr_uid: str, msg: str) -> Union[bytes, anchor="lm", ) # 防御力 - defence = int(char.base_attributes["defence"]) + defence = int(char.base_attributes.defence) add_defence = int( char.add_attr.get("DefenceDelta", 0) + defence * char.add_attr.get("DefenceAddedRatio", 0) @@ -233,7 +236,7 @@ async def draw_char_img(char_data: Dict, sr_uid: str, msg: str) -> Union[bytes, anchor="lm", ) # 速度 - speed = int(char.base_attributes["speed"]) + speed = int(char.base_attributes.speed) add_speed = int( char.add_attr.get("SpeedDelta", 0) + speed * char.add_attr.get("SpeedAddedRatio", 0) @@ -253,7 +256,7 @@ async def draw_char_img(char_data: Dict, sr_uid: str, msg: str) -> Union[bytes, anchor="lm", ) # 暴击率 - critical_chance = char.base_attributes["CriticalChanceBase"] + critical_chance = char.base_attributes.CriticalChanceBase critical_chance_base = char.add_attr.get("CriticalChanceBase", 0) critical_chance = (critical_chance + critical_chance_base) * 100 attr_bg_draw.text( @@ -264,7 +267,7 @@ async def draw_char_img(char_data: Dict, sr_uid: str, msg: str) -> Union[bytes, "rm", ) # 暴击伤害 - critical_damage = char.base_attributes["CriticalDamageBase"] + critical_damage = char.base_attributes.CriticalDamageBase critical_damage_base = char.add_attr.get("CriticalDamageBase", 0) critical_damage = (critical_damage + critical_damage_base) * 100 attr_bg_draw.text( @@ -337,8 +340,8 @@ async def draw_char_img(char_data: Dict, sr_uid: str, msg: str) -> Union[bytes, skill_panel_img = Image.open(TEXT_PATH / "skill_panel.png") skill_img = ( Image.open( - SKILL_PATH / f'{char.char_id}_' - f'{skill_type_map[skill["skillAttackType"]][1]}.png' + SKILL_PATH / f"{char.char_id}_" + f"{skill_type_map[skill.skillAttackType][1]}.png" ) .convert("RGBA") .resize((55, 55)) @@ -348,21 +351,21 @@ async def draw_char_img(char_data: Dict, sr_uid: str, msg: str) -> Union[bytes, skill_panel_img_draw = ImageDraw.Draw(skill_panel_img) skill_panel_img_draw.text( (108, 25), - f'{skill_type_map[skill["skillAttackType"]][0]}', + f"{skill_type_map[skill.skillAttackType][0]}", white_color, sr_font_26, "lm", ) skill_panel_img_draw.text( (89, 55), - f'Lv.{skill["skillLevel"]}', + f"Lv.{skill.skillLevel}", white_color, sr_font_26, "lm", ) skill_panel_img_draw.text( (75, 90), - f'{skill["skillName"]}', + f"{skill.skillName}", (105, 105, 105), sr_font_20, "mm", @@ -374,7 +377,7 @@ async def draw_char_img(char_data: Dict, sr_uid: str, msg: str) -> Union[bytes, # 武器 if char.equipment != {}: weapon_bg = Image.open(TEXT_PATH / "weapon_bg.png") - weapon_id = char.equipment["equipmentID"] + weapon_id = char.equipment.equipmentID weapon_img = ( Image.open(WEAPON_PATH / f"{weapon_id}.png") .convert("RGBA") @@ -384,24 +387,24 @@ async def draw_char_img(char_data: Dict, sr_uid: str, msg: str) -> Union[bytes, weapon_bg_draw = ImageDraw.Draw(weapon_bg) weapon_bg_draw.text( (345, 47), - f'{char.equipment["equipmentName"]}', + f"{char.equipment.equipmentName}", white_color, sr_font_34, "lm", ) if hasattr(sr_font_34, "getsize"): weapon_name_len = sr_font_34.getsize( # type: ignore - char.equipment["equipmentName"] + char.equipment.equipmentName )[0] else: - bbox = sr_font_34.getbbox(char.equipment["equipmentName"]) + bbox = sr_font_34.getbbox(char.equipment.equipmentName) weapon_name_len = bbox[2] - bbox[0] # 放阶 rank_img = Image.open(TEXT_PATH / "ImgNewBg.png") rank_img_draw = ImageDraw.Draw(rank_img) rank_img_draw.text( (70, 44), - f'{NUM_MAP[char.equipment["equipmentRank"]]}阶', + f"{NUM_MAP[char.equipment.equipmentRank]}阶", white_color, sr_font_28, "mm", @@ -409,21 +412,21 @@ async def draw_char_img(char_data: Dict, sr_uid: str, msg: str) -> Union[bytes, weapon_bg.paste(rank_img, (weapon_name_len + 330, 2), rank_img) rarity_img = Image.open( - TEXT_PATH / f'LightCore_Rarity{char.equipment["equipmentRarity"]}.png' + TEXT_PATH / f"LightCore_Rarity{char.equipment.equipmentRarity}.png" ).resize((306, 72)) weapon_bg.paste(rarity_img, (223, 55), rarity_img) weapon_bg_draw.text( (498, 90), - f'Lv.{char.equipment["equipmentLevel"]}', + f"Lv.{char.equipment.equipmentLevel}", white_color, sr_font_28, "mm", ) # 武器技能 - desc = light_cone_ranks[str(char.equipment["equipmentID"])]["desc"] - desc_params = light_cone_ranks[str(char.equipment["equipmentID"])]["params"][ - char.equipment["equipmentRank"] - 1 + desc = light_cone_ranks[str(char.equipment.equipmentID)]["desc"] + desc_params = light_cone_ranks[str(char.equipment.equipmentID)]["params"][ + char.equipment.equipmentRank - 1 ] for i in range(len(desc_params)): temp = math.floor(desc_params[i] * 1000) / 10 @@ -460,15 +463,15 @@ async def draw_char_img(char_data: Dict, sr_uid: str, msg: str) -> Union[bytes, relic_score = 0 for relic in char.char_relic: - rarity = RelicId2Rarity[str(relic["relicId"])] + rarity = RelicId2Rarity[str(relic.relicId)] relic_img = Image.open(TEXT_PATH / f"yq_bg{rarity}.png") - if str(relic["SetId"])[0] == "3": + if str(relic.SetId)[0] == "3": relic_piece_img = Image.open( - RELIC_PATH / f'{relic["SetId"]}_{relic["Type"] - 5}.png' + RELIC_PATH / f"{relic.SetId}_{relic.Type - 5}.png" ) else: relic_piece_img = Image.open( - RELIC_PATH / f'{relic["SetId"]}_{relic["Type"] - 1}.png' + RELIC_PATH / f"{relic.SetId}_{relic.Type - 1}.png" ) relic_piece_new_img = relic_piece_img.resize( (105, 105), Image.Resampling.LANCZOS @@ -479,15 +482,15 @@ async def draw_char_img(char_data: Dict, sr_uid: str, msg: str) -> Union[bytes, relic_piece_new_img, ) rarity_img = Image.open( - TEXT_PATH / f'LightCore_Rarity' - f'{RelicId2Rarity[str(relic["relicId"])]}.png' + TEXT_PATH / f"LightCore_Rarity" + f"{RelicId2Rarity[str(relic.relicId)]}.png" ).resize((200, 48)) relic_img.paste(rarity_img, (-10, 80), rarity_img) relic_img_draw = ImageDraw.Draw(relic_img) - if len(relic["relicName"]) <= 5: - main_name = relic["relicName"] + if len(relic.relicName) <= 5: + main_name = relic.relicName else: - main_name = relic["relicName"][:2] + relic["relicName"][4:] + main_name = relic.relicName[:2] + relic.relicName[4:] relic_img_draw.text( (30, 70), main_name, @@ -497,9 +500,9 @@ async def draw_char_img(char_data: Dict, sr_uid: str, msg: str) -> Union[bytes, ) # 主属性 - main_value = relic["MainAffix"]["Value"] - main_name: str = relic["MainAffix"]["Name"] - main_level: int = relic["Level"] + main_value = relic.MainAffix.Value + main_name = relic.MainAffix.Name + main_level = relic.Level if main_name in ["攻击力", "生命值", "防御力", "速度"]: mainValueStr = f"{main_value:.1f}" @@ -536,21 +539,21 @@ async def draw_char_img(char_data: Dict, sr_uid: str, msg: str) -> Union[bytes, single_relic_score = 0 main_value_score = await get_relic_score( - relic["MainAffix"]["Property"], + relic.MainAffix.Property, main_value, char.char_name, True, - relic["Type"], + relic.Type, ) single_relic_score += main_value_score - for index, i in enumerate(relic["SubAffixList"]): - subName: str = i["Name"] - subCnt = i["Cnt"] - subValue = i["Value"] - subProperty = i["Property"] + for index, i in enumerate(relic.SubAffixList): + subName = i.Name + subCnt = i.Cnt + subValue = i.Value + subProperty = i.Property tmp_score = await get_relic_score( - subProperty, subValue, char.char_name, False, relic["Type"] + subProperty, subValue, char.char_name, False, relic.Type ) single_relic_score += tmp_score @@ -594,7 +597,7 @@ async def draw_char_img(char_data: Dict, sr_uid: str, msg: str) -> Union[bytes, anchor="rm", ) - char_info.paste(relic_img, RELIC_POS[str(relic["Type"])], relic_img) + char_info.paste(relic_img, RELIC_POS[str(relic.Type)], relic_img) relic_score += single_relic_score if relic_score > 210: relic_value_level = Image.open(TEXT_PATH / "CommonIconSSS.png") diff --git a/StarRailUID/starrailuid_charinfo/get_char_img.py b/StarRailUID/starrailuid_charinfo/get_char_img.py index af203d2..7b3a25a 100644 --- a/StarRailUID/starrailuid_charinfo/get_char_img.py +++ b/StarRailUID/starrailuid_charinfo/get_char_img.py @@ -1,19 +1,28 @@ -import json -from pathlib import Path import re -from typing import Dict, Optional, Tuple, Union +from typing import List, Optional, Tuple, Union, cast from gsuid_core.logger import logger from starrail_damage_cal.excel.model import ( AvatarPromotionConfig, EquipmentPromotionConfig, ) -from starrail_damage_cal.to_data import api_to_dict +from starrail_damage_cal.map.SR_MAP_PATH import AvatarRankSkillUp +from starrail_damage_cal.model import ( + AttributeBounsStatusAdd, + AvatarBaseAttributes, + AvatarEquipmentInfo, + EquipmentBaseAttributes, + MihomoAvatarAttributeBonus, + MihomoAvatarExtraAbility, + MihomoAvatarSkill, + MihomoCharacter, + RankData, +) +from starrail_damage_cal.to_data import api_to_dict, characterSkillTree from .draw_char_img import draw_char_img from ..utils.error_reply import CHAR_HINT from ..utils.map.SR_MAP_PATH import ( - AvatarRankSkillUp, EquipmentID2Name, EquipmentID2Rarity, Property2Name, @@ -21,7 +30,6 @@ from ..utils.map.SR_MAP_PATH import ( avatarId2EnName, avatarId2Name, avatarId2Rarity, - characterSkillTree, rankId2Name, skillId2AttackType, skillId2Effect, @@ -87,7 +95,7 @@ async def draw_char_info_img(raw_mes: str, sr_uid: str): async def get_char_args( msg: str, uid: str -) -> Union[Tuple[Dict, Optional[str], Optional[int], Optional[int]], str]: +) -> Union[Tuple[MihomoCharacter, Optional[str], Optional[int], Optional[int]], str]: # 可能进来的值 # 六命希儿带于夜色中换1000xxxx4青雀遗器换1000xxxx6希儿头换银狼手 # 六命希儿带于夜色中换1000xxxx6希儿头 @@ -115,10 +123,18 @@ async def get_char_args( char_data = await make_new_charinfo(uid, fake_name) else: char_data = await get_char_data(uid, fake_name) + if isinstance(char_data, str): return char_data + continue + if isinstance(char_data, str): + return char_data + + if isinstance(char_data, dict): + return "请先输入角色名噢~" + if "遗器" in part: char_data = await get_fake_char_data( char_data, @@ -142,18 +158,28 @@ async def get_char_args( else: weapon, weapon_affix = await get_fake_weapon_str(part) - return char_data, weapon, weapon_affix, talent_num + return cast( + Tuple[MihomoCharacter, Optional[str], Optional[int], Optional[int]], + ( + char_data, + weapon, + weapon_affix, + talent_num, + ), + ) -async def change_equip(uid: str, char_data: Dict, part: str, s: str, i: int) -> Dict: +async def change_equip( + uid: str, char_data: MihomoCharacter, part: str, s: str, i: int +) -> Union[MihomoCharacter, str]: char_name = part.replace(part[-1], "").replace(uid, "") fake_data = await get_char_data(uid, char_name) if isinstance(fake_data, str): - return {} + return fake_data relicmap = i + 1 - for equip in fake_data["RelicInfo"]: - if str(str(equip["relicId"])[-1]) == str(relicmap): - char_data["RelicInfo"][i] = equip + for equip in fake_data.RelicInfo: + if str(str(equip.relicId)[-1]) == str(relicmap): + char_data.RelicInfo[i] = equip break return char_data @@ -189,96 +215,113 @@ async def get_fake_weapon_str(msg: str) -> Tuple[str, Optional[int]]: async def get_fake_char_data( - char_data: Dict, change_name: str, changeuid: str -) -> Union[Dict, str]: + char_data: MihomoCharacter, change_name: str, changeuid: str +) -> Union[MihomoCharacter, str]: original_data = await get_char_data(changeuid, change_name) if isinstance(original_data, str): return original_data - if isinstance(original_data, Dict): - char_data["RelicInfo"] = original_data["RelicInfo"] + if isinstance(original_data, MihomoCharacter): + char_data.RelicInfo = original_data.RelicInfo return char_data async def get_char_data( uid: str, char_name: str, enable_self: bool = True -) -> Union[Dict, str]: - player_path = PLAYER_PATH / str(uid) - SELF_PATH = player_path / "SELF" +) -> Union[MihomoCharacter, str]: if "开拓者" in str(char_name): char_name = "开拓者" char_id = await name_to_avatar_id(char_name) if char_id == "": char_name = await alias_to_char_name(char_name) - if char_name is False: - return "请输入正确的角色名" - char_path = player_path / f"{char_name}.json" - char_self_path = SELF_PATH / f"{char_name}.json" - path = Path() - if char_path.exists(): - path = char_path - elif enable_self and char_self_path.exists(): - path = char_self_path - else: - char_id_list, _ = await api_to_dict(uid, save_path=PLAYER_PATH) - charname_list = [] - if isinstance(char_id_list, str): - return char_id_list - for char in char_id_list: - charname = avatarId2Name[str(char)] - charname_list.append(charname) - if str(char_name) in charname_list: - if char_path.exists(): - path = char_path - elif enable_self and char_self_path.exists(): - path = char_self_path - else: - return CHAR_HINT.format(char_name, char_name) - - with Path.open(path, encoding="utf8") as fp: - return json.load(fp) + char_id_list, chars = await api_to_dict(uid, save_path=PLAYER_PATH) + charname_list = [] + for char in char_id_list: + charname = avatarId2Name[str(char)] + charname_list.append(charname) + if char_name in charname_list: + return chars[char_id_list[charname_list.index(char_name)]] + return CHAR_HINT.format(char_name, char_name) async def make_new_charinfo( uid: str, fake_name: str, -): - char_data = {} - char_data["uid"] = uid - char_data["nickName"] = "test" +) -> MihomoCharacter: + char_data = MihomoCharacter( + uid="", + nickName="test", + avatarId=0, + avatarName="", + avatarElement="", + avatarRarity="", + avatarPromotion=0, + avatarLevel=1, + avatarSkill=[], + avatarExtraAbility=[], + avatarAttributeBonus=[], + RelicInfo=[], + avatarEnName="", + baseAttributes=AvatarBaseAttributes( + hp=0, + attack=0, + defence=0, + speed=0, + CriticalChanceBase=0, + CriticalDamageBase=0, + BaseAggro=0, + ), + equipmentInfo=AvatarEquipmentInfo( + equipmentID=0, + equipmentName="", + equipmentLevel=0, + equipmentPromotion=0, + equipmentRank=0, + equipmentRarity=0, + baseAttributes=EquipmentBaseAttributes(hp=0, attack=0, defence=0), + ), + rank=0, + rankList=[], + ) + char_data.uid = uid + char_data.nickName = "test" char_id = await name_to_avatar_id(fake_name) if char_id == "": fake_name = await alias_to_char_name(fake_name) - if fake_name is False: - return "请输入正确的角色名" char_id = await name_to_avatar_id(fake_name) - char_data["avatarId"] = int(char_id) - char_data["avatarName"] = fake_name - char_data["avatarElement"] = avatarId2DamageType[str(char_data["avatarId"])] - char_data["avatarRarity"] = str(avatarId2Rarity[str(char_data["avatarId"])]) - char_data["avatarPromotion"] = 6 - char_data["avatarLevel"] = 80 - char_data["avatarSkill"] = await get_skill_list(char_data["avatarId"]) - char_data["avatarExtraAbility"] = await get_extra_list(char_data["avatarId"]) - char_data["avatarAttributeBonus"] = await get_attribute_list(char_data["avatarId"]) - char_data["RelicInfo"] = [] - char_data["avatarEnName"] = avatarId2EnName[str(char_data["avatarId"])] - char_data["rank"] = 0 - char_data["rankList"] = [] - char_data["baseAttributes"] = await get_baseAttributes(char_data["avatarId"]) - char_data["equipmentInfo"] = {} + char_data.avatarId = int(char_id) + char_data.avatarName = fake_name + char_data.avatarElement = avatarId2DamageType[str(char_data.avatarId)] + char_data.avatarRarity = str(avatarId2Rarity[str(char_data.avatarId)]) + char_data.avatarPromotion = 6 + char_data.avatarLevel = 80 + char_data.avatarSkill = await get_skill_list(char_data.avatarId) + char_data.avatarExtraAbility = await get_extra_list(char_data.avatarId) + char_data.avatarAttributeBonus = await get_attribute_list(char_data.avatarId) + char_data.RelicInfo = [] + char_data.avatarEnName = avatarId2EnName[str(char_data.avatarId)] + char_data.rank = 0 + char_data.rankList = [] + char_data.baseAttributes = await get_baseAttributes(char_data.avatarId) return char_data async def get_baseAttributes( char_id: int, -): +) -> AvatarBaseAttributes: # 处理基础属性 - base_attributes = {} - + base_attributes = AvatarBaseAttributes( + hp=0, + attack=0, + defence=0, + speed=0, + CriticalChanceBase=0, + CriticalDamageBase=0, + BaseAggro=0, + ) avatar_promotion_base = None for avatar in AvatarPromotionConfig: - if avatar.AvatarID == str(char_id): + if avatar.AvatarID == str(char_id) and avatar.Promotion == 6: avatar_promotion_base = avatar break @@ -287,142 +330,147 @@ async def get_baseAttributes( raise ValueError(msg) # 攻击力 - base_attributes["attack"] = ( + base_attributes.attack = ( avatar_promotion_base.AttackBase.Value + avatar_promotion_base.AttackAdd.Value * (80 - 1) ) # 防御力 - base_attributes["defence"] = ( + base_attributes.defence = ( avatar_promotion_base.DefenceBase.Value + avatar_promotion_base.DefenceAdd.Value * (80 - 1) ) # 血量 - base_attributes["hp"] = ( + base_attributes.hp = ( avatar_promotion_base.HPBase.Value + avatar_promotion_base.HPAdd.Value * (80 - 1) ) # 速度 - base_attributes["speed"] = avatar_promotion_base.SpeedBase.Value + base_attributes.speed = avatar_promotion_base.SpeedBase.Value # 暴击率 - base_attributes["CriticalChanceBase"] = avatar_promotion_base.CriticalChance.Value + base_attributes.CriticalChanceBase = avatar_promotion_base.CriticalChance.Value # 暴击伤害 - base_attributes["CriticalDamageBase"] = avatar_promotion_base.CriticalDamage.Value + base_attributes.CriticalDamageBase = avatar_promotion_base.CriticalDamage.Value # 嘲讽 - base_attributes["BaseAggro"] = avatar_promotion_base.BaseAggro.Value + base_attributes.BaseAggro = avatar_promotion_base.BaseAggro.Value return base_attributes async def get_attribute_list( char_id: int, -): +) -> List[MihomoAvatarAttributeBonus]: attribute_list = [] for attributeid in [201, 202, 203, 204, 205, 206, 207, 208, 209, 210]: - attribute_bonus_temp = {} - attribute_bonus_temp["attributeBonusId"] = char_id * 1000 + attributeid - attribute_bonus_temp["attributeBonusLevel"] = 1 - status_add = characterSkillTree[str(char_id)][ - str(attribute_bonus_temp["attributeBonusId"]) - ]["levels"][0]["properties"] - attribute_bonus_temp["statusAdd"] = {} - if status_add: - for property_ in status_add: - attribute_bonus_temp["statusAdd"]["property"] = property_["type"] - attribute_bonus_temp["statusAdd"]["name"] = Property2Name[ - property_["type"] - ] - attribute_bonus_temp["statusAdd"]["value"] = property_["value"] - attribute_list.append(attribute_bonus_temp) + attribute_bonus_temp = MihomoAvatarAttributeBonus( + attributeBonusId=0, + attributeBonusLevel=0, + statusAdd=AttributeBounsStatusAdd(property_="", name="", value=0), + ) + attribute_bonus_temp.attributeBonusId = char_id * 1000 + attributeid + attribute_bonus_temp.attributeBonusLevel = 1 + status_add = ( + characterSkillTree[str(char_id)][str(attribute_bonus_temp.attributeBonusId)] + .levels[0] + .properties + ) + for property_ in status_add: + attribute_bonus_temp.statusAdd.property_ = property_.type + attribute_bonus_temp.statusAdd.name = Property2Name[property_.type] + attribute_bonus_temp.statusAdd.value = property_.value + attribute_list.append(attribute_bonus_temp) return attribute_list async def get_extra_list( char_id: int, -): +) -> List[MihomoAvatarExtraAbility]: extra_list = [] for extraid in [101, 102, 103]: - extra_temp = {} - extra_temp["extraAbilityId"] = char_id * 1000 + extraid - extra_temp["extraAbilityLevel"] = 1 + extra_temp = MihomoAvatarExtraAbility( + extraAbilityId=0, + extraAbilityLevel=0, + ) + extra_temp.extraAbilityId = char_id * 1000 + extraid + extra_temp.extraAbilityLevel = 1 extra_list.append(extra_temp) return extra_list async def get_skill_list( char_id: int, -): +) -> List[MihomoAvatarSkill]: Skilllist = [] for skillid in [1, 2, 3, 4, 7]: - skill_temp = {} - skill_temp["skillId"] = char_id * 100 + skillid - skill_temp["skillName"] = skillId2Name[str(skill_temp["skillId"])] - skill_temp["skillEffect"] = skillId2Effect[str(skill_temp["skillId"])] - skill_temp["skillAttackType"] = skillId2AttackType[str(skill_temp["skillId"])] + skill_temp = MihomoAvatarSkill( + skillId=0, + skillName="", + skillEffect="", + skillAttackType="", + skillLevel=0, + ) + skill_temp.skillId = char_id * 100 + skillid + skill_temp.skillName = skillId2Name[str(skill_temp.skillId)] + skill_temp.skillEffect = skillId2Effect[str(skill_temp.skillId)] + skill_temp.skillAttackType = skillId2AttackType[str(skill_temp.skillId)] skilllevel = 10 if skillid == 1: skilllevel = 6 if skillid == 7: skilllevel = 1 - skill_temp["skillLevel"] = skilllevel + skill_temp.skillLevel = skilllevel Skilllist.append(skill_temp) return Skilllist -async def get_rank_list( - char_id: str, +def get_rank_list( + char_id: int, talent_num: int, -): +) -> List[RankData]: rank_temp = [] for index in range(talent_num): - rankTemp = {} + rankTemp = RankData( + rankId=0, + rankName="", + ) rank_id = int(str(char_id) + "0" + str(index + 1)) - rankTemp["rankId"] = rank_id - rankTemp["rankName"] = rankId2Name[str(rank_id)] + rankTemp.rankId = rank_id + rankTemp.rankName = rankId2Name[str(rank_id)] rank_temp.append(rankTemp) return rank_temp async def get_char( - char_data: dict, + char_data: MihomoCharacter, weapon: Optional[str] = None, weapon_affix: Optional[int] = None, talent_num: Optional[int] = None, ): if isinstance(talent_num, int): # 处理命座 - rank_temp = [] - char_data["rank"] = talent_num - for index in range(talent_num): - rankTemp = {} - rank_id = int(str(char_data["avatarId"]) + "0" + str(index + 1)) - rankTemp["rankId"] = rank_id - rankTemp["rankName"] = rankId2Name[str(rank_id)] - rank_temp.append(rankTemp) - char_data["rankList"] = rank_temp + char_data.rank = talent_num + char_data.rankList = get_rank_list(char_data.avatarId, talent_num) # 处理命座中的 level_up_skills - if char_data.get("rankList"): - for rank_item in char_data["rankList"]: - rank_id = rank_item["rankId"] + if char_data.rankList: + for rank_item in char_data.rankList: + rank_id = rank_item.rankId level_up_skill = AvatarRankSkillUp[str(rank_id)] if level_up_skill: for item in level_up_skill: - skill_id = item["id"] - skill_up_num = item["num"] + skill_id = item.id + skill_up_num = item.num # 查找skill_id在不在avatarSkill中 - for index, skill_item in enumerate(char_data["avatarSkill"]): - if str(skill_id) == str(skill_item["skillId"]): + for index, skill_item in enumerate(char_data.avatarSkill): + if skill_id == str(skill_item.skillId): if skill_id[-1] == 1: skilllevel_max = 7 else: skilllevel_max = 12 skilllevel = min( skilllevel_max, - char_data["avatarSkill"][index]["skillLevel"] + char_data.avatarSkill[index].skillLevel + skill_up_num, ) - char_data["avatarSkill"][index]["skillLevel"] = ( - skilllevel - ) + char_data.avatarSkill[index].skillLevel = skilllevel break if isinstance(weapon, str): @@ -431,19 +479,26 @@ async def get_char( if equipmentid == "": weapon = await alias_to_weapon_name(weapon) equipmentid = await name_to_weapon_id(weapon) - equipment_info = {} - equipment_info["equipmentID"] = int(equipmentid) - equipment_info["equipmentName"] = EquipmentID2Name[str(equipmentid)] + equipment_info = AvatarEquipmentInfo( + equipmentID=0, + equipmentName="", + equipmentLevel=0, + equipmentPromotion=0, + equipmentRank=0, + equipmentRarity=0, + baseAttributes=EquipmentBaseAttributes(hp=0, attack=0, defence=0), + ) + equipment_info.equipmentID = int(equipmentid) + equipment_info.equipmentName = EquipmentID2Name[str(equipmentid)] - equipment_info["equipmentLevel"] = 80 - equipment_info["equipmentPromotion"] = 6 - equipment_info["equipmentRank"] = weapon_affix - equipment_info["equipmentRarity"] = EquipmentID2Rarity[str(equipmentid)] - equipment_base_attributes = {} + equipment_info.equipmentLevel = 80 + equipment_info.equipmentPromotion = 6 + equipment_info.equipmentRank = weapon_affix if weapon_affix else 1 + equipment_info.equipmentRarity = EquipmentID2Rarity[str(equipmentid)] equipment_promotion_base = None for equipment in EquipmentPromotionConfig: - if equipment.EquipmentID == str(equipmentid): + if equipment.EquipmentID == str(equipmentid) and equipment.Promotion == 6: equipment_promotion_base = equipment break if not equipment_promotion_base: @@ -451,21 +506,20 @@ async def get_char( raise ValueError(msg) # 生命值 - equipment_base_attributes["hp"] = ( + equipment_info.baseAttributes.hp = ( equipment_promotion_base.BaseHP.Value + equipment_promotion_base.BaseHPAdd.Value * (80 - 1) ) # 攻击力 - equipment_base_attributes["attack"] = ( + equipment_info.baseAttributes.attack = ( equipment_promotion_base.BaseAttack.Value + equipment_promotion_base.BaseAttackAdd.Value * (80 - 1) ) # 防御力 - equipment_base_attributes["defence"] = ( + equipment_info.baseAttributes.defence = ( equipment_promotion_base.BaseDefence.Value + equipment_promotion_base.BaseDefenceAdd.Value * (80 - 1) ) - equipment_info["baseAttributes"] = equipment_base_attributes - char_data["equipmentInfo"] = equipment_info + char_data.equipmentInfo = equipment_info return char_data diff --git a/StarRailUID/utils/image/image_tools.py b/StarRailUID/utils/image/image_tools.py index a18e3ba..0f47ac5 100644 --- a/StarRailUID/utils/image/image_tools.py +++ b/StarRailUID/utils/image/image_tools.py @@ -8,7 +8,6 @@ from ..resource.RESOURCE_PATH import CU_BG_PATH BG_PATH = Path(__file__).parent / "bg" NM_BG_PATH = BG_PATH / "nm_bg" -SP_BG_PATH = BG_PATH / "sp_bg" if list(CU_BG_PATH.iterdir()) != []: bg_path = CU_BG_PATH diff --git a/StarRailUID/utils/map/SR_MAP_PATH.py b/StarRailUID/utils/map/SR_MAP_PATH.py index 373bf17..bd7f0f4 100644 --- a/StarRailUID/utils/map/SR_MAP_PATH.py +++ b/StarRailUID/utils/map/SR_MAP_PATH.py @@ -1,5 +1,5 @@ from pathlib import Path -from typing import Dict, List, TypedDict, Union +from typing import Dict, List, TypedDict from msgspec import Struct, json as msgjson @@ -81,8 +81,8 @@ with Path.open(MAP / SetId2Name_fileName, encoding="UTF-8") as f: with Path.open(MAP / rankId2Name_fileName, encoding="UTF-8") as f: rankId2Name = msgjson.decode(f.read(), type=Dict[str, str]) -with Path.open(MAP / characterSkillTree_fileName, encoding="UTF-8") as f: - characterSkillTree = msgjson.decode(f.read(), type=Dict[str, Dict]) +# with Path.open(MAP / characterSkillTree_fileName, encoding="UTF-8") as f: +# characterSkillTree = msgjson.decode(f.read(), type=Dict[str, Dict]) with Path.open(MAP / avatarId2DamageType_fileName, encoding="UTF-8") as f: avatarId2DamageType = msgjson.decode(f.read(), type=Dict[str, str]) @@ -119,5 +119,5 @@ with Path.open(MAP / RelicId2MainAffixGroup_fileName, encoding="UTF-8") as f: with Path.open(current / "AvatarRelicScore.json", encoding="UTF-8") as f: AvatarRelicScore = msgjson.decode(f.read(), type=List[Dict]) -with Path.open(MAP / avatarRankSkillUp_fileName, encoding="UTF-8") as f: - AvatarRankSkillUp = msgjson.decode(f.read(), type=Dict[str, Union[List[LU], None]]) +# with Path.open(MAP / avatarRankSkillUp_fileName, encoding="UTF-8") as f: +# AvatarRankSkillUp = msgjson.decode(f.read(), type=Dict[str, Union[List[LU], None]])