script_task.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. day = time_now.day + 1
  78. time_set = time_set.replace(day=day, hour=12)
  79. else:
  80. time_set = time_set.replace(hour=12)
  81. self.set_next_run(task='FrogBoss', target=time_set - time_delta)
  82. def do_bet(self):
  83. logger.hr('do bet', level=2)
  84. self.screenshot()
  85. count_left = self.O_LEFT_COUNT.ocr(self.device.image)
  86. count_right = self.O_RIGHT_COUNT.ocr(self.device.image)
  87. match self.config.model.frog_boss.frog_boss_config.strategy_frog:
  88. case Strategy.Majority:
  89. click_image = self.I_BET_LEFT if count_left > count_right else self.I_BET_RIGHT
  90. case Strategy.Minority:
  91. click_image = self.I_BET_LEFT if count_left < count_right else self.I_BET_RIGHT
  92. case Strategy.Bilibili:
  93. click_image = self.I_BET_LEFT if count_left > count_right else self.I_BET_RIGHT
  94. case _:
  95. raise ValueError(f'Unknown bet mode: {self.config.model.frog_boss.frog_boss_config.strategy_frog}')
  96. logger.info(f'You strategy is {self.config.model.frog_boss.frog_boss_config.strategy_frog} and bet on {click_image}')
  97. self.ui_click_until_disappear(click_image)
  98. gold_30_timer = Timer(10)
  99. gold_30_timer.start()
  100. while 1:
  101. self.screenshot()
  102. if self.appear(self.I_GOLD_30_CHECK):
  103. break
  104. if gold_30_timer.reached():
  105. logger.info('Gold 30 not appear')
  106. break
  107. if self.appear_then_click(self.I_GOLD_30, interval=3):
  108. continue
  109. # 正式下注
  110. logger.info('Formal bet')
  111. while 1:
  112. self.screenshot()
  113. if self.appear(self.I_BETTED):
  114. break
  115. if self.appear_then_click(self.I_GOLD_30, interval=2):
  116. continue
  117. if self.appear_then_click(self.I_BET_SURE, interval=2):
  118. continue
  119. if self.appear_then_click(self.I_UI_CONFIRM, interval=2):
  120. continue
  121. if self.appear_then_click(self.I_UI_CONFIRM_SAMLL, interval=2):
  122. continue
  123. def detect(self) -> bool:
  124. """
  125. 检测是左边赢了还是右边赢的
  126. :return: True 左边赢了
  127. """
  128. if self.appear(self.I_SUCCESS_LEFT) and self.appear(self.I_FAILURE_RIGHT):
  129. result = True
  130. logger.info('Left win')
  131. elif self.appear(self.I_SUCCESS_RIGHT) and self.appear(self.I_FAILURE_LEFT):
  132. result = False
  133. logger.info('Right win')
  134. else:
  135. result = True
  136. return result
  137. def get_bilibili(self) -> RuleImage:
  138. """
  139. 获取博主的策略选择
  140. :return:
  141. """
  142. pass
  143. if __name__ == '__main__':
  144. from module.config.config import Config
  145. from module.device.device import Device
  146. c = Config('oas1')
  147. d = Device(c)
  148. t = ScriptTask(c, d)
  149. t.run()