Skip to content

Commit

Permalink
✨ Support zzz challenge
Browse files Browse the repository at this point in the history
* feat: zzz note by stoken
  • Loading branch information
omg-xtao authored Jul 15, 2024
1 parent c71fb05 commit 910a0c1
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 5 deletions.
51 changes: 51 additions & 0 deletions simnet/client/components/chronicle/zzz.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from simnet.errors import BadRequest, DataNotPublic
from simnet.models.lab.record import RecordCard
from simnet.models.zzz.calculator import ZZZCalculatorCharacterDetails
from simnet.models.zzz.chronicle.challenge import ZZZChallenge
from simnet.models.zzz.chronicle.notes import ZZZNote
from simnet.models.zzz.chronicle.stats import ZZZUserStats, ZZZAvatarBasic, ZZZBuddyBasic
from simnet.utils.enums import Game
Expand Down Expand Up @@ -98,6 +99,32 @@ async def get_zzz_notes(

return ZZZNote(**data)

async def get_zzz_notes_by_stoken(
self,
lang: Optional[str] = None,
) -> ZZZNote:
"""Get zzz's real-time notes.
Args:
lang (Optional[str], optional): The language of the data. Defaults to None.
Returns:
ZZZNote (ZZZNote): The requested real-time notes.
Raises:
BadRequest: If the request is invalid.
"""
stoken = self.cookies.get("stoken")
if stoken is None:
raise ValueError("stoken not found in cookies.")
stuid = self.cookies.get("stuid")
if stuid is None and self.account_id is None:
raise ValueError("account_id or stuid not found")
if self.account_id is not None and stuid is None:
self.cookies.set("stuid", str(self.account_id))
data = await self._request_zzz_record("widget", lang=lang)
return ZZZNote(**data)

async def get_zzz_user(
self,
player_id: Optional[int] = None,
Expand Down Expand Up @@ -189,6 +216,30 @@ async def get_zzz_buddy_list(
data = await self._request_zzz_record("buddy/info", player_id, lang=lang)
return ZZZBuddyBasic(**data)

async def get_zzz_challenge(
self,
player_id: Optional[int] = None,
previous: bool = False,
lang: Optional[str] = None,
) -> ZZZChallenge:
"""Get zzz challenge runs.
Args:
player_id (Optional[int], optional): The player ID. Defaults to None.
previous (bool, optional): Whether to get previous runs. Defaults to False.
lang (Optional[str], optional): The language of the data. Defaults to None.
Returns:
ZZZChallenge: The requested challenge runs.
Raises:
BadRequest: If the request is invalid.
DataNotPublic: If the requested data is not public.
"""
payload = dict(schedule_type=2 if previous else 1, need_all="true")
data = await self._request_zzz_record("challenge", player_id, lang=lang, payload=payload)
return ZZZChallenge(**data)

async def get_record_card(
self,
account_id: Optional[int] = None,
Expand Down
25 changes: 22 additions & 3 deletions simnet/models/zzz/character.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ class ZZZBaseCharacter(APIModel):
id: int
element_type: int
rarity: str
group_icon_path: str
hollow_icon_path: str

@property
def icon(self) -> str:
return (
f"https://act-webstatic.hoyoverse.com/game_record/zzz/"
f"role_square_avatar/role_square_avatar_{self.id}.png"
)


class ZZZPartialCharacter(ZZZBaseCharacter):
Expand All @@ -24,13 +29,27 @@ class ZZZPartialCharacter(ZZZBaseCharacter):
avatar_profession: int
level: int
rank: int
group_icon_path: str
hollow_icon_path: str


class ZZZBaseBuddy(APIModel):
"""Base Buddy model."""

id: int
name: str
rarity: str
level: int

@property
def icon(self) -> str:
return (
f"https://act-webstatic.hoyoverse.com/game_record/zzz/"
f"bangboo_square_avatar/bangboo_square_avatar_{self.id}.png"
)


class ZZZPartialBuddy(ZZZBaseBuddy):
"""Buddy"""

name: str
star: int
85 changes: 85 additions & 0 deletions simnet/models/zzz/chronicle/challenge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
from typing import List, Optional

from pydantic import Field

from simnet.models.base import APIModel
from simnet.models.starrail.chronicle.base import PartialTime
from simnet.models.zzz.character import ZZZBaseBuddy, ZZZBaseCharacter


class ZZZFloorBuff(APIModel):
"""A buff"""

title: str
text: str


class ZZZChallengeCharacter(ZZZBaseCharacter):
"""Challenge character"""

level: int


class ZZZFloorMonsterInfo(APIModel):
"""Monster info"""

id: int
name: str
weak_element_type: int


class ZZZFloorMonster(APIModel):
"""Monster"""

level: int
list: List[ZZZFloorMonsterInfo]


class ZZZFloorNode(APIModel):
"""A node"""

avatars: List[ZZZChallengeCharacter]
buddy: ZZZBaseBuddy
element_type_list: List[int]
monster_info: ZZZFloorMonster


class ZZZFloor(APIModel):
"""Floor in a season."""

layer_index: int
rating: str
layer_id: int
buffs: List[ZZZFloorBuff]
node_1: ZZZFloorNode
node_2: ZZZFloorNode
challenge_time: str
zone_name: str
floor_challenge_time: PartialTime


class ZZZChallengeRate(APIModel):
"""A challenge rate."""

times: int
rating: str


class ZZZChallenge(APIModel):
"""Challenge in a season."""

season: int = Field(alias="schedule_id")
begin_time: Optional[PartialTime] = Field(alias="hadal_begin_time")
end_time: Optional[PartialTime] = Field(alias="hadal_end_time")

fast_layer_time: int
max_layer: int
has_data: bool

rating_list: List[ZZZChallengeRate]
floors: List[ZZZFloor] = Field(alias="all_floor_detail")

@property
def total_stars(self) -> int:
star_map = {"S": 3, "A": 2, "B": 1}
return sum(star_map.get(i.rating, 0) * i.times for i in self.rating_list)
4 changes: 2 additions & 2 deletions simnet/models/zzz/chronicle/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ class ZZZAvatarBasic(APIModel):
class ZZZBuddyBasic(APIModel):
"""Basic buddy"""

buddy_list: typing.Sequence[character.ZZZBaseBuddy] = Field(alias="list")
buddy_list: typing.Sequence[character.ZZZPartialBuddy] = Field(alias="list")


class ZZZUserStats(ZZZAvatarBasic):
"""User stats with characters without equipment."""

stats: ZZZStats
cur_head_icon_url: str
buddy_list: typing.Sequence[character.ZZZBaseBuddy]
buddy_list: typing.Sequence[character.ZZZPartialBuddy]

0 comments on commit 910a0c1

Please sign in to comment.