switch_soul.py 4.7 KB

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