host.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # This Python file uses the following encoding: utf-8
  2. # @author runhey
  3. # github https://github.com/runhey
  4. from cached_property import cached_property
  5. from tasks.GlobalGame.config import TeamFlow, Transport
  6. from module.team_flow.mqtt import Mqtt
  7. from module.config.config import Config
  8. from module.team_flow.player import Player
  9. from module.team_flow.task import Task
  10. def on_message(client, userdata, msg):
  11. userdata.match_topic[msg.topic](msg.payload)
  12. class Host(Mqtt, Player):
  13. def __init__(self, config: Config):
  14. Player.__init__(self, config.global_game.team_flow.username)
  15. Mqtt.__init__(self, config.global_game.team_flow)
  16. self.config = config
  17. self.players: list[Player] = []
  18. self.set_on_message(on_message)
  19. @cached_property
  20. def match_topic(self):
  21. return {
  22. 'FirstNotice': self.on_first_notice,
  23. 'LastWill': self.on_last_will,
  24. 'TaskStart': self.on_task_start,
  25. 'Strategy': self.on_strategy
  26. }
  27. def on_first_notice(self, payload):
  28. pass
  29. def on_last_will(self, payload):
  30. pass
  31. def on_task_start(self, payload):
  32. pass
  33. def on_strategy(self, payload):
  34. pass
  35. def update_multi_tasks(self):
  36. """
  37. 作为主角, 更新自身的多人任务的缓存
  38. 也就是从 config -> multi_tasks
  39. :return:
  40. """
  41. for key, value in self.config.model.items():
  42. if key == 'orochi':
  43. continue
  44. elif key == 'fallen_sun':
  45. continue
  46. elif key == 'eternity_sea':
  47. continue
  48. elif key == 'evo_zone':
  49. continue
  50. if __name__ == '__main__':
  51. host = Host(Config('oas1'))