示例#1
0
        private async Task GenerateItemSetByChampion(ChampionViewModel champion, LoLMode mode, CancellationToken cancelToken)
        {
            // Create a unique instance of BuildSource to be thread safe
            // I'm afraid of having corruption with a shared "Document" property if I use a single shared instance
            IBuildSource buildSource = (T)Activator.CreateInstance(typeof(T));
            await buildSource.InitAsync(champion.Name, mode);

            if (!buildSource.IsValidContent())
            {
                throw new InvalidOperationException("Invalid content");
            }

            LoLItemSetViewModel itemSetViewModel = ItemSetUtil.CreateItemSetPerChampion(buildSource, champion, mode, Configuration.ShowSkillsOrder);

            if (itemSetViewModel == null)
            {
                throw new InvalidOperationException("LoLItemSetViewModel is null");
            }

            // Create Item set JSON file into LoL directory
            string itemSetDir = LoLPathUtil.CreateItemSetDirectory(Configuration.LoLDirectory, champion.Name);

            string itemSetFileName     = ItemSetUtil.GetFormattedItemSetFileName(buildSource, mode, Configuration.ApplicationPrefixName);
            string itemSetAbsolutePath = Path.Combine(itemSetDir, itemSetFileName);

            await FileUtil.CreateJsonFileAsync(itemSetAbsolutePath, itemSetViewModel, cancelToken);
        }
示例#2
0
 public InfoChampion(ChampionViewModel champion, FacadeViewModel facade)
 {
     InitializeComponent();
     Facade                = facade;
     this.Champion         = champion;
     BindingContext        = champion;
     FavoriSwitch.Toggled += ChangementFavori;
 }
示例#3
0
 private static void PostFixChampionNames(List <ChampionViewModel> champions)
 {
     foreach (var championAlias in _dictKnownChampionAlias)
     {
         ChampionViewModel championToFix = champions.FirstOrDefault(c => c.Name == championAlias.Key);
         championToFix.Name = championAlias.Value;
     }
 }
示例#4
0
        private static string GetPageTitle(IBuildSource source, LoLMode mode, ChampionViewModel champion)
        {
            string sourceName    = source.GetSourceName();
            string championName  = champion.Name;
            string championInfo  = LoLModeUtil.FormatChampionInfoByMode(source, mode);
            string sourceVersion = source.GetVersion();

            // Example for classic mode: OPGG - Annie Middle - v11.07
            // Example for ARAM mode: OPGG - Annie ARAM - v11.07
            return($"{sourceName} - {championName} {championInfo} - v{sourceVersion}");
        }
示例#5
0
        public static HomeViewModel Load()
        {
            HomeViewModel hmv = new HomeViewModel();

            hmv.Roles = LoadRoles();
            hmv.Ranks = LoadRanks();
            IList <Champion> champions;

            using (var data = new SqlData())
            {
                champions = data.GetChampions();
            }
            hmv.Champions = new List <ChampionViewModel>();
            foreach (var champion in champions)
            {
                var championVM = new ChampionViewModel();
                championVM.Id   = champion.Id;
                championVM.Name = champion.Name;
                string linkName;
                if (champion.Name.Contains(" "))
                {
                    linkName = champion.Name.Replace(" ", string.Empty).Replace("'", string.Empty).Replace(".", string.Empty);
                }
                else
                {
                    linkName = champion.Name.Replace("'", string.Empty).Replace(".", string.Empty).ToLower().FirstLetterToUpper();
                }
                switch (linkName)
                {
                case "Kogmaw":
                    linkName = "KogMaw";
                    break;

                case "Reksai":
                    linkName = "RekSai";
                    break;

                case "Fiddlesticks":
                    linkName = "FiddleSticks";
                    break;

                case "Wukong":
                    linkName = "MonkeyKing";
                    break;
                }
                championVM.ImageUrl = string.Format(@"http://ddragon.leagueoflegends.com/cdn/5.16.1/img/champion/{0}.png", linkName);
                hmv.Champions.Add(championVM);
            }
            return(hmv);
        }
