# Path: abilities/power_abilities.py
# class PowerAbilities(Enum):
#     Berserk = 0
#     Regeneration = 1
#     PowerAttack = 2
#     Parry = 3
#     Sneak = 4
#     Backstab = 5
# 
# Path: components/level_tree.py
# class LevelTree(object):
#     NAME = "level_tree"
#     """
#     The goal of this Tree is to return advantages of a level recursively.
#     """
#     def __init__(self):
#         super().__init__()
#         self.stats_modifiers = {}
#         self.abilities_modifiers = {}
# 
#     def get_stat_modifiers(self, current_level):
#         final_modifiers = {}
#         ordered_modifiers = sorted(self.stats_modifiers.keys())
#         for level in ordered_modifiers:
#             if int(level) > int(current_level):
#                 continue
# 
#             for stat_modifier in self.stats_modifiers[level]:
#                 if stat_modifier in final_modifiers:
#                     final_modifiers[stat_modifier.uid] += stat_modifier.get_leveled_value(current_level, level)
#                 else:
#                     final_modifiers[stat_modifier.uid] = stat_modifier.get_leveled_value(current_level, level)
# 
#         return final_modifiers
# 
#     def get_ability_modifiers(self, current_level):
#         final_modifiers = {}
#         for level in sorted(self.abilities_modifiers.keys()):
#             if level > current_level:
#                 continue
#             for ability_modifier in self.abilities_modifiers[level]:
#                 if ability_modifier.uid in final_modifiers:
#                     final_modifiers[ability_modifier.uid] += ability_modifier.get_leveled_value(current_level, level)
#                 else:
#                     final_modifiers[ability_modifier.uid] = ability_modifier.get_leveled_value(current_level, level)
# 
#         return final_modifiers
# 
#     def add_stat_modifier(self, level, stat_modifier):
#         if level not in self.stats_modifiers:
#             self.stats_modifiers[level] = []
#         self.stats_modifiers[level].append(stat_modifier)
# 
#     def add_ability_modifier(self, level, ability_modifier):
#         if level not in self.abilities_modifiers:
#             self.abilities_modifiers[level] = []
#         self.abilities_modifiers[level].append(ability_modifier.power)
# 
# Path: components/race.py
# class Race(Component):
#     NAME = 'character_race'
#     """
#     Racial characteristics and bonuses
#     """
#     def __init__(self, uid, name, level_tree, body_template_uid):
#         super().__init__()
#         self.uid = uid
#         self.name = name
#         # TODO Some races won't be leveled, should acknowledge a level_tree of one
#         # TODO and avoid registering a pool
#         self.level_tree = level_tree
#         self.body_template_uid = body_template_uid
#         self.get_level = lambda: 0
# 
#     def copy(self):
#         return Race(
#             uid=self.uid,
#             name=self.name,
#             level_tree=self.level_tree,
#             body_template_uid=self.body_template_uid
#         )
# 
#     def on_register(self, host):
#         super().on_register(host)
#         host.register_query_responder(self, QueryType.StatModifier, self.respond_stat_modifier_query)
#         if self.level_tree:
#             results = host.transmit_query(self, QueryType.ExperiencePool, name=self.name)
#             self.get_level = results[0]
# 
#     def respond_stat_modifier_query(self, stat):
#         if self.level_tree:
#             modifiers = self.level_tree.get_stat_modifiers(self.get_level())
#             if stat in modifiers:
#                 return modifiers[stat]
# 
# Path: stats/enums.py
# class StatsEnum(Enum):
#     Health = 'health'
#     Mana = 'mana'
#     Strength = 'strength'
#     Dexterity = 'dexterity'
#     Constitution = 'constitution'
#     Intelligence = 'intelligence'
#     Charisma = 'charisma'
#     Wisdom = 'wisdom'
#     Sharpness = 'sharpness'
#     Hardness = 'hardness'
#     Weight = 'weight'
#     Size = 'size'
#     Potency = 'potency'
#     MaxDamage = 'max_damage'
#     MinDamage = 'min_damage'
#     ArmorClass = 'armor_class'
# 
# Path: stats/stat.py
# class StatModifier(object):
#     def __init__(self, uid, value, level_progression=0):
#         self.uid = uid
#         self.value = value
#         self.level_progression = level_progression
# 
#     def __int__(self):
#         return
# 
#     def get_leveled_value(self, level, initial_level):
#         if self.level_progression > 0:
#             multiplier = (level - initial_level) / self.level_progression
#             return math.ceil(self.value * multiplier)
#         else:
#             return self.value


