# Path: intelligine/synergy/event/attack/NearAttackableEvent.py
# 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)
# 
#         try:
#             self.map(context, parameters, stop_at_first=True, filter=filter)
#         except NearNothingFound:
#             raise NotConcernedEvent()
# 
#         brain_part = get_brain_part(context, object_id, BRAIN_PART_ATTACK)
#         if not brain_part.can_attack(context, object_id, parameters[self._near_name][0]):
#             raise NotConcernedEvent()
# 
#         return parameters


from synergine.synergy.event.Action import Action
from intelligine.synergy.event.attack.NearAttackableEvent import NearAttackableEvent
from random import randint


class NearAttackableAction(Action):

    _listen = NearAttackableEvent

    def __init__(self, object_id, parameters):
        super().__init__(object_id, parameters)

    def prepare(self, context):
        pass

    def run(self, obj, context, synergy_manager):
        # TODO: reprendre ?
        for obj_id_attackable in self._parameters['objects_ids_attackable']:

# Path: intelligine/synergy/event/attack/NearAttackableEvent.py
# 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)
# 
#         try:
#             self.map(context, parameters, stop_at_first=True, filter=filter)
#         except NearNothingFound:
#             raise NotConcernedEvent()
# 
#         brain_part = get_brain_part(context, object_id, BRAIN_PART_ATTACK)
#         if not brain_part.can_attack(context, object_id, parameters[self._near_name][0]):
#             raise NotConcernedEvent()
# 
#         return parameters


# Path: intelligine/synergy/event/attack/NearAttackableAction.py
from synergine.synergy.event.Action import Action
from intelligine.synergy.event.attack.NearAttackableEvent import NearAttackableEvent
from random import randint



class NearAttackableAction(Action):

    _listen = NearAttackableEvent

    def __init__(self, object_id, parameters):
        super().__init__(object_id, parameters)

    def prepare(self, context):
        pass

    def run(self, obj, context, synergy_manager):
        # TODO: reprendre ?
        for obj_id_attackable in self._parameters['objects_ids_attackable']:

            obj_attackable = synergy_manager.get_map().get_object(obj_id_attackable)