DnD_5e.attack_class.saving_throw_attacks module

class DnD_5e.attack_class.saving_throw_attacks.SavingThrowMixin(**kwargs)[source]

Bases: object

get_dc() int[source]
Returns:

DC

Return type:

non-negative integer

get_save_type() str[source]
Returns:

ability score for saving throws

Return type:

one of these strings: “strength”, “dexterity”, “constitution”, “intelligence”, “wisdom”, “charisma”

get_prob_fail_save(**kwargs)[source]
Parameters:
  • target (Combatant) – the target you are forcing to make the saving throw

  • mod (int) – the modifier for the target’s saving throw. Use this or target

Returns:

the probability that target (or somebody with a saving throw modifier of mod) fails the saving throw

do_saving_thow(source, target) bool[source]
class DnD_5e.attack_class.saving_throw_attacks.SavingThrowAttack(**kwargs)[source]

Bases: SavingThrowMixin, Attack

This class represents Attacks that require a saving throw from the target instead of a roll to hit

get_damage_on_success() bool[source]
Returns:

damage on success

Return type:

bool

get_prob_hit(**kwargs) float[source]
Parameters:
  • target – the target who is making the saving throw

  • mod – the target’s modifier to the saving throw

Returns:

the probability of target failing their saving throw

get_dpr(**kwargs) float[source]
Parameters:

target (Combatant) – the target you are trying to hit

Returns:

the average damage per round (dpr)

make_attack(source, target, adv=0) int | None[source]

Call target. take_saving_throw() to see if the target makes the save. Call send_damage() (that method will handle whether to damage on a successful save).

Parameters:
  • source (Combatant) – the Combatant that is making the attack

  • target (Combatant) – the Combatant that source is attacking

  • adv (one of these integers: -1, 0, 1) – advantage, disadvantage, or neither on the saving throw

Returns:

the damage taken (if the attack misses, damage taken is None)

Return type:

non-negative integer or None

Raise:

ValueError if target can’t take attacks

on_hit(source, target, adv=0, crit=0)[source]

The target failed the save, now do whatever happens on a failed save

Parameters:
  • source (Combatant) – the Combatant that is making the attack

  • target (Combatant) – the Combatant that source is attacking

  • adv (one of these integers: -1, 0, 1) – advantage, disadvantage, or neither on the attack roll

Returns:

the damage taken

on_miss(source, target, adv=0, crit=0)[source]

The target made the save, now do whatever happens on a successful save

Parameters:
  • source (Combatant) – the Combatant that is making the attack

  • target (Combatant) – the Combatant that source is attacking

  • adv (one of these integers: -1, 0, 1) – advantage, disadvantage, or neither on the attack roll

Returns:

the damage taken

send_damage(target, saved: bool = False) int | None[source]

Roll damage using self.roll_damage and store the result in variable damage. Call target. take_damage(), passing in damage and _damage_type.

Arguments crit and crit_multiplier are not needed because crits are not possible

Parameters:
  • target (Combatant) – the Combatant that is taking the damage

  • saved (bool) – if this is True, damage is none if not _damage_on_success or half damage if _damage_on_success

Returns:

the damage taken (as returned by target.take_damage)

Return type:

non-negative integer or None

class DnD_5e.attack_class.saving_throw_attacks.SaveOrDieAttack(**kwargs)[source]

Bases: SavingThrowMixin, Attack

Attacks where the target must make a saving throw and if it fails it dies. Does not work for attacks that have a saving throw and then a save or die. For that, you need a different approach (maybe a MultiAttack?)

get_threshold() int[source]
Returns:

the hp below which the target must save or die

get_save_on_miss() bool[source]
Returns:

True if the target still has to make the saving throw if the main attack missed, False otherwise

get_dpr(**kwargs) float[source]

Calculate the damage per round, assuming that if the target fails the saving throw (and thus dies), they also take the damage of

Parameters:

target (Combatant) – the target you are trying to hit

Returns:

the average damage per round (dpr)

make_attack(source, target, adv: int = 0)[source]

Roll attack using roll_attack() and store the result in variable result. Call target. take_attack() to see if the attack hits. If the attack hits, call send_damage().

Parameters:
  • source (Combatant) – the Combatant that is making the attack

  • target (Combatant) – the Combatant that source is attacking

  • adv (one of these integers: -1, 0, 1) – advantage, disadvantage, or neither on the attack roll

Returns:

the damage taken (if the attack misses, damage taken is None)

Return type:

non-negative integer or None

Raise:

ValueError if source can’t send attacks or target can’t take attacks

class DnD_5e.attack_class.saving_throw_attacks.HitAndSaveAttack(**kwargs)[source]

Bases: SavingThrowMixin, Attack

Attacks where the attacker makes a regular (roll to hit) attack and then, if that hits, makes a saving throw attack

get_save_damage_dice()[source]
Returns:

saving throw damage dice

get_save_damage_type() str[source]
Returns:

damage type for saving throw damage

get_damage_on_success() bool[source]
Returns:

whether the target takes damage on a successful save

on_hit(source, target, adv=0, crit=0)[source]

The attack hit! Do all the normal Attack stuff (i.e., send damage), then have the target make a saving throw. :param source: the Combatant that is making the attack :type source: Combatant :param target: the Combatant that source is attacking :type target: Combatant :param adv: advantage, disadvantage, or neither on the attack roll :type adv: one of these integers: -1, 0, 1 :type crit: whether or not the hit was a crit :return: the total damage taken

roll_save_damage()[source]

Roll _damage_dice (if crit == 1, multiply the number of dice to roll by crit_multiplier), then add _damage_mod

Returns:

the damage rolled

Return type:

namedtuple

Raise:

ValueError if crit_multiplier is invalid

send_save_damage(target, saved: bool = False) int | None[source]

Roll damage using self.roll_save_damage and store the result in variable damage. Call target. take_damage(), passing in damage and _damage_type.

Parameters:
  • target (Combatant) – the Combatant that is taking the damage

  • saved (bool) – if this is True, damage is none if not _damage_on_success or half damage if _damage_on_success

Returns:

the damage taken (as returned by target.take_damage)

Return type:

non-negative integer or None