TakeableAction.py 1.1KB

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