26 lines
650 B
Python
26 lines
650 B
Python
import dataclasses
|
|
|
|
D20_MAX = 20
|
|
|
|
|
|
@dataclasses.dataclass(frozen=True)
|
|
class Throw:
|
|
results: list[int]
|
|
sides: int
|
|
modifier: int = 0
|
|
|
|
@property
|
|
def total(self) -> int:
|
|
"""calculate the total of the throw, accounting for the modifier"""
|
|
return sum(self.results) + self.modifier
|
|
|
|
@property
|
|
def is_critical_hit(self) -> bool:
|
|
"""check if the throw is a 20 on a 1d20"""
|
|
return self.sides == D20_MAX and self.results == [D20_MAX]
|
|
|
|
@property
|
|
def is_critical_miss(self) -> bool:
|
|
"""check if the throw is a 1 on a 1d20"""
|
|
return self.sides == D20_MAX and self.results == [1]
|