general_battle.py 24 KB

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