示例#6
0
        public ActionResult AddEdit(ChampionViewModel model)
        {
            if (ModelState.IsValid)
            {
                var champion = _context.Champions.Where(x => x.Id == model.Id)
                               .Include(x => x.Spells)
                               .FirstOrDefault();
                if (champion == null)
                {
                    champion = new Champion
                    {
                        Spells = new List <Spell>()
                    };
                    _context.Champions.Add(champion);
                }
                champion.Name           = model.Name;
                champion.SummonerSpellD = _context.SummonerSpells.FirstOrDefault(x => x.Id == model.SummonerSpellDId);
                champion.SummonerSpellF = _context.SummonerSpells.FirstOrDefault(x => x.Id == model.SummonerSpellFId);


                SpellInjection(model.SpellP, champion, "P");
                SpellInjection(model.SpellQ, champion, "Q");
                SpellInjection(model.SpellW, champion, "W");
                SpellInjection(model.SpellE, champion, "E");
                SpellInjection(model.SpellR, champion, "R");

                if (model.Image != null && model.Image.Length > 0)
                {
                    using (var ms = new MemoryStream())
                    {
                        model.Image.CopyTo(ms);
                        var bytearray = ms.ToArray();
                        champion.Logo = string.Format("data:{1};base64,{0}",
                                                      Convert.ToBase64String(bytearray),
                                                      model.Image.ContentType);
                    }
                }

                _context.SaveChanges();
                return(RedirectToAction(nameof(Index)));
            }
            model.AllSummonerSpells = _context.SummonerSpells.Select(x => new SelectListItem
            {
                Value = x.Id.ToString(),
                Text  = x.Name
            }).ToList();

            return(View(model));
        }
示例#7
0
        public IActionResult Kenzhebayev()
        {
            var championModels = new List <ChampionViewModel>();
            var akaliViewModel = new ChampionViewModel
            {
                Name      = "Akali",
                SplashUrl = "https://ddragon.leagueoflegends.com/cdn/img/champion/splash/Akali_0.jpg",
                Fraction  = "Ionia",
                ShortBio  = "Abandoning the Kinkou Order and her title of the Fist of Shadow, Akali now strikes alone, " +
                            "ready to be the deadly weapon her people need. Though she holds onto all she learned from her master " +
                            "Shen, she has pledged to defend Ionia from its enemies, one kill at a time. Akali may strike in silence, " +
                            "but her message will be heard loud and clear: fear the assassin with no master.",
                CurrentUpdateStats = new ChampionViewModel.StatsViewModel()
                {
                    BaseHealth = 575,
                    BaseMana   = 200,
                    IsEnergy   = true,
                    BaseDamage = 62.4,
                },
                UrlFractionIcon = "https://static.wikia.nocookie.net/leagueoflegends/images/a/ae/Ionia_Crest.png",
            };

            var gangplankViewModel = new ChampionViewModel
            {
                Name      = "Gangplank",
                SplashUrl = "https://ddragon.leagueoflegends.com/cdn/img/champion/splash/Gangplank_0.jpg",
                Fraction  = "Bilgewater",
                ShortBio  = "As unpredictable as he is brutal, the dethroned reaver king Gangplank is feared far and wide. " +
                            "Once, he ruled the port city of Bilgewater, and while his reign is over, there are those who believe this " +
                            "has only made him more dangerous. Gangplank would see Bilgewater bathed in blood once more before letting someone " +
                            "else take it—and now with pistol, cutlass, and barrels of gunpowder, he is determined to reclaim what he has lost.",
                CurrentUpdateStats = new ChampionViewModel.StatsViewModel()
                {
                    BaseHealth = 540,
                    BaseMana   = 280,
                    IsEnergy   = false,
                    BaseDamage = 64,
                },
                UrlFractionIcon = "https://static.wikia.nocookie.net/leagueoflegends/images/0/06/Bilgewater_Crest.png",
            };

            championModels.Add(akaliViewModel);
            championModels.Add(gangplankViewModel);

            return(View(championModels));
        }
