switch_soul.py 4.5 KB

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