Source code for sidequest_common.schemas.talents

 1"""Talent calculator schemas: a class's three talent trees from Battle.net, and members' saved builds.
 2
 3``class`` is a Python keyword, so the Python-side attribute is ``wow_class``; ``Field(alias=...)`` maps it to the
 4wire name ``class`` in both directions, same as ``sidequest_common.schemas.events``.
 5
 6A build's ``code`` holds one digit per talent node (its spent rank, 0-9), node order sorted by
 7``(row, col)`` within each tree, the three trees joined by ``-``; trailing zeros may be trimmed. This is also the
 8share-link format: ``/talents/?class=druid&build=<code>``.
 9"""
10
11from datetime import datetime  # pydantic needs it at runtime
12from uuid import UUID  # pydantic needs it at runtime
13
14from pydantic import BaseModel, ConfigDict, Field
15
16from sidequest_common.schemas.events import WowClass
17
18MAX_TALENT_POINTS = 51
19FIRST_TALENT_LEVEL = 10
20TALENT_ROW_POINTS = 5
21"""A tree row opens once this many points, times the row minus one, are spent in that tree."""
22MAX_TALENT_BUILDS = 20
23TALENT_BUILD_NAME_MAX = 60
24TALENT_BUILD_NOTE_MAX = 200
25
26
[docs] 27class TalentRank(BaseModel): 28 """One learnable rank of a talent node: the spell it grants and that rank's tooltip text.""" 29 30 spell_id: int 31 description: str
32 33
[docs] 34class TalentNode(BaseModel): 35 """One node in a specialization's talent tree, positioned on its grid.""" 36 37 id: int 38 row: int 39 col: int 40 max_rank: int 41 talent_id: int 42 name: str 43 icon_url: str | None = Field(default=None, description="The spell icon of the node's first rank, or null.") 44 ranks: list[TalentRank] 45 requires: int | None = Field(description="The node id that must be at max rank before this one, or null.")
46 47
[docs] 48class TalentTreeSchema(BaseModel): 49 """One specialization's talent tree, as shown on the calculator.""" 50 51 spec_id: int 52 name: str 53 icon_url: str | None 54 nodes: list[TalentNode]
55 56
[docs] 57class ClassTalents(BaseModel): 58 """A class's three talent trees, as returned by ``GET /api/talents/{wow_class}``.""" 59 60 model_config = ConfigDict(populate_by_name=True, serialize_by_alias=True) 61 62 wow_class: WowClass = Field(alias="class") 63 trees: list[TalentTreeSchema] = Field(description="The class's three specialization trees, in spec order.") 64 max_points: int = Field(default=MAX_TALENT_POINTS, description="The most points a build may spend in total.") 65 first_level: int = Field(default=FIRST_TALENT_LEVEL, description="The level a character gets its first point.")
66 67
[docs] 68class TalentBuildCreate(BaseModel): 69 """Body for ``POST /api/me/talent-builds``: a build the member wants to save.""" 70 71 model_config = ConfigDict(populate_by_name=True) 72 73 wow_class: WowClass = Field(alias="class") 74 name: str = Field(min_length=1, max_length=TALENT_BUILD_NAME_MAX) 75 code: str = Field(min_length=1, max_length=200, description="The build's talent code; see the module docs.") 76 note: str | None = Field(default=None, max_length=TALENT_BUILD_NOTE_MAX)
77 78
[docs] 79class TalentBuildPinUpdate(BaseModel): 80 """Body for ``PUT /api/talent-builds/{id}/pin`` (officer): pin or unpin a build for raids.""" 81 82 pinned: bool
83 84
[docs] 85class TalentBuildSchema(BaseModel): 86 """A saved talent build, as listed by ``GET /api/me/talent-builds`` or ``GET /api/talent-builds``.""" 87 88 model_config = ConfigDict(from_attributes=True, populate_by_name=True, serialize_by_alias=True) 89 90 id: UUID 91 wow_class: WowClass = Field(alias="class") 92 name: str 93 code: str 94 note: str | None 95 pinned: bool 96 member_id: int 97 member_name: str 98 created_at: datetime