host.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. task_name: str = key
  43. if key == 'orochi':
  44. continue
  45. elif key == 'fallen_sun':
  46. continue
  47. elif key == 'eternity_sea':
  48. continue
  49. elif key == 'evo_zone':
  50. continue
  51. elif key == 'soul':
  52. continue
  53. else:
  54. continue
  55. if __name__ == '__main__':
  56. host = Host(Config('oas1'))