# Path: animation.py
# def animate_point(game_state, position, graphic_chars):
#     if not game_state.player.dungeon_mask.can_see_point(position):
#         return
#     camera = game_state.camera
#     x, y = camera.dungeon_to_screen_position(position)
#     for graphic_char in graphic_chars:
#         game_state.prepare_draw()
#         console.set_color_fg((x, y), graphic_char.color_fg)
#         console.set_symbol((x, y), graphic_char.icon)
#         for _ in range(settings.MISSILE_ANIMATION_DELAY):
#             console.flush()
# 
# Path: compositecore.py
# class Leaf(Component):
#     """
#     Abstract leaf class of composite design pattern.
# 
#     Component classes of leaf type should inherit from this class.
#     """
# 
#     def __init__(self):
#         super(Leaf, self).__init__()
# 
#     def get_relative_of_type(self, component_type):
#         return self.parent.get_child_or_ancestor(component_type)
# 
#     def has_relative_of_type(self, component_type):
#         return self.parent.has_child_or_ancestor(component_type)
# 
# Path: graphic.py
# class GraphicChar(Leaf):
#     """
#     Composites holding this has a graphical representation as a char.
#     """
# 
#     def __init__(self, color_bg, color_fg, icon):
#         super(GraphicChar, self).__init__()
#         self.component_type = "graphic_char"
#         self._color_bg = color_bg
#         self._color_fg = color_fg
#         self._icon = icon
# 
#     @property
#     def color_bg(self):
#         if self._color_bg:
#             return self._color_bg
#         elif self.next:
#             return self.next.color_bg
#         return None
# 
# 
#     @color_bg.setter
#     def color_bg(self, value):
#         self._color_bg = value
# 
#     @property
#     def color_fg(self):
#         if self._color_fg:
#             return self._color_fg
#         elif self.next:
#             return self.next.color_fg
#         return None
# 
#     @color_fg.setter
#     def color_fg(self, value):
#         self._color_fg = value
# 
#     @property
#     def icon(self):
#         if self._icon:
#             return self._icon
#         elif self.next:
#             return self.next.icon
#         return None
# 
#     @icon.setter
#     def icon(self, value):
#         self._icon = value
# 
#     def copy(self):
#         """
#         Makes a copy of this component.
#         """
#         return GraphicChar(self.color_bg, self.color_fg, self.icon)
# 
# Path: statusflags.py
# class StatusFlags(Leaf):
#     """
#     Composites holding this has status flags, describing their behaviour.
#     """
#     INVISIBILE = 0
#     SEE_INVISIBILITY = 1
#     FLYING = 2
#     IS_ALIVE = 3
#     CAN_OPEN_DOORS = 4
#     HAS_HEART = 5
# 
#     def __init__(self, status_flags=[]):
#         super(StatusFlags, self).__init__()
#         self.component_type = "status_flags"
#         self._status_flags = set(status_flags)
#         self._temp_status_flags = set()
# 
#     def has_status(self, status):
#         """
#         Returns True if parent entity has the status given.
#         """
#         if not self.next is None:
#             return (status in self._status_flags or
#                     status in self._temp_status_flags or
#                     next.has_status(status))
#         else:
#             return (status in self._status_flags or
#                     status in self._temp_status_flags)
# 
#     def add_temp_status(self, status):
#         """
#         Adds a temporary status that will be removed the next tick.
#         """
#         self._temp_status_flags.add(status)
# 
#     def before_tick(self, time):
#         self._temp_status_flags = set()


