DnD_5e.attack_class package
Submodules
DnD_5e.attack_class.saving_throw_attacks module
- class DnD_5e.attack_class.saving_throw_attacks.SavingThrowMixin(**kwargs)[source]
Bases:
object- 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 throwmod (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
- class DnD_5e.attack_class.saving_throw_attacks.SavingThrowAttack(**kwargs)[source]
Bases:
SavingThrowMixin,AttackThis class represents Attacks that require a saving throw from the target instead of a roll to hit
- 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. Callsend_damage()(that method will handle whether to damage on a successful save).- Parameters:
- 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
- on_miss(source, target, adv=0, crit=0)[source]
The target made the save, now do whatever happens on a successful save
- class DnD_5e.attack_class.saving_throw_attacks.SaveOrDieAttack(**kwargs)[source]
Bases:
SavingThrowMixin,AttackAttacks 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_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, callsend_damage().- Parameters:
- 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,AttackAttacks where the attacker makes a regular (roll to hit) attack and then, if that hits, makes a saving throw attack
- 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
DnD_5e.attack_class.spell_attacks module
- class DnD_5e.attack_class.spell_attacks.Spell(**kwargs)[source]
Bases:
AttackThis class represents spells
- get_casting_time() int[source]
- Returns:
amount of time it takes cast self, in rounds
- Return type:
a positive integer for the number of rounds, or one of these strings: “1 action”, “1 bonus action”, “1 reaction”
- get_components() list[source]
- Returns:
the components needed to cast self
- Return type:
list of strings
- make_attack(source, target, adv: int = 0, level: int | None = None) int[source]
First, try to spend the appropriate spell slot. Then, call the superclass method.
- Parameters:
- 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.spell_attacks.SavingThrowSpell(**kwargs)[source]
Bases:
Spell,SavingThrowAttackSpells that require the target to make a saving throw
- class DnD_5e.attack_class.spell_attacks.HealingSpell(**kwargs)[source]
Bases:
SpellSpells that heal (i.e., add hit points) instead of dealing damage; damage is used as healing
- make_attack(source, target, adv: int = 0, level=None) int[source]
Spend the appropriate spell slot, then roll damage and heal the target for that amount
- Parameters:
source (Combatant) – the Combatant that is sending the healing
target (Combatant) – the Combatant that source is healing
adv (one of these integers: -1, 0, 1) – advantage, disadvantage, or neither on the attack roll (NOT USED FOR THIS METHOD)
level (integer between 1 and 9 (inclusive)) – the level the spell is being cast at
- Returns:
the points the target is healed for
- Return type:
non-negative integer
- Raise:
ValueError if input is invalid
Module contents
- class DnD_5e.attack_class.Attack(**kwargs)[source]
Bases:
objectThis class represents attacks
- get_damage_dice() DamageDice[source]
- Returns:
damage dice
- Return type:
- get_range() int[source]
- Returns:
range for ranged attacks
- Return type:
usually a positive integer, but currently other types are also supported
- get_max_hit() int[source]
- Returns:
the maximum number that could result from an attack roll
- Return type:
- get_min_hit() int[source]
- Returns:
the minimum number that could result from an attack roll
- Return type:
- get_average_hit() float[source]
- Returns:
the average number that would result from an attack roll
- Return type:
- get_max_damage() int[source]
- Returns:
the maximum number that could result from a damage roll (not counting extra damage from a critical hit)
- Return type:
- get_min_damage() int[source]
- Returns:
the minimum number that could result from a damage roll (not counting extra damage from a critical hit)
- Return type:
- get_average_damage() float[source]
- Returns:
the average number that would result from a damage roll
- Return type:
- get_prob_hit(**kwargs) float[source]
- Parameters:
ac – the ac you’re trying to hit
- Returns:
the probability of rolling greater than or equal to ac
- get_dpr(**kwargs) float[source]
- Parameters:
ac (int) – the armor class you need to hit
- Returns:
the average damage per round (dpr)
- set_attack_mod(attack_mod: int)[source]
Set self._attack_mod
- Parameters:
attack_mod (int) – the new attack mod
- Returns:
None
- Raise:
ValueError if attack_mod is not an integer
- shift_attack_mod(attack_mod: int)[source]
Modify self._attack_mod by the given value
- Parameters:
attack_mod (int) – the damage mod to shift by
- Returns:
None
- Raise:
ValueError if attack_mod is not an integer
- set_damage_mod(damage_mod: int)[source]
Set self._damage_mod to the given value
- Parameters:
damage_mod (int) – the new damage mod
- Returns:
None
- Raise:
ValueError if damage_mod is not an integer
- shift_damage_mod(damage_mod: int)[source]
Modify self._damage_mod by the given value
- Parameters:
damage_mod (int) – the damage mod to shift by
- Returns:
None
- Raise:
ValueError if damage_mod is not an integer
- roll_attack(adv: int = 0) Tuple[int, int][source]
Roll a d20 (with advantage/disadvantage as computed with adv and
_adv), adding_attack_mod- Parameters:
adv (int) – advantage, disadvantage, or neither on the attack roll
- Returns:
the roll and an indication of whether it was a critical hit, critical miss, or neither
- Return type:
TYPE_ROLL_RESULT
- roll_damage(crit: int = 0, crit_multiplier: int = 2)[source]
Roll
_damage_dice(if crit == 1, multiply the number of dice to roll by crit_multiplier), then add_damage_mod- Parameters:
crit (one of these integers: -1, 0, 1) – indicates whether the hit was a crit
crit_multiplier (positive integer) – the multiplier for dice num if the hit is a crit
- Returns:
the damage rolled
- Return type:
namedtuple
- Raise:
ValueError if crit_multiplier is invalid
- make_attack(source, target, adv: int = 0) int | None[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, callsend_damage().- Parameters:
- 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
- on_hit(source, target, adv=0, crit=0) int[source]
You hit the target, now do whatever happens on a hit
- on_miss(source, target, adv=0, crit=0)[source]
You missed the target, now do whatever happens on a miss
- send_damage(target, crit: int = 0, crit_multiplier: int = 2) int[source]
Roll damage using
roll_damage()and store the result in variable damage. Call target.take_damage(), passing in damage anddamage_type.- Parameters:
target (Combatant) – the Combatant that is taking the damage
crit (one of these integers: -1, 0, 1) – indicates whether the hit was a crit
crit_multiplier (positive integer) – the number to multiply dice num by if the hit is a crit
- Returns:
the damage taken, as returned by target.take_damage
- Return type:
non-negative integer or None
- class DnD_5e.attack_class.MultiAttack(**kwargs)[source]
Bases:
AttackContainer for multiple Attacks
- current_eq(other) bool[source]
For this class, it is the same as __eq__.
- Parameters:
other (MultiAttack) – the MultiAttack to be compared
- Returns:
True if self is identical to other, False otherwise
- Return type:
- get_attack_by_name(name) Attack | None[source]
Get an Attack from
_attack_listwith the given name- Parameters:
name (str) – the name of the Attack
- Returns:
the first Attack with the given name (or None, if no match is found)
- Raise:
ValueError if name is invalid
- get_max_damage() int[source]
- Returns:
The maximum damage combined across all attacks
- Return type:
non-negative integer
- get_min_damage() int[source]
- Returns:
The minimum damage combined across all attacks
- Return type:
non-negative integer
- get_average_damage() int[source]
- Returns:
The average damage combined across all attacks
- Return type:
non-negative integer
- add_attack(attack: Attack)[source]
Add attack to the end of self._attack_list
- Parameters:
attack (Attack) – the Attack to add
- Returns:
None
- Raise:
ValueError if attack is not an Attack
- make_attack(source, target, adv: int = 0) int | None[source]
Convert target and adv to lists so that each attack has one target and one adv. If target or adv is too short of a sequence, the last value in the provided list will be copied as needed. For each attack in
get_attacks(), call the attack the appropriate target with the appropriate adv.- Parameters:
- Returns:
the total damage taken
- Return type:
non-negative integer
- Raise:
ValueError if source can’t send attacks