mirror of
https://github.com/PaiGramTeam/StarRailDamageCal.git
synced 2024-11-16 04:45:43 +00:00
fix weapon is None
This commit is contained in:
parent
5da37953a9
commit
f9b7ab94f9
@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "starrail_damage_cal"
|
||||
version = "1.6.0"
|
||||
version = "1.6.1"
|
||||
description = "For StarRail Role Damage Cal"
|
||||
authors = [
|
||||
{name = "qwerdvd", email = "105906879+qwerdvd@users.noreply.github.com"},
|
||||
|
@ -22,7 +22,10 @@ class AvatarInstance:
|
||||
self.raw_data.skill,
|
||||
)
|
||||
self.avatar = BaseAvatarinfo(self.raw_data.avatar)
|
||||
self.weapon = Weapon.create(self.raw_data.weapon)
|
||||
if self.raw_data.weapon is None:
|
||||
self.weapon = None
|
||||
else:
|
||||
self.weapon = Weapon.create(self.raw_data.weapon)
|
||||
self.relic_set = RelicSet().create(self.raw_data.relic)
|
||||
|
||||
self.base_attr = self.cal_role_base_attr()
|
||||
@ -31,7 +34,8 @@ class AvatarInstance:
|
||||
self.cal_relic_attr_add()
|
||||
self.cal_avatar_attr_add()
|
||||
self.cal_avatar_eidolon_add()
|
||||
self.cal_weapon_attr_add()
|
||||
if self.weapon is not None:
|
||||
self.cal_weapon_attr_add()
|
||||
|
||||
def merge_attribute_bonus(self, add_attribute: Dict[str, float]):
|
||||
for attribute in add_attribute:
|
||||
@ -49,6 +53,9 @@ class AvatarInstance:
|
||||
else:
|
||||
base_attr[attr_name] = attr_value
|
||||
|
||||
if self.weapon is None:
|
||||
return base_attr
|
||||
|
||||
weapon_attribute = self.weapon.weapon_base_attribute
|
||||
for attr_name, attr_value in weapon_attribute.items():
|
||||
if attr_name in base_attr:
|
||||
@ -85,15 +92,18 @@ class AvatarInstance:
|
||||
self.attribute_bonus[bonus_property] = value
|
||||
|
||||
def cal_weapon_attr_add(self):
|
||||
if self.weapon is None:
|
||||
return
|
||||
self.merge_attribute_bonus(self.weapon.weapon_attribute)
|
||||
|
||||
async def get_damage_info(self):
|
||||
Ultra_Use = self.avatar.Ultra_Use()
|
||||
self.attribute_bonus = await self.weapon.weapon_ability(
|
||||
Ultra_Use,
|
||||
self.base_attr,
|
||||
self.attribute_bonus,
|
||||
)
|
||||
if self.weapon is not None:
|
||||
self.attribute_bonus = await self.weapon.weapon_ability(
|
||||
Ultra_Use,
|
||||
self.base_attr,
|
||||
self.attribute_bonus,
|
||||
)
|
||||
for set_skill in self.relic_set.SetSkill:
|
||||
self.attribute_bonus = await set_skill.set_skill_ability(
|
||||
self.base_attr,
|
||||
|
@ -4686,10 +4686,9 @@ class Robin(BaseAvatar):
|
||||
)
|
||||
|
||||
# 终结技攻击加成计算
|
||||
attack = (
|
||||
base_attr["attack"] * (1 + attribute_bonus["AttackAddedRatio"])
|
||||
+ attribute_bonus["AttackDelta"]
|
||||
)
|
||||
attack = base_attr["attack"] * (
|
||||
1 + attribute_bonus.get("AttackAddedRatio", 0)
|
||||
) + attribute_bonus.get("AttackDelta", 0)
|
||||
add_attack = (attack * self.Skill_num("Ultra", "Ultra_A")) + self.Skill_num(
|
||||
"Ultra", "Ultra_G"
|
||||
)
|
||||
|
@ -70,7 +70,7 @@ class DamageInstanceAvatar(Struct):
|
||||
|
||||
class DamageInstance:
|
||||
avatar: DamageInstanceAvatar
|
||||
weapon: DamageInstanceWeapon
|
||||
weapon: Union[DamageInstanceWeapon, None]
|
||||
relic: List[DamageInstanceRelic]
|
||||
skill: List[DamageInstanceSkill]
|
||||
|
||||
@ -90,12 +90,15 @@ class DamageInstance:
|
||||
Union[List, None],
|
||||
),
|
||||
)
|
||||
self.weapon = DamageInstanceWeapon(
|
||||
id_=char.equipment["equipmentID"],
|
||||
level=char.equipment["equipmentLevel"],
|
||||
rank=char.equipment["equipmentRank"],
|
||||
promotion=char.equipment["equipmentPromotion"],
|
||||
)
|
||||
if char.equipment.get("equipmentID") is not None:
|
||||
self.weapon = DamageInstanceWeapon(
|
||||
id_=char.equipment["equipmentID"],
|
||||
level=char.equipment["equipmentLevel"],
|
||||
rank=char.equipment["equipmentRank"],
|
||||
promotion=char.equipment["equipmentPromotion"],
|
||||
)
|
||||
else:
|
||||
self.weapon = None
|
||||
self.relic = []
|
||||
for relic in char.char_relic:
|
||||
self.relic.append(msgspec.convert(relic, DamageInstanceRelic))
|
||||
|
@ -33,9 +33,13 @@ async def get_char_card_info(
|
||||
with Path.open(path / f"{uid!s}.json", "w") as file:
|
||||
file.write(req.text)
|
||||
try:
|
||||
print(req.json())
|
||||
return convert(req.json(), type=MihomoData)
|
||||
except msgspec.ValidationError as e:
|
||||
if req.text == '{"detail":"Queue timeout"}':
|
||||
if (
|
||||
req.text
|
||||
== '{"detail":"Queue timeout,please refer to https://discord.gg/pkdTJ9svEh for more infomation"}'
|
||||
):
|
||||
raise MihomoQueueTimeoutError from e
|
||||
if req.text == '{"detail":"Invalid uid"}':
|
||||
raise InvalidUidError(uid) from e
|
||||
|
2
test.py
2
test.py
@ -5,7 +5,7 @@ from starrail_damage_cal.cal_damage import DamageCal
|
||||
|
||||
|
||||
async def test_get_damage_data_by_uid() -> None:
|
||||
data = await DamageCal.get_all_damage_data_by_uid(uid="100895938")
|
||||
data = await DamageCal.get_all_damage_data_by_uid(uid="121006662")
|
||||
if isinstance(data, Union[List, dict]):
|
||||
print(json.dumps(data, ensure_ascii=False, indent=4))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user