behaviour.py 1.3KB

123456789101112131415161718192021222324252627282930
  1. # coding: utf-8
  2. import time
  3. from sandbox.tile.user_action import UserAction
  4. from synergine2.config import Config
  5. from synergine2.simulation import Simulation
  6. from synergine2.simulation import Subject
  7. from synergine2_xyz.move.simulation import MoveToBehaviour as BaseMoveToBehaviour
  8. class MoveToBehaviour(BaseMoveToBehaviour):
  9. def __init__(
  10. self,
  11. config: Config,
  12. simulation: Simulation,
  13. subject: Subject,
  14. ) -> None:
  15. super().__init__(config, simulation, subject)
  16. self._walk_duration = float(self.config.resolve('game.move.walk_ref_time'))
  17. self._run_duration = float(self.config.resolve('game.move.run_ref_time'))
  18. self._crawl_duration = float(self.config.resolve('game.move.crawl_ref_time'))
  19. def _can_move_to_next_step(self, move_to_data: dict) -> bool:
  20. if move_to_data['gui_action'] == UserAction.ORDER_MOVE:
  21. return time.time() - move_to_data['last_intention_time'] >= self._walk_duration
  22. if move_to_data['gui_action'] == UserAction.ORDER_MOVE_FAST:
  23. return time.time() - move_to_data['last_intention_time'] >= self._run_duration
  24. if move_to_data['gui_action'] == UserAction.ORDER_MOVE_CRAWL:
  25. return time.time() - move_to_data['last_intention_time'] >= self._crawl_duration