Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HSR pure fiction #1

Merged
merged 3 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions genshin/client/components/chronicle/starrail.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,15 @@ async def get_starrail_rogue(
payload = dict(schedule_type=schedule_type, need_detail="true")
data = await self._request_starrail_record("rogue", uid, lang=lang, payload=payload)
return models.StarRailRogue(**data)

async def get_starrail_pure_fiction(
self,
uid: typing.Optional[int] = None,
*,
previous: bool = False,
lang: typing.Optional[str] = None,
) -> models.StarRailPureFiction:
"""Get starrail pure fiction runs."""
payload = dict(schedule_type=2 if previous else 1, need_all="true")
data = await self._request_starrail_record("challenge_story", uid, lang=lang, payload=payload)
return models.StarRailPureFiction(**data)
82 changes: 80 additions & 2 deletions genshin/models/starrail/chronicle/challenge.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
"""Starrail chronicle challenge."""

from typing import List
from typing import TYPE_CHECKING, Any, Dict, List

if TYPE_CHECKING:
import pydantic.v1 as pydantic
else:
try:
import pydantic.v1 as pydantic
except ImportError:
import pydantic

from genshin.models.model import Aliased, APIModel
from genshin.models.starrail.character import FloorCharacter

from .base import PartialTime

__all__ = ["FloorNode", "StarRailChallenge", "StarRailFloor"]
__all__ = [
"FictionBuff",
"FictionFloor",
"FictionFloorNode",
"FloorNode",
"StarRailChallenge",
"StarRailFloor",
"StarRailPureFiction",
]


class FloorNode(APIModel):
Expand Down Expand Up @@ -41,3 +57,65 @@ class StarRailChallenge(APIModel):
has_data: bool

floors: List[StarRailFloor] = Aliased("all_floor_detail")


class FictionBuff(APIModel):
"""Buff for a Pure Fiction floor."""

id: int
name: str = Aliased("name_mi18n")
description: str = Aliased("desc_mi18n")
icon: str


class FictionFloorNode(FloorNode):
"""Node for a Pure Fiction floor."""

buff: FictionBuff
score: int


class FictionFloor(APIModel):
"""Floor in a Pure Fiction challenge."""

id: int = Aliased("maze_id")
name: str
round_num: int
star_num: int
node_1: FictionFloorNode
node_2: FictionFloorNode
is_fast: bool

@property
def score(self) -> int:
"""Total score of the floor."""
return self.node_1.score + self.node_2.score


class StarRailPureFiction(APIModel):
"""Pure Fiction challenge in a season."""

name: str
season_id: int
begin_time: PartialTime
end_time: PartialTime

total_stars: int = Aliased("star_num")
max_floor: str
total_battles: int = Aliased("battle_num")
has_data: bool

floors: List[FictionFloor] = Aliased("all_floor_detail")
max_floor_id: int

@pydantic.root_validator(pre=True)
def __unnest_groups(cls, values: Dict[str, Any]) -> Dict[str, Any]:
if "groups" in values and isinstance(values["groups"], List):
groups: List[Dict[str, Any]] = values["groups"]
if len(groups) > 0:
values["name"] = groups[0]["name_mi18n"]
values["season_id"] = groups[0]["schedule_id"]
values["begin_time"] = groups[0]["begin_time"]
values["end_time"] = groups[0]["end_time"]

return values
Loading