TakeableEvent.py 1.4KB

12345678910111213141516171819202122232425262728
  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, CANT_CARRY_STILL
  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) and \
  10. not context.metas.value.get(CANT_CARRY_STILL, object_id, allow_empty=True)
  11. def __init__(self, actions):
  12. super().__init__(actions)
  13. self._mechanism = ArroundMechanism
  14. def _object_match(self, object_id, context, parameters={}):
  15. # TODO: Nettoyer (refact possible sur ces objets ont tel states, comme dans concern)
  16. for obj_near_id in parameters['objects_ids_near']:
  17. if context.metas.list.have(Simulation.STATE, obj_near_id, TRANSPORTABLE):
  18. if 'objects_ids_transportable' not in parameters:
  19. parameters['objects_ids_transportable'] = []
  20. parameters['objects_ids_transportable'].append(obj_near_id)
  21. if 'objects_ids_transportable' not in parameters:
  22. return False
  23. return True