script_task.py 5.7 KB

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