DnD_5e.combatant package
Submodules
DnD_5e.combatant.character module
- class DnD_5e.combatant.character.Character(**kwargs)[source]
Bases:
CombatantThis is for characters (PC, NPC, whatever)
- take_damage(damage: int, damage_type: str | None = None, is_critical: bool = False) int[source]
Take damage, applying vulnerabilities, resistances, and immunities as necessary
- should_die_from_damage(damage_taken: int, damage_type: str | None = None)[source]
Return whether taking the specified amount of damage should result in self dying :param damage_taken: the total amount of damage taken :param damage_type: the damage type :return:
- become_conscious()[source]
Become conscious (removing unconcsious, unstable, and stable conditions)
- Returns:
None
- fail_death_save()[source]
Record that self failed a death save, die if this is the third failed death save
- Returns:
None
- succeed_death_save()[source]
Record that self succeeded a death save, stabilize if this is the third successful death save
- Returns:
None
DnD_5e.combatant.creature module
DnD_5e.combatant.spellcaster module
- class DnD_5e.combatant.spellcaster.SpellCaster(**kwargs)[source]
Bases:
CombatantA Combatant that can cast spells
- current_eq(other) bool[source]
Compare self and other to determine if they are identical based on the attributes checked in equals and also these attributes:
spell_slots- Parameters:
other (SpellCaster) – the SpellCaster to compare
- Returns:
True if self is identical to other, False otherwise
- Return type:
- get_full_spell_slots() dict[source]
- Returns:
full/maximum spell slots
- Return type:
dict mapping int to int
- get_level_spell_slots(level: int) int[source]
Determine the number of spell slots available for a given level
- Parameters:
level (integer from 1 to 9 (inclusive)) – the spell level to look at
- Returns:
the number of available spell slots
- Return type:
- Raise:
ValueError if level is invalid
- can_cast(spell: Spell) bool[source]
Determine if self can cast the given Spell. Note: does not check spell slots.
- Parameters:
spell (py:class:Spell) – the Spell self is trying to cast
- Returns:
True if self can cast spell, False otherwise
- Return type:
- add_spell(spell: Spell)[source]
Add a given spell
- Parameters:
spell (Spell) – the Spell to add
- Returns:
None
- Raise:
ValueError if spell is not a Spell
Module contents
- class DnD_5e.combatant.Combatant(**kwargs)[source]
Bases:
objectThis class represents anything with a stat block that can fight
- current_eq(other) bool[source]
Check to see if self is identical to other by looking at everything in equals as well as the following attributes:
armor,current_hp,temp_hp,speed,conditions,vision,vulnerabilities,resistances,immunities,adv_to_be_hit, py:attr:weapons (don’t have to be identical, just equal),attacks,items,size, andteam
- get_unarmored_ac() int[source]
Get unarmored AC. Can be overridden with a Feature.
- Returns:
ac when not wearing armor
- Return type:
positive integer
- is_bloodied() bool[source]
Tell whether self is bloodied (current hit points at or below half of maximum)
- Returns:
True if self is bloodied, False otherwise
- Return type:
- get_hp_to_max() int[source]
Get the number of hit points needed to bring
current_hptomax_hp- Returns:
difference between max hp and current hp
- Return type:
non-negative integer
- has_condition(condition: str) bool[source]
Check self._conditions to see if self has the given condition
- get_vision() str[source]
- Returns:
vision
- Return type:
one of these strings: “normal”, “darkvision”, “blindsight”, “truesight”
- can_see(light_src: str) bool[source]
Determine whether self can see a given light source
- Parameters:
light_src (one of these strings: "normal", "dark", "magic") – a kind of light
- Returns:
True if self can see light_src, False otherwise
- Return type:
- Raise:
ValueError if light_src is not valid input
- get_ability(ability: str) int[source]
Get the ability score modifier indicated by ability
- Parameters:
ability (one of these strings: "strength", "dexterity", "constitution", "intelligence", "wisdom", "charisma") – the name of an ability score
- Returns:
the ability score modifier
- Return type:
- Raise:
ValueError if ability is not valid
- has_expertise(item: str) bool[source]
Check to see if self has a proficiency called item
- Parameters:
item (str) – a weapon name/type, ability score, etc.
- Returns:
True if self has a proficiency called item, False otherwise
- has_weapon_proficiency(weapon: Weapon) bool[source]
Check to see whether self has proficiency with the given weapon
- has_armor_proficiency(arm) bool[source]
Check to see whether self has proficiency with the given armor. Note: checks armor name based on class name (e.g., ChainMailArmor)
- Parameters:
arm (
Armor) – the armor in question- Returns:
True if self has proficiency with arm, False otherwise
- Return type:
- Raise:
ValueError if arm is not a Armor
- is_vulnerable(thing) bool[source]
Check to see if self is vulnerable to a given thing (usually a string for a damage type)
- Parameters:
thing – what we’re checking for vulnerability
- Returns:
True if self is vulnerable to thing, False otherwise
- Return type:
- is_resistant(thing) bool[source]
Check to see if self is resistant to a given thing (usually a string for a damage type)
- Parameters:
thing – what we’re checking for resistance
- Returns:
True if self is resistant to thing, False otherwise
- Return type:
- is_immune(thing) bool[source]
Check to see if self is resistant to a given thing (usually a string for a damage type)
- Parameters:
thing – what we’re checking for immunity
- Returns:
True if self is immune to thing, False otherwise
- Return type:
- get_saving_throw(ability: str) int[source]
Get the modifier for an ability saving throw.
Warning
This does not roll the saving throw, it just returns the modifier to use for the throw
- Parameters:
ability (one of these strings: "strength", "dexterity", "constitution", "intelligence", "wisdom", "charisma') – an ability score name
- Returns:
the modifier for an ability saving throw
- Return type:
- Raise:
ValueError if ability is not valid
- get_adv_to_be_hit() int[source]
The sum of advantage (+1) and disadvantage (-1) circumstances affecting self is stored in
_adv_to_be_hit. Look at this number and return an integer indicating whether an attack against self has advantage, disadvantage, or neither- Returns:
advantage to be hit (positive means advantage, negative means disadvantage, 0 means neither)
- Return type:
- get_feature_dict()[source]
Get the dictionary that maps self’s methods to the overloaded methods of any
Features self has. Internal use only! :return: feature_dict :rtype: dict
- get_feature_classes()[source]
- Returns:
all the Features affecting self
- Return type:
set of
Features
- has_feature_class(item) bool[source]
Check whether self has the given
Feature- Parameters:
item (py:class:Feature) – the feature to look for
- Returns:
True if self has the feature, False otherwise
- Return type:
- get_feature_methods()[source]
- Returns:
all the methods affected by the Features self has
- Return type:
set of methods
- has_feature_method(item: str) bool[source]
Check whether self has a Feature affecting the given method
- get_fighting_styles() set[source]
If self has the “fighting style” feature, return
fighting_styles(create it if it doesn’t already exist). Otherwise, return None- Returns:
fighting styles, or None
- Return type:
set of strings, or None
- has_fighting_style(fighting_style: str) bool[source]
Check to see if self has the fighting style fighting_style
- get_main_hand() Weapon | None[source]
- Returns:
what self is carrying in main hand
- Return type:
Weapon
- get_off_hand() Weapon | Shield | None[source]
- Returns:
what self is carrying in off hand
- Return type:
WeaponorShield
- get_attack_by_name(name: str)[source]
Find an attack by name and return it if it exists
- Parameters:
name (str) – the name of the
Attackwe are looking for- Returns:
the Attack, or None if self does not have an Attack with the given name
- get_weapon_attacks(weapon) list[source]
Get all attacks based on a given Weapon
- Parameters:
weapon (Weapon) – the Weapon to look for
- Returns:
a list of all attacks based on weapon
- get_enemy_tactic() CombatantTactic[source]
- Returns:
enemy_tactic (tactic for selecting who to attack)
- Return type:
CombatantTactic
- get_heal_tactic() CombatantTactic[source]
- Returns:
heal_tactic (tactic for selecting who to heal)
- Return type:
CombatantTactic
- get_attack_tactic() AttackTactic[source]
- Returns:
attack_tactic (tactic for selecting who to attack)
- Return type:
AttackTactic
- set_logger(logger: str)[source]
Set self._logger to the logger with the name specified in logger
- Parameters:
logger – the name of the Logger to use, or the logging.Logger object itself
- Returns:
None
- set_ac(ac: int)[source]
Set the armor class
- Parameters:
ac (positive integer) – the new ac
- Returns:
None
- Raise:
ValueError if ac is invalid
- set_armor(arm: Armor | None)[source]
Set the armor (and set the AC if appropriate). Assume arm is Armor or None.
- Parameters:
arm (
Armor) – the Armor to wear- Returns:
- set_temp_hp(hp: int)[source]
Set temporary hp
- Parameters:
hp (non-negative integer) – the new temporary hit points
- Returns:
None
- add_vulnerability(item)[source]
Add the given vulnerability
- Parameters:
item – the vulnerability to add
- Returns:
None
- remove_vulnerability(item)[source]
Remove the given vulnerability
- Parameters:
item – the vulnerability to remove
- Returns:
None
- add_resistance(item)[source]
Add the given resistance
- Parameters:
item – the resistance to add
- Returns:
None
- remove_resistance(item)[source]
Remove the given resistance
- Parameters:
item – the resistance to remove
- Returns:
None
- add_immunity(item)[source]
Add the given immunity
- Parameters:
item – the immunity to add
- Returns:
None
- remove_immunity(item)[source]
Remove the given immunity
- Parameters:
item – the immunity to remove
- Returns:
None
- modify_adv_to_be_hit(adv: int)[source]
Modify the advantage to be hit
- Parameters:
adv (int) – the number to modify
_adv_to_be_hitby- Returns:
None
- Raise:
ValueError if adv is invalid
- add_feature(feature: str)[source]
Add the given feature
- Parameters:
feature (str) – the feature to add
- Returns:
None
- add_feature_class(feature)[source]
Add the given Feature
- Parameters:
feature (Feature) – the Feature to add
- Returns:
None
- add_fighting_style(fighting_style: str)[source]
Add the given fighting style
- Parameters:
fighting_style – the fighting style to add
- Returns:
None
- Raise:
ValueError if fighting_style is invalid or if self already has fighting_stlye
- add_weapon(weapon: Weapon)[source]
Add the given weapon
- Parameters:
weapon (Weapon) – the Weapon to add
- Returns:
None
- Raise:
ValueError if weapon is invalid
- remove_weapon(weapon: Weapon)[source]
Remove the given weapon (based on identity) and all its attacks
- Parameters:
weapon (a Weapon) – the Weapon to remove
- Returns:
None
- add_weapon_attacks(weapon: Weapon)[source]
Add all the Attacks that weapon can make to self._attacks
- Parameters:
weapon (Weapon) – the Weapon to add attacks for
- Returns:
None
- get_weapon_attack_mod(weapon)[source]
Get the base modifier for attacks with a given weapon (based on str/dex, features, etc.)
- Parameters:
weapon (
Weapon) – the weapon to look at- Returns:
attack modifier
- Return type:
- get_weapon_damage_mod(weapon)[source]
Get the base modifier for damage attacks with a given weapon (based on str/dex, features, etc.). May seem like duplication of get_weapon_attack_mod, but this is a different method so it’s easier to overload with a Feature
- Parameters:
weapon (
Weapon) – the weapon to look at- Returns:
damage modifier
- Return type:
- get_weapon_attack_modifiers(weapon)[source]
Gets the modifiers for attacks with a given weapon (based on str/dex, features, etc.)
- add_attack(attack: Attack)[source]
Add the given attack
- Parameters:
attack (Attack) – the Attack to add
- Returns:
None
- remove_attack(attack: Attack)[source]
Remove the given
Attack...Warning:: this calls list.remove(item), which uses item’s built-in
__eq__()method.__eq__()is overriden forAttackto do a comparison based on instance variables and not memory address.- Parameters:
attack – the
Attackto remove- Returns:
None
- remove_weapon_attacks(weapon: Weapon)[source]
Remove all the attacks related to Weapon.
Warning
Doesn’t check to see whether self actually has the given weapon (checking something that is usually False is not that important), but no unexpected behavior happens if this is the case.
- Parameters:
weapon (Weapon) – the Weapon to remove attacks based on
- Returns:
None
- add_condition(condition: str)[source]
Add the given condition
- Parameters:
condition (str) – the condition to add
- Returns:
None
- remove_condition(condition: str)[source]
Remove the given condition
- Parameters:
condition (str) – the condition to remove
- Returns:
None
- set_vision(vision: str)[source]
Set vision to the given value
- Parameters:
vision (str) – the vision to change to
- Returns:
None
- Raise:
ValueError if vision is invalid
- set_size(size: str)[source]
Set size to the given size
- Parameters:
size (str) – the size to change to
- Returns:
None
- Raise:
ValueError if size is invalid
- set_team(team)[source]
Set team to the given Team. Does not check that team is valid (this is to avoid circular imports)
- Parameters:
team – the team to change to
- Returns:
None
- set_enemy_tactic(tact)[source]
Set rule for who to attack to tact
- Parameters:
tact (
CombatantTactic) – theTacticself uses to select an enemyCombatant- Returns:
None
- set_heal_tactic(tact)[source]
Set rule for who to heal to tact
- Parameters:
tact (
CombatantTactic) – theTacticself uses to select a who to healCombatant- Returns:
None
- set_attack_tactic(tact)[source]
Set rule for which attack to use to tact
- Parameters:
tact (
AttackTactic) – theTacticself uses to select an enemyAttack- Returns:
None
- select_action() str[source]
Choose what action to take. # TODO: support actions other than “Attack”
- Returns:
a string representing the action chosen
- Return type:
- select_attack(**kwargs)[source]
Choose which of self’s attacks to use
- Parameters:
kwargs – keyword arguments
- Returns:
the chosen attack
- Return type:
Attack
- send_attack(target, attack: Attack, adv=0) int | None[source]
Attack a given target using a given attack
- take_attack(attack_result: Tuple[int, int], source=None, attack: Attack | None = None) bool[source]
Read in an attack roll and determine whether the attack hits or not
- Parameters:
attack_result (TYPE_ROLL_RESULT) – first number in tuple indicates roll value, second number indicates crit value
source – the thing that is making the attack (usually a Combatant)
attack (Attack) – the Attack that is received
- Returns:
True if the attack hits, False otherwise
- Return type:
- take_saving_throw(save_type: str, dc: int, attack: Attack | None = None, adv: int = 0) bool[source]
Respond to something that asks for a saving throw
- Parameters:
save_type (one of these strings: "strength", "dexterity", "constitution", "intelligence", "wisdom", "charisma") – the kind of saving throw to make
dc (int) – to succeed, the roll must be greater than or equal to the dc
attack (Attack) – the Attack that is asking for a saving throw
adv (int) – indicates advantage, disadvantage, or neither
- Returns:
True if self makes the saving throw, False otherwise
- Return type:
- should_die_from_damage(damage_taken: int, damage_type: str | None = None)[source]
Return whether taking the specified amount of damage should result in self dying :param damage_taken: the total amount of damage taken :param damage_type: the damage type :return:
- take_damage(damage: int, damage_type: str | None = None, is_critical: bool = False) int[source]
Take damage, applying vulnerabilities, resistances, and immunities as necessary