Files
COC_API/app/game/generators/entity_factory.py

48 lines
1.3 KiB
Python

import uuid
from typing import Dict, List, Any, Tuple
from app.game.utils.common import Dice
from app.game.models.entities import Entity
from app.game.loaders.races_loader import RaceRepository
from app.game.loaders.profession_loader import ProfessionRepository
from app.game.generators.level_progression import DEFAULT_LEVEL_PROGRESSION
from app.game.systems.leveling import set_level
dice = Dice()
progression = DEFAULT_LEVEL_PROGRESSION
def build_char(name:str, origin_story:str, race_id:str, profession_id:str,ability_pathway:str,level:int=1) -> Entity:
races = RaceRepository()
professions = ProfessionRepository()
race = races.get(race_id)
profession = professions.get(profession_id)
profession.ability_paths
e = Entity(
uuid = str(uuid.uuid4()),
name = name,
origin_story = origin_story,
race =race,
ability_pathway=ability_pathway,
profession = profession
)
# apply race ability scores
for stat, delta in vars(race.ability_scores).items():
# Get current score (default to 10 if missing)
current = getattr(e.ability_scores, stat, 10)
# Apply modifier
new_value = current + int(delta)
# Update the stat
setattr(e.ability_scores, stat, new_value)
set_level(e,level,progression)
return e