/// <summary> Fetch relic tier GP bonus info. </summary> public async Task <int[]> GetRelicMetadata() { Stream resp; try { var payload = new GameDataCommand() { collection = "tableList" }; payload.match = new Dictionary <string, object>() { { "id", "galactic_power_per_relic_tier" } }; resp = await MakeApiRequest(payload, URL_DATA); } catch (ApiErrorException e) { DisplayError(e.Response == null ? e.Message : e.Response.ReasonPhrase, "Relic Info"); return(new int[] { }); } DataTable[] retval; using (StreamReader sr = new StreamReader(resp)) using (JsonReader js = new JsonTextReader(sr)) { JsonSerializer ser = new JsonSerializer(); retval = ser.Deserialize <DataTable[]>(js); } resp.Dispose(); if (retval == null || retval.Length == 0) { return(new int[] { }); } return(retval.First().rowList .Select(r => int.TryParse(r.value, out int val) ? val : -1) .OrderBy(x => x) .ToArray()); }
/// <summary> Retrieve misc. data about each defined character. </summary> /// <remarks> This data is not included in what gets returned for a player's roster. </remarks> public async Task <UnitDetails[]> GetUnitDetails() { Stream resp; try { // This table contains an enormous amount of information. // To avoid downloading hundreds of MB of data, filter down to // only one version of each player-unlockable character, then // limit the fields returned to the few that we can actually use. var payload = new GameDataCommand() { collection = "unitsList" }; payload.match = new Dictionary <string, object>() { { "obtainable", true }, { "rarity", 7 } }; payload.project = new Dictionary <string, object>() { { "baseId", 1 }, { "forceAlignment", 1 }, { "combatType", 1 }, { "categoryIdList", 1 }, { "nameKey", 1 } }; resp = await MakeApiRequest(payload, URL_DATA); } catch (ApiErrorException e) { DisplayError(e.Response == null ? e.Message : e.Response.ReasonPhrase, "Relic Info"); return(new UnitDetails[] { }); } UnitDetails[] units; using (StreamReader sr = new StreamReader(resp)) using (JsonReader js = new JsonTextReader(sr)) { JsonSerializer ser = new JsonSerializer(); units = ser.Deserialize <UnitDetails[]>(js); } resp.Dispose(); if (units == null || units.Length == 0) { return(new UnitDetails[] { }); } // Delete several units that aren't actually obtainable // TODO: Find a better way to filter these automatically units = units.Where(u => { var suffixes = new string[] { "_DUEL", "_GLEVENT", "_EVENT", "_MARQUEE" }; var badnames = new string[] { "AWAKENEDREY", "AMILYNHOLDO_RADDUS", "FOTF_VADER", "VULTUREDROID_tb" }; foreach (var x in suffixes) { if (u.baseId.EndsWith(x)) { return(false); } } return(!badnames.Contains(u.baseId)); }).ToArray(); // Now fetch the 'categoryList' table resp = null; try { var payload = new GameDataCommand() { collection = "categoryList" }; resp = await MakeApiRequest(payload, URL_DATA); } catch (ApiErrorException e) { DisplayError(e.Response == null ? e.Message : e.Response.ReasonPhrase, "Relic Info"); return(new UnitDetails[] { }); } Category[] categories; using (StreamReader sr = new StreamReader(resp)) using (JsonReader js = new JsonTextReader(sr)) { JsonSerializer ser = new JsonSerializer(); categories = ser.Deserialize <Category[]>(js); } resp.Dispose(); if (categories == null || categories.Length == 0) { return(new UnitDetails[] { }); } // Map "categoryIdList" values to localized strings foreach (var unit in units) { List <string> newtags = new List <string>(); foreach (string cat in unit.categoryIdList) { // Ignore "self-tags", they're not interesting to us if (cat.StartsWith("selftag_")) { continue; } var match = categories.FirstOrDefault(c => c.id == cat); if (match != null) { //if (!match.visible) // disable for now, this info might be interesting // continue; if (match.descKey != "Placeholder" && !match.descKey.Contains("_")) { newtags.Add(match.descKey); } // Add manual translation for interesting hidden categories with no official description else if (missing_category_translations.ContainsKey(match.id)) { newtags.Add(missing_category_translations[match.id]); } } } unit.categoryIdList = newtags.Distinct().OrderBy(c => c).ToArray(); } return(units); }