diff options
| -rw-r--r-- | character.py | 7 | ||||
| -rw-r--r-- | creature.py | 40 | ||||
| -rw-r--r-- | game.py | 6 | ||||
| -rw-r--r-- | main.py | 9 |
4 files changed, 52 insertions, 10 deletions
diff --git a/character.py b/character.py index e7bc97b..75329ed 100644 --- a/character.py +++ b/character.py @@ -1,9 +1,9 @@ import re import json -from abc import ABC, abstractmethod from dataclasses import dataclass, asdict from items import Armor +from game import LevelingPlan _skill_ability = { @@ -32,11 +32,6 @@ _skill_ability = { "lore2": "int" } -class LevelingPlan(ABC): - @abstractmethod - def build(self, level: int): - pass - class FeaturesPlan(LevelingPlan, dict): @classmethod diff --git a/creature.py b/creature.py index e30f877..aa830f6 100644 --- a/creature.py +++ b/creature.py @@ -1,6 +1,6 @@ import csv -from game import Difficulty, RollInfo +from game import Difficulty, RollInfo, LevelingPlan def safe_item_level(creature_level: int): if creature_level <= 3: @@ -41,10 +41,19 @@ def parse_stat(str_data): else: return RollInfo.parse(str_data) +def get_range_value(range_stat: tuple, value="avg"): + if value == "min": + return range_stat[0] + if value == "max": + return range_stat[1] + if value == "avg": + return (range_stat[0]+range_stat[1]) // 2 + class StatsDB: stat_names = ["ac","abilities","attack_bonus", "hp", "perception", "saves", "resistances", "skills", "strike_damage"] + saves = ["reflex", "will", "fortitude"] def __init__(self) -> None: self.stats = dict() @@ -53,7 +62,36 @@ class StatsDB: self.stats["resistances"] = {k:(v["minimum"], v["maximum"]) for k,v in self.stats["resistances"].items()} + + def get(self, stat, level, difficulty=Difficulty.Moderate, range_value="avg"): + if stat in StatsDB.saves: + stat = "saves" + value = self.stats[stat][level] + if isinstance(value, dict): + value = value[difficulty] + if isinstance(value, tuple): + value = get_range_value(value, range_value) + return value + + stats = StatsDB() +class CreaturePlan(LevelingPlan, dict): + stat_names = ["ac", "attack_bonus", "hp", "perception", "strike_damage"] + + def __init__(self, data=None, + default_difficulty = Difficulty.Moderate, + stat_range_value="avg") -> None: + super().__init__({k: default_difficulty for k in self.stat_names+StatsDB.saves}) + if data is not None: + self.update(data) + self.stat_range_value = stat_range_value + + def build(self, level: int): + res = dict() + for stat, difficulty in self.items(): + res[stat] = stats.get(stat, level, difficulty, self.stat_range_value) + return res + # if __name__ == '__main__': # main() @@ -1,6 +1,7 @@ import re from enum import Enum from dataclasses import dataclass +from abc import ABC, abstractmethod from distribution import Distribution @@ -85,3 +86,8 @@ class RollInfo: def distribution(self): return self.dice_count * d(self.die_size) + self.bonus + +class LevelingPlan(ABC): + @abstractmethod + def build(self, level: int): + pass @@ -1,6 +1,7 @@ import math from character import CharacterPlan -from game import Roll, d +from game import Difficulty, Roll, d +from creature import CreaturePlan import pb2e @@ -155,8 +156,10 @@ def main4(): print(char.toJSON()) def main5(): - from creature import stats - print(stats.stats) + creature_plan = CreaturePlan(default_difficulty=Difficulty.Moderate) + creature_plan["reflex"] = Difficulty.High + creature = creature_plan.build(10) + print(creature) if __name__ == '__main__': |