示例#8
0
        /// <summary>
        /// Generate item set by champion and returns true if successfully generated
        /// </summary>
        /// <param name="champion"></param>
        /// <param name="cancelToken"></param>
        /// <returns>True if successfully generated item set</returns>
        private async Task <bool> TryGenerateItemSetByChampion(ChampionViewModel champion, CancellationToken cancelToken)
        {
            List <Task> tasks = new List <Task>();

            try
            {
                // Mode = classic
                Task generateItemSetClassic = GenerateItemSetByChampion(champion, LoLMode.Classic, cancelToken);
                tasks.Add(generateItemSetClassic);

                // Mode = aram (?)
                if (Configuration.DownloadAramBuilds)
                {
                    Task generateItemSetAram = GenerateItemSetByChampion(champion, LoLMode.ARAM, cancelToken);
                    tasks.Add(generateItemSetAram);
                }

                await Task.WhenAll(tasks);

                // Log success
                string successMessage = "Succefully downloaded item set";
                if (Configuration.DownloadAramBuilds)
                {
                    successMessage += " + ARAM";
                }
                string log = LoggerUtil.FormatLogByBuildSource(BuildSourceName, successMessage, champion.Name);
                LogHandler(log);

                return(true);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);

                string errLog = LoggerUtil.FormatLogByBuildSource(BuildSourceName, "Failed to download item set", champion.Name, e.Message);
                LogHandler(errLog);

                return(false);
            }
        }
        public void Champion_Property_Test()
        {
            var champions = new List <Champion>();

            champions.Add(new Champion()
            {
                ID = 1, Title = "Champion title 1", Name = "Champion name 1"
            });
            champions.Add(new Champion()
            {
                ID = 2, Title = "Champion title 2", Name = "Champion name 2"
            });

            var mockChampionService = new Mock <IChampionDataService>();

            mockChampionService.Setup(ws => ws.GetChampions()).Returns(champions);

            var vm = new ChampionViewModel(mockChampionService.Object, null);

            var allChampions = vm.Champions;

            Assert.IsNotNull(allChampions);
            Assert.IsTrue(allChampions.Count == 2);
        }
示例#10
0
        public ActionResult Index()
        {
            var championViewModel = new ChampionViewModel();

            return(View(championViewModel));
        }
示例#11
0
 public int Update([FromBody] ChampionViewModel champion)
 {
     return(repository.Update(mapper.Map <ChampionEntity>(champion)));
 }
示例#12
0
 public static LoLItemSetViewModel CreateItemSetPerChampion(IBuildSource source, ChampionViewModel champion, LoLMode mode, bool showSkillsOrder)
 {
     return(new LoLItemSetViewModel()
     {
         Title = GetPageTitle(source, mode, champion),
         Map = LoLModeUtil.GetMapNameByMode(mode),
         AssociatedChampions = new List <int> {
             champion.Id
         },
         Blocks = CreateBlockItems(source, showSkillsOrder)
     });
 }
