NearAttackableEvent.py 1.2KB

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