NearAttackableEvent.py 1.3KB

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