Skip to content

Commit

Permalink
Extract objectives
Browse files Browse the repository at this point in the history
  • Loading branch information
raimannma committed Sep 20, 2024
1 parent 08befc8 commit 7433561
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion deadlock_api/models/active_match.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pydantic import BaseModel, ConfigDict
from pydantic import BaseModel, ConfigDict, computed_field


class ActiveMatchPlayer(BaseModel):
Expand All @@ -9,6 +9,48 @@ class ActiveMatchPlayer(BaseModel):
hero_id: int


class ActiveMatchObjectives(BaseModel):
model_config = ConfigDict(populate_by_name=True)

core: bool
tier1_lane1: bool
tier1_lane2: bool
tier1_lane3: bool
tier1_lane4: bool
tier2_lane1: bool
tier2_lane2: bool
tier2_lane3: bool
tier2_lane4: bool
titan: bool
titan_shield_generator_1: bool
titan_shield_generator_2: bool
barrack_boss_lane1: bool
barrack_boss_lane2: bool
barrack_boss_lane3: bool
barrack_boss_lane4: bool

@classmethod
def from_mask(cls, mask: int):
return cls(
core=bool(mask & (1 << 0)),
tier1_lane1=bool(mask & (1 << 1)),
tier1_lane2=bool(mask & (1 << 2)),
tier1_lane3=bool(mask & (1 << 3)),
tier1_lane4=bool(mask & (1 << 4)),
tier2_lane1=bool(mask & (1 << 5)),
tier2_lane2=bool(mask & (1 << 6)),
tier2_lane3=bool(mask & (1 << 7)),
tier2_lane4=bool(mask & (1 << 8)),
titan=bool(mask & (1 << 9)),
titan_shield_generator_1=bool(mask & (1 << 10)),
titan_shield_generator_2=bool(mask & (1 << 11)),
barrack_boss_lane1=bool(mask & (1 << 12)),
barrack_boss_lane2=bool(mask & (1 << 13)),
barrack_boss_lane3=bool(mask & (1 << 14)),
barrack_boss_lane4=bool(mask & (1 << 15)),
)


class ActiveMatch(BaseModel):
model_config = ConfigDict(populate_by_name=True)

Expand All @@ -29,6 +71,16 @@ class ActiveMatch(BaseModel):
match_score: int
region_mode: int

@computed_field
@property
def objectives_team0(self) -> ActiveMatchObjectives:
return ActiveMatchObjectives.from_mask(self.objectives_mask_team0)

@computed_field
@property
def objectives_team1(self) -> ActiveMatchObjectives:
return ActiveMatchObjectives.from_mask(self.objectives_mask_team1)


class APIActiveMatch(BaseModel):
model_config = ConfigDict(populate_by_name=True)
Expand Down

0 comments on commit 7433561

Please sign in to comment.