# Path: intelligine/core/exceptions.py
# class NearNothingFound(NearException):
#     pass
# 
# Path: intelligine/shorcut/brain.py
# def get_brain_part(context, object_id, brain_part_name):
#     object_class = context.metas.value.get(INSTANCE_CLASS, object_id)
#     object_brain_schema = context.metas.value.get(BRAIN_SCHEMA, object_class)
#     return object_brain_schema[brain_part_name]
# 
# Path: intelligine/synergy/event/src/NearEvent.py
# class NearEvent(Event):
# 
#     _mechanism = AroundMechanism
#     _near_name = None
#     _near_map = lambda self, near_object_id, context: False
# 
#     # TODO: parameters en entre/sortie c pas bon ca
#     def map(self, context, parameters, stop_at_first=False, filter=lambda near_object_id, context: True):
#         parameters[self._near_name] = []
#         for near_object_id in parameters['objects_ids_near']:
#             if self._near_map(near_object_id, context) and filter(near_object_id, context):
#                 parameters[self._near_name].append(near_object_id)
#                 if stop_at_first:
#                     return
#         if not parameters[self._near_name]:
#             raise NearNothingFound()
# 
# Path: intelligine/cst.py
# ATTACKABLE = IncrementedNamedInt.get('intelligine.attackable')
# 
# COLONY = IncrementedNamedInt.get('intelligine.colony')
# 
# COL_FIGHTER = IncrementedNamedInt.get('intelligine.col.walker')
# 
# BRAIN_PART_ATTACK = IncrementedNamedInt.get('intelligine.brain.part.attack')


from intelligine.core.exceptions import NearNothingFound
from intelligine.shorcut.brain import get_brain_part
from synergine.core.exceptions import NotConcernedEvent
from intelligine.synergy.event.src.NearEvent import NearEvent
from synergine_xyz.mechanism.AroundMechanism import AroundMechanism
from intelligine.cst import ATTACKABLE, COLONY, COL_FIGHTER, BRAIN_PART_ATTACK


class NearAttackableEvent(NearEvent):

    _mechanism = AroundMechanism
    _concern = COL_FIGHTER
    _near_name = 'objects_ids_attackable'
    _near_map = lambda self, near_object_id, context: context.metas.states.have(near_object_id, ATTACKABLE)

    def _prepare(self, object_id, context, parameters={}):
        obj_colony_id = context.metas.value.get(COLONY, object_id)
        # TODO: Le critère pas la même colonie est du ressort du brain.

# Path: intelligine/core/exceptions.py
# class NearNothingFound(NearException):
#     pass
# 
# Path: intelligine/shorcut/brain.py
# def get_brain_part(context, object_id, brain_part_name):
#     object_class = context.metas.value.get(INSTANCE_CLASS, object_id)
#     object_brain_schema = context.metas.value.get(BRAIN_SCHEMA, object_class)
#     return object_brain_schema[brain_part_name]
# 
# Path: intelligine/synergy/event/src/NearEvent.py
# class NearEvent(Event):
# 
#     _mechanism = AroundMechanism
#     _near_name = None
#     _near_map = lambda self, near_object_id, context: False
# 
#     # TODO: parameters en entre/sortie c pas bon ca
#     def map(self, context, parameters, stop_at_first=False, filter=lambda near_object_id, context: True):
#         parameters[self._near_name] = []
#         for near_object_id in parameters['objects_ids_near']:
#             if self._near_map(near_object_id, context) and filter(near_object_id, context):
#                 parameters[self._near_name].append(near_object_id)
#                 if stop_at_first:
#                     return
#         if not parameters[self._near_name]:
#             raise NearNothingFound()
# 
# Path: intelligine/cst.py
# ATTACKABLE = IncrementedNamedInt.get('intelligine.attackable')
# 
# COLONY = IncrementedNamedInt.get('intelligine.colony')
# 
# COL_FIGHTER = IncrementedNamedInt.get('intelligine.col.walker')
# 
# BRAIN_PART_ATTACK = IncrementedNamedInt.get('intelligine.brain.part.attack')


# Path: intelligine/synergy/event/attack/NearAttackableEvent.py
from intelligine.core.exceptions import NearNothingFound
from intelligine.shorcut.brain import get_brain_part
from synergine.core.exceptions import NotConcernedEvent
from intelligine.synergy.event.src.NearEvent import NearEvent
from synergine_xyz.mechanism.AroundMechanism import AroundMechanism
from intelligine.cst import ATTACKABLE, COLONY, COL_FIGHTER, BRAIN_PART_ATTACK



class NearAttackableEvent(NearEvent):

    _mechanism = AroundMechanism
    _concern = COL_FIGHTER
    _near_name = 'objects_ids_attackable'
    _near_map = lambda self, near_object_id, context: context.metas.states.have(near_object_id, ATTACKABLE)

    def _prepare(self, object_id, context, parameters={}):
        obj_colony_id = context.metas.value.get(COLONY, object_id)
        # TODO: Le critère pas la même colonie est du ressort du brain.

        filter = lambda near_object_id, context: obj_colony_id != context.metas.value.get(COLONY, near_object_id)