switch_soul.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. # This Python file uses the following encoding: utf-8
  2. # @author runhey
  3. # github https://github.com/runhey
  4. from time import sleep
  5. from module.base.timer import Timer
  6. from tasks.base_task import BaseTask
  7. from tasks.Component.GeneralInvite.assets import GeneralInviteAssets
  8. from tasks.Component.GeneralInvite.config_invite import InviteConfig, InviteNumber, FindMode
  9. from tasks.Component.SwitchSoul.assets import SwitchSoulAssets
  10. from module.logger import logger
  11. class SwitchSoul(BaseTask, SwitchSoulAssets):
  12. def run_switch_soul(self, target: tuple or list[tuple]):
  13. """
  14. 保证在式神录的界面
  15. :return:
  16. """
  17. self.click_preset()
  18. self.switch_souls(target)
  19. def click_preset(self) -> None:
  20. """
  21. 点击预设
  22. :return:
  23. """
  24. while 1:
  25. self.screenshot()
  26. if self.appear(self.I_SOU_SWITCH_1):
  27. break
  28. if self.appear(self.I_SOU_SWITCH_2):
  29. break
  30. if self.appear(self.I_SOU_SWITCH_3):
  31. break
  32. if self.appear(self.I_SOU_SWITCH_4):
  33. break
  34. if self.appear_then_click(self.I_SOUL_PRESET, interval=1):
  35. continue
  36. logger.info('Click preset in switch soul')
  37. def switch_soul_one(self, group: int, team: int) -> None:
  38. """
  39. 设置一个队伍的预设御魂
  40. :param group: 只能是[1-7]
  41. :param team: 只能是[1-4]
  42. :return:
  43. """
  44. def get_group_assets(group: int) -> tuple:
  45. match = {
  46. 1: tuple([self.C_SOU_GROUP_1, self.I_SOU_CHECK_GROUP_1]),
  47. 2: tuple([self.C_SOU_GROUP_2, self.I_SOU_CHECK_GROUP_2]),
  48. 3: tuple([self.C_SOU_GROUP_3, self.I_SOU_CHECK_GROUP_3]),
  49. 4: tuple([self.C_SOU_GROUP_4, self.I_SOU_CHECK_GROUP_4]),
  50. 5: tuple([self.C_SOU_GROUP_5, self.I_SOU_CHECK_GROUP_5]),
  51. 6: tuple([self.C_SOU_GROUP_6, self.I_SOU_CHECK_GROUP_6]),
  52. 7: tuple([self.C_SOU_GROUP_7, self.I_SOU_CHECK_GROUP_7]),
  53. }
  54. return match[group]
  55. def get_team_asset(team: int):
  56. match = {
  57. 1: self.I_SOU_SWITCH_1,
  58. 2: self.I_SOU_SWITCH_2,
  59. 3: self.I_SOU_SWITCH_3,
  60. 4: self.I_SOU_SWITCH_4,
  61. }
  62. return match[team]
  63. if group < 1 or group > 7:
  64. raise ValueError('Switch soul_one group must be in [1-7]')
  65. if team < 1 or team > 4:
  66. raise ValueError('Switch soul_one team must be in [1-4]')
  67. target_click, target_check = get_group_assets(group)
  68. while 1:
  69. self.screenshot()
  70. if self.appear(target_check):
  71. break
  72. if self.appear_then_click(target_click, interval=1):
  73. continue
  74. # 点击队伍
  75. target_team = get_team_asset(team)
  76. for i in range(3):
  77. sleep(0.8)
  78. self.screenshot()
  79. if self.appear_then_click(self.I_SOU_SWITCH_SURE, interval=1):
  80. continue
  81. if not self.appear_then_click(target_team, interval=1):
  82. logger.warning(f'Click team {team} failed in group {group}')
  83. logger.info(f'Switch soul_one group {group} team {team}')
  84. def switch_souls(self, target: tuple or list[tuple]) -> None:
  85. """
  86. 切换御魂
  87. :param target: [(1, 1), (2, 2), (3, 3), (4, 4)] 或者是单独的一个元组(4, 4) 第一个是组, 第二个是队伍
  88. :return:
  89. """
  90. if isinstance(target, tuple):
  91. target = [target]
  92. for group, team in target:
  93. group = int(group)
  94. team = int(team)
  95. self.switch_soul_one(group, team)
  96. def exit_shikigami_records(self) -> None:
  97. """
  98. 退出式神录的界面
  99. :return:
  100. """
  101. while 1:
  102. self.screenshot()
  103. if not self.appear(self.I_SOU_CHECK_IN):
  104. break
  105. if self.appear_then_click(self.I_RECORD_SOUL_BACK, interval=1):
  106. continue
  107. logger.info('Exit shikigami records')
  108. if __name__ == '__main__':
  109. from module.config.config import Config
  110. from module.device.device import Device
  111. c = Config('oas1')
  112. d = Device(c)
  113. s = SwitchSoul(c, d)
  114. s.click_preset()
  115. s.switch_soul_one(7, 2)