fix tests

This commit is contained in:
evilchili
2024-06-30 16:09:20 -07:00
parent a8bb6de008
commit 68251ff4e9
5 changed files with 59 additions and 47 deletions
+1
View File
@@ -1,5 +1,6 @@
from .character import *
from .classes import *
from .constants import *
from .log import *
from .modifiers import *
from .skill import *
+29 -20
View File
@@ -6,6 +6,7 @@ from sqlalchemy.orm import Mapped, mapped_column, relationship
from ttfrog.db.base import BaseObject, SlugMixin
from ttfrog.db.schema.classes import CharacterClass, ClassAttribute
from ttfrog.db.schema.constants import Conditions, DamageType, Defenses
from ttfrog.db.schema.modifiers import Modifier, ModifierMixin, Stat
from ttfrog.db.schema.skill import Skill
@@ -212,6 +213,7 @@ class Character(BaseObject, SlugMixin, ModifierMixin):
)
_vision: Mapped[int] = mapped_column(default=None, nullable=True, info={"min": 0, "modifiable": True})
exhaustion: Mapped[int] = mapped_column(nullable=False, default=0, info={"min": 0, "max": 5})
class_map = relationship("CharacterClassMap", cascade="all,delete,delete-orphan")
class_list = association_proxy("class_map", "id", creator=class_map_creator)
@@ -272,6 +274,10 @@ class Character(BaseObject, SlugMixin, ModifierMixin):
def traits(self):
return self.ancestry.traits
@property
def initiative(self):
return self._apply_modifiers("initiative", self.dexterity.bonus)
@property
def speed(self):
return self._apply_modifiers("speed", self.ancestry.speed)
@@ -294,7 +300,7 @@ class Character(BaseObject, SlugMixin, ModifierMixin):
@property
def vision_in_darkness(self):
return self.apply_modifiers("vision_in_darkness", self.vision if self.vision is not None else 0)
return self._apply_modifiers("vision_in_darkness", self.vision if self.vision is not None else 0)
@property
def level(self):
@@ -314,23 +320,26 @@ class Character(BaseObject, SlugMixin, ModifierMixin):
return None
return mapping[0]
def immune(self, damage_type: str, magical: bool = False):
return self.defense(damage_type, magical) == 'immune'
def immune(self, damage_type: DamageType):
return self.defense(damage_type) == Defenses.immune
def resistant(self, damage_type: str, magical: bool = False):
return self.defense(damage_type, magical) == 'resistant'
def resistant(self, damage_type: DamageType):
return self.defense(damage_type) == Defenses.resistant.value
def vulnerable(self, damage_type: str, magical: bool = False):
return self.defense(damage_type, magical) == 'vulnerable'
def vulnerable(self, damage_type: DamageType):
return self.defense(damage_type) == Defenses.vulnerable
def absorbs(self, damage_type: str, magical: bool = False):
return self.defense(damage_type, magical) == 'absorbs'
def absorbs(self, damage_type: DamageType):
return self.defense(damage_type) == Defenses.absorbs
def defense(self, damage_type: str, magical: bool = False):
attr_name = damage_type
if magical:
attr_name = f"magical_{attr_name}"
return self._apply_modifiers(f"defenses.{attr_name}", None)
def conditions(self):
return [self._apply_modifiers(f"conditions.{name}") for name in Conditions]
def condition(self, condition_name: str):
return self._apply_modifiers(f"conditions.{condition_name}", False)
def defense(self, damage_type: DamageType):
return self._apply_modifiers(damage_type, None)
def check_modifier(self, skill: Skill, save: bool = False):
# if the skill is not assigned, but we have modifiers, apply them to zero.
@@ -387,13 +396,13 @@ class Character(BaseObject, SlugMixin, ModifierMixin):
self._hit_dice.append(HitDie(character_id=self.id, character_class_id=newclass.id))
def remove_class(self, target):
self.class_map = [m for m in self.class_map if m.character_class != target]
for mapping in self.character_class_attribute_map:
if mapping.character_class == target:
self.remove_class_attribute(mapping.class_attribute)
for skill in target.skills:
self.remove_skill(skill, proficient=True, expert=False, character_class=target)
self._hit_dice = [die for die in self._hit_dice if die.character_class != target]
self.class_map = [m for m in self.class_map if m.character_class != target]
def remove_class_attribute(self, attribute):
self.character_class_attribute_map = [
@@ -474,15 +483,15 @@ class Character(BaseObject, SlugMixin, ModifierMixin):
def apply_healing(self, value: int):
self.hit_points = min(self.hit_points + value, self._max_hit_points)
def apply_damage(self, value: int, damage_type: str, magical=False):
def apply_damage(self, value: int, damage_type: DamageType):
total = value
if self.absorbs(damage_type, magical):
if self.absorbs(damage_type):
return self.apply_healing(total)
if self.immune(damage_type, magical):
if self.immune(damage_type):
return
if self.resistant(damage_type, magical):
if self.resistant(damage_type):
total = int(value / 2)
elif self.vulnerable(damage_type, magical):
elif self.vulnerable(damage_type):
total = value * 2
if total <= self.temp_hit_points: