/// <summary> /// Retrieves the attributes for a given champ (ability cooldowns, mana costs, etc.) /// </summary> /// <param name="championName">Internal champion name (i.e. Vel'Koz -> Velkoz)</param> /// <returns></returns> private async Task <ChampionAttributes> GetChampionInformation(string championName) { string latestVersion; try { string versionJSON = await WebRequestUtil.GetResponse(VERSION_ENDPOINT); List <string> versions = JsonConvert.DeserializeObject <List <string> >(versionJSON); latestVersion = versions[0]; } catch (WebException e) { throw new InvalidOperationException("Error retrieving game version", e); } string championJSON; try { championJSON = await WebRequestUtil.GetResponse(String.Format(CHAMPION_INFO_ENDPOINT, latestVersion, championName)); } catch (WebException e) { throw new InvalidOperationException("Error retrieving champion data for '" + championName + "'", e); } dynamic championData = JsonConvert.DeserializeObject <dynamic>(championJSON); return(ChampionAttributes.FromData(championData.data[championName])); }
/// <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); } }
private void WaitForGameInitialization() { Task.Run(async() => { while (true) { if (masterCancelToken.IsCancellationRequested) { return; } try { if (await WebRequestUtil.IsLive("https://127.0.0.1:2999/liveclientdata/allgamedata")) { break; } else { await Task.Delay(1000); continue; } } 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); await Task.Delay(1000); continue; } } await OnGameInitialized(); }); }
private static async void RetrieveItemInfo() { string latestVersion; try { string versionJSON = await WebRequestUtil.GetResponse(VERSION_ENDPOINT); List <string> versions = JsonConvert.DeserializeObject <List <string> >(versionJSON); latestVersion = versions[0]; } catch (WebException e) { throw new InvalidOperationException("Error retrieving game version", e); } string itemsJSON; try { itemsJSON = await WebRequestUtil.GetResponse(String.Format(ITEM_INFO_ENDPOINT, latestVersion)); } catch (WebException e) { throw new InvalidOperationException("Error retrieving item data", e); } dynamic itemsData = JsonConvert.DeserializeObject <dynamic>(itemsJSON); ParseItemInfo(itemsData); }
/// <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); }