示例#13
0
        // GET: ItemsController
        public ActionResult Index(int?cid, int?vscid)
        {
            ChampionViewModel mainChamp = null;
            MatchUpViewModel  vscVM     = null;

            if (cid.HasValue)
            {
                mainChamp = _context.Champions
                            .Include(x => x.Spells)
                            .Include(x => x.SummonerSpellD)
                            .Include(x => x.SummonerSpellF)
                            .Where(x => x.Id == cid)
                            .Select(x => new ChampionViewModel
                {
                    Id       = x.Id,
                    ImageSrc = x.Logo,
                    Name     = x.Name,
                    SpellP   = x.Spells.Where(s => s.SpellType == "P").Select(s => new SpellViewModel
                    {
                        Name        = s.Name,
                        Description = s.Description,
                        ImageSrc    = s.Logo
                    }).FirstOrDefault(),
                    SpellQ = x.Spells.Where(s => s.SpellType == "Q").Select(s => new SpellViewModel
                    {
                        Name        = s.Name,
                        Description = s.Description,
                        ImageSrc    = s.Logo
                    }).FirstOrDefault(),
                    SpellW = x.Spells.Where(s => s.SpellType == "W").Select(s => new SpellViewModel
                    {
                        Name        = s.Name,
                        Description = s.Description,
                        ImageSrc    = s.Logo
                    }).FirstOrDefault(),
                    SpellE = x.Spells.Where(s => s.SpellType == "E").Select(s => new SpellViewModel
                    {
                        Name        = s.Name,
                        Description = s.Description,
                        ImageSrc    = s.Logo
                    }).FirstOrDefault(),
                    SpellR = x.Spells.Where(s => s.SpellType == "R").Select(s => new SpellViewModel
                    {
                        Name        = s.Name,
                        Description = s.Description,
                        ImageSrc    = s.Logo
                    }).FirstOrDefault(),
                    SummonerSpellD = new SummonerSpellViewModel
                    {
                        Name        = x.SummonerSpellD.Name,
                        Description = x.SummonerSpellD.Description,
                        ImageSrc    = x.SummonerSpellD.Logo
                    },
                    SummonerSpellF = new SummonerSpellViewModel
                    {
                        Name        = x.SummonerSpellF.Name,
                        Description = x.SummonerSpellF.Description,
                        ImageSrc    = x.SummonerSpellF.Logo
                    },
                    AllSummonerSpells = _context.SummonerSpells.Select(s => new SelectListItem
                    {
                        Value = x.Id.ToString(),
                        Text  = x.Name
                    }).ToList(),
                })
                            .FirstOrDefault();
                var matchUp = _context.MatchUps
                              .Include(x => x.MainChampionRunes)
                              .ThenInclude(x => x.PrimaryMainRune)
                              .ThenInclude(x => x.RuneCategory)
                              .Include(x => x.MainChampionRunes)
                              .ThenInclude(x => x.PrimaryRune1)
                              .ThenInclude(x => x.RuneCategory)
                              .Include(x => x.MainChampionRunes)
                              .ThenInclude(x => x.PrimaryRune2)
                              .Include(x => x.MainChampionRunes)
                              .ThenInclude(x => x.PrimaryRune3)
                              .Include(x => x.MainChampionRunes)
                              .ThenInclude(x => x.SecondaryRune1)
                              .ThenInclude(x => x.RuneCategory)
                              .Include(x => x.MainChampionRunes)
                              .ThenInclude(x => x.SecondaryRune2)
                              .Include(x => x.MainChampionRunes)
                              .ThenInclude(x => x.SecondaryRune3)
                              .Include(x => x.ItemSets)
                              .ThenInclude(x => x.Item)
                              .Include(x => x.VsChampion)
                              .Where(x => x.MainChampion.Id == cid && ((!vscid.HasValue && x.VsChampion == null) || (x.VsChampion.Id == vscid)))
                              .FirstOrDefault();
                vscVM = new MatchUpViewModel
                {
                    Id           = matchUp.Id,
                    VsChampionId = vscid,
                    VsChampion   = matchUp.VsChampion == null ? null : new ChampionViewModel {
                        ImageSrc = matchUp.VsChampion.Logo,
                        Name     = matchUp.VsChampion.Name
                    },
                    PrimaryRuneCategoryId   = matchUp.MainChampionRunes.PrimaryMainRune.RuneCategory.Id,
                    SecondaryRuneCategoryId = matchUp.MainChampionRunes.SecondaryRune1.RuneCategory.Id,
                    PrimaryMainRuneId       = matchUp.MainChampionRunes.PrimaryMainRune.Id,
                    PrimaryLevel1RuneId     = matchUp.MainChampionRunes.PrimaryRune1.Id,
                    PrimaryLevel2RuneId     = matchUp.MainChampionRunes.PrimaryRune2.Id,
                    PrimaryLevel3RuneId     = matchUp.MainChampionRunes.PrimaryRune3.Id,
                    SecondaryLevel1RuneId   = matchUp.MainChampionRunes.SecondaryRune1.Id,
                    SecondaryLevel2RuneId   = matchUp.MainChampionRunes.SecondaryRune2.Id,
                    SecondaryLevel3RuneId   = matchUp.MainChampionRunes.SecondaryRune3.Id,
                    StrongerEarly           = matchUp.StrongerEarly,
                    StrongerMid             = matchUp.StrongerMid,
                    StrongerLate            = matchUp.StrongerLate,
                    Items = matchUp.ItemSets.Select(y => new ItemViewModel
                    {
                        Name        = y.Item.Name,
                        ImageSrc    = y.Item.Logo,
                        Description = y.Item.Description
                    }),
                    AllRuneCategories = _context.RuneCategories.Select(y => new RuneCategoriesViewModel
                    {
                        Id          = y.Id,
                        Name        = y.Name,
                        Description = y.Description,
                        ImageSrc    = y.Logo,
                    }),
                    AllSecondaryRuneCategories = _context.RuneCategories.Select(y => new RuneCategoriesViewModel
                    {
                        Id          = y.Id,
                        Name        = y.Name,
                        Description = y.Description,
                        ImageSrc    = y.Logo,
                    }),
                    AllMainRunes = _context.MainRunes
                                   .Where(y => y.RuneCategory.Id == matchUp.MainChampionRunes.PrimaryMainRune.RuneCategory.Id)
                                   .OrderBy(y => y.Sort)
                                   .Select(y => new MainRunesViewModel
                    {
                        Id          = y.Id,
                        Name        = y.Name,
                        Description = y.Description,
                        ImageSrc    = y.Logo,
                    }).ToList(),
                    AllLevel1Runes = _context.Runes
                                     .Where(y => y.LevelRune == 1 && y.RuneCategory.Id == matchUp.MainChampionRunes.PrimaryMainRune.RuneCategory.Id)
                                     .OrderBy(y => y.Sort)
                                     .Select(y => new RuneViewModel
                    {
                        Id          = y.Id,
                        Name        = y.Name,
                        Description = y.Description,
                        ImageSrc    = y.Logo,
                    }),
                    AllLevel2Runes = _context.Runes
                                     .Where(y => y.LevelRune == 2 && y.RuneCategory.Id == matchUp.MainChampionRunes.PrimaryMainRune.RuneCategory.Id)
                                     .OrderBy(y => y.Sort)
                                     .Select(y => new RuneViewModel
                    {
                        Id          = y.Id,
                        Name        = y.Name,
                        Description = y.Description,
                        ImageSrc    = y.Logo,
                    }),
                    AllLevel3Runes = _context.Runes
                                     .Where(y => y.LevelRune == 3 && y.RuneCategory.Id == matchUp.MainChampionRunes.PrimaryMainRune.RuneCategory.Id)
                                     .OrderBy(y => y.Sort)
                                     .Select(y => new RuneViewModel
                    {
                        Id          = y.Id,
                        Name        = y.Name,
                        Description = y.Description,
                        ImageSrc    = y.Logo,
                    }),
                    AllLevel1SecondaryRunes = _context.Runes
                                              .Where(y => y.LevelRune == 1 && y.RuneCategory.Id == matchUp.MainChampionRunes.SecondaryRune1.RuneCategory.Id)
                                              .OrderBy(y => y.Sort)
                                              .Select(y => new RuneViewModel
                    {
                        Id          = y.Id,
                        Name        = y.Name,
                        Description = y.Description,
                        ImageSrc    = y.Logo,
                    }),
                    AllLevel2SecondaryRunes = _context.Runes
                                              .Where(y => y.LevelRune == 2 && y.RuneCategory.Id == matchUp.MainChampionRunes.SecondaryRune1.RuneCategory.Id)
                                              .OrderBy(y => y.Sort)
                                              .Select(y => new RuneViewModel
                    {
                        Id          = y.Id,
                        Name        = y.Name,
                        Description = y.Description,
                        ImageSrc    = y.Logo,
                    }),
                    AllLevel3SecondaryRunes = _context.Runes
                                              .Where(y => y.LevelRune == 3 && y.RuneCategory.Id == matchUp.MainChampionRunes.SecondaryRune1.RuneCategory.Id)
                                              .OrderBy(y => y.Sort)
                                              .Select(y => new RuneViewModel
                    {
                        Id          = y.Id,
                        Name        = y.Name,
                        Description = y.Description,
                        ImageSrc    = y.Logo,
                    }),
                };
            }
            MainPageViewModel model = new MainPageViewModel
            {
                cid         = cid,
                vscid       = vscid,
                Champion    = mainChamp,
                VsChampion  = vscVM,
                AllVsChamps = _context.MatchUps.Include(x => x.VsChampion).Where(x => x.MainChampion.Id == cid).Select(x => new MatchUpViewModel
                {
                    WinRate    = x.WinRate,
                    VsChampion = new ChampionViewModel
                    {
                        Id       = x.VsChampion.Id,
                        Name     = x.VsChampion.Name,
                        ImageSrc = x.VsChampion.Logo
                    }
                }).ToList()
            };


            return(View(model));
        }
