app_lisium/backend/character.py
2025-11-02 11:12:06 -06:00

202 lines
5.9 KiB
Python

from dataclasses import dataclass, field
from typing import List, Dict, Any, Union
@dataclass
class Effect:
attribute: str # name of attribute to change
operation: str # 'add', 'subtract', 'set', 'append'
value: Any # value to apply
def apply(self, character: 'Character'):
# Handle numeric attributes
if self.operation == 'add':
setattr(character, self.attribute, getattr(character, self.attribute) + self.value)
elif self.operation == 'subtract':
setattr(character, self.attribute, getattr(character, self.attribute) - self.value)
elif self.operation == 'set':
setattr(character, self.attribute, self.value)
elif self.operation == 'append':
current = getattr(character, self.attribute)
if isinstance(current, list):
if isinstance(self.value, list):
current.extend(self.value)
else:
current.append(self.value)
setattr(character, self.attribute, current)
else:
raise ValueError(f"Attribute '{self.attribute}' is not a list.")
else:
raise ValueError(f"Unknown operation: {self.operation}")
@dataclass
class Feature:
name: str
description: str
effects: List[Effect] = field(default_factory=list)
def apply(self, character: 'Character'):
for effect in self.effects:
effect.apply(character)
@dataclass
class Character:
name: str = ""
level: int = 0
race: str = ""
subrace: str = ""
class_: str = ""
subclass: str = ""
background: str = ""
alignment: str = ""
size: str = ""
age: int = 0
gender: str = ""
height: str = ""
weight: int = 0
deity: str = ""
strength_base: int = 0
dexterity_base: int = 0
constitution_base: int = 0
intelligence_base: int = 0
wisdom_base: int = 0
charisma_base: int = 0
armor_base: int = 0
strength: int = 0
dexterity: int = 0
constitution: int = 0
intelligence: int = 0
wisdom: int = 0
charisma: int = 0
armor: int = 0
strength_modifier: int = 0
dexterity_modifier: int = 0
constitution_modifier: int = 0
intelligence_modifier: int = 0
wisdom_modifier: int = 0
charisma_modifier: int = 0
proficiency: int = 0
inspiration: bool = False
experience: int = 0
proficiencies_armor: List[str] = field(default_factory=list)
proficiencies_weapons: List[str] = field(default_factory=list)
proficiencies_tools: List[str] = field(default_factory=list)
languages: List[str] = field(default_factory=list)
strength_save: int = 0
dexterity_save: int = 0
constitution_save: int = 0
intelligence_save: int = 0
wisdom_save: int = 0
charisma_save: int = 0
hp: int = 0
hp_max: int = 0
hp_temp: int = 0
hit_die: str = ""
initiative: int = 0
deathsaves_successes: int = 0
deathsaves_failures: int = 0
fire_resistance: bool = False
poison_resistance: bool = False
psychic_resistance: bool = False
cold_resistance: bool = False
thunder_resistance: bool = False
acid_resistance: bool = False
force_resistance: bool = False
radiant_resistance: bool = False
necrotic_resistance: bool = False
bludgeoning_resistance: bool = False
piercing_resistance: bool = False
slashing_resistance: bool = False
immunities: List[str] = field(default_factory=list)
vulnerabilities: List[str] = field(default_factory=list)
speed_base: int = 0
speed_type: List[str] = field(default_factory=list)
darkvision: int = 0
blindsight: int = 0
tremorsense: int = 0
truesight: int = 0
passive_perception: int = 0
athletics: int = 0
acrobatics: int = 0
sleight_of_hand: int = 0
stealth: int = 0
arcana: int = 0
history: int = 0
investigation: int = 0
nature: int = 0
religion: int = 0
animal_handling: int = 0
insight: int = 0
medicine: int = 0
perception: int = 0
survival: int = 0
deception: int = 0
intimidation: int = 0
performance: int = 0
persuasion: int = 0
athletics_passive: int = 0
acrobatics_passive: int = 0
sleight_of_hand_passive: int = 0
stealth_passive: int = 0
arcana_passive: int = 0
history_passive: int = 0
investigation_passive: int = 0
nature_passive: int = 0
religion_passive: int = 0
animal_handling_passive: int = 0
insight_passive: int = 0
medicine_passive: int = 0
perception_passive: int = 0
survival_passive: int = 0
deception_passive: int = 0
intimidation_passive: int = 0
performance_passive: int = 0
persuasion_passive: int = 0
passive_perception: int = 0
passive_investigation: int = 0
passive_insight: int = 0
spellcasting_ability: str = ""
spell_save_dc: int = 0
spell_attack_bonus: int = 0
known_spells: List[str] = field(default_factory=list)
prepared_spells: List[str] = field(default_factory=list)
spell_slots: Dict[str, Any] = field(default_factory=dict)
cantrips: List[str] = field(default_factory=list)
spellcasting_class: str = ""
exhaustion_level: int = 0
conditions_active: List[str] = field(default_factory=list)
cp: int = 0
sp: int = 0
ep: int = 0
gp: int = 0
pp: int = 0
equipment: List[str] = field(default_factory=list)
features: List[str] = field(default_factory=list)
traits: List[str] = field(default_factory=list)
personality_traits: List[str] = field(default_factory=list)
ideals: List[str] = field(default_factory=list)
bonds: List[str] = field(default_factory=list)
flaws: List[str] = field(default_factory=list)
notes: str = ""
custom_attributes: Dict[str, Any] = field(default_factory=dict)
def apply_features(character: Character, features: List[Feature]):
for feature in features:
feature.apply(character)