private void Kappa_Authed(object sender, EventArgs e) { srcBook = this.session.Me.Masteries; book = new MasteryBook(); foreach (var srcPage in srcBook.BookPages) { var page = new MasteryPage { Id = srcPage.PageId, Name = srcPage.Name }; if (srcPage.Current) { book.Selected = page.Id; } foreach (var talent in srcPage.TalentEntries) { page.Masteries.Add(talent.TalentId.ToString(), talent.Rank); } book.Pages.Add(page); } }
public static async Task SetMasterySetups(JObject jObject) { bool flag; string obj = jObject["activeId"].ToObject<string>(); MasterySetup[] array = jObject["setups"].Select<JToken, MasterySetup>(new Func<JToken, MasterySetup>(InventoryHelper.ToMasterySetup)).ToArray<MasterySetup>(); MasteryBook masteryBook = new MasteryBook() { ActiveId = obj, Setups = array }; MasteryBook masteryBook1 = masteryBook; LittleClient client = JsApiService.Client; object[] objArray = new object[] { "masteries", masteryBook1 }; await client.Invoke("storage.set", objArray); RiotAccount[] all = JsApiService.AccountBag.GetAll(); for (int i = 0; i < (int)all.Length; i++) { InventoryHelper.ClearMasteryCache(all[i]); } InventoryHelper.SaveRiotMasteryBook(masteryBook1); }
private static void SaveRiotMasteryBook(MasteryBook book) { MasterySetup[] array = (book.Setups ?? new MasterySetup[0]).Take<MasterySetup>(20).ToArray<MasterySetup>(); MasteryBookPageDTO[] masteryBookPageDTOArray = array.Select<MasterySetup, MasteryBookPageDTO>(new Func<MasterySetup, MasteryBookPageDTO>(InventoryHelper.ToMasteryBookPage)).ToArray<MasteryBookPageDTO>(); Dictionary<string, string[]> dictionary = ( from x in (IEnumerable<MasteryBookPageDTO>)masteryBookPageDTOArray select x.Name).ToLookup<string, string>((string x) => x).ToDictionary<IGrouping<string, string>, string, string[]>((IGrouping<string, string> x) => x.Key, (IGrouping<string, string> x) => x.ToArray<string>()); for (int i = 0; i < (int)masteryBookPageDTOArray.Length; i++) { MasteryBookPageDTO masteryBookPageDTO = masteryBookPageDTOArray[i]; masteryBookPageDTO.PageId = (double)(i + 1); if (string.IsNullOrEmpty(masteryBookPageDTO.Name) || (int)dictionary[masteryBookPageDTO.Name].Length > 1) { masteryBookPageDTO.Name = string.Format("#{0:00}. {1}", i, masteryBookPageDTO.Name); } if (((IEnumerable<MasteryBookPageDTO>)masteryBookPageDTOArray).All<MasteryBookPageDTO>((MasteryBookPageDTO x) => !x.Current) && array[i].Id == book.ActiveId) { masteryBookPageDTO.Current = true; } } if ((int)masteryBookPageDTOArray.Length > 0) { if (((IEnumerable<MasteryBookPageDTO>)masteryBookPageDTOArray).All<MasteryBookPageDTO>((MasteryBookPageDTO x) => !x.Current)) { masteryBookPageDTOArray[0].Current = true; } } RiotAccount[] all = JsApiService.AccountBag.GetAll(); for (int j = 0; j < (int)all.Length; j++) { RiotAccount riotAccount = all[j]; MasteryBookDTO masteryBookDTO = new MasteryBookDTO() { SummonerId = (double)riotAccount.SummonerId, BookPages = masteryBookPageDTOArray.ToList<MasteryBookPageDTO>() }; riotAccount.InvokeAsync<object>("masteryBookService", "saveMasteryBook", masteryBookDTO); InventoryHelper.ClearMasteryCache(riotAccount); } }
private async Task ImportMasteries(RiotAccount account) { string str; Func<MasteryBookPageDTO, string> func = (MasteryBookPageDTO page) => page.PageId.ToString(CultureInfo.InvariantCulture); MasteryBookDTO masteryBookDTO = await account.InvokeAsync<MasteryBookDTO>("masteryBookService", "getMasteryBook", account.SummonerId); MasteryBookDTO masteryBookDTO1 = masteryBookDTO; List<MasteryBookPageDTO> bookPages = masteryBookDTO1.BookPages; IOrderedEnumerable<MasteryBookPageDTO> pageId = from page in bookPages orderby page.PageId select page; IEnumerable<MasterySetup> talentEntries = from page in pageId let masteries = from x in page.TalentEntries select new Mastery() { Id = x.TalentId, Rank = x.Rank } select new MasterySetup() { Id = func(page), Name = page.Name, Masteries = masteries.ToArray<Mastery>() }; List<MasteryBookPageDTO> masteryBookPageDTOs = masteryBookDTO1.BookPages; MasteryBookPageDTO masteryBookPageDTO = masteryBookPageDTOs.FirstOrDefault<MasteryBookPageDTO>((MasteryBookPageDTO x) => x.Current); if (masteryBookPageDTO != null) { str = func(masteryBookPageDTO); } else { str = null; } string str1 = str; LittleClient client = JsApiService.Client; object[] objArray = new object[] { "masteries", null }; MasteryBook masteryBook = new MasteryBook() { ActiveId = str1, Setups = talentEntries.ToArray<MasterySetup>() }; objArray[1] = masteryBook; await client.Invoke("storage.set", objArray); }
private static void SaveRiotMasteryBook(MasteryBook book) { MasterySetup[] masterySetupArray = Enumerable.ToArray<MasterySetup>(Enumerable.Take<MasterySetup>((IEnumerable<MasterySetup>) (book.Setups ?? new MasterySetup[0]), 20)); MasteryBookPageDTO[] masteryBookPageDtoArray = Enumerable.ToArray<MasteryBookPageDTO>(Enumerable.Select<MasterySetup, MasteryBookPageDTO>((IEnumerable<MasterySetup>) masterySetupArray, new Func<MasterySetup, MasteryBookPageDTO>(InventoryHelper.ToMasteryBookPage))); Dictionary<string, string[]> dictionary = Enumerable.ToDictionary<IGrouping<string, string>, string, string[]>((IEnumerable<IGrouping<string, string>>) Enumerable.ToLookup<string, string>(Enumerable.Select<MasteryBookPageDTO, string>((IEnumerable<MasteryBookPageDTO>) masteryBookPageDtoArray, (Func<MasteryBookPageDTO, string>) (x => x.Name)), (Func<string, string>) (x => x)), (Func<IGrouping<string, string>, string>) (x => x.Key), (Func<IGrouping<string, string>, string[]>) (x => Enumerable.ToArray<string>((IEnumerable<string>) x))); for (int index = 0; index < masteryBookPageDtoArray.Length; ++index) { MasteryBookPageDTO masteryBookPageDto = masteryBookPageDtoArray[index]; masteryBookPageDto.PageId = (double) (index + 1); if (string.IsNullOrEmpty(masteryBookPageDto.Name) || dictionary[masteryBookPageDto.Name].Length > 1) masteryBookPageDto.Name = string.Format("#{0:00}. {1}", (object) index, (object) masteryBookPageDto.Name); if (Enumerable.All<MasteryBookPageDTO>((IEnumerable<MasteryBookPageDTO>) masteryBookPageDtoArray, (Func<MasteryBookPageDTO, bool>) (x => !x.Current)) && masterySetupArray[index].Id == book.ActiveId) masteryBookPageDto.Current = true; } if (masteryBookPageDtoArray.Length > 0 && Enumerable.All<MasteryBookPageDTO>((IEnumerable<MasteryBookPageDTO>) masteryBookPageDtoArray, (Func<MasteryBookPageDTO, bool>) (x => !x.Current))) masteryBookPageDtoArray[0].Current = true; foreach (RiotAccount account in JsApiService.AccountBag.GetAll()) { RiotAccount riotAccount = account; string destination = "masteryBookService"; string method = "saveMasteryBook"; MasteryBookDTO masteryBookDto1 = new MasteryBookDTO(); masteryBookDto1.SummonerId = (double) account.SummonerId; masteryBookDto1.BookPages = Enumerable.ToList<MasteryBookPageDTO>((IEnumerable<MasteryBookPageDTO>) masteryBookPageDtoArray); MasteryBookDTO masteryBookDto2 = masteryBookDto1; riotAccount.InvokeAsync<object>(destination, method, (object) masteryBookDto2); InventoryHelper.ClearMasteryCache(account); } }
public static async Task SetMasterySetups(JObject jObject) { string activeId = jObject["activeId"].ToObject<string>(); MasterySetup[] setups = Enumerable.ToArray<MasterySetup>(Enumerable.Select<JToken, MasterySetup>((IEnumerable<JToken>) jObject["setups"], new Func<JToken, MasterySetup>(InventoryHelper.ToMasterySetup))); MasteryBook book = new MasteryBook() { ActiveId = activeId, Setups = setups }; await JsApiService.Client.Invoke("storage.set", new object[2] { (object) "masteries", (object) book }); foreach (RiotAccount account in JsApiService.AccountBag.GetAll()) InventoryHelper.ClearMasteryCache(account); InventoryHelper.SaveRiotMasteryBook(book); }