Exemple #1
0
        private bool StoreRiotItemData(ItemListStatic items)
        {
            bool success = false;

            try
            {
                string file = string.Format(@"{0}\Data\Items\getItems.{1}.bin", PublicStaticVariables.thisAppDataDir, items.Version);
                string dir  = string.Format(@"{0}\Data\Items", PublicStaticVariables.thisAppDataDir);

                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }

                using (FileStream fs = File.Open(file, FileMode.Create))
                    using (StreamWriter sw = new StreamWriter(fs))
                        using (JsonWriter jw = new JsonTextWriter(sw))
                        {
                            jw.Formatting = Formatting.Indented;

                            JsonSerializer serializer = new JsonSerializer();
                            serializer.Serialize(jw, items);
                        }
                success = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                success = false;
            }
            return(success);
        }
Exemple #2
0
        public static Item ObterItem(long itemID, ItemListStatic itens, string versao)
        {
            if (itemID > 0)
            {
                var conversao = itens.Items.TryGetValue((int)itemID, out var item);

                if (conversao)
                {
                    return(new Item
                    {
                        Nome = item.Name,
                        UrlIcone = $"//ddragon.leagueoflegends.com/cdn/{versao}/img/item/{item.Image.Full}"
                    });
                }
                else
                {
                    return(new Item
                    {
                        Nome = $"Item {itemID} não encontrado",
                        UrlIcone = "/images/image_not_found.png"
                    });
                }
            }

            return(null);
        }
Exemple #3
0
        public bool LoadRiotItemData(string version)
        {
            bool success = false;

            try
            {
                string file;
                file = string.Format(@"{0}\Data\Items\getItems.{1}.bin", PublicStaticVariables.thisAppDataDir, version);


                string dir = string.Format(@"{0}\Data\Items", PublicStaticVariables.thisAppDataDir);

                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }

                StreamReader re = new StreamReader(file);
                try
                {
                    JsonTextReader reader = new JsonTextReader(re);

                    JsonSerializer se         = new JsonSerializer();
                    object         parsedData = se.Deserialize(reader);

                    ItemListStatic items = JsonConvert.DeserializeObject <ItemListStatic>(parsedData.ToString());

                    SortRiotItemData(items);

                    success = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    success = false;
                }
                finally
                {
                    re.Close();
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("Could not find file") && ex.Message.Contains("getItems"))
                {
                    //TODO: This exception usually means the data are not on the computer and will be downloaded
                }
                else
                {
                    MessageBox.Show(ex.ToString());
                }
                success = false;
            }
            return(success);
        }
        internal static void RunCorrections(ItemListStatic item)
        {
            var keys = new List <int>(item.Items.Keys);

            foreach (int key in keys)
            {
                ItemStatic temp = item.Items[key];

                ItemCorrection(temp);
            }
        }
Exemple #5
0
 private static ItemStatic getItem(int itemId)
 {
     if (Items == null)
     {
         Items = StaticRiotApi.GetInstance(API_KEY).GetItems(Region.na, ItemData.all);
     }
     if (Items.Items.ContainsKey(itemId))
     {
         var item = Items.Items[itemId];
         return(item);
     }
     return(Items.Items.Values.First());
 }
