general_battle.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. # This Python file uses the following encoding: utf-8
  2. # @author runhey
  3. # github https://github.com/runhey
  4. import time
  5. import random
  6. from time import sleep
  7. import cv2
  8. from module.base.timer import Timer
  9. from module.base.utils import get_color, color_similar
  10. from tasks.base_task import BaseTask
  11. from tasks.Component.GeneralBattle.config_general_battle import GreenMarkType, GeneralBattleConfig
  12. from tasks.Component.GeneralBattle.assets import GeneralBattleAssets
  13. from tasks.Component.GeneralBattle.config_general_battle import GreenMarkType, GeneralBattleConfig
  14. from tasks.Component.GeneralBuff.config_buff import BuffClass
  15. from tasks.Component.GeneralBuff.general_buff import GeneralBuff
  16. from module.logger import logger
  17. class GeneralBattle(GeneralBuff, GeneralBattleAssets):
  18. """
  19. 使用这个通用的战斗必须要求这个任务的config有config_general_battle
  20. """
  21. def run_general_battle(self, config: GeneralBattleConfig = None, buff: BuffClass or list[BuffClass] = None) -> bool:
  22. """
  23. 运行脚本
  24. :return:
  25. """
  26. logger.hr("General battle start", 2)
  27. if config is None:
  28. config = GeneralBattleConfig()
  29. # 本人选择的策略是只要进来了就算一次,不管是不是打完了
  30. # 战斗统计
  31. self.current_count += 1
  32. logger.info(f"Current count: {self.current_count}")
  33. # 战前设置
  34. self.battle_before(buff, config)
  35. # 绿标
  36. if self.is_in_battle(False):
  37. self.green_mark(config.green_enable, config.green_mark)
  38. # 战中设置
  39. win = self.battle_wait(config.random_click_swipt_enable)
  40. if win:
  41. return True
  42. else:
  43. return False
  44. def battle_before(self, buff: BuffClass | list[BuffClass], config: GeneralBattleConfig, timeout: float = 5) -> bool:
  45. """战斗前设置
  46. :return: True:进入战斗或点击了准备按钮且识别不到准备按钮了 False:超过timeout s还没有进入战斗且没有点击过准备
  47. """
  48. timeout_timer = Timer(timeout).start()
  49. confed = False
  50. while not timeout_timer.reached():
  51. self.screenshot()
  52. if self.is_in_real_battle(False): # 战斗阶段
  53. return True
  54. if self.appear_then_click(self.I_DISABLE_7DAYS_DIFF_SOUL, interval=0.6): # 关闭御魂不一致提示
  55. continue
  56. if self.appear_then_click(self.I_CONFIRM_CLOSE_DIFF_SOUL, interval=0.6): # 确认关闭御魂不一致提示
  57. continue
  58. if self.is_in_prepare(False): # 战斗准备阶段
  59. if not getattr(config, 'lock_team_enable', False): # 没有锁定阵容
  60. if self.current_count == 1 and not confed: # 第一次战斗且是本次第一次配置
  61. self.switch_preset_team(config.preset_enable, config.preset_group, config.preset_team)
  62. self.check_and_open_buff(buff)
  63. confed = True
  64. # 点击准备(锁定阵容自动点准备,不锁定阵容前面也已经配置完毕需要点准备)
  65. if self.appear_then_click(self.I_PREPARE_HIGHLIGHT, interval=0.8):
  66. continue
  67. continue
  68. # 未知界面, 既不是准备界面也不是战斗界面
  69. logger.info('Wait for preparation page')
  70. sleep(random.uniform(0.4, 0.8))
  71. return False
  72. def run_general_battle_back(self, config: GeneralBattleConfig = None, exit_four: bool = False) -> bool:
  73. """
  74. 进入挑战然后直接返回
  75. :param config:
  76. :return:
  77. """
  78. # 如果没有锁定队伍那么在点击准备后才退出的,退四的话就直接退出
  79. if not config.lock_team_enable and not exit_four:
  80. # 点击准备按钮
  81. self.wait_until_appear(self.I_PREPARE_HIGHLIGHT)
  82. while 1:
  83. self.screenshot()
  84. if self.appear_then_click(self.I_PREPARE_HIGHLIGHT, interval=1.5):
  85. continue
  86. if not (self.appear(self.I_PRESET) or self.appear(self.I_PRESET_WIT_NUMBER)):
  87. break
  88. logger.info(f"Click {self.I_PREPARE_HIGHLIGHT.name}")
  89. # 点击返回
  90. while 1:
  91. self.screenshot()
  92. if self.appear_then_click(self.I_EXIT, interval=1.5):
  93. continue
  94. if self.appear(self.I_EXIT_ENSURE):
  95. break
  96. logger.info(f"Click {self.I_EXIT.name}")
  97. # 点击返回确认
  98. while 1:
  99. self.screenshot()
  100. if self.appear_then_click(self.I_EXIT_ENSURE, interval=1.5):
  101. continue
  102. if self.appear(self.I_FALSE):
  103. break
  104. logger.info(f"Click {self.I_EXIT_ENSURE.name}")
  105. # 点击失败确认
  106. self.wait_until_appear(self.I_FALSE)
  107. while 1:
  108. self.screenshot()
  109. if self.appear_then_click(self.I_FALSE, interval=1.5):
  110. continue
  111. if not self.appear(self.I_FALSE):
  112. break
  113. logger.info(f"Click {self.I_FALSE.name}")
  114. return True
  115. def exit_battle(self, skip_first: bool = False) -> bool:
  116. """
  117. 在战斗的时候强制退出战斗
  118. :return:
  119. """
  120. if skip_first:
  121. self.screenshot()
  122. if not self.appear(self.I_EXIT):
  123. return False
  124. # 点击返回
  125. logger.info(f"Click {self.I_EXIT.name}")
  126. while 1:
  127. self.screenshot()
  128. if self.appear_then_click(self.I_EXIT, interval=1.5):
  129. continue
  130. if self.appear(self.I_EXIT_ENSURE):
  131. break
  132. # 点击返回确认
  133. while 1:
  134. self.screenshot()
  135. if self.appear_then_click(self.I_EXIT_ENSURE, interval=1.5):
  136. continue
  137. if self.appear_then_click(self.I_FALSE, interval=1.5):
  138. continue
  139. if not self.appear(self.I_EXIT):
  140. break
  141. return True
  142. def battle_wait(self, random_click_swipt_enable: bool) -> bool:
  143. """
  144. 等待战斗结束 !!!
  145. 很重要 这个函数是原先写的, 优化版本在tasks/Secret/script_task下。本着不改动原先的代码的原则,所以就不改了
  146. :param random_click_swipt_enable:
  147. :return:
  148. """
  149. # 有的时候是长战斗,需要在设置stuck检测为长战斗
  150. # 但是无需取消设置,因为如果有点击或者滑动的话 handle_control_check会自行取消掉
  151. self.device.stuck_record_add('BATTLE_STATUS_S')
  152. self.device.click_record_clear()
  153. # 战斗过程 随机点击和滑动 防封
  154. logger.info("Start battle process")
  155. win: bool = False
  156. while 1:
  157. self.screenshot()
  158. # 如果出现赢 就点击, 第二个是针对封魔的图片
  159. if self.appear(self.I_WIN, threshold=0.8) or self.appear(self.I_DE_WIN):
  160. logger.info("Battle result is win")
  161. if self.appear(self.I_DE_WIN):
  162. self.ui_click_until_disappear(self.I_DE_WIN)
  163. win = True
  164. break
  165. # 如果出现失败 就点击,返回False
  166. if self.appear(self.I_FALSE, threshold=0.8):
  167. logger.info("Battle result is false")
  168. win = False
  169. break
  170. # 如果领奖励
  171. if self.appear(self.I_REWARD, threshold=0.6):
  172. win = True
  173. break
  174. # 如果领奖励出现金币
  175. if self.appear(self.I_REWARD_GOLD, threshold=0.8):
  176. win = True
  177. break
  178. # 如果开启战斗过程随机滑动
  179. if random_click_swipt_enable:
  180. self.random_click_swipt()
  181. # 再次确认战斗结果
  182. logger.info("Reconfirm the results of the battle")
  183. while 1:
  184. self.screenshot()
  185. if win:
  186. # 点击赢了
  187. action_click = random.choice([self.C_WIN_1, self.C_WIN_2, self.C_WIN_3])
  188. if self.appear_then_click(self.I_WIN, action=action_click, interval=0.5):
  189. continue
  190. if not self.appear(self.I_WIN):
  191. break
  192. else:
  193. # 如果失败且 点击失败后
  194. if self.appear_then_click(self.I_FALSE, threshold=0.6):
  195. continue
  196. if not self.appear(self.I_FALSE, threshold=0.6):
  197. return False
  198. # 最后保证能点击 获得奖励
  199. if not self.wait_until_appear(self.I_REWARD):
  200. # 有些的战斗没有下面的奖励,所以直接返回
  201. logger.info("There is no reward, Exit battle")
  202. return win
  203. logger.info("Get reward")
  204. while 1:
  205. self.screenshot()
  206. # 如果出现领奖励
  207. action_click = random.choice([self.C_REWARD_1, self.C_REWARD_2, self.C_REWARD_3])
  208. if (self.appear_then_click(self.I_REWARD, action=action_click, interval=1.5) or
  209. self.appear_then_click(self.I_REWARD_GOLD, action=action_click, interval=1.5)# or
  210. # self.appear_then_click(self.I_REWARD_STATISTICS, action=action_click, interval=1.5) or
  211. # self.appear_then_click(self.I_REWARD_PURPLE_SNAKE_SKIN, action=action_click, interval=1.5) or
  212. # self.appear_then_click(self.I_REWARD_GOLD_SNAKE_SKIN, action=action_click, interval=1.5) or
  213. # self.appear_then_click(self.I_REWARD_EXP_SOUL_4, action=action_click, interval=1.5) or
  214. # self.appear_then_click(self.I_REWARD_SOUL_5, action=action_click, interval=1.5) or
  215. # self.appear_then_click(self.I_REWARD_SOUL_6, action=action_click, interval=1.5)
  216. ):
  217. continue
  218. # 未知结算弹窗(皮肤碎片等):点一下空白区域尝试跳过
  219. if self.appear(self.I_STATISTICS) and not self.appear(self.I_REWARD)and not self.appear(self.I_WIN):
  220. self.click(self.C_RANDOM_CLICK) #碎片
  221. self.appear_then_click(self.I_CONFIRM_CLOSE_DIFF_SOUL) #整个皮肤
  222. continue
  223. if (not self.appear(self.I_REWARD) and
  224. not self.appear(self.I_REWARD_GOLD)# and
  225. # not self.appear(self.I_REWARD_STATISTICS) and
  226. # not self.appear(self.I_REWARD_PURPLE_SNAKE_SKIN) and
  227. # not self.appear(self.I_REWARD_GOLD_SNAKE_SKIN) and
  228. # not self.appear(self.I_REWARD_EXP_SOUL_4) and
  229. # not self.appear(self.I_REWARD_SOUL_5) and
  230. # not self.appear(self.I_REWARD_SOUL_6)
  231. ):
  232. break
  233. return win
  234. def green_mark(self, enable: bool = False, mark_mode: GreenMarkType = GreenMarkType.GREEN_MAIN):
  235. """
  236. 绿标, 如果不使能就直接返回
  237. :param enable:
  238. :param mark_mode:
  239. :return:
  240. """
  241. if enable:
  242. logger.info("Green is enable")
  243. x, y = None, None
  244. match mark_mode:
  245. case GreenMarkType.GREEN_LEFT1:
  246. x, y = self.C_GREEN_LEFT_1.coord()
  247. logger.info("Green left 1")
  248. case GreenMarkType.GREEN_LEFT2:
  249. x, y = self.C_GREEN_LEFT_2.coord()
  250. logger.info("Green left 2")
  251. case GreenMarkType.GREEN_LEFT3:
  252. x, y = self.C_GREEN_LEFT_3.coord()
  253. logger.info("Green left 3")
  254. case GreenMarkType.GREEN_LEFT4:
  255. x, y = self.C_GREEN_LEFT_4.coord()
  256. logger.info("Green left 4")
  257. case GreenMarkType.GREEN_LEFT5:
  258. x, y = self.C_GREEN_LEFT_5.coord()
  259. logger.info("Green left 5")
  260. case GreenMarkType.GREEN_MAIN:
  261. x, y = self.C_GREEN_MAIN.coord()
  262. logger.info("Green main")
  263. # 等待那个准备的消失
  264. while 1:
  265. self.screenshot()
  266. if not self.appear(self.I_PREPARE_HIGHLIGHT):
  267. break
  268. # 判断有无坐标的偏移
  269. self.appear_then_click(self.I_LOCAL)
  270. time.sleep(0.3)
  271. # 点击绿标
  272. self.device.click(x, y)
  273. def switch_preset_team(self, enable: bool = False, preset_group: int = 1, preset_team: int = 1):
  274. """
  275. 切换预设的队伍, 要求是在不锁定队伍时的情况下
  276. :param enable:
  277. :param preset_group:
  278. :param preset_team:
  279. :return:
  280. """
  281. if not enable:
  282. logger.info("Preset is disable")
  283. return None
  284. logger.info("Preset is enable")
  285. # 点击预设按钮
  286. while 1:
  287. self.screenshot()
  288. if self.appear(self.I_PRESET_ENSURE):
  289. break
  290. # 首个队伍没有满足5个式神,未出现预设按钮的情况下跳出循环
  291. if self.appear(self.I_PRESENT_LESS_THAN_5):
  292. break
  293. if self.appear_then_click(self.I_PRESET, threshold=0.8, interval=1):
  294. continue
  295. if self.appear_then_click(self.I_PRESET_WIT_NUMBER, threshold=0.8, interval=1):
  296. continue
  297. if self.ocr_appear(self.O_PRESET):
  298. self.click(self.O_PRESET, interval=1)
  299. continue
  300. if self.ocr_appear(self.O_PRESET_FULL):
  301. self.click(self.O_PRESET_FULL, interval=1)
  302. continue
  303. logger.info("Click preset button")
  304. def get_unselect_color(tmp1, tmp2, tmp3, size):
  305. # 获取未选择分组的颜色,3组之中必定存在两个颜色相似
  306. # area 参数格式是(x1,y1,x2,y2)
  307. color_1 = get_color(self.device.image,
  308. (tmp1.roi_back[0], tmp1.roi_back[1],
  309. tmp1.roi_back[0] + size[0], tmp1.roi_back[1] + size[1]))
  310. color_2 = get_color(self.device.image,
  311. (tmp2.roi_back[0], tmp2.roi_back[1],
  312. tmp2.roi_back[0] + size[0], tmp2.roi_back[1] + size[1]))
  313. color_3 = get_color(self.device.image,
  314. (tmp3.roi_back[0], tmp3.roi_back[1],
  315. tmp3.roi_back[0] + size[0], tmp3.roi_back[1] + size[1]))
  316. if color_similar(color_1, color_2):
  317. return color_1
  318. if color_similar(color_2, color_3):
  319. return color_2
  320. return color_3
  321. # 选择预设组
  322. tmp = self.__getattribute__("C_PRESET_GROUP_" + str(preset_group))
  323. if tmp is None:
  324. tmp = self.C_PRESET_GROUP_1
  325. color_size = [self.C_PRESET_GROUP_1.roi_back[2],
  326. self.C_PRESET_GROUP_1.roi_back[3]]
  327. # unselected_color = get_unselect_color(self.C_PRESET_GROUP_1, self.C_PRESET_GROUP_2, self.C_PRESET_GROUP_3, size=color_size)
  328. # 考虑到有些预设组没有预设,所以这里取一个比较固定的颜色
  329. unselected_color = (224.9, 208.3, 187.4)
  330. while True:
  331. self.screenshot()
  332. color_tmp = get_color(self.device.image,
  333. (tmp.roi_back[0], tmp.roi_back[1], tmp.roi_back[0] + color_size[0],
  334. tmp.roi_back[1] + color_size[1]))
  335. if color_similar(color_tmp, unselected_color):
  336. self.click(tmp, interval=0.2)
  337. continue
  338. break
  339. logger.info("Select preset group")
  340. # 选择预设的队伍
  341. time.sleep(0.5)
  342. tmp = self.__getattribute__("C_PRESET_TEAM_" + str(preset_team))
  343. if tmp is None:
  344. tmp = self.C_PRESET_TEAM_1
  345. color_size = [5, 5]
  346. # unselected_color = get_unselect_color(self.C_PRESET_TEAM_1, self.C_PRESET_TEAM_2, self.C_PRESET_TEAM_3, size=color_size )
  347. unselected_color = (216.8, 185.0, 146.8)
  348. while True:
  349. self.screenshot()
  350. color_tmp = get_color(self.device.image,
  351. (tmp.roi_back[0], tmp.roi_back[1], tmp.roi_back[0] + color_size[0],
  352. tmp.roi_back[1] + color_size[1]))
  353. if color_similar(color_tmp, unselected_color):
  354. self.click(tmp, interval=0.2)
  355. continue
  356. break
  357. self.click(tmp)
  358. logger.info("Select preset team")
  359. # 点击预设确认
  360. self.wait_until_appear(self.I_PRESET_ENSURE, wait_time=1)
  361. while 1:
  362. self.screenshot()
  363. if not self.appear(self.I_PRESET_ENSURE):
  364. break
  365. if self.appear_then_click(self.I_PRESET_ENSURE, threshold=0.8, interval=0.2):
  366. continue
  367. logger.info("Click preset ensure")
  368. def random_click_swipt(self):
  369. if 0 <= random.randint(0, 500) <= 3: # 百分之4的概率
  370. rand_type = random.randint(0, 2)
  371. match rand_type:
  372. case 0:
  373. self.click(self.C_RANDOM_CLICK, interval=20)
  374. case 1:
  375. self.swipe(self.S_BATTLE_RANDOM_LEFT, interval=20)
  376. case 2:
  377. self.swipe(self.S_BATTLE_RANDOM_RIGHT, interval=20)
  378. # 重新设置为长战斗
  379. # self.device.stuck_record_add('BATTLE_STATUS_S')
  380. else:
  381. time.sleep(0.4) # 这样的好像不对
  382. # 判断是否在战斗中
  383. def is_in_battle(self, is_screenshot: bool = True) -> bool:
  384. """
  385. 判断是否在战斗中
  386. tip: 因为有friends判别, 所以即使在准备界面也会识别在战斗中
  387. :return:
  388. """
  389. if is_screenshot:
  390. self.screenshot()
  391. if self.appear(self.I_BATTLE_INFO) or \
  392. self.appear(self.I_FRIENDS) or \
  393. self.appear(self.I_WIN) or \
  394. self.appear(self.I_FALSE) or \
  395. self.appear(self.I_REWARD):
  396. return True
  397. else:
  398. return False
  399. def is_in_real_battle(self, is_screenshot: bool = True):
  400. """
  401. 判断是否在真正的战斗中(不是战斗准备界面也不是战斗结束界面)
  402. :param is_screenshot:
  403. :return:
  404. """
  405. if is_screenshot:
  406. self.screenshot()
  407. return self.appear(self.I_BATTLE_INFO)
  408. def is_in_prepare(self, is_screenshot: bool = True) -> bool:
  409. """
  410. 判断是否在准备中
  411. :return:
  412. """
  413. if is_screenshot:
  414. self.screenshot()
  415. if self.appear(self.I_BUFF):
  416. return True
  417. elif self.appear(self.I_PREPARE_HIGHLIGHT):
  418. return True
  419. elif self.appear(self.I_PREPARE_DARK):
  420. return True
  421. elif self.appear(self.I_PRESET) or self.appear(self.I_PRESET_WIT_NUMBER):
  422. return True
  423. else:
  424. return False
  425. def check_take_over_battle(self, is_screenshot: bool, config: GeneralBattleConfig) -> bool or None:
  426. """
  427. 中途接入战斗,并且接管
  428. :return: 赢了返回True, 输了返回False, 不是在战斗中返回None
  429. """
  430. if is_screenshot:
  431. self.screenshot()
  432. if not self.is_in_battle():
  433. return None
  434. return self.run_general_battle(config=config)
  435. def check_lock(self, enable: bool, lock_image, unlock_image):
  436. """
  437. 检测是否锁定队伍,
  438. :param enable:
  439. :param lock_image:
  440. :param unlock_image:
  441. :return:
  442. """
  443. if enable:
  444. logger.info("Lock team")
  445. while 1:
  446. self.screenshot()
  447. if self.appear(lock_image):
  448. break
  449. if self.appear_then_click(unlock_image, interval=1):
  450. continue
  451. else:
  452. logger.info("Unlock team")
  453. while 1:
  454. self.screenshot()
  455. if self.appear(unlock_image):
  456. break
  457. if self.appear_then_click(lock_image, interval=1):
  458. continue
  459. def check_and_open_buff(self, buff: BuffClass or list[BuffClass] = None):
  460. """
  461. 检测是否开启buff
  462. :param buff:
  463. :return:
  464. """
  465. if not buff:
  466. return
  467. logger.info(f'Open buff {buff}')
  468. self.ui_click(self.I_BUFF, self.I_CLOUD, interval=2)
  469. if isinstance(buff, BuffClass):
  470. buff = [buff]
  471. match_method = {
  472. BuffClass.AWAKE: (self.awake, True),
  473. BuffClass.SOUL: (self.soul, True),
  474. BuffClass.GOLD_50: (self.gold_50, True),
  475. BuffClass.GOLD_100: (self.gold_100, True),
  476. BuffClass.EXP_50: (self.exp_50, True),
  477. BuffClass.EXP_100: (self.exp_100, True),
  478. BuffClass.AWAKE_CLOSE: (self.awake, False),
  479. BuffClass.SOUL_CLOSE: (self.soul, False),
  480. BuffClass.GOLD_50_CLOSE: (self.gold_50, False),
  481. BuffClass.GOLD_100_CLOSE: (self.gold_100, False),
  482. BuffClass.EXP_50_CLOSE: (self.exp_50, False),
  483. BuffClass.EXP_100_CLOSE: (self.exp_100, False),
  484. }
  485. for b in buff:
  486. func, is_open = match_method[b]
  487. func(is_open)
  488. time.sleep(0.1)
  489. logger.info(f'Open buff success')
  490. while 1:
  491. self.screenshot()
  492. if not self.appear(self.I_CLOUD):
  493. break
  494. if self.appear_then_click(self.I_BUFF, interval=1):
  495. continue
  496. def boss_mark(self, enable=True) -> bool:
  497. if not enable or self._boss_mark_flag:
  498. return False
  499. if self.ocr_appear(self.O_BOSS_MARK):
  500. self.screenshot()
  501. if self.ocr_appear(self.O_BOSS_MARK):
  502. self._boss_mark_flag = True
  503. logger.info('Boss marked')
  504. self.device.stuck_record_add('BATTLE_STATUS_S')
  505. return True
  506. if self.device.click_record.count(str(self.O_BOSS_MARK)) >= 3:
  507. self._boss_mark_flag = True
  508. logger.info('Boss mark skipped due to maybe no boss')
  509. self.device.stuck_record_add('BATTLE_STATUS_S')
  510. return False
  511. if self.click(self.O_BOSS_MARK, interval=1.8):
  512. return False
  513. return False
  514. def boss_mark_reset(self):
  515. self._boss_mark_flag = False
  516. if __name__ == '__main__':
  517. from module.config.config import Config
  518. from module.device.device import Device
  519. c = Config('oas1')
  520. d = Device(c)
  521. t = GeneralBattle(c, d)
  522. self = t
  523. # t.check_buff([BuffClass.EXP_50, BuffClass.GOLD_50])
  524. img = cv2.imread(r"E:\preset3.png")
  525. img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
  526. self.device.image = img
  527. def get_unselect_color(tmp1, tmp2, tmp3, size):
  528. # 获取未选择分组的颜色,3组之中必定存在两个颜色相似
  529. # area 参数格式是(x1,y1,x2,y2)
  530. color_1 = get_color(self.device.image,
  531. (tmp1.roi_back[0], tmp1.roi_back[1],
  532. tmp1.roi_back[0] + size[0], tmp1.roi_back[1] + size[1]))
  533. color_2 = get_color(self.device.image,
  534. (tmp2.roi_back[0], tmp2.roi_back[1],
  535. tmp2.roi_back[0] + size[0], tmp2.roi_back[1] + size[1]))
  536. color_3 = get_color(self.device.image,
  537. (tmp3.roi_back[0], tmp3.roi_back[1],
  538. tmp3.roi_back[0] + size[0], tmp3.roi_back[1] + size[1]))
  539. if color_similar(color_1, color_2):
  540. return color_1
  541. if color_similar(color_2, color_3):
  542. return color_2
  543. return color_3
  544. color_size = [self.C_PRESET_GROUP_1.roi_back[2],
  545. self.C_PRESET_GROUP_1.roi_back[3]]
  546. unselected_color = get_unselect_color(self.C_PRESET_GROUP_1, self.C_PRESET_GROUP_2, self.C_PRESET_GROUP_3,
  547. size=color_size)
  548. print("")
  549. color_size = [5, 5]
  550. unselected_color = get_unselect_color(self.C_PRESET_TEAM_1, self.C_PRESET_TEAM_2, self.C_PRESET_TEAM_3,
  551. size=color_size
  552. )
  553. print("")