Skip to content

SavingThrowData

saving_throw_data

SavingThrowData dataclass

Immutable container for saving throw values.

Each field represents the target number required to succeed on a d20 roll against a specific category of effect. Lower values indicate better saves.

Attributes:

Name Type Description
death_ray_or_poison int

Resistance to poison and instant-death effects

magic_wands int

Resistance to effects from magical wands

paralysis_or_petrify int

Resistance to paralysis and petrification effects

dragon_breath int

Resistance to breath weapons and area attacks

spells int

Resistance to general spell effects

Source code in src/rpgleveler/core/saving_throw_data.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
@dataclass(frozen=True)
class SavingThrowData:
    """
    Immutable container for saving throw values.

    Each field represents the target number required to succeed on a d20 roll
    against a specific category of effect. Lower values indicate better saves.

    Attributes:
        death_ray_or_poison: Resistance to poison and instant-death effects
        magic_wands: Resistance to effects from magical wands
        paralysis_or_petrify: Resistance to paralysis and petrification effects
        dragon_breath: Resistance to breath weapons and area attacks
        spells: Resistance to general spell effects
    """
    death_ray_or_poison: int
    magic_wands: int
    paralysis_or_petrify: int
    dragon_breath: int
    spells: int

    def add(self, other: SavingThrowData) -> SavingThrowData:
        """
        Combine two saving throw datasets.

        This is primarily used to apply racial modifiers to base class values.

        Args:
            other: Another `SavingThrowData` instance to add.

        Returns:
            A new `SavingThrowData` instance with combined values.
        """
        return SavingThrowData(
            death_ray_or_poison=self.death_ray_or_poison + other.death_ray_or_poison,
            magic_wands=self.magic_wands + other.magic_wands,
            paralysis_or_petrify=self.paralysis_or_petrify + other.paralysis_or_petrify,
            dragon_breath=self.dragon_breath + other.dragon_breath,
            spells=self.spells + other.spells,
        )

    def to_dict(self) -> dict[str, int]:
        return vars(self)

    @classmethod
    def from_dict(cls, data: dict[str, int]) -> SavingThrowData:
        return cls(**data)

add(other)

Combine two saving throw datasets.

This is primarily used to apply racial modifiers to base class values.

Parameters:

Name Type Description Default
other SavingThrowData

Another SavingThrowData instance to add.

required

Returns:

Type Description
SavingThrowData

A new SavingThrowData instance with combined values.

Source code in src/rpgleveler/core/saving_throw_data.py
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
def add(self, other: SavingThrowData) -> SavingThrowData:
    """
    Combine two saving throw datasets.

    This is primarily used to apply racial modifiers to base class values.

    Args:
        other: Another `SavingThrowData` instance to add.

    Returns:
        A new `SavingThrowData` instance with combined values.
    """
    return SavingThrowData(
        death_ray_or_poison=self.death_ray_or_poison + other.death_ray_or_poison,
        magic_wands=self.magic_wands + other.magic_wands,
        paralysis_or_petrify=self.paralysis_or_petrify + other.paralysis_or_petrify,
        dragon_breath=self.dragon_breath + other.dragon_breath,
        spells=self.spells + other.spells,
    )