from abilities.ability import Ability
from abilities.power_abilities import PowerAbilities
from components.level_tree import LevelTree
from components.race import Race
from stats.enums import StatsEnum
from stats.stat import StatModifier
def build_orc_race():
    # An orc won't get uglier over time but it could gain abilities.
    orc_level_tree = LevelTree()
    orc_level_tree.stats_modifiers = {
        1: [
            StatModifier(StatsEnum.Strength, 2),
            StatModifier(StatsEnum.Constitution, 2),
            StatModifier(StatsEnum.Charisma, -2),
            StatModifier(StatsEnum.Intelligence, -2)
        ]
    }
    orc_level_tree.abilities_modifiers = {
        1: [Ability(PowerAbilities.Berserk, 1)]
    }
    orc_race = Race("orc", "Orc", orc_level_tree, "humanoid")

    return orc_race


def build_troll_race():
    troll_level_tree = LevelTree()
    troll_level_tree.stats_modifiers = {
        1: [
            StatModifier(StatsEnum.Strength, 4),
            StatModifier(StatsEnum.Constitution, 4),
            StatModifier(StatsEnum.Charisma, -4),
            StatModifier(StatsEnum.Intelligence, -4)
        ]
    }
    troll_level_tree.abilities_modifiers = {

# Path: abilities/power_abilities.py
# class PowerAbilities(Enum):
#     Berserk = 0
#     Regeneration = 1
#     PowerAttack = 2
#     Parry = 3
#     Sneak = 4
#     Backstab = 5
# 
# Path: components/level_tree.py
# class LevelTree(object):
#     NAME = "level_tree"
#     """
#     The goal of this Tree is to return advantages of a level recursively.
#     """
#     def __init__(self):
#         super().__init__()
#         self.stats_modifiers = {}
#         self.abilities_modifiers = {}
# 
#     def get_stat_modifiers(self, current_level):
#         final_modifiers = {}
#         ordered_modifiers = sorted(self.stats_modifiers.keys())
#         for level in ordered_modifiers:
#             if int(level) > int(current_level):
#                 continue
# 
#             for stat_modifier in self.stats_modifiers[level]:
#                 if stat_modifier in final_modifiers:
#                     final_modifiers[stat_modifier.uid] += stat_modifier.get_leveled_value(current_level, level)
#                 else:
#                     final_modifiers[stat_modifier.uid] = stat_modifier.get_leveled_value(current_level, level)
# 
#         return final_modifiers
# 
#     def get_ability_modifiers(self, current_level):
#         final_modifiers = {}
#         for level in sorted(self.abilities_modifiers.keys()):
#             if level > current_level:
#                 continue
#             for ability_modifier in self.abilities_modifiers[level]:
#                 if ability_modifier.uid in final_modifiers:
#                     final_modifiers[ability_modifier.uid] += ability_modifier.get_leveled_value(current_level, level)
#                 else:
#                     final_modifiers[ability_modifier.uid] = ability_modifier.get_leveled_value(current_level, level)
# 
#         return final_modifiers
# 
#     def add_stat_modifier(self, level, stat_modifier):
#         if level not in self.stats_modifiers:
#             self.stats_modifiers[level] = []
#         self.stats_modifiers[level].append(stat_modifier)
# 
#     def add_ability_modifier(self, level, ability_modifier):
#         if level not in self.abilities_modifiers:
#             self.abilities_modifiers[level] = []
#         self.abilities_modifiers[level].append(ability_modifier.power)
# 
# Path: components/race.py
# class Race(Component):
#     NAME = 'character_race'
#     """
#     Racial characteristics and bonuses
#     """
#     def __init__(self, uid, name, level_tree, body_template_uid):
#         super().__init__()
#         self.uid = uid
#         self.name = name
#         # TODO Some races won't be leveled, should acknowledge a level_tree of one
#         # TODO and avoid registering a pool
#         self.level_tree = level_tree
#         self.body_template_uid = body_template_uid
#         self.get_level = lambda: 0
# 
#     def copy(self):
#         return Race(
#             uid=self.uid,
#             name=self.name,
#             level_tree=self.level_tree,
#             body_template_uid=self.body_template_uid
#         )
# 
#     def on_register(self, host):
#         super().on_register(host)
#         host.register_query_responder(self, QueryType.StatModifier, self.respond_stat_modifier_query)
#         if self.level_tree:
#             results = host.transmit_query(self, QueryType.ExperiencePool, name=self.name)
#             self.get_level = results[0]
# 
#     def respond_stat_modifier_query(self, stat):
#         if self.level_tree:
#             modifiers = self.level_tree.get_stat_modifiers(self.get_level())
#             if stat in modifiers:
#                 return modifiers[stat]
# 
# Path: stats/enums.py
# class StatsEnum(Enum):
#     Health = 'health'
#     Mana = 'mana'
#     Strength = 'strength'
#     Dexterity = 'dexterity'
#     Constitution = 'constitution'
#     Intelligence = 'intelligence'
#     Charisma = 'charisma'
#     Wisdom = 'wisdom'
#     Sharpness = 'sharpness'
#     Hardness = 'hardness'
#     Weight = 'weight'
#     Size = 'size'
#     Potency = 'potency'
#     MaxDamage = 'max_damage'
#     MinDamage = 'min_damage'
#     ArmorClass = 'armor_class'
# 
# Path: stats/stat.py
# class StatModifier(object):
#     def __init__(self, uid, value, level_progression=0):
#         self.uid = uid
#         self.value = value
#         self.level_progression = level_progression
# 
#     def __int__(self):
#         return
# 
#     def get_leveled_value(self, level, initial_level):
#         if self.level_progression > 0:
#             multiplier = (level - initial_level) / self.level_progression
#             return math.ceil(self.value * multiplier)
#         else:
#             return self.value


# Path: data/python_templates/races.py
from abilities.ability import Ability
from abilities.power_abilities import PowerAbilities
from components.level_tree import LevelTree
from components.race import Race
from stats.enums import StatsEnum
from stats.stat import StatModifier

def build_orc_race():
    # An orc won't get uglier over time but it could gain abilities.
    orc_level_tree = LevelTree()
    orc_level_tree.stats_modifiers = {
        1: [
            StatModifier(StatsEnum.Strength, 2),
            StatModifier(StatsEnum.Constitution, 2),
            StatModifier(StatsEnum.Charisma, -2),
            StatModifier(StatsEnum.Intelligence, -2)
        ]
    }
    orc_level_tree.abilities_modifiers = {
        1: [Ability(PowerAbilities.Berserk, 1)]
    }
    orc_race = Race("orc", "Orc", orc_level_tree, "humanoid")

    return orc_race


def build_troll_race():
    troll_level_tree = LevelTree()
    troll_level_tree.stats_modifiers = {
        1: [
            StatModifier(StatsEnum.Strength, 4),
            StatModifier(StatsEnum.Constitution, 4),
            StatModifier(StatsEnum.Charisma, -4),
            StatModifier(StatsEnum.Intelligence, -4)
        ]
    }
    troll_level_tree.abilities_modifiers = {

        1: [Ability(PowerAbilities.Regeneration, 1)]