script_task.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. # This Python file uses the following encoding: utf-8
  2. # @author runhey
  3. # github https://github.com/runhey
  4. import copy
  5. from time import sleep
  6. from datetime import time, datetime, timedelta
  7. from exceptiongroup import catch
  8. from winerror import NOERROR
  9. from tasks.GameUi.game_ui import GameUi
  10. from tasks.GameUi.page import page_main, page_summon, page_guild, page_mall, page_friends
  11. from tasks.DailyTrifles.config import DailyTriflesConfig
  12. from tasks.DailyTrifles.assets import DailyTriflesAssets
  13. from tasks.Component.Summon.summon import Summon
  14. from module.logger import logger
  15. from module.exception import TaskEnd
  16. from module.base.timer import Timer
  17. class ScriptTask(GameUi, Summon, DailyTriflesAssets):
  18. def run(self):
  19. con = self.config.daily_trifles.trifles_config
  20. if con.one_summon:
  21. self.run_one_summon()
  22. if con.guild_wish:
  23. pass
  24. if con.friend_love:
  25. self.run_friend_love()
  26. if con.luck_msg:
  27. self.run_luck_msg()
  28. if con.store_sign or con.buy_sushi_count > 0:
  29. self.run_store_sign()
  30. self.set_next_run('DailyTrifles', success=True, finish=False)
  31. raise TaskEnd('DailyTrifles')
  32. def run_one_summon(self):
  33. self.ui_get_current_page()
  34. self.ui_goto(page_summon)
  35. self.summon_one()
  36. self.back_summon_main()
  37. def run_guild_wish(self):
  38. pass
  39. def run_luck_msg(self):
  40. self.ui_get_current_page()
  41. self.ui_goto(page_friends)
  42. while 1:
  43. self.screenshot()
  44. if self.appear(self.I_LUCK_TITLE):
  45. break
  46. if self.appear_then_click(self.I_LUCK_MSG, interval=1):
  47. continue
  48. logger.info('Start luck msg')
  49. check_timer = Timer(2)
  50. check_timer.start()
  51. while 1:
  52. self.screenshot()
  53. if self.appear_then_click(self.I_CLICK_BLESS, interval=1):
  54. continue
  55. if self.appear_then_click(self.I_ONE_CLICK_BLESS, interval=1):
  56. continue
  57. if self.ui_reward_appear_click():
  58. logger.info('Get reward of luck msg')
  59. break
  60. if check_timer.reached():
  61. logger.warning('There is no any luck msg')
  62. break
  63. self.ui_click(self.I_UI_BACK_RED, self.I_CHECK_MAIN)
  64. def run_friend_love(self):
  65. self.ui_get_current_page()
  66. self.ui_goto(page_friends)
  67. while 1:
  68. self.screenshot()
  69. if self.appear(self.I_L_LOVE):
  70. break
  71. if self.appear_then_click(self.I_L_FRIENDS, interval=1):
  72. continue
  73. logger.info('Start friend love')
  74. check_timer = Timer(2)
  75. check_timer.start()
  76. while 1:
  77. self.screenshot()
  78. if self.appear_then_click(self.I_L_COLLECT, interval=1):
  79. continue
  80. if self.ui_reward_appear_click():
  81. logger.info('Get reward of friend love')
  82. break
  83. if check_timer.reached():
  84. logger.warning('There is no any love')
  85. break
  86. self.ui_click(self.I_UI_BACK_RED, self.I_CHECK_MAIN)
  87. def run_store(self):
  88. self.ui_get_current_page()
  89. self.ui_goto(page_mall, confirm_wait=3)
  90. if self.config.daily_trifles.trifles_config.store_sign:
  91. self.run_store_sign()
  92. if self.config.daily_trifles.trifles_config.buy_sushi_count > 0:
  93. self.run_buy_sushi()
  94. self.ui_click(self.I_UI_BACK_YELLOW, self.I_CHECK_MALL)
  95. self.ui_get_current_page()
  96. self.ui_goto(page_main)
  97. def run_store_sign(self):
  98. while 1:
  99. self.screenshot()
  100. if self.appear(self.I_GIFT_RECOMMEND):
  101. break
  102. if self.appear_then_click(self.I_ROOM_GIFT, interval=1):
  103. continue
  104. self.screenshot()
  105. self.appear_then_click(self.I_GIFT_RECOMMEND, interval=1)
  106. logger.info('Enter store sign')
  107. sleep(1) # 等个动画
  108. self.screenshot()
  109. if not self.appear(self.I_GIFT_SIGN):
  110. logger.warning('There is no gift sign')
  111. return
  112. if self.ui_get_reward(self.I_GIFT_SIGN, click_interval=2.5):
  113. logger.info('Get reward of gift sign')
  114. def run_buy_sushi(self):
  115. # 进入Special
  116. while 1:
  117. from tasks.RichMan.assets import RichManAssets
  118. self.screenshot()
  119. if self.appear(RichManAssets.I_SIDE_CHECK_SPECIAL):
  120. break
  121. if self.appear_then_click(RichManAssets.I_MALL_SUNDRY, interval=1):
  122. continue
  123. if self.appear_then_click(RichManAssets.I_SIDE_SURE_SPECIAL, interval=1):
  124. continue
  125. def detect_buy_count(base_element) -> (int, int):
  126. # 返回count,price
  127. MAX_PRICE = 9999
  128. MAX_COUNT = 9999
  129. roi = copy.deepcopy(base_element.roi_front)
  130. roi[0] = roi[0] + roi[2]
  131. roi[1] = roi[1] + roi[3] - 30
  132. roi[2] = 60
  133. roi[3] = 30
  134. self.O_STORE_SUSHI_PRICE.roi = roi
  135. _price = self.O_STORE_SUSHI_PRICE.detect_text(self.device.image)
  136. # 保守策略,避免OCR错误购买
  137. try:
  138. _price = int(_price)
  139. except Exception as e:
  140. _price = MAX_PRICE
  141. if _price < 60:
  142. return 0, MAX_PRICE
  143. _count = (_price - 60) / 20
  144. return _count, _price
  145. roi = None
  146. # 购买体力
  147. while 1:
  148. self.screenshot()
  149. # count, price = detect_buy_count(roi)
  150. # if count >= self.config.model.daily_trifles.trifles_config.buy_sushi_count:
  151. # break
  152. if self.appear(self.I_STORE_COST_TYPE_JADE):
  153. count, price = detect_buy_count(self.I_STORE_COST_TYPE_JADE)
  154. if count >= self.config.daily_trifles.trifles_config.buy_sushi_count:
  155. break
  156. self.ui_click_until_disappear(self.I_STORE_COST_TYPE_JADE, interval=2)
  157. logger.info(f"Buy Sushi With {price} Jade")
  158. continue
  159. if self.appear(self.I_SPECIAL_SUSHI):
  160. # 此处确定当前购买体力所需勾玉数量的位置,用于后续识别
  161. count, price = detect_buy_count(self.I_SPECIAL_SUSHI)
  162. if count >= self.config.daily_trifles.trifles_config.buy_sushi_count:
  163. break
  164. self.ui_click(self.I_SPECIAL_SUSHI, stop=self.I_STORE_COST_TYPE_JADE, interval=2)
  165. continue
  166. return
  167. if __name__ == '__main__':
  168. from module.config.config import Config
  169. from module.device.device import Device
  170. c = Config('oas1')
  171. d = Device(c)
  172. t = ScriptTask(c, d)
  173. t.run_store()