import random
import trigger
import colors
import gametime
import icon
import messenger
from animation import animate_point
from compositecore import Leaf
from graphic import GraphicChar
from statusflags import StatusFlags
        self.crit_chance = crit_chance
        self.crit_multiplier = crit_multiplier
        self.crit_message = crit_message

    def send_miss_message(self):
        messenger.msg.send_visual_message(self.miss_message %
                                          {"source_entity": self.source_entity.description.long_name,
                                           "target_entity": self.target_entity.description.long_name},
                                          self.target_entity.position.value)

    def send_hit_message(self, message_template, damage_caused):
        source_entity_name = self.source_entity.description.long_name if self.source_entity else None
        target_entity_name = self.target_entity.description.long_name if self.target_entity else None
        m = message_template % {"source_entity": source_entity_name,
                                "target_entity": target_entity_name,
                                "damage": str(int(damage_caused))}
        messenger.msg.send_visual_message(m, self.target_entity.position.value)

    def is_a_hit(self):
        return self.target_entity.dodger.is_a_hit(self.accuracy) or self.target_entity.has("sleeping")

    def is_a_crit(self):
        return self.crit_chance > random.random() or self.target_entity.has("sleeping")

    def hit_target(self):
        is_crit = self.is_a_crit()
        damage = self.damage
        if is_crit:
            damage = self.damage * self.crit_multiplier
            animate_point(self.target_entity.game_state.value, self.target_entity.position.value,

# Path: animation.py
# def animate_point(game_state, position, graphic_chars):
#     if not game_state.player.dungeon_mask.can_see_point(position):
#         return
#     camera = game_state.camera
#     x, y = camera.dungeon_to_screen_position(position)
#     for graphic_char in graphic_chars:
#         game_state.prepare_draw()
#         console.set_color_fg((x, y), graphic_char.color_fg)
#         console.set_symbol((x, y), graphic_char.icon)
#         for _ in range(settings.MISSILE_ANIMATION_DELAY):
#             console.flush()
# 
# Path: compositecore.py
# class Leaf(Component):
#     """
#     Abstract leaf class of composite design pattern.
# 
#     Component classes of leaf type should inherit from this class.
#     """
# 
#     def __init__(self):
#         super(Leaf, self).__init__()
# 
#     def get_relative_of_type(self, component_type):
#         return self.parent.get_child_or_ancestor(component_type)
# 
#     def has_relative_of_type(self, component_type):
#         return self.parent.has_child_or_ancestor(component_type)
# 
# Path: graphic.py
# class GraphicChar(Leaf):
#     """
#     Composites holding this has a graphical representation as a char.
#     """
# 
#     def __init__(self, color_bg, color_fg, icon):
#         super(GraphicChar, self).__init__()
#         self.component_type = "graphic_char"
#         self._color_bg = color_bg
#         self._color_fg = color_fg
#         self._icon = icon
# 
#     @property
#     def color_bg(self):
#         if self._color_bg:
#             return self._color_bg
#         elif self.next:
#             return self.next.color_bg
#         return None
# 
# 
#     @color_bg.setter
#     def color_bg(self, value):
#         self._color_bg = value
# 
#     @property
#     def color_fg(self):
#         if self._color_fg:
#             return self._color_fg
#         elif self.next:
#             return self.next.color_fg
#         return None
# 
#     @color_fg.setter
#     def color_fg(self, value):
#         self._color_fg = value
# 
#     @property
#     def icon(self):
#         if self._icon:
#             return self._icon
#         elif self.next:
#             return self.next.icon
#         return None
# 
#     @icon.setter
#     def icon(self, value):
#         self._icon = value
# 
#     def copy(self):
#         """
#         Makes a copy of this component.
#         """
#         return GraphicChar(self.color_bg, self.color_fg, self.icon)
# 
# Path: statusflags.py
# class StatusFlags(Leaf):
#     """
#     Composites holding this has status flags, describing their behaviour.
#     """
#     INVISIBILE = 0
#     SEE_INVISIBILITY = 1
#     FLYING = 2
#     IS_ALIVE = 3
#     CAN_OPEN_DOORS = 4
#     HAS_HEART = 5
# 
#     def __init__(self, status_flags=[]):
#         super(StatusFlags, self).__init__()
#         self.component_type = "status_flags"
#         self._status_flags = set(status_flags)
#         self._temp_status_flags = set()
# 
#     def has_status(self, status):
#         """
#         Returns True if parent entity has the status given.
#         """
#         if not self.next is None:
#             return (status in self._status_flags or
#                     status in self._temp_status_flags or
#                     next.has_status(status))
#         else:
#             return (status in self._status_flags or
#                     status in self._temp_status_flags)
# 
#     def add_temp_status(self, status):
#         """
#         Adds a temporary status that will be removed the next tick.
#         """
#         self._temp_status_flags.add(status)
# 
#     def before_tick(self, time):
#         self._temp_status_flags = set()


# Path: entityeffect.py
import random
import trigger
import colors
import gametime
import icon
import messenger
from animation import animate_point
from compositecore import Leaf
from graphic import GraphicChar
from statusflags import StatusFlags

        self.crit_chance = crit_chance
        self.crit_multiplier = crit_multiplier
        self.crit_message = crit_message

    def send_miss_message(self):
        messenger.msg.send_visual_message(self.miss_message %
                                          {"source_entity": self.source_entity.description.long_name,
                                           "target_entity": self.target_entity.description.long_name},
                                          self.target_entity.position.value)

    def send_hit_message(self, message_template, damage_caused):
        source_entity_name = self.source_entity.description.long_name if self.source_entity else None
        target_entity_name = self.target_entity.description.long_name if self.target_entity else None
        m = message_template % {"source_entity": source_entity_name,
                                "target_entity": target_entity_name,
                                "damage": str(int(damage_caused))}
        messenger.msg.send_visual_message(m, self.target_entity.position.value)

    def is_a_hit(self):
        return self.target_entity.dodger.is_a_hit(self.accuracy) or self.target_entity.has("sleeping")

    def is_a_crit(self):
        return self.crit_chance > random.random() or self.target_entity.has("sleeping")

    def hit_target(self):
        is_crit = self.is_a_crit()
        damage = self.damage
        if is_crit:
            damage = self.damage * self.crit_multiplier
            animate_point(self.target_entity.game_state.value, self.target_entity.position.value,

                          [GraphicChar(None, colors.RED, "X")])