script_task.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 datetime import time, datetime, timedelta
  6. from module.logger import logger
  7. from module.exception import TaskEnd
  8. from module.base.timer import Timer
  9. from tasks.GameUi.game_ui import GameUi
  10. from tasks.GameUi.page import page_main, page_team, page_shikigami_records
  11. from tasks.Component.GeneralBattle.general_battle import GeneralBattle
  12. from tasks.Component.GeneralRoom.general_room import GeneralRoom
  13. from tasks.Component.GeneralInvite.general_invite import GeneralInvite
  14. from tasks.Component.SwitchSoul.switch_soul import SwitchSoul
  15. class ScriptTask(GameUi, GeneralBattle, GeneralRoom, GeneralInvite, SwitchSoul):
  16. def run(self):
  17. conf = self.config.tako
  18. if conf.switch_soul.enable:
  19. self.ui_get_current_page()
  20. self.ui_goto(page_shikigami_records)
  21. self.run_switch_soul(conf.switch_soul.switch_group_team)
  22. if conf.switch_soul.enable_switch_by_name:
  23. self.ui_get_current_page()
  24. self.ui_goto(page_shikigami_records)
  25. self.run_switch_soul_by_name(conf.switch_soul.group_name,
  26. conf.switch_soul.team_name)
  27. # 加成
  28. conf_buff = conf.tako_config
  29. if conf_buff.enable:
  30. self.ui_get_current_page()
  31. self.ui_goto(page_main)
  32. self.open_buff()
  33. if conf_buff.buff_gold_50_click:
  34. self.gold_50()
  35. if conf_buff.buff_gold_100_click:
  36. self.gold_100()
  37. if conf_buff.buff_exp_50_click:
  38. self.exp_50()
  39. if conf_buff.buff_exp_100_click:
  40. self.exp_100()
  41. self.close_buff()
  42. # 进入
  43. self.ui_get_current_page()
  44. self.ui_goto(page_team)
  45. if 5 <= self.start_time.weekday() <= 6:
  46. # 周末
  47. self.check_zones('喷怒的石距')
  48. else:
  49. self.check_zones('石距')
  50. if not self.create_room():
  51. self.exit_task()
  52. self.ensure_public()
  53. self.create_ensure()
  54. # 进入到了房间里面
  55. wait_timer = Timer(60)
  56. wait_timer.start()
  57. while 1:
  58. self.screenshot()
  59. if not self.is_in_room():
  60. continue
  61. if wait_timer.reached():
  62. logger.warning('Wait for too long, exit')
  63. self.exit_room()
  64. break
  65. if not self.appear(self.I_ADD_1):
  66. # 有人进来了,可以进行挑战
  67. logger.info('There is someone in the room and start the challenge')
  68. self.click_fire()
  69. self.run_general_battle()
  70. break
  71. self.exit_task()
  72. def exit_task(self):
  73. """
  74. 退出任务
  75. :return:
  76. """
  77. conf_buff = self.config.tako.tako_config
  78. self.ui_get_current_page()
  79. self.ui_goto(page_main)
  80. if conf_buff.enable:
  81. self.ui_get_current_page()
  82. self.ui_goto(page_main)
  83. self.open_buff()
  84. if conf_buff.buff_gold_50_click:
  85. self.gold_50(False)
  86. if conf_buff.buff_gold_100_click:
  87. self.gold_100(False)
  88. if conf_buff.buff_exp_50_click:
  89. self.exp_50(False)
  90. if conf_buff.buff_exp_100_click:
  91. self.exp_100(False)
  92. self.close_buff()
  93. self.set_next_run(task='Tako', success=True, finish=False)
  94. raise TaskEnd('Tako')
  95. def battle_wait(self, random_click_swipt_enable: bool) -> bool:
  96. # 重写
  97. self.device.stuck_record_add('BATTLE_STATUS_S')
  98. self.device.click_record_clear()
  99. # 战斗过程 随机点击和滑动 防封
  100. logger.info("Start battle process")
  101. while 1:
  102. self.screenshot()
  103. if self.appear(self.I_WIN) or self.appear(self.I_REWARD):
  104. logger.info('Win battle')
  105. self.ui_click_until_disappear(self.I_WIN)
  106. while 1:
  107. self.screenshot()
  108. if self.appear(self.I_CHECK_MAIN) or self.appear(self.I_CHECK_TEAM):
  109. break
  110. if self.click(self.C_REWARD_2, interval=2):
  111. continue
  112. return True
  113. if self.appear(self.I_FALSE):
  114. logger.warning('False battle')
  115. self.ui_click_until_disappear(self.I_FALSE)
  116. return False
  117. if __name__ == '__main__':
  118. from module.config.config import Config
  119. from module.device.device import Device
  120. c = Config('oas1')
  121. d = Device(c)
  122. t = ScriptTask(c, d)
  123. t.screenshot()
  124. t.run()