script_task.py 5.9 KB

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