login.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. # This Python file uses the following encoding: utf-8
  2. # @author runhey
  3. # github https://github.com/runhey
  4. from tasks.Restart.config_scheduler import Scheduler
  5. from module.logger import logger
  6. from module.base.timer import Timer
  7. from tasks.Restart.assets import RestartAssets
  8. from tasks.base_task import BaseTask
  9. from module.exception import TaskEnd, RequestHumanTakeover, GameTooManyClickError, GameStuckError
  10. class LoginHandler(BaseTask, RestartAssets):
  11. def _app_handle_login(self) -> bool:
  12. """
  13. 最终是在庭院界面
  14. :return:
  15. """
  16. logger.hr('App login')
  17. confirm_timer = Timer(1.5, count=2).start()
  18. orientation_timer = Timer(10)
  19. login_success = False
  20. while 1:
  21. # Watch device rotation
  22. if not login_success and orientation_timer.reached():
  23. # Screen may rotate after starting an app
  24. self.device.get_orientation()
  25. orientation_timer.reset()
  26. self.screenshot()
  27. # 确认进入庭院
  28. if self.appear_then_click(self.I_LOGIN_SCROOLL_CLOSE, interval=2):
  29. logger.info('Open scroll')
  30. continue
  31. if self.appear(self.I_LOGIN_SCROOLL_OPEN, interval=0.2):
  32. if confirm_timer.reached():
  33. logger.info('Login to main confirm')
  34. break
  35. else:
  36. confirm_timer.reset()
  37. # 登录成功
  38. if self.appear(self.I_LOGIN_SCROOLL_OPEN, interval=0.5):
  39. logger.info('Login success')
  40. login_success = True
  41. # 网络异常
  42. # if self.ocr_appear(self.O_LOGIN_NETWORK):
  43. # logger.error('Network error')
  44. # raise RequestHumanTakeover('Network error')
  45. # 右上角的红色的关闭
  46. if self.appear_then_click(self.I_LOGIN_RED_CLOSE, interval=0.6):
  47. logger.info('Close red close')
  48. continue
  49. # 左上角的黄色关闭
  50. if self.appear_then_click(self.I_LOGIN_YELLOW_CLOSE, interval=0.6):
  51. logger.info('Close yellow close')
  52. continue
  53. # 点击’进入游戏‘
  54. if not self.appear(self.I_LOGIN_8):
  55. continue
  56. if self.ocr_appear_click(self.O_LOGIN_ENTER_GAME, interval=2.5):
  57. continue
  58. return login_success
  59. def app_handle_login(self) -> bool:
  60. for _ in range(2):
  61. self.device.stuck_record_clear()
  62. self.device.click_record_clear()
  63. try:
  64. self._app_handle_login()
  65. if self.config.restart.harvest_config.enable:
  66. self.harvest()
  67. return True
  68. except (GameTooManyClickError, GameStuckError) as e:
  69. logger.warning(e)
  70. self.device.app_stop()
  71. self.device.app_start()
  72. continue
  73. logger.critical('Login failed more than 3')
  74. logger.critical('Azur Lane server may be under maintenance, or you may lost network connection')
  75. raise RequestHumanTakeover
  76. def harvest(self):
  77. """
  78. 获得奖励
  79. :return: 如果没有发现任何奖励后退出
  80. """
  81. logger.hr('Harvest')
  82. timer_harvest = Timer(3) # 如果连续3秒没有发现任何奖励,退出
  83. while 1:
  84. self.screenshot()
  85. # 点击'获得奖励'
  86. if self.ui_reward_appear_click():
  87. continue
  88. # 获得奖励
  89. if self.appear_then_click(self.I_UI_AWARD, interval=1):
  90. continue
  91. # 勾玉
  92. if self.appear_then_click(self.I_HARVEST_JADE, interval=1):
  93. continue
  94. # 签到
  95. if self.appear_then_click(self.I_HARVEST_SIGN, interval=1):
  96. continue
  97. if self.appear_then_click(self.I_HARVEST_SIGN_2, interval=1):
  98. continue
  99. # 999天的签到福袋
  100. if self.appear_then_click(self.I_HARVEST_SIGN_999, interval=1):
  101. continue
  102. # 邮件
  103. if self.appear_then_click(self.I_HARVEST_MAIL, interval=1):
  104. continue
  105. if self.appear_then_click(self.I_HARVEST_MAIL_ALL, interval=1):
  106. continue
  107. if self.appear_then_click(self.I_HARVEST_MAIL_CONFIRM, interval=1):
  108. continue
  109. if self.appear_then_click(self.I_HARVEST_MAIL_OPEN, interval=1):
  110. continue
  111. # 红色的关闭
  112. if self.appear_then_click(self.I_UI_BACK_RED, interval=1):
  113. continue
  114. # 三秒内没有发现任何奖励,退出
  115. if not timer_harvest.started():
  116. timer_harvest.start()
  117. else:
  118. if timer_harvest.reached():
  119. logger.info('No more reward')
  120. return