script_task.py 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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()
  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_FRIENDSHIP_UP, interval=1):
  47. continue
  48. if self.appear_then_click(self.I_LUCK_MSG, interval=1):
  49. continue
  50. logger.info('Start luck msg')
  51. check_timer = Timer(2)
  52. check_timer.start()
  53. while 1:
  54. self.screenshot()
  55. if self.appear_then_click(self.I_CLICK_BLESS, interval=1):
  56. continue
  57. if self.appear_then_click(self.I_ONE_CLICK_BLESS, interval=1):
  58. continue
  59. if self.ui_reward_appear_click():
  60. logger.info('Get reward of luck msg')
  61. break
  62. if check_timer.reached():
  63. logger.warning('There is no any luck msg')
  64. break
  65. self.ui_click(self.I_UI_BACK_RED, self.I_CHECK_MAIN)
  66. def run_friend_love(self):
  67. self.ui_get_current_page()
  68. self.ui_goto(page_friends)
  69. while 1:
  70. self.screenshot()
  71. if self.appear(self.I_L_LOVE):
  72. break
  73. if self.appear_then_click(self.I_FRIENDSHIP_UP, interval=1):
  74. continue
  75. if self.appear_then_click(self.I_L_FRIENDS, interval=1):
  76. continue
  77. logger.info('Start friend love')
  78. check_timer = Timer(2)
  79. check_timer.start()
  80. while 1:
  81. self.screenshot()
  82. if self.appear_then_click(self.I_L_COLLECT, interval=1):
  83. continue
  84. if self.ui_reward_appear_click():
  85. logger.info('Get reward of friend love')
  86. break
  87. if check_timer.reached():
  88. logger.warning('There is no any love')
  89. break
  90. self.ui_click(self.I_UI_BACK_RED, self.I_CHECK_MAIN)
  91. def run_store(self):
  92. self.ui_get_current_page()
  93. self.ui_goto(page_mall, confirm_wait=3)
  94. if self.config.daily_trifles.trifles_config.store_sign:
  95. self.run_store_sign()
  96. if self.config.daily_trifles.trifles_config.buy_sushi_count > 0:
  97. self.run_buy_sushi()
  98. self.ui_click(self.I_UI_BACK_YELLOW, self.I_CHECK_MALL)
  99. self.ui_get_current_page()
  100. self.ui_goto(page_main)
  101. def run_store_sign(self):
  102. while 1:
  103. self.screenshot()
  104. if self.appear(self.I_GIFT_RECOMMEND):
  105. break
  106. if self.appear_then_click(self.I_ROOM_GIFT, interval=1):
  107. continue
  108. self.screenshot()
  109. self.appear_then_click(self.I_GIFT_RECOMMEND, interval=1)
  110. logger.info('Enter store sign')
  111. sleep(1) # 等个动画
  112. self.screenshot()
  113. if not self.appear(self.I_GIFT_SIGN):
  114. logger.warning('There is no gift sign')
  115. return
  116. if self.ui_get_reward(self.I_GIFT_SIGN, click_interval=2.5):
  117. logger.info('Get reward of gift sign')
  118. def run_buy_sushi(self):
  119. # 进入Special
  120. while 1:
  121. from tasks.RichMan.assets import RichManAssets
  122. self.screenshot()
  123. if self.appear(RichManAssets.I_SIDE_CHECK_SPECIAL):
  124. break
  125. if self.appear_then_click(RichManAssets.I_MALL_SUNDRY, interval=1):
  126. continue
  127. if self.appear_then_click(RichManAssets.I_SIDE_SURE_SPECIAL, interval=1):
  128. continue
  129. def detect_buy_count(base_element) -> (int, int):
  130. # 返回count,price
  131. MAX_PRICE = 9999
  132. MAX_COUNT = 9999
  133. roi = copy.deepcopy(base_element.roi_front)
  134. roi[0] = roi[0] + roi[2]
  135. roi[1] = roi[1] + roi[3] - 30
  136. roi[2] = 60
  137. roi[3] = 30
  138. self.O_STORE_SUSHI_PRICE.roi = roi
  139. _price = self.O_STORE_SUSHI_PRICE.detect_text(self.device.image)
  140. # 保守策略,避免OCR错误购买
  141. try:
  142. _price = int(_price)
  143. except Exception as e:
  144. _price = MAX_PRICE
  145. if _price < 60:
  146. return 0, MAX_PRICE
  147. _count = (_price - 60) / 20
  148. return _count, _price
  149. roi = None
  150. # 购买体力
  151. while 1:
  152. self.screenshot()
  153. # count, price = detect_buy_count(roi)
  154. # if count >= self.config.model.daily_trifles.trifles_config.buy_sushi_count:
  155. # break
  156. if self.appear(self.I_STORE_COST_TYPE_JADE):
  157. count, price = detect_buy_count(self.I_STORE_COST_TYPE_JADE)
  158. if count >= self.config.daily_trifles.trifles_config.buy_sushi_count:
  159. break
  160. self.ui_click_until_disappear(self.I_STORE_COST_TYPE_JADE, interval=2)
  161. logger.info(f"Buy Sushi With {price} Jade")
  162. continue
  163. if self.appear(self.I_SPECIAL_SUSHI):
  164. # 此处确定当前购买体力所需勾玉数量的位置,用于后续识别
  165. count, price = detect_buy_count(self.I_SPECIAL_SUSHI)
  166. if count >= self.config.daily_trifles.trifles_config.buy_sushi_count:
  167. break
  168. self.ui_click(self.I_SPECIAL_SUSHI, stop=self.I_STORE_COST_TYPE_JADE, interval=2)
  169. continue
  170. return
  171. if __name__ == '__main__':
  172. from module.config.config import Config
  173. from module.device.device import Device
  174. c = Config('oas1')
  175. d = Device(c)
  176. t = ScriptTask(c, d)
  177. t.run_store()