summon.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. # This Python file uses the following encoding: utf-8
  2. # @author runhey
  3. # github https://github.com/runhey
  4. import time
  5. import random
  6. from tasks.Component.Summon.assets import SummonAssets
  7. from tasks.base_task import BaseTask
  8. from module.logger import logger
  9. import re
  10. class Summon(BaseTask, SummonAssets):
  11. def summon(self):
  12. """
  13. 召唤, 就是随机画一个, 划线
  14. :return:
  15. """
  16. self.screenshot()
  17. random_swipe = random.randint(0, 3)
  18. target_swipe = None
  19. match random_swipe:
  20. case 0: target_swipe = self.S_RANDOM_SWIPE_1
  21. case 1: target_swipe = self.S_RANDOM_SWIPE_2
  22. case 2: target_swipe = self.S_RANDOM_SWIPE_3
  23. case 3: target_swipe = self.S_RANDOM_SWIPE_4
  24. case _: target_swipe = self.S_RANDOM_SWIPE_1
  25. self.swipe(target_swipe, interval=0.5)
  26. def summon_mystery_pattern(self):
  27. """
  28. 每月神秘图案
  29. :return:
  30. """
  31. # 目前只测试了7月的,其他月份的我是根据截图描的,可能需要调整
  32. # 一月
  33. jan = [(400, 119), (406, 525), (862, 123), (864, 521), (402, 121)]
  34. # 二月、八月
  35. febAndAug = [(450, 105), (453, 525)]
  36. # 三月、九月
  37. marAndSep = [(390, 304), (886, 302)]
  38. # 四月、十月
  39. aprAndOct = [(402, 526), (862, 125)]
  40. # 五月、十一月
  41. mayAndNov = [(414, 207), (648, 550), (870, 209)]
  42. # 六月、十二月
  43. junAndDec = [(413, 138), (850, 133), (856, 226), (415, 239), (416, 140), (531, 136), (535, 590), (791, 586),
  44. (760, 131)]
  45. # 七月
  46. jul = [(418, 124), (421, 504), (853, 511), (855, 128)]
  47. # 月份字典
  48. month_dict = {
  49. 1: jan,
  50. 2: febAndAug,
  51. 3: marAndSep,
  52. 4: aprAndOct,
  53. 5: mayAndNov,
  54. 6: junAndDec,
  55. 7: jul,
  56. 8: febAndAug,
  57. 9: marAndSep,
  58. 10: aprAndOct,
  59. 11: mayAndNov,
  60. 12: junAndDec
  61. }
  62. # 获取当前月份
  63. current_month = time.localtime().tm_mon
  64. current_pattern = month_dict.get(current_month, None)
  65. if current_pattern is None:
  66. logger.warning(f'不支持的月份: {current_month}')
  67. return
  68. self.screenshot()
  69. self.device.draw_adb(current_pattern)
  70. def summon_one(self,draw_mystery_pattern=False):
  71. """
  72. 确保在召唤界面,每日召唤一次
  73. 召唤结束后回到 召唤主界面
  74. :return:
  75. """
  76. logger.info('Summon one')
  77. self.wait_until_appear(self.I_BLUE_TICKET)
  78. while True:
  79. ticket_info = self.O_ONE_TICKET.ocr(self.device.image)
  80. # 处理 None 和空字符串
  81. if ticket_info is None or ticket_info == '':
  82. ticket_info = 0
  83. else:
  84. # 使用正则表达式提取字符串中的数字
  85. match = re.search(r'\d+', ticket_info)
  86. if match:
  87. ticket_info = int(match.group())
  88. else:
  89. logger.warning(f'Invalid ticket_info value: {ticket_info}, expected a numeric string')
  90. ticket_info = 0 # 将无效值设置为默认值 0
  91. if ticket_info <= 0:
  92. logger.warning('There is no any one blue ticket')
  93. return
  94. # 某些情况下滑动异常
  95. self.S_RANDOM_SWIPE_1.name = 'S_RANDOM_SWIPE'
  96. self.S_RANDOM_SWIPE_2.name = 'S_RANDOM_SWIPE'
  97. self.S_RANDOM_SWIPE_3.name = 'S_RANDOM_SWIPE'
  98. self.S_RANDOM_SWIPE_4.name = 'S_RANDOM_SWIPE'
  99. while 1:
  100. self.screenshot()
  101. if self.appear(self.I_ONE_TICKET):
  102. break
  103. if self.appear_then_click(self.I_BLUE_TICKET, interval=1):
  104. continue
  105. # 画一张票
  106. time.sleep(0.5)
  107. while 1:
  108. self.screenshot()
  109. if self.appear(self.I_SM_CONFIRM, interval=0.6):
  110. self.ui_click_until_disappear(self.I_SM_CONFIRM)
  111. break
  112. if self.appear(self.I_SM_CONFIRM_2, interval=0.6):
  113. self.ui_click_until_disappear(self.I_SM_CONFIRM_2)
  114. break
  115. if self.appear(self.I_ONE_TICKET, interval=1):
  116. # 某些时候会点击到 “语言召唤”
  117. if self.appear_then_click(self.I_UI_CANCEL, interval=0.8):
  118. continue
  119. if draw_mystery_pattern:
  120. self.summon_mystery_pattern()
  121. else:
  122. self.summon()
  123. continue
  124. logger.info('Summon one success')
  125. def back_summon_main(self):
  126. """
  127. 返回召唤主界面
  128. :return:
  129. """
  130. while 1:
  131. self.screenshot()
  132. if self.appear(self.I_BLUE_TICKET):
  133. break
  134. if self.appear_then_click(self.I_UI_BACK_YELLOW):
  135. continue
  136. if self.appear_then_click(self.I_UI_BACK_YELLOW):
  137. continue