general_battle.py 23 KB

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