Skip to content

Commit

Permalink
fix weapon is None
Browse files Browse the repository at this point in the history
  • Loading branch information
baiqwerdvd committed May 17, 2024
1 parent 5da3795 commit f9b7ab9
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 21 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]"},
Expand Down
24 changes: 17 additions & 7 deletions starrail_damage_cal/damage/Avatar.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ def __init__(self, raw_data: Character):
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()
Expand All @@ -31,7 +34,8 @@ def __init__(self, raw_data: Character):
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:
Expand All @@ -49,6 +53,9 @@ def cal_role_base_attr(self):
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:
Expand Down Expand Up @@ -85,15 +92,18 @@ def cal_avatar_attr_add(self):
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,
Expand Down
7 changes: 3 additions & 4 deletions starrail_damage_cal/damage/AvatarDamage/AvatarDamage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4686,10 +4686,9 @@ async def getdamage(
)

# 终结技攻击加成计算
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"
)
Expand Down
17 changes: 10 additions & 7 deletions starrail_damage_cal/damage/Base/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class DamageInstanceAvatar(Struct):

class DamageInstance:
avatar: DamageInstanceAvatar
weapon: DamageInstanceWeapon
weapon: Union[DamageInstanceWeapon, None]
relic: List[DamageInstanceRelic]
skill: List[DamageInstanceSkill]

Expand All @@ -90,12 +90,15 @@ def __init__(self, char):
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))
Expand Down
6 changes: 5 additions & 1 deletion starrail_damage_cal/mihomo/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


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))

Expand Down

0 comments on commit f9b7ab9

Please sign in to comment.