script_task.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. # This Python file uses the following encoding: utf-8
  2. # @author runhey
  3. # github https://github.com/runhey
  4. from cached_property import cached_property
  5. from datetime import datetime
  6. from module.exception import TaskEnd
  7. from module.logger import logger
  8. from module.atom.image import RuleImage
  9. from module.base.timer import Timer
  10. from tasks.GameUi.game_ui import GameUi
  11. from tasks.GameUi.page import page_main
  12. from tasks.Component.RightActivity.right_activity import RightActivity
  13. from tasks.Component.GeneralBattle.assets import GeneralBattleAssets
  14. from tasks.Component.config_base import TimeDelta
  15. from tasks.FrogBoss.assets import FrogBossAssets
  16. from tasks.FrogBoss.config import Strategy
  17. class ScriptTask(RightActivity, FrogBossAssets, GeneralBattleAssets):
  18. def run(self):
  19. self.enter(self.I_FROG_BOSS_ENTER)
  20. # 进入主界面
  21. while 1:
  22. self.screenshot()
  23. # 已经下注
  24. if self.appear(self.I_BETTED):
  25. logger.info('You have betted')
  26. break
  27. # 休息中
  28. if self.appear(self.I_FROG_BOSS_REST):
  29. logger.info('Frog Boss Rest')
  30. break
  31. # 竞猜成功
  32. if self.appear(self.I_BET_SUCCESS):
  33. logger.info('You bet win')
  34. self.detect()
  35. while 1:
  36. self.screenshot()
  37. if self.appear(self.I_BET_LEFT) and self.appear(self.I_BET_RIGHT):
  38. break
  39. if self.appear_then_click(self.I_BET_SUCCESS_BOX, interval=1):
  40. continue
  41. if self.appear_then_click(self.I_REWARD, interval=2):
  42. continue
  43. if self.appear_then_click(self.I_NEXT_COMPETITION, interval=4):
  44. continue
  45. continue
  46. # 竞猜失败
  47. if self.appear(self.I_BET_FAILURE):
  48. logger.info('You bet lose')
  49. self.ui_click_until_disappear(self.I_NEXT_COMPETITION)
  50. self.detect()
  51. continue
  52. # 正式竞猜
  53. if self.appear(self.I_BET_LEFT) and self.appear(self.I_BET_RIGHT):
  54. self.do_bet()
  55. continue
  56. logger.info('FrogBoss end')
  57. self.next_run()
  58. raise TaskEnd('FrogBoss')
  59. def next_run(self):
  60. time = self.config.model.frog_boss.frog_boss_config.before_end_frog
  61. time_delta = TimeDelta(hours=time.hour, minutes=time.minute, seconds=time.second)
  62. time_now = datetime.now()
  63. time_set = time_now.replace(minute=0, second=0, microsecond=0)
  64. if 10 <= time_now.hour < 12:
  65. time_set = time_set.replace(hour=14)
  66. elif 12 <= time_now.hour < 14:
  67. time_set = time_set.replace(hour=16)
  68. elif 14 <= time_now.hour < 16:
  69. time_set = time_set.replace(hour=18)
  70. elif 16 <= time_now.hour < 18:
  71. time_set = time_set.replace(hour=20)
  72. elif 18 <= time_now.hour < 20:
  73. time_set = time_set.replace(hour=22)
  74. elif 20 <= time_now.hour < 22:
  75. time_set = time_set.replace(hour=0) + TimeDelta(days=1)
  76. elif 22 <= time_now.hour < 24:
  77. time_set = time_set.replace(hour=12) + TimeDelta(days=1)
  78. else:
  79. time_set = time_set.replace(hour=12)
  80. self.set_next_run(task='FrogBoss', target=time_set - time_delta)
  81. def do_bet(self):
  82. logger.hr('do bet', level=2)
  83. self.screenshot()
  84. count_left = self.O_LEFT_COUNT.ocr(self.device.image)
  85. count_right = self.O_RIGHT_COUNT.ocr(self.device.image)
  86. match self.config.model.frog_boss.frog_boss_config.strategy_frog:
  87. case Strategy.Majority:
  88. click_image = self.I_BET_LEFT if count_left > count_right else self.I_BET_RIGHT
  89. case Strategy.Minority:
  90. click_image = self.I_BET_LEFT if count_left < count_right else self.I_BET_RIGHT
  91. case Strategy.Bilibili:
  92. click_image = self.I_BET_LEFT if count_left > count_right else self.I_BET_RIGHT
  93. case _:
  94. raise ValueError(f'Unknown bet mode: {self.config.model.frog_boss.frog_boss_config.strategy_frog}')
  95. logger.info(f'You strategy is {self.config.model.frog_boss.frog_boss_config.strategy_frog} and bet on {click_image}')
  96. self.ui_click_until_disappear(click_image)
  97. gold_30_timer = Timer(10)
  98. gold_30_timer.start()
  99. while 1:
  100. self.screenshot()
  101. if self.appear(self.I_GOLD_30_CHECK):
  102. break
  103. if gold_30_timer.reached():
  104. logger.info('Gold 30 not appear')
  105. break
  106. if self.appear_then_click(self.I_GOLD_30, interval=3):
  107. continue
  108. # 正式下注
  109. logger.info('Formal bet')
  110. while 1:
  111. self.screenshot()
  112. if self.appear(self.I_BETTED):
  113. break
  114. if self.appear_then_click(self.I_GOLD_30, interval=2):
  115. continue
  116. if self.appear_then_click(self.I_BET_SURE, interval=2):
  117. continue
  118. if self.appear_then_click(self.I_UI_CONFIRM, interval=2):
  119. continue
  120. if self.appear_then_click(self.I_UI_CONFIRM_SAMLL, interval=2):
  121. continue
  122. def detect(self) -> bool:
  123. """
  124. 检测是左边赢了还是右边赢的
  125. :return: True 左边赢了
  126. """
  127. if self.appear(self.I_SUCCESS_LEFT) and self.appear(self.I_FAILURE_RIGHT):
  128. result = True
  129. logger.info('Left win')
  130. elif self.appear(self.I_SUCCESS_RIGHT) and self.appear(self.I_FAILURE_LEFT):
  131. result = False
  132. logger.info('Right win')
  133. else:
  134. result = True
  135. return result
  136. def get_bilibili(self) -> RuleImage:
  137. """
  138. 获取博主的策略选择
  139. :return:
  140. """
  141. pass
  142. if __name__ == '__main__':
  143. from module.config.config import Config
  144. from module.device.device import Device
  145. c = Config('oas1')
  146. d = Device(c)
  147. t = ScriptTask(c, d)
  148. t.run()