TakeableAction.py 1.2KB

123456789101112131415161718192021222324252627282930
  1. from intelligine.synergy.event.move.MoveAction import MoveAction
  2. from synergine.core.Core import Core
  3. from synergine.synergy.event.Action import Action
  4. from intelligine.synergy.event.transport.TakeableEvent import TakeableEvent
  5. from intelligine.cst import CANT_PUT_STILL, BRAIN_PART_TAKE
  6. from synergine.synergy.event.exception.ActionAborted import ActionAborted
  7. class TakeableAction(Action):
  8. _listen = TakeableEvent
  9. _depend = [MoveAction]
  10. def __init__(self, object_id, parameters):
  11. super().__init__(object_id, parameters)
  12. def run(self, obj, context, synergy_manager):
  13. obj_id_transportable = self._parameters[TakeableEvent.PARAM_TAKE]
  14. obj_transportable = synergy_manager.get_map().get_object(obj_id_transportable)
  15. if not obj_transportable.is_takable():
  16. raise ActionAborted()
  17. obj_carried = obj_transportable.get_what_carry()
  18. obj_carried.set_carried_by(obj)
  19. obj.carry(obj_carried)
  20. cant_put_still = Core.get_configuration_manager().get('ant.take.cant_put_still')
  21. context.metas.value.set(CANT_PUT_STILL, obj.get_id(), cant_put_still)
  22. obj.get_brain().get_part(BRAIN_PART_TAKE).done(obj, obj_carried, context)