def run(self): while (True): # 大厅和游戏进程 名字不同 lobby_client = win32gui.FindWindow(None, LOL_CLIENT_NAME) game_client = win32gui.FindWindow(None, LOL_IN_GAME_CLIENT_NAME) if lobby_client != 0 and game_client == 0: # 正常逻辑,现在去截张图 然后看页面是什么状态 rect = win32gui.GetWindowRect(lobby_client) # keep the func work properly when user open different size of client, # we create a variable called enlargement factor enlargement_factor = getEnlargementFactor(rect) UserInGameInfo.getInstance().setEnlargementFactor(enlargement_factor) current_status = self._getCurrentStatus(rect, enlargement_factor) print("current_status ->", current_status) client_info = ClientInfo(True, current_status) client_info.setPosition(rect) self.keeper.emit(client_info) elif game_client != 0: # 进入游戏阶段 client_info = ClientInfo(True, ClientStatus.InGame) rect = win32gui.GetWindowRect(game_client) client_info.setPosition(rect) enlargement_factor = getEnlargementFactor(rect, "in_game") UserInGameInfo.getInstance().setEnlargementFactor(enlargement_factor) self.keeper.emit(client_info) else: self.keeper.emit(ClientInfo(False)) # lol client haven't start yet time.sleep(self._heart_beat_rate)
def _getCurrentStatus(self, position, factor=1.0): client_banner_img = grabImgByRect( genRelativePos(position, STATUS_AREA, factor), threshold=200) highlight_name = img2Str(client_banner_img) print("highlight_name ->", highlight_name) # 如果返回的是InRoom 状态, 这时需要额外关注 POSITION_AREA 区域字体的变化 if highlight_name == "InRoom": # 降低阈值 再次判断 client_banner_img = grabImgByRect( genRelativePos(position, BP_AREA, factor), threshold=150) twice_title = img2Str(client_banner_img) print("twice_title ->", twice_title) position_label_img = grabImgByRect( genRelativePos(position, POSITION_AREA, factor), threshold=140) position = img2Str(position_label_img) if (position is not None) and (position != "") and \ (position in POSITION_SET): # 有位置信息 print("Assigned user position in ", position) UserInGameInfo.getInstance().setUserPosition(position) return ClientStatus.str2Status(position) else: # 如果没有位置信息 if twice_title == "InRoom" and not self.twice_flag: self.twice_flag = True return ClientStatus.str2Status("InRoom") else: return ClientStatus.str2Status(twice_title) else: self.twice_flag = False return ClientStatus.str2Status(highlight_name)
def run(self): print(self.name + " has started.") while self.__running.isSet(): if self.client_info.getStatusIndex() == ClientStatus.InGame: if win32gui.FindWindow(None, LOL_IN_GAME_CLIENT_NAME) != 0 \ and win32api.GetAsyncKeyState(VK_CODE['p']): print("key p was pressed") if UserInGameInfo.getInstance().getEnemyInfoArea() is not None \ and UserInGameInfo.getInstance().getYourselfChamp() is not None \ and len(UserInGameInfo.getInstance().getEnemyInfo().keys()) > 1: self._instance_lock.acquire() enemy_info = UserInGameInfo.getInstance().getEnemyInfo( ) self_champion = UserInGameInfo.getInstance( ).getYourselfChamp() self_position = UserInGameInfo.getInstance( ).getUserPosition() enemy_gears = extractDictValue(enemy_info) recommend_gears = itemSuggestion( self_position, self_champion, enemy_gears) UserInGameInfo.getInstance().setRecommendGears( recommend_gears) self._instance_lock.release() time.sleep(1)
def copyAndPasteChampName(): champ_name = UserInGameInfo.getInstance().getRecommendChampAutoCountList() enlargement_factor = UserInGameInfo.getInstance().getEnlargementFactor() lobby_client = win32gui.FindWindow(None, LOL_CLIENT_NAME) if lobby_client != 0: rect = win32gui.GetWindowRect(lobby_client) relative_point = getChampSearchBoxPoint(rect, CHAMP_SEARCH_BOX_POINT, enlargement_factor) if champ_name is not None: pasteToSearchBox(relative_point, champ_name) else: NotificationWindow.warning( 'BP Champion Session', "It seems like you don't have any one recommend champion..\n Good Luck then", callback=None)
def copyAndPasteGearName(): gear_name = UserInGameInfo.getInstance().getRecommendGearAutoCountList() enlargement_factor = UserInGameInfo.getInstance().getEnlargementFactor() game_client = win32gui.FindWindow(None, LOL_IN_GAME_CLIENT_NAME) if game_client != 0: rect = win32gui.GetWindowRect(game_client) relative_point = getGearSearchBoxPoint(rect, GEAR_SEARCH_BOX_POINT, enlargement_factor) if gear_name is not None: pasteToSearchBox(relative_point, gear_name.replace("_", " ")) else: UserInGameInfo.getInstance().resetGearCounter() NotificationWindow.warning( 'Item Suggestion Session', "Poro wil rerun the item recommendation list..\n Good Luck then", callback=None)
def run(self): print(self.name + " has started.") while self.__running.isSet(): if self.client_info.getStatusIndex() == ClientStatus.InGame: if win32gui.FindWindow(None, LOL_IN_GAME_CLIENT_NAME) != 0 \ and win32api.GetAsyncKeyState(win32con.VK_TAB): print("tab was pressed") if UserInGameInfo.getInstance().getEnemyInfoArea() is None: self._instance_lock.acquire() # crop the whole image, since we dont know where is the enemy tab_panel = grabImgByRect(self.crop_position, binarize=False) # 把整张图片切成五份, 但是我们不知道左边是敌人还是右边是敌人,所以需要比较一次 teamLeft = cropImgByRect(tab_panel, TEAM_LEFT_IN_TAB) teamRight = cropImgByRect(tab_panel, TEAM_RIGHT_IN_TAB) left_five_imgs = split2NPieces(teamLeft, interval=21, horizontal=False) left_results = ProfileModel.getInstance().predictImgs( left_five_imgs) # right_five_imgs = split2NPieces(teamRight, interval=21, horizontal=False) right_results = ProfileModel.getInstance().predictImgs( right_five_imgs) print("left_results->", left_results) print("right_results->", right_results) # TODO 因为准确率的问题,(不能全部识别对, 所以认对3/5 就算, 实际排位中两方英雄都不一样) if len( set(UserInGameInfo.getInstance(). getEnemyTeamList()).difference( set(right_results))) <= 3: if self.right_twice_flag: UserInGameInfo.getInstance().setEnemyInfoArea( TEAM_RIGHT_IN_TAB) self.right_twice_flag = True elif len( set(UserInGameInfo.getInstance(). getEnemyTeamList()).intersection( set(left_results))) >= 3: if self.left_twice_flag: UserInGameInfo.getInstance().setEnemyInfoArea( TEAM_LEFT_IN_TAB) self.left_twice_flag = True self._instance_lock.release() else: # once we got to know which is enemy, we can only crop small part of pics enemy_panel_area = UserInGameInfo.getInstance( ).getEnemyInfoArea() tab_panel = grabImgByRect(self.crop_position, binarize=False) # 从整张图片提取出来敌人的部分 enemy_info_img = cropImgByRect(tab_panel, enemy_panel_area) # 在这里还需要截自己的装备 self_info_img = None if enemy_panel_area == expandCropArea( TEAM_LEFT_IN_TAB): self_info_img = cropImgByRect( tab_panel, expandCropArea(TEAM_RIGHT_IN_TAB)) else: self_info_img = cropImgByRect( tab_panel, expandCropArea(TEAM_LEFT_IN_TAB)) enemy_info = decodeImgs(enemy_info_img) if len( set(enemy_info.keys()).intersection( set(UserInGameInfo.getInstance(). getEnemyTeamList()))) >= 3: print("enemy_info ->", enemy_info) UserInGameInfo.getInstance().setEnemyInfo( enemy_info) if UserInGameInfo.getInstance().getYourselfChamp( ) is not None: self_team_info = decodeImgs(self_info_img) self_champ = UserInGameInfo.getInstance( ).getYourselfChamp() self_gear = self_team_info.get(self_champ, None) if self_gear is not None: print("self_gear[\"gears\"] ->", self_gear["gears"]) UserInGameInfo.getInstance().setYourselfGears( set(self_gear.get("gears", set())) - set(NONE_LIST)) print( "output gear = ", UserInGameInfo.getInstance(). getYourselfGears()) UserInGameInfo.getInstance( ).setGearDetectedFlag(True) else: # 1. self_champ is wrong # 2. 截取到了地面 pass time.sleep(self._capture_rate)
def inGameAnalysis(client_info): global pop_threshold if len(in_game_thread_pool) == 0: NotificationWindow.suggest( 'Game Mode', "Ready to fright! \n" "Poro will continue to give you suggestions. \n help you to win this game", callback=None) enemy_team_catcher = ImgCatcherThread( "ENEMY_TEAM_PROFILE_CATCHER", client_info, ImgCropType.ENEMY_TEAM_5_CHAMP, genRelativePos(client_info.getPosition(), ENEMY_TEAM_AREA, client_info.getEnlargementFactor())) in_game_thread_pool.append(enemy_team_catcher) enemy_team_catcher.setDaemon(True) enemy_team_catcher.start() tab_catcher = TabKeyListener("TAB_IMG_CATCHER", client_info, TAB_PANEL) in_game_thread_pool.append(tab_catcher) tab_catcher.setDaemon(True) tab_catcher.start() user_champ_catcher = ImgCatcherThread("USER_S_CHAMP_CATCHER", client_info, ImgCropType.USER_S_CHAMP_AREA, USER_S_CHAMP_AREA) in_game_thread_pool.append(user_champ_catcher) user_champ_catcher.setDaemon(True) user_champ_catcher.start() shop_key_catcher = ShopPKeyListener("SHOP_P_CATCHER", client_info) in_game_thread_pool.append(shop_key_catcher) shop_key_catcher.setDaemon(True) shop_key_catcher.start() mini_map_catcher = ImgCatcherThread("MINI_MAP_CATCHER", client_info, ImgCropType.MINI_MAP, MINI_MAP_BOX, 1) in_game_thread_pool.append(mini_map_catcher) mini_map_catcher.setDaemon(True) mini_map_catcher.start() if UserInGameInfo.getInstance().getGearDetectedFlag(): # show enemy champion info and gears NotificationWindow.threat( 'In Game Detection Session', """Enemy team has purchased these following gears:<html> <head><style>.info{{text-align:left;height:40px}}.info span{{display:inline-block; vertical-align:middle;padding:20px 0;}}.info img{{width:32px; height:auto;vertical-align:middle}}#class_icon{{width:15px}}#lane_icon{{width:15px; margin-left:5px}}</style></head><body>{}</body></html>""" .format(UserInGameInfo.getInstance().getEnemyTeamDetailHTML()), callback=None) # show your self champion and gear NotificationWindow.detect( 'In Game Detection Session', """For Now, you have these gears:<html> <head><style>.info{{text-align:left;height:40px}}.info span{{display:inline-block; vertical-align:middle;padding:20px 0;}}.info img{{width:32px; height:auto;vertical-align:middle}}#class_icon{{width:15px}}#lane_icon{{width:15px; margin-left:5px}}</style></head><body>{}</body></html>""" .format(UserInGameInfo.getInstance().getSelfChampAndGearHTML()), callback=None) UserInGameInfo.getInstance().setGearDetectedFlag(False) if UserInGameInfo.getInstance().getGearRecommendFlag(): # show item suggestion (remember to modify the callback func) NotificationWindow.suggest( 'Item Suggestion Session', """Poro highly recommends you to choose gears:<html> <head><style>.info{{text-align:left;height:40px}}.info span{{display:inline-block; vertical-align:middle;padding:20px 0;}}.info img{{width:32px; height:auto;vertical-align:middle}}#class_icon{{width:15px}}#lane_icon{{width:15px; margin-left:5px}}</style></head><body>{}</body></html>""" .format(UserInGameInfo.getInstance().getRecommendGears()), callback=copyAndPasteGearName) UserInGameInfo.getInstance().setGearRecommendFlag(False) if pop_threshold >= 0 and len( UserInGameInfo.getInstance().getEnemyTeamList()) == 5: NotificationWindow.detect( 'BP Champion Session', """Enemy team has choose these following champions:<html> <head><style>.info{{text-align:left;height:40px}}.info span{{display:inline-block; vertical-align:middle;padding:20px 0;}}.info img{{width:32px; height:auto;vertical-align:middle}}#class_icon{{width:15px}}#lane_icon{{width:15px; margin-left:5px}}</style></head><body>{}</body></html>""" .format(UserInGameInfo.getInstance().getEnemyTeamListHTML()), callback=None) pop_threshold -= 1 if pop_threshold == -1 and UserInGameInfo.getInstance().getEnemyInfoArea( ) is not None: # 得到在左还是在右的信息 NotificationWindow.detect( 'In Game Detection Session', """Poro has recognized your enemy team on your tab panel <br/> There are:<html> <head><style>.info{{text-align:left;height:40px}}.info span{{display:inline-block; vertical-align:middle;padding:20px 0;}}.info img{{width:32px; height:auto;vertical-align:middle}}#class_icon{{width:15px}}#lane_icon{{width:15px; margin-left:5px}}</style></head><body>{}</body></html>""" .format(UserInGameInfo.getInstance().getEnemyTeamListSimpleHTML()), callback=None) pop_threshold -= 1 if pop_threshold == -2 and UserInGameInfo.getInstance().getYourselfChamp( ) is not None: NotificationWindow.detect( 'In Game Detection Session', """Poro has recognized your champion is:<html> <head><style>.info{{text-align:left;height:40px}}.info span{{display:inline-block; vertical-align:middle;padding:20px 0;}}.info img{{width:32px; height:auto;vertical-align:middle}}#class_icon{{width:15px}}#lane_icon{{width:15px; margin-left:5px}}</style></head><body>{}</body></html>""" .format(UserInGameInfo.getInstance().getYourselfChampHTML()), callback=None) pop_threshold -= 1 if pop_threshold < -2: warning_info = UserInGameInfo.getInstance().getWarningInfo() for content in warning_info: NotificationWindow.threat( 'In Game Warning Session', """Poro has recognized there might have some dangerous:<html> <head><style>.info{{text-align:left;height:40px}}.info span{{display:inline-block; vertical-align:middle;padding:20px 0;}}.info img{{width:32px; height:auto;vertical-align:middle}}#class_icon{{width:15px}}#lane_icon{{width:15px; margin-left:5px}}</style></head><body>{}</body></html>""" .format(content), callback=None) pop_threshold -= 1
def bpSessionAnalysis(client_info): if len(bp_session_thread_pool) == 0: ban_you_catcher = ImgCatcherThread( "BAN_YOU_IMG_CATCHER", client_info, ImgCropType.BAN_5_CHAMP, genRelativePos(client_info.getPosition(), BAN_AREA_YOU, client_info.getEnlargementFactor())) ban_enemy_catcher = ImgCatcherThread( "BAN_ENEMY_IMG_CATCHER", client_info, ImgCropType.ENEMY_BAN_5_CHAMP, genRelativePos(client_info.getPosition(), BAN_AREA_ENEMY, client_info.getEnlargementFactor())) bp_session_thread_pool.append(ban_you_catcher) bp_session_thread_pool.append(ban_enemy_catcher) ban_you_catcher.setDaemon(True) ban_enemy_catcher.setDaemon(True) ban_you_catcher.start() ban_enemy_catcher.start() if UserInGameInfo.getInstance().getBannedChampionsSize( ) >= BANNED_CHAMP_SIZE: NotificationWindow.detect( 'BP Champion Session', """You team has banned these following champions:<html> <head><style>.info{{text-align:left;height:40px}}.info span{{display:inline-block; vertical-align:middle;padding:20px 0;}}.info img{{width:32px; height:auto;vertical-align:middle}}#class_icon{{width:15px}}#lane_icon{{width:15px; margin-left:5px}}</style></head><body>{}</body></html>""" .format(UserInGameInfo.getInstance().getBannedChampListHTML()), callback=None) if UserInGameInfo.getInstance().getEnemyBannedChampionsSize( ) >= BANNED_CHAMP_SIZE: UserInGameInfo.getInstance().setEnemyFlag(True) NotificationWindow.threat( 'BP Champion Session', """Enemy team has banned these following champions:<html> <head><style>.info{{text-align:left;height:40px}}.info span{{display:inline-block; vertical-align:middle;padding:20px 0;}}.info img{{width:32px; height:auto;vertical-align:middle}}#class_icon{{width:15px}}#lane_icon{{width:15px; margin-left:5px}}</style></head><body>{}</body></html>""" .format( UserInGameInfo.getInstance().getEnemyBannedChampListHTML()), callback=None) # 在这里可以进行英雄推荐了 if UserInGameInfo.getInstance().getEnemyBannedChampionsSize() >= BANNED_CHAMP_SIZE and \ UserInGameInfo.getInstance().getBannedChampionsSize() >= BANNED_CHAMP_SIZE: print("UserPosition :", UserInGameInfo.getInstance().getUserPosition()) UserInGameInfo.getInstance().initRecommendChampList() NotificationWindow.suggest( 'BP Champion Session', """Poro highly recommends you to choose champion:<html> <head><style>.info{{text-align:left;height:40px}}.info span{{display:inline-block; vertical-align:middle;padding:20px 0;}}.info img{{width:32px; height:auto;vertical-align:middle}}#class_icon{{width:15px}}#lane_icon{{width:15px; margin-left:5px}}</style></head><body>{}</body></html>""" .format(UserInGameInfo.getInstance().getRecommendChampListHTML()), callback=copyAndPasteChampName)
def statusChange(client): global pop_threshold if client.hasAlive(): if not client.isGameMode(): # 非游戏和 房间阶段 NotificationWindow.info( 'Info', "LOL Client Status: Your are in <u><b>{}</b></u> Panel".format( client.getStatus()["name"]), callback=None) # TODO 暂时防误杀 if client.getStatus()["name"] != "InRoom": if len(bp_session_thread_pool) > 0: [thread.stop() for thread in bp_session_thread_pool] if len(in_game_thread_pool) > 0: [thread.stop() for thread in in_game_thread_pool] bp_session_thread_pool.clear() in_game_thread_pool.clear() pop_threshold = POPUP_THRESHOLD # 重置所有游戏信息 ImgCatcherThread.resetLocalList() UserInGameInfo.getInstance().resetAll() else: # 游戏阶段, BP, 选英雄, 游戏内 # detect user's position if client.getStatusIndex() == ClientStatus.AssignPosition: if UserInGameInfo.getInstance().hasPositionInfo(): NotificationWindow.detect( 'Entering Game Mode...', "You are assigned in <u><b>{}</b></u> position.". format(UserInGameInfo.getInstance().getUserPosition()), callback=None) # picking champions elif client.getStatusIndex() == ClientStatus.ChooseChampion: if random.randint(0, 1) == 1: NotificationWindow.detect( 'BP Champion Session', "You have entered Champion BP Session.", callback=None) # TODO 都是为了测试, 正式时候可以删除 if not UserInGameInfo.getInstance().hasPositionInfo(): print( "Since we join the custom room, so we assigned a TOP position to you" ) UserInGameInfo.getInstance().setUserPosition("TOP") NotificationWindow.detect( 'BP Champion Session', "You has been assigned in <u><b>TOP</b></u> position. <br/> Tips: " "Since we join the custom room, so we assigned a TOP position to you", callback=None) # 这里开启一个线程 去捕捉 图片 预测 不需要跟pyqt挂钩 bpSessionAnalysis(client) else: if len(bp_session_thread_pool) > 0: for thread in bp_session_thread_pool: thread.stop() bp_session_thread_pool.clear() inGameAnalysis(client) else: NotificationWindow.warning( 'Warning', "Assistant has lost connection to LOL client", callback=None)