NearAttackableEvent.py 1.1KB

123456789101112131415161718192021222324252627
  1. from synergine.synergy.event.Event import Event
  2. from xyzworld.mechanism.ArroundMechanism import ArroundMechanism
  3. from intelligine.cst import ATTACKER, ATTACKABLE, COLONY, ALIVE
  4. class NearAttackableEvent(Event):
  5. def concern(self, object_id, context):
  6. return context.metas.states.have(object_id, [ATTACKER, ALIVE])
  7. def __init__(self, actions):
  8. super().__init__(actions)
  9. self._mechanism = ArroundMechanism
  10. def _object_match(self, object_id, context, parameters={}):
  11. # TODO: nettoyer
  12. obj_colony_id = context.metas.value.get(COLONY, object_id)
  13. for obj_near_id in parameters['objects_ids_near']:
  14. if context.metas.states.have(obj_near_id, [ATTACKABLE]):
  15. if obj_colony_id != context.metas.value.get(COLONY, obj_near_id):
  16. if 'objects_ids_attackable' not in parameters:
  17. parameters['objects_ids_attackable'] = []
  18. parameters['objects_ids_attackable'].append(obj_near_id)
  19. if 'objects_ids_attackable' not in parameters:
  20. return False
  21. return True