Source code for sidequest_common.schemas.pvp

  1"""Battleground scoreboards the addon records, and the members-only match history and PvP boards built from them.
  2
  3The ``battlegrounds`` block is additive on top of the ``SQX1:`` export ``v: 2``: older sites ignore it, so the
  4version number doesn't change. The game hides the scoreboard while a match runs (``C_PvP.GetScoreInfo`` is secret
  5in an active match), so the addon records it once the match has ended.
  6"""
  7
  8from datetime import datetime  # pydantic needs it at runtime
  9from enum import StrEnum
 10from uuid import UUID  # pydantic needs it at runtime
 11
 12from pydantic import BaseModel, ConfigDict, Field
 13
 14from sidequest_common.schemas.events import WowClass
 15
 16MAX_BATTLEGROUNDS = 50
 17"""Matches in one export."""
 18MAX_BATTLEGROUND_PLAYERS = 80
 19"""Scoreboard rows in one match (40 a side is the largest battleground)."""
 20SAME_MATCH_SECONDS = 120
 21"""Two recordings of the same battleground ending this close together are one match (several members record it)."""
 22PVP_MATCHES_PAGE_SIZE = 25
 23PVP_BOARD_SIZE = 10
 24
 25
[docs] 26class BattlegroundWinner(StrEnum): 27 """Which side won a battleground.""" 28 29 ALLIANCE = "alliance" 30 HORDE = "horde" 31 DRAW = "draw"
32 33
[docs] 34class BattlegroundFaction(StrEnum): 35 """A scoreboard row's side.""" 36 37 ALLIANCE = "alliance" 38 HORDE = "horde"
39 40
[docs] 41class ExportBattlegroundPlayer(BaseModel): 42 """One scoreboard row, as ``C_PvP.GetScoreInfo`` gives it once the match has ended. 43 44 ``name`` is the player's name as the scoreboard shows it. ``wow_class`` is the class file name (``WARRIOR``), 45 lowercased by the site. Counters the scoreboard doesn't show for this battleground are 0. 46 """ 47 48 model_config = ConfigDict(populate_by_name=True) 49 50 name: str = Field(min_length=1, max_length=64) 51 faction: BattlegroundFaction 52 race: str | None = Field(default=None, max_length=40) 53 wow_class: str | None = Field(default=None, alias="class", max_length=20) 54 killing_blows: int = Field(default=0, ge=0) 55 honorable_kills: int = Field(default=0, ge=0) 56 deaths: int = Field(default=0, ge=0) 57 honor_gained: int = Field(default=0, ge=0) 58 damage_done: int = Field(default=0, ge=0) 59 healing_done: int = Field(default=0, ge=0)
60 61
[docs] 62class ExportBattleground(BaseModel): 63 """One finished battleground in the export payload. 64 65 ``id`` is the addon's own id for the recording (recorder plus end time); the site also merges recordings of the 66 same match by other members (same ``instance_id``, ``ended_at`` within ``SAME_MATCH_SECONDS``). 67 ``my_faction`` is the recorder's side. ``winner`` is ``None`` if the game didn't say. 68 """ 69 70 id: str = Field(min_length=1, max_length=80) 71 map: str = Field(min_length=1, max_length=80) 72 instance_id: int = Field(ge=0) 73 ended_at: int = Field(gt=0) 74 duration: int = Field(default=0, ge=0) 75 winner: BattlegroundWinner | None = None 76 my_faction: BattlegroundFaction 77 players: list[ExportBattlegroundPlayer] = Field(default_factory=list, max_length=MAX_BATTLEGROUND_PLAYERS)
78 79
[docs] 80class BattlegroundImportCounts(BaseModel): 81 """Counts for the ``battlegrounds`` section of one import. ``merged`` matches another member already recorded.""" 82 83 new: int = 0 84 merged: int = 0
85 86
[docs] 87class PvpPlayerRow(BaseModel): 88 """One scoreboard row on the site. ``character_slug`` links a guild character's row to its character page.""" 89 90 model_config = ConfigDict(populate_by_name=True, serialize_by_alias=True) 91 92 name: str 93 faction: BattlegroundFaction 94 race: str | None 95 wow_class: WowClass | None = Field(alias="class") 96 killing_blows: int 97 honorable_kills: int 98 deaths: int 99 honor_gained: int 100 damage_done: int 101 healing_done: int 102 guild_member: bool 103 """True when the row is a SideQuest character.""" 104 character_slug: str | None
105 106
[docs] 107class PvpMatchSummary(BaseModel): 108 """One battleground in the match history.""" 109 110 id: UUID 111 map: str 112 ended_at: datetime 113 duration: int 114 winner: BattlegroundWinner | None 115 guild_faction: BattlegroundFaction 116 """The side the recording member played on.""" 117 won: bool | None 118 """Whether the guild's side won; ``None`` if the winner is unknown or a draw.""" 119 guild_players: list[str] 120 """The SideQuest characters in the match.""" 121 recorded_by: str
122 123
[docs] 124class PvpMatchDetail(PvpMatchSummary): 125 """One battleground with its full scoreboard, highest honorable kills first.""" 126 127 players: list[PvpPlayerRow]
128 129
[docs] 130class PvpMatchPage(BaseModel): 131 """One page of the match history, newest first.""" 132 133 page: int 134 page_count: int 135 matches: list[PvpMatchSummary]
136 137
[docs] 138class PvpBoardEntry(BaseModel): 139 """One guild character on a PvP board.""" 140 141 model_config = ConfigDict(populate_by_name=True, serialize_by_alias=True) 142 143 name: str 144 wow_class: WowClass | None = Field(alias="class") 145 character_slug: str | None 146 value: int
147 148
[docs] 149class PvpBoards(BaseModel): 150 """Totals over every recorded battleground for SideQuest characters, ten to a board.""" 151 152 matches: int 153 """Battlegrounds recorded in total.""" 154 wins: list[PvpBoardEntry] 155 honorable_kills: list[PvpBoardEntry] 156 killing_blows: list[PvpBoardEntry] 157 honor_gained: list[PvpBoardEntry] 158 damage_done: list[PvpBoardEntry] 159 healing_done: list[PvpBoardEntry]