/// <summary> /// Queries updated game data from the LoL live client API. /// </summary> private void QueryPlayerInfo() { string json; try { json = WebRequestUtil.GetResponse("https://127.0.0.1:2999/liveclientdata/allgamedata"); } catch (WebException e) { // TODO: Account for League client disconnects, game ended, etc. without crashing the whole program throw new InvalidOperationException("Couldn't connect with the game client", e); } var gameData = JsonConvert.DeserializeObject <dynamic>(json); gameEvents = (gameData.events.Events as JArray).ToObject <List <Event> >(); // Get active player info activePlayer = ActivePlayer.FromData(gameData.activePlayer); // Get player champion info (IsDead, Items, etc) champions = (gameData.allPlayers as JArray).ToObject <List <Champion> >(); playerChampion = champions.Find(x => x.SummonerName == activePlayer.SummonerName); // Update active player based on player champion data activePlayer.IsDead = playerChampion.IsDead; // Update champion LED module information if (championModule != null) { championModule.UpdatePlayerInfo(activePlayer); } }
/// <summary> /// Queries updated game data from the LoL live client API. /// </summary> private async Task QueryPlayerInfo(bool firstTime = false) { string json; try { json = await WebRequestUtil.GetResponse("https://127.0.0.1:2999/liveclientdata/allgamedata"); } catch (WebException e) { Console.WriteLine("InvalidOperationException: Game client disconnected"); throw new InvalidOperationException("Couldn't connect with the game client", e); } var gameData = JsonConvert.DeserializeObject <dynamic>(json); gameState.GameEvents = (gameData.events.Events as JArray).ToObject <List <Event> >(); // Get active player info gameState.ActivePlayer = ActivePlayer.FromData(gameData.activePlayer); // Get player champion info (IsDead, Items, etc) gameState.Champions = (gameData.allPlayers as JArray).ToObject <List <Champion> >(); gameState.PlayerChampion = gameState.Champions.Find(x => x.SummonerName == gameState.ActivePlayer.SummonerName); // Update active player based on player champion data gameState.ActivePlayer.IsDead = gameState.PlayerChampion.IsDead; // Update champion LED module information if (championModule != null) { championModule.UpdateGameState(gameState); } // Update player ability cooldowns gameState.PlayerAbilityCooldowns = championModule?.AbilitiesOnCooldown; // Set current game state CurrentGameState = gameState; // This call is possibly not needed because the reference is always the same // Get player items foreach (Item item in gameState.PlayerChampion.Items) { SetModuleForItem(item); } // Process game events ProcessGameEvents(firstTime); }