summon.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. class Summon(BaseTask, SummonAssets):
  10. def summon(self):
  11. """
  12. 召唤, 就是随机画一个, 划线
  13. :return:
  14. """
  15. self.screenshot()
  16. random_swipe = random.randint(0, 3)
  17. target_swipe = None
  18. match random_swipe:
  19. case 0: target_swipe = self.S_RANDOM_SWIPE_1
  20. case 1: target_swipe = self.S_RANDOM_SWIPE_2
  21. case 2: target_swipe = self.S_RANDOM_SWIPE_3
  22. case 3: target_swipe = self.S_RANDOM_SWIPE_4
  23. case _: target_swipe = self.S_RANDOM_SWIPE_1
  24. self.swipe(target_swipe, interval=0.5)
  25. def summon_one(self):
  26. """
  27. 确保在召唤界面,每日召唤一次
  28. 召唤结束后回到 召唤主界面
  29. :return:
  30. """
  31. logger.info('Summon one')
  32. self.wait_until_appear(self.I_BLUE_TICKET)
  33. ticket_info = self.O_ONE_TICKET.ocr(self.device.image)
  34. if '1' not in ticket_info:
  35. logger.warning('There is no any one blue ticket')
  36. return
  37. while 1:
  38. self.screenshot()
  39. if self.appear(self.I_ONE_TICKET):
  40. break
  41. if self.appear_then_click(self.I_BLUE_TICKET, interval=1):
  42. continue
  43. # 画一张票
  44. time.sleep(0.5)
  45. while 1:
  46. self.screenshot()
  47. if self.appear(self.I_SM_CONFIRM):
  48. logger.info('Summon one success')
  49. break
  50. if self.appear(self.I_ONE_TICKET, interval=1):
  51. self.summon()
  52. continue
  53. while 1:
  54. self.screenshot()
  55. if not self.appear(self.I_SM_CONFIRM):
  56. break
  57. if self.appear_then_click(self.I_SM_CONFIRM):
  58. continue
  59. def back_summon_main(self):
  60. """
  61. 返回召唤主界面
  62. :return:
  63. """
  64. while 1:
  65. self.screenshot()
  66. if self.appear(self.I_BLUE_TICKET):
  67. break
  68. if self.appear_then_click(self.I_UI_BACK_BLUE):
  69. continue
  70. if self.appear_then_click(self.I_UI_BACK_YELLOW):
  71. continue