def match(self, template, module=None): """ 当前设备图片识别 :param template: 识别图片对象或路径 :param module: 当template为路径时,可以指定的模块路径 :return: 匹配结果 boolean """ if type(template) == str: template = self.get_img(self.get_module_path(template, module)) return Match.match(self.adb.screen, template)
def get_img(self, filename): """ 返回图片池中的该图片,若不存在则添加至图片池再返回 :param filename: 图片文件名 :return: 图片对象 """ if filename not in self.images: # self.images[filename] = cv2.imread(self.image_path + "/" + filename) self.images[filename] = Match.cv_imread(os.path.join(self.image_path, filename)) return self.images[filename]
def match_touch(self, template, module=None): """ 匹配并点击图像在设备截图中的随机点 :param template: 识别图片对象或路径 :param module: 当template为路径时,可以指定的模块路径 :return: """ if type(template) == str: template = self.get_img(self.get_module_path(template, module)) pos_list = Match.get_match_pos(self.adb.screen, template, self.threshold) if pos_list: pos = fun.get_random_pos(*pos_list[0]) if pos: self.adb.click(pos) return True return False
def yeyuanhuo(self, tan=0, zen=0, chi=0): """业原火 该功能用于业原火副本。可以选择贪嗔痴不同的挑战次数。需要处于庭院或业原火挑战界面。 :param tan: 贪的数量 :param zen: 嗔的数量 :param chi: 痴的数量 :return: """ self.module = "业原火" self.logger.info("任务: " + self.module) option = list("贪嗔痴") options = {"贪": int(tan), "嗔": int(zen), "痴": int(chi)} for category in option: self.logger.info("%s\t%s" % (category, options[category])) self.adb.screenshot() # 进入业原火界面 for i in range(5): if self.match_touch("探索.png", "主页"): self.logger.info("进入探索页面") self.mood.mood_sleep() self.adb.screenshot() if self.match_touch("御魂.png", "公共"): self.logger.info("进入御魂页面") self.mood.mood_sleep() pos = Match.get_ratio_pos(self.adb.screen, [0.6, 0.3], [0.8, .75]) self.logger.info(pos) self.adb.click(pos) self.logger.info("进入业原火页面") break # 检查是否锁定阵容 self._locking_() # 开始业原火流程 for category in option: count = options[category] if count: if self.match_touch("%s.png" % category): self.logger.info("切换至" + category) i = 0 while i < count: if self._combat_(): i += 1 self.logger.info("当前为第%s次%s" % (i, category)) self.logger.info("总共进行了%s次%s" % (i, category))
def _end_(self, invite=False): """ 判断并点击界面跳过结算界面(旧版本宝箱结算) :return: 结算结果 """ # 等待结束 while True: end_sign = None # 结算成功标志 self.adb.screenshot() # 截图 # 一旦检测到结算标志进入循环,再次检测不到退出 while self.matchs( ("战斗胜利.png", "公共"), ("战斗失败.png", "公共"), ("结束标志.png", "公共"), ("贪吃鬼.png", "公共"), ("宝箱.png", "公共"), ("宝箱2.png", "公共"), ): self.logger.info("检测到结算页面") end_sign = True # 默认邀请队友 if invite: if self._invite_(): break if self.match("战斗失败.png", "公共"): self.logger.info("检测到战斗失败") end_sign = False end_regions = [ [[0.625, 0.9], [0.8, 0.98]], [[0.93, 0.33], [0.98, 0.66]], ] pos = fun.get_random_pos(*Match.get_ratio_pos(self.adb.screen, *fun.choice(end_regions))) self.logger.info(f"点击屏幕:{pos}") self.adb.click(pos) self.mood.mood_sleep() # 随机等待 self.adb.screenshot() # 截图 self.mood.mood_sleep() # 随机等待 if end_sign is not None: # 结算后跳出结算循环 self.logger.info("结算成功") return end_sign
async def _handler( self, request: web.Request) -> Union[web.Response, web.FileResponse]: """ Super simple HTTP handler. Parameters ---------- request : web.Request AIOHTTP request object. """ if request.method == 'GET': self.logger.debug( f'{request.remote} accessed {self.IP}:{self.port}{request.path}' ) return WebServer._http_error_handler() # Auth check for json elif request.method == 'POST': try: faceit = await request.json() except JSONDecodeError: self.logger.warning( f'{request.remote} sent a invalid json POST ') return WebServer._http_error_handler('json-body') self.logger.debug(f'webhook = \n {pprint.pformat(faceit)}') if faceit['retry_count'] == 0: if faceit['event'] == 'match_status_ready': self.logger.debug(f'{faceit["payload"]["id"]} is ready') match_exists = False for match_check in self.bot.matches: self.logger.debug(f'{match_check.match_id}') if match_check.match_id == str( faceit['payload']['id']): match_exists = True self.logger.error('Match already exists') break if not match_exists: self.logger.info('Creating channels') team1_channel: discord.VoiceChannel = await self.bot.get_channel( 787774505854042132).create_voice_channel( name=faceit["payload"]["teams"][0]["name"], user_limit=6) team2_channel: discord.VoiceChannel = await self.bot.get_channel( 787774505854042132).create_voice_channel( name=faceit["payload"]["teams"][1]["name"], user_limit=6) team1_roster = [] for team1_player in faceit["payload"]["teams"][0][ "roster"]: team1_roster.append( (team1_player['id'], team1_player['nickname'])) team2_roster = [] for team2_player in faceit["payload"]["teams"][1][ "roster"]: team2_roster.append( (team2_player['id'], team2_player['nickname'])) team1_invite = await team1_channel.create_invite( max_age=7200) team2_invite = await team2_channel.create_invite( max_age=7200) new_match = Match( faceit['payload']['id'], team1_channel, team2_channel, team1_invite, team2_invite, faceit["payload"]["teams"][0]["name"], faceit["payload"]["teams"][1]["name"], team1_roster, team2_roster) self.bot.matches.append(new_match) self.logger.debug(len(self.bot.matches)) self.logger.debug('finishing creating the match') if not self.bot.cogs[ 'CSGO'].update_scorecard.is_running(): self.logger.debug('starting loop thingy') self.bot.cogs['CSGO'].update_scorecard.start() if faceit['event'] == 'match_status_finished' or faceit[ 'event'] == 'match_status_aborted' or faceit[ 'event'] == 'match_status_cancelled': self.logger.debug(f'{faceit["payload"]["id"]} is over') match: Match = None for match_check in self.bot.matches: self.logger.debug(f'{match_check.match_id}') if match_check.match_id == str( faceit['payload']['id']): match = match_check self.logger.debug(f'Found match {match.match_id}') break if match is not None: for member in match.team1_channel.members + match.team2_channel.members: try: await member.move_to( channel=self.bot.get_channel( 784164015122546751), reason=f'Match Complete') except (discord.HTTPException, discord.Forbidden): self.logger.error(f'Could not move {member}') await match.team1_channel.delete( reason=f'{faceit["payload"]["id"]} Complete') await match.team2_channel.delete( reason=f'{faceit["payload"]["id"]} Complete') self.bot.matches.remove(match) self.logger.debug('Sending 200') return web.Response(status=200) else: # Used to decline any requests what doesn't match what our # API expects. self.logger.warning(f'{request.remote} sent an invalid request.') return WebServer._http_error_handler("request-type")
def jiejie(self): """结界突破 该功能用于结界突破。目前功能仍使用的老旧代码,请谨慎使用。 :return: """ self.module = "结界" self.logger.info("任务: 结界突破") # 结界对象大小 jiejie_object_width = 455 jiejie_object_height = 160 while True: self.adb.screenshot() # 检查是否在结界界面 if not (self.match("突破标志.png") or self.match("突破标志.png")): self.logger.warning("当前不在结界界面") if self.match_touch("结界突破.png", "公共"): self.logger.info("已自动进入结界突破界面") self.adb.screenshot() else: self.logger.error("无法进入结界突破界面,任务停止") break # 匹配目标 screen = self.adb.screen self.adb.threshold = 0.98 # 判断当前次数 if self.match("寮次数.png"): self.logger.warning("突破次数不足") # 等待15-20分钟 fun.random_time(15 * 60, 20 * 60) self.adb.threshold = 0.9 self.logger.info("获取结界目标") pos_list = Match.get_match_pos(self.adb.screen, self.get_img("突破对象标志.png"), 0.92) if pos_list: self.logger.info("获取到{}个结界目标".format(len(pos_list))) # 开始遍历结界目标 for pos in pos_list: self.adb.screenshot() if not self.match_touch("宝箱.png", "公共"): self.match_touch("宝箱2.png", "公共") pos_begin = (pos[1][0] - jiejie_object_width, pos[1][1] - jiejie_object_height) pos_end = pos[1] self.logger.info("开始节点:{}结束节点:{}".format(pos_begin, pos_end)) # 判断坐标真实有效,排除显示不全的目标 if pos_begin[0] > 0 and pos_begin[1] > 0: jiejie_img = screen[pos_begin[1]:pos_end[1], pos_begin[0]:pos_end[0]] Match.show_img(jiejie_img, time=800) if Match.match(jiejie_img, self.get_img(self.get_module_path("败北.png"))): self.logger.info("目标状态:败北") elif Match.match(jiejie_img, self.get_img(self.get_module_path("击破.png"))): self.logger.info("目标状态:击破") else: self.logger.info("目标状态:未突破") self.adb.click(fun.get_random_pos(*pos)) # #### self.mood.mood_sleep() self.adb.screenshot() if self.match_touch("进攻.png"): self.logger.info("开始突破") self.adb.screenshot() if self._end_(): self.logger.info("突破成功") self.mood.mood_sleep() break else: self.logger.info("突破失败") else: self.logger.info("未检测到结界挑战页面") else: self.logger.warning("无效的坐标") # 遍历完后滑动列表 else: self.adb.slide_event(1200, 875, dc="u", distance=700) self.mood.mood_sleep() else: self.logger.warning("未获取到结界目标")