MoveAction.py 1.3KB

123456789101112131415161718192021222324252627282930313233
  1. from synergine.synergy.event.Action import Action
  2. from intelligine.synergy.event.move.MoveEvent import MoveEvent
  3. from synergine.synergy.event.exception.ActionAborted import ActionAborted
  4. from intelligine.cst import BRAIN_PART_MOVE
  5. from synergine_xyz.cst import BLOCKED_SINCE
  6. class MoveAction(Action):
  7. _listen = MoveEvent
  8. def __init__(self, object_id, parameters):
  9. super().__init__(object_id, parameters)
  10. self._move_to_point = None
  11. self._move_to_direction = None
  12. def run(self, obj, context, synergy_manager):
  13. try:
  14. self._apply_move(obj, context)
  15. except ActionAborted:
  16. # TODO: Dans l'obj ces lignes
  17. blocked_since = context.metas.value.get(BLOCKED_SINCE, self._object_id, allow_empty=True, empty_value=0)
  18. context.metas.value.set(BLOCKED_SINCE, obj.get_id(), blocked_since+1)
  19. def _apply_move(self, obj, context):
  20. # TODO: il ne faut pas choisir une direction 14.
  21. if MoveEvent.PARAM_DIRECTION not in self._parameters or self._parameters[MoveEvent.PARAM_DIRECTION] == 14:
  22. raise ActionAborted()
  23. obj.set_position(self._parameters[MoveEvent.PARAM_POSITION])
  24. obj.set_previous_direction(self._parameters[MoveEvent.PARAM_DIRECTION])
  25. obj.get_brain().get_part(BRAIN_PART_MOVE).done(obj, context)