# 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

class EffectQueue(Leaf):
    def __init__(self):
        super(EffectQueue, self).__init__()
        self.component_type = "effect_queue"
        self._effect_queue = [None for _ in range(len(EffectTypes.ALLTYPES))]
        for effect_type in EffectTypes.ALLTYPES:
            self._effect_queue[effect_type] = []

    @property
    def effects(self):
        return [effect for effect_group in self._effect_queue for effect in effect_group]

    def add(self, effect):
        if effect.meld_id:
            if not any(effect.meld_id == e.meld_id for e in self.effects):
                self._add(effect)
            else:
                [e for e in self.effects][0].meld(effect)
        else:
            self._add(effect)

    def _add(self, effect):
        self._effect_queue[effect.effect_type].append(effect)
        effect.queue = self

    def remove(self, effect):
        self._effect_queue[effect.effect_type].remove(effect)
        effect.queue = None


# 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


class EffectQueue(Leaf):
    def __init__(self):
        super(EffectQueue, self).__init__()
        self.component_type = "effect_queue"
        self._effect_queue = [None for _ in range(len(EffectTypes.ALLTYPES))]
        for effect_type in EffectTypes.ALLTYPES:
            self._effect_queue[effect_type] = []

    @property
    def effects(self):
        return [effect for effect_group in self._effect_queue for effect in effect_group]

    def add(self, effect):
        if effect.meld_id:
            if not any(effect.meld_id == e.meld_id for e in self.effects):
                self._add(effect)
            else:
                [e for e in self.effects][0].meld(effect)
        else:
            self._add(effect)

    def _add(self, effect):
        self._effect_queue[effect.effect_type].append(effect)
        effect.queue = self

    def remove(self, effect):
        self._effect_queue[effect.effect_type].remove(effect)
        effect.queue = None


    def remove_effects_with_id(self, effect_id):