示例#14
0
        // GET: ItemsController/Create
        public ActionResult AddEdit(int id)
        {
            var model = new ChampionViewModel {
                SpellP = new SpellViewModel(),
                SpellQ = new SpellViewModel(),
                SpellW = new SpellViewModel(),
                SpellE = new SpellViewModel(),
                SpellR = new SpellViewModel()
            };
            var champion = _context.Champions.Where(x => x.Id == id)
                           .Include(x => x.SummonerSpellD)
                           .Include(x => x.SummonerSpellF)
                           .Include(x => x.Spells)
                           .FirstOrDefault();

            if (champion != null)
            {
                model.Id               = id;
                model.Name             = champion.Name;
                model.SummonerSpellDId = champion.SummonerSpellD?.Id ?? 0;
                model.SummonerSpellFId = champion.SummonerSpellF?.Id ?? 0;
                model.SpellP           = champion.Spells.Where(x => x.SpellType == "P").Select(x => new SpellViewModel
                {
                    Id          = x.Id,
                    Name        = x.Name,
                    Description = x.Description,
                    ImageSrc    = x.Logo
                }).FirstOrDefault() ?? new SpellViewModel();
                model.SpellQ = champion.Spells.Where(x => x.SpellType == "Q").Select(x => new SpellViewModel
                {
                    Id          = x.Id,
                    Name        = x.Name,
                    Description = x.Description,
                    ImageSrc    = x.Logo
                }).FirstOrDefault() ?? new SpellViewModel();
                model.SpellW = champion.Spells.Where(x => x.SpellType == "W").Select(x => new SpellViewModel
                {
                    Id          = x.Id,
                    Name        = x.Name,
                    Description = x.Description,
                    ImageSrc    = x.Logo
                }).FirstOrDefault() ?? new SpellViewModel();
                model.SpellE = champion.Spells.Where(x => x.SpellType == "E").Select(x => new SpellViewModel
                {
                    Id          = x.Id,
                    Name        = x.Name,
                    Description = x.Description,
                    ImageSrc    = x.Logo
                }).FirstOrDefault() ?? new SpellViewModel();
                model.SpellR = champion.Spells.Where(x => x.SpellType == "R").Select(x => new SpellViewModel
                {
                    Id          = x.Id,
                    Name        = x.Name,
                    Description = x.Description,
                    ImageSrc    = x.Logo
                }).FirstOrDefault() ?? new SpellViewModel();
                model.ImageSrc = champion.Logo;
            }
            model.AllSummonerSpells = _context.SummonerSpells.Select(x => new SelectListItem
            {
                Value = x.Id.ToString(),
                Text  = x.Name
            }).ToList();

            return(View(model));
        }