NearAttackableEvent.py 1.3KB

123456789101112131415161718192021222324252627282930
  1. from intelligine.core.exceptions import NearNothingFound
  2. from synergine.core.exceptions import NotConcernedEvent
  3. from intelligine.synergy.event.src.NearEvent import NearEvent
  4. from synergine_xyz.mechanism.AroundMechanism import AroundMechanism
  5. from intelligine.cst import ATTACKABLE, COLONY, COL_FIGHTER, BRAIN_PART_ATTACK
  6. class NearAttackableEvent(NearEvent):
  7. _mechanism = AroundMechanism
  8. _concern = COL_FIGHTER
  9. _near_name = 'objects_ids_attackable'
  10. _near_map = lambda self, near_object_id, context: context.metas.states.have(near_object_id, ATTACKABLE)
  11. def _prepare(self, object_id, context, parameters={}):
  12. obj_colony_id = context.metas.value.get(COLONY, object_id)
  13. # TODO: Le critère pas la même colonie est du ressort du brain.
  14. filter = lambda near_object_id, context: obj_colony_id != context.metas.value.get(COLONY, near_object_id)
  15. try:
  16. self.map(context, parameters, stop_at_first=True, filter=filter)
  17. except NearNothingFound:
  18. raise NotConcernedEvent()
  19. brain_part = self._get_brain_part(context, object_id, BRAIN_PART_ATTACK)
  20. if not brain_part.can_attack(context, object_id, parameters[self._near_name][0]):
  21. raise NotConcernedEvent()
  22. return parameters