TakeableEvent.py 1.3KB

123456789101112131415161718192021222324252627
  1. from synergine.synergy.event.Event import Event
  2. from xyzworld.mechanism.ArroundMechanism import ArroundMechanism
  3. from intelligine.synergy.Simulation import Simulation
  4. from intelligine.cst import TRANSPORTABLE, TRANSPORTER, ALIVE, CARRYING
  5. class TakeableEvent(Event):
  6. def concern(self, object_id, context):
  7. return context.metas.list.have(Simulation.STATE, object_id, TRANSPORTER) and \
  8. context.metas.list.have(Simulation.STATE, object_id, ALIVE) and \
  9. not context.metas.list.have(Simulation.STATE, object_id, CARRYING)
  10. def __init__(self, actions):
  11. super().__init__(actions)
  12. self._mechanism = ArroundMechanism
  13. def _object_match(self, object_id, context, parameters={}):
  14. # TODO: Nettoyer (refact possible sur ces objets ont tel states, comme dans concern)
  15. for obj_near_id in parameters['objects_ids_near']:
  16. if context.metas.list.have(Simulation.STATE, obj_near_id, TRANSPORTABLE):
  17. if 'objects_ids_transportable' not in parameters:
  18. parameters['objects_ids_transportable'] = []
  19. parameters['objects_ids_transportable'].append(obj_near_id)
  20. if 'objects_ids_transportable' not in parameters:
  21. return False
  22. return True