Exemple #6
0
        internal static UpsetModel GetUpsetModel()
        {
            UpsetModel model = new UpsetModel();

            if (Items == null)
            {
                Items = StaticRiotApi.GetInstance(API_KEY).GetItems(Region.na, ItemData.all);
            }
            if (PotentialUpgrades == null)
            {
                InitializePotentialUpgrades();
            }
            model.CompleteItems     = Items.Items.Where(x => x.Value.Into == null && x.Value.From != null).Select(x => x.Value).ToList();
            model.PotentialUpgrades = PotentialUpgrades;
            return(model);
        }
        public void UpdateItems()
        {
            UpdateStatus("Updating items...");
            int            i     = 0;
            double         prog  = 0;
            ItemListStatic items = StaticApi.GetItems(_basereg, ItemData.image);

            foreach (KeyValuePair <int, ItemStatic> it in items.Items)
            {
                i++;
                prog = (double)i / items.Items.Count;
                UpdateProgress((int)(prog * 100));

                if (!File.Exists(ItemsDirectory + @"\" + it.Value.Id.ToString() + ".png"))
                {
                    _wbc.DownloadFile(DataDragonRealm.Cdn + "/" + DataDragonRealm.Dd + "/img/item/" + it.Value.Image.Full, ItemsDirectory + @"\" + it.Value.Id.ToString() + ".png");
                    UpdateStatus("Item " + it.Value.Id.ToString() + ".png");
                }
            }
            UpdateStatus("Items Updated");
        }
Exemple #8
0
 public ItemListStaticWrapper(ItemListStatic items, Language language, string version)
 {
     ItemListStatic = items;
     Language       = language;
     Version        = version;
 }
Exemple #9
0
        public PartidaViewModel(Partida partida, ChampionListStatic campeoes, string ultimaVersao, string contaJogadorPrincipal, ItemListStatic itens, SummonerSpellListStatic spells)
        {
            var idTimeAliado = partida.Participants.First(y => y.ParticipantId == partida.ParticipantIdentities.First(k => k.Player.CurrentAccountId == contaJogadorPrincipal).ParticipantId).TeamId;

            var timeAliado = partida.Teams.First(x => x.TeamId == idTimeAliado);

            TimeAliado = new TimeViewModel(timeAliado);

            TimeAliado.Participantes = partida.Participants.Where(x => x.TeamId == idTimeAliado).Select(participante => new ParticipanteViewModel(partida, campeoes, ultimaVersao, "", itens, participante, spells, true)).ToList();


            var timeInimigo = partida.Teams.First(x => x.TeamId != idTimeAliado);

            TimeInimigo = new TimeViewModel(timeInimigo);

            TimeInimigo.Participantes = partida.Participants.Where(x => x.TeamId != idTimeAliado).Select(participante => new ParticipanteViewModel(partida, campeoes, ultimaVersao, "", itens, participante, spells, true)).ToList();
        }
Exemple #10
0
        private void SortRiotItemData(ItemListStatic items)
        {
            itemGold_Names.Clear();
            //Sort items by price
            foreach (System.Collections.Generic.KeyValuePair <int, RiotSharp.StaticDataEndpoint.ItemStatic> i in items.Items)
            {
                //Removes rengar upgraded trinket from cluttering the Item list, the base rengar tricket desciption has all information needed
                if (!(i.Value.Gold.Purchasable == false && i.Value.RequiredChampion == "Rengar"))
                {
                    //Removes the explorer ward from the item list, it might have been available in the past but it doesn't matter much. Same with golden transcendence
                    if (i.Value.Name != "Explorer's Ward" && i.Value.Name != "Golden Transcendence")
                    {
                        //Remove the duplicate free Buiscuit that used to be obtained from mastery, either way this item doesn't matter much
                        if (!(i.Value.Name == "Total Biscuit of Rejuvenation" && i.Value.Gold.TotalPrice == 0))
                        {
                            //Add Stealth Detection tag where i think it is missing
                            if (i.Value.Description.Contains("Vision Ward"))
                            {
                                if (i.Value.Tags == null)
                                {
                                    i.Value.Tags.Add("Stealth");
                                }
                                else if (!i.Value.Tags.Contains("Stealth"))
                                {
                                    i.Value.Tags.Add("Stealth");
                                }
                            }
                            itemGold_Names.Add(new KeyValuePair <int, int>(i.Value.Id, i.Value.Gold.TotalPrice));
                        }
                    }
                }
            }



            itemGold_Names.Sort(Compare2);

            itemsPrepared.Clear();
            //Loop through all sorted item names and store item data
            foreach (var item in itemGold_Names)
            {
                ItemStatic i = items.Items[item.Key];

                int           enchantBaseId = 0;
                ItemStatic    enchantBaseItem;
                CreateItemDiv newItem = new CreateItemDiv();
                if (i.Name.Contains("Enchantment:") && i.From != null)                 //todo: added && i.From != null
                {
                    enchantBaseId = Convert.ToInt16(i.From[0]);
                    items.Items.TryGetValue(enchantBaseId, out enchantBaseItem);
                    newItem.SetupItemInformation(i, items.Version, enchantBaseItem);
                }
                else
                {
                    newItem.SetupItemInformation(i, items.Version);
                }
                itemsPrepared.Add(newItem);
            }

            ItemDataCorrections.RunCorrections(items);


            version = items.Version;
        }
 public ItemListStaticWrapper(ItemListStatic items, Language language, ItemData itemData)
 {
     ItemListStatic = items;
     Language = language;
     ItemData = itemData;
 }
Exemple #12
0
        private async Task CollectStaticData(IServiceProvider serviceProvider)
        {
            var staticDataEndpoints     = serviceProvider.GetService <IStaticDataEndpoints>();
            var championRepository      = serviceProvider.GetService <IChampionStaticDataRepository>();
            var summonerSpellRepository = serviceProvider.GetService <ISummonerSpellStaticDataRepository>();
            var itemRepository          = serviceProvider.GetService <IItemStaticDataRepository>();
            var runeRepository          = serviceProvider.GetService <IRunesStaticDataRepository>();

            //Champions
            IEnumerable <Db_LccChampion> championsInDatabase = championRepository.GetAllChampions();

            if (championsInDatabase.Count() == 0)
            {
                ChampionListStatic championsListFromRiot = await staticDataEndpoints.Champion.GetChampionsAsync(Region.euw);

                foreach (ChampionStatic champion in championsListFromRiot.Champions.Values)
                {
                    championRepository.InsertChampionInformation(new Db_LccChampion()
                    {
                        ChampionId   = champion.Id,
                        ChampionName = champion.Name,
                        ImageFull    = champion.Image.Full
                    });
                }

                championRepository.Save();
            }

            //Items
            IEnumerable <Db_LccItem> itemsInDatabase = itemRepository.GetAllItems();

            if (itemsInDatabase.Count() == 0)
            {
                ItemListStatic itemsListFromRiot = await staticDataEndpoints.Item.GetItemsAsync(Region.euw);

                foreach (ItemStatic item in itemsListFromRiot.Items.Values)
                {
                    itemRepository.InsertItem(new Db_LccItem()
                    {
                        ItemId    = item.Id,
                        ItemName  = item.Name,
                        ImageFull = item.Image.Full
                    });
                }

                itemRepository.Save();
            }

            //SummonerSpells
            IEnumerable <Db_LccSummonerSpell> lccSummonerSpellInformation = summonerSpellRepository.GetAllSummonerSpells();

            if (lccSummonerSpellInformation.Count() == 0)
            {
                SummonerSpellListStatic summonerSpellListFromRiot = await staticDataEndpoints.SummonerSpell.GetSummonerSpellsAsync(Region.euw);

                foreach (SummonerSpellStatic summoner in summonerSpellListFromRiot.SummonerSpells.Values)
                {
                    summonerSpellRepository.InsertSummonerSpell(new Db_LccSummonerSpell()
                    {
                        SummonerSpellId   = summoner.Id,
                        SummonerSpellName = summoner.Name,
                        ImageFull         = summoner.Image.Full
                    });
                }

                summonerSpellRepository.Save();
            }

            //Runes
            IEnumerable <Db_LccRune> lccRuneInformation = runeRepository.GetAllRunes();

            if (lccRuneInformation.Count() == 0)
            {
                IList <RuneReforged> runeListFromRiot = await staticDataEndpoints.Rune.GetRunesReforgedAsync(Region.euw);

                foreach (RuneReforged rune in runeListFromRiot)
                {
                    runeRepository.InsertRune(new Db_LccRune()
                    {
                        RuneId       = rune.Id,
                        RuneName     = rune.Name,
                        RunePathName = rune.RunePathName,
                        Key          = rune.Key,
                        ShortDesc    = rune.ShortDesc,
                        LongDesc     = rune.LongDesc,
                        Icon         = rune.Icon
                    });
                }

                runeRepository.Save();
            }
        }
        public async void RetrieveStaticItemsTest()
        {
            ItemListStatic items = await creepScore.RetrieveItemsData(CreepScore.Region.NA, StaticDataConstants.ItemListData.All);

            Assert.Equal("item", items.type);
        }
        /// <summary>
        /// Constroi um participante
        /// </summary>
        /// <param name="partida">Partida atual</param>
        /// <param name="campeoes">Lista de campeoes</param>
        /// <param name="versao">Versao do jogo</param>
        /// <param name="contaId">AccoutId do participante, somente é utilizado se o participante for nulo</param>
        /// <param name="itens">Lista de itens do jogo</param>
        /// <param name="participant">Participante que vem da api</param>
        public ParticipanteViewModel(Partida partida, ChampionListStatic campeoes, string versao, string contaId, ItemListStatic itens, Participant participant, SummonerSpellListStatic feiticos, bool detalhado = false)
        {
            var participante = participant ?? partida.Participants.First(y => y.ParticipantId == partida.ParticipantIdentities.First(k => k.Player.CurrentAccountId == contaId).ParticipantId);

            var campeao =
                campeoes
                .Champions
                .FirstOrDefault(c => c.Value.Id == participante.ChampionId).Value;

            NomeCampeao = campeao.Name;

            UrlIconeCampeao = Util.RetornarIconeCampeao(versao, campeao);

            OuroAcumulado = participante.Stats.GoldEarned > 100 ? participante.Stats.GoldEarned.ToString("0,.#K") : participante.Stats.GoldEarned.ToString();

            KDA = $"{participante.Stats.Kills}/{participante.Stats.Deaths}/{participante.Stats.Assists}";

            Lane = Util.RetornarLaneFinalJogador(participante.Timeline.Lane, participante.Timeline.Role);

            NivelMaximoAtingido = participante.Stats.ChampLevel;

            Vitoria = participante.Stats.Winner;

            Data = partida.GameCreation.ToString("dd/MM/yyyy");

            ItensFinais = new List <Item>();

            ItensFinais.AdicionarItem(participante.Stats.Item0, itens, versao);
            ItensFinais.AdicionarItem(participante.Stats.Item1, itens, versao);
            ItensFinais.AdicionarItem(participante.Stats.Item2, itens, versao);
            ItensFinais.AdicionarItem(participante.Stats.Item3, itens, versao);
            ItensFinais.AdicionarItem(participante.Stats.Item4, itens, versao);
            ItensFinais.AdicionarItem(participante.Stats.Item5, itens, versao);
            var ward = Util.ObterItem(participante.Stats.Item6, itens, versao);

            if (ward != null)
            {
                Ward = ward;
            }

            GameId = partida.GameId;
            var jogador = partida.ParticipantIdentities.First(x => x.ParticipantId == participante.ParticipantId).Player;

            AccountId  = jogador.CurrentAccountId;
            SummonerId = jogador.SummonerId;

            if (detalhado)
            {
                NomeJogador = jogador.SummonerName;
                double ouroPorMinuto;

                try
                {
                    ouroPorMinuto = participante.Stats.GoldEarned / partida.GameDuration.TotalMinutes;
                }
                catch (Exception)
                {
                    ouroPorMinuto = 0;
                }

                OuroPorMinuto = ouroPorMinuto.ToString("0.#");

                Farm = participante.Stats.TotalMinionsKilled + participante.Stats.NeutralMinionsKilled;

                double farmPorMinuto;

                try
                {
                    farmPorMinuto = Convert.ToDouble(Farm) / partida.GameDuration.TotalMinutes;
                }
                catch (Exception)
                {
                    farmPorMinuto = 0;
                }

                FarmPorMinuto = farmPorMinuto.ToString("0.#");

                if (feiticos != null)
                {
                    Feitico1 = AdicionarFeitico(participante.Spell1Id, feiticos, versao);
                    Feitico2 = AdicionarFeitico(participante.Spell2Id, feiticos, versao);
                }
            }
        }
Exemple #15
0
        public static void AdicionarItem(this List <Item> itensTratados, long itemID, ItemListStatic itens, string versao)
        {
            var item = Util.ObterItem(itemID, itens, versao);

            if (item != null)
            {
                itensTratados.Add(item);
            }
        }
Exemple #16
0
 private static ItemStatic getItem(int itemId)
 {
     if (Items == null)
     {
         Items = StaticRiotApi.GetInstance(API_KEY).GetItems(Region.na, ItemData.all);
     }
     if (Items.Items.ContainsKey(itemId))
     {
         var item = Items.Items[itemId];
         return item;
     }
     return Items.Items.Values.First();
 }
Exemple #17
0
 internal static UpsetModel GetUpsetModel()
 {
     UpsetModel model = new UpsetModel();
     if (Items == null) Items = StaticRiotApi.GetInstance(API_KEY).GetItems(Region.na, ItemData.all);
     if (PotentialUpgrades == null) InitializePotentialUpgrades();
     model.CompleteItems = Items.Items.Where(x => x.Value.Into == null && x.Value.From != null).Select(x => x.Value).ToList();
     model.PotentialUpgrades = PotentialUpgrades;
     return model;
 }
 public ItemListStaticWrapper(ItemListStatic items, Language language, ItemData itemData)
 {
     ItemListStatic = items;
     Language       = language;
     ItemData       = itemData;
 }