# Path: abilities/physical_abilities.py
# class PhysicalAbilities(Enum):
#     GRASP = 0
#     STAND = 1
#     SEE = 2
#     HEAR = 3
#     BITE = 4
#     PUNCH = 5
#     KICK = 6
#     EAT = 7
#     THINK = 8
#     MOVE = 9
#     LIVE = 10
#     BREATHE = 11
# 
# Path: bodies/body_part_tree.py
# class BodypartTree(object):
#     CONNECTION_TYPE_CENTER = 0
#     CONNECTION_TYPE_ATTACHED = 1
#     CONNECTION_TYPE_INSERTED = 2
# 
#     def __init__(self, central_node_name, central_body_part_uid):
#         self.nodes = [BodypartTreeNode(central_node_name, central_body_part_uid, self.CONNECTION_TYPE_CENTER)]
# 
#     def copy(self):
#         return copy.deepcopy(self)
# 
#     def attach(self, parent_node_name, children_node_name, children_body_part_uid):
#         self._bind_new_child_to_parent(
#             parent_node_name, children_node_name, children_body_part_uid, self.CONNECTION_TYPE_ATTACHED)
# 
#     def insert(self, parent_node_name, children_node_name, children_body_part_uid):
#         self._bind_new_child_to_parent(
#             parent_node_name, children_node_name, children_body_part_uid, self.CONNECTION_TYPE_INSERTED)
# 
#     def _bind_new_child_to_parent(self, parent_node_name, children_node_name, children_body_part_uid, connection_type):
#         parent_node = next((node for node in self.nodes if node.name == parent_node_name), None)
#         if parent_node:
#             child_bodypart_node = BodypartTreeNode(children_node_name, children_body_part_uid, connection_type)
#             parent_node.add_child_node(child_bodypart_node)
#             self.nodes.append(child_bodypart_node)
#         else:
#             logger_.error("Tried to bind bodypart {} to non existing parent {}.".format(
#                 children_node_name, parent_node_name))
# 
# Path: combat/enums.py
# class ThreatLevel(Enum):
#     Minor = 0
#     Major = 1
#     Critical = 2
#     Fatal = 3


import logging
import random
import six
from abilities.physical_abilities import PhysicalAbilities
from bodies.body_part_tree import BodypartTree
from combat.enums import ThreatLevel
from components.component import Component
                return node.instance

    def get_body_parts(self, uid):
        body_parts = []
        for node in self.bodypart_tree.nodes:
            if not node.instance:
                print("WTF")
            else:
                if node.instance.uid == uid:
                    body_parts.append(node.instance)

        return body_parts

    @staticmethod
    def _random_roll_body_part(body_parts):
        tries = 0
        max_tries = 3
        while tries < max_tries:
            tries += 1
            for node in body_parts:
                if random.randrange(0, 100) <= node.instance.relative_size:
                    return node

        return random.choice(body_parts)

    def get_random_body_part_for_threat_level(self, threat_level):
        size_sorted_body_parts = [node for node in self.bodypart_tree.nodes
                                  if node.instance.threat_level == threat_level]
        if not size_sorted_body_parts:
            if threat_level < ThreatLevel.Fatal:

# Path: abilities/physical_abilities.py
# class PhysicalAbilities(Enum):
#     GRASP = 0
#     STAND = 1
#     SEE = 2
#     HEAR = 3
#     BITE = 4
#     PUNCH = 5
#     KICK = 6
#     EAT = 7
#     THINK = 8
#     MOVE = 9
#     LIVE = 10
#     BREATHE = 11
# 
# Path: bodies/body_part_tree.py
# class BodypartTree(object):
#     CONNECTION_TYPE_CENTER = 0
#     CONNECTION_TYPE_ATTACHED = 1
#     CONNECTION_TYPE_INSERTED = 2
# 
#     def __init__(self, central_node_name, central_body_part_uid):
#         self.nodes = [BodypartTreeNode(central_node_name, central_body_part_uid, self.CONNECTION_TYPE_CENTER)]
# 
#     def copy(self):
#         return copy.deepcopy(self)
# 
#     def attach(self, parent_node_name, children_node_name, children_body_part_uid):
#         self._bind_new_child_to_parent(
#             parent_node_name, children_node_name, children_body_part_uid, self.CONNECTION_TYPE_ATTACHED)
# 
#     def insert(self, parent_node_name, children_node_name, children_body_part_uid):
#         self._bind_new_child_to_parent(
#             parent_node_name, children_node_name, children_body_part_uid, self.CONNECTION_TYPE_INSERTED)
# 
#     def _bind_new_child_to_parent(self, parent_node_name, children_node_name, children_body_part_uid, connection_type):
#         parent_node = next((node for node in self.nodes if node.name == parent_node_name), None)
#         if parent_node:
#             child_bodypart_node = BodypartTreeNode(children_node_name, children_body_part_uid, connection_type)
#             parent_node.add_child_node(child_bodypart_node)
#             self.nodes.append(child_bodypart_node)
#         else:
#             logger_.error("Tried to bind bodypart {} to non existing parent {}.".format(
#                 children_node_name, parent_node_name))
# 
# Path: combat/enums.py
# class ThreatLevel(Enum):
#     Minor = 0
#     Major = 1
#     Critical = 2
#     Fatal = 3


# Path: components/body.py
import logging
import random
import six
from abilities.physical_abilities import PhysicalAbilities
from bodies.body_part_tree import BodypartTree
from combat.enums import ThreatLevel
from components.component import Component

                return node.instance

    def get_body_parts(self, uid):
        body_parts = []
        for node in self.bodypart_tree.nodes:
            if not node.instance:
                print("WTF")
            else:
                if node.instance.uid == uid:
                    body_parts.append(node.instance)

        return body_parts

    @staticmethod
    def _random_roll_body_part(body_parts):
        tries = 0
        max_tries = 3
        while tries < max_tries:
            tries += 1
            for node in body_parts:
                if random.randrange(0, 100) <= node.instance.relative_size:
                    return node

        return random.choice(body_parts)

    def get_random_body_part_for_threat_level(self, threat_level):
        size_sorted_body_parts = [node for node in self.bodypart_tree.nodes
                                  if node.instance.threat_level == threat_level]
        if not size_sorted_body_parts:
            if threat_level < ThreatLevel.Fatal:

                return self.get_random_body_part_for_threat_level(ThreatLevel[threat_level.value + 1])