event.py 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # coding: utf-8
  2. import typing
  3. from synergine2.simulation import Event
  4. from opencombat.const import COLLECTION_ALIVE
  5. if typing.TYPE_CHECKING:
  6. from opencombat.simulation.subject import TileSubject
  7. DEFAULT_WEAPON_TYPE = 'DEFAULT_WEAPON_TYPE'
  8. class NewVisibleOpponent(Event):
  9. def __init__(
  10. self,
  11. observer_subject_id: int,
  12. observed_subject_id: int,
  13. ) -> None:
  14. self.observer_subject_id = observer_subject_id
  15. self.observed_subject_id = observed_subject_id
  16. class NoLongerVisibleOpponent(Event):
  17. def __init__(
  18. self,
  19. observer_subject_id: int,
  20. observed_subject_id: int,
  21. ) -> None:
  22. self.observer_subject_id = observer_subject_id
  23. self.observed_subject_id = observed_subject_id
  24. class FireEvent(Event):
  25. def __init__(
  26. self,
  27. shooter_subject_id: int,
  28. target_position: typing.Tuple[int, int],
  29. weapon_type: str=DEFAULT_WEAPON_TYPE,
  30. ) -> None:
  31. self.shooter_subject_id = shooter_subject_id
  32. self.target_position = target_position
  33. self.weapon_type = weapon_type
  34. class DieEvent(Event):
  35. @classmethod
  36. def apply_subject_death(cls, subject: 'TileSubject') -> None:
  37. subject.remove_collection(COLLECTION_ALIVE)
  38. subject.intentions.remove_all()
  39. def __init__(
  40. self,
  41. shooter_subject_id: int,
  42. shoot_subject_id: int,
  43. ) -> None:
  44. self.shooter_subject_id = shooter_subject_id
  45. self.shoot_subject_id = shoot_subject_id