public IActionResult Brew() { var allPotions = potionRepository.GetAllPotions(); var model = new FullPotionViewModel { AllPotions = allPotions, CraftablePotions = potionRepository.GetCraftablePotions(allPotions, herbCountRepository.CountByRarity(User.Identity.Name), User.Identity.Name) }; return(View(model)); }
public IActionResult Brew(FullPotionViewModel model) { if (model.HerbalismMod == null) { model.HerbalismMod = 0; } var allPotions = potionRepository.GetAllPotions(); model.AllPotions = allPotions; var potion = allPotions.Where(x => x.Id == model.SelectedPotionId).FirstOrDefault(); var userName = User.Identity.Name; var herbsByRarity = herbCountRepository.CountByRarity(userName); if (!potionRepository.IsCraftable(potion, herbsByRarity, userName)) { model.CraftablePotions = potionRepository.GetCraftablePotions(allPotions, herbsByRarity, userName); model.Message = "You can't brew that potion! Stop pressing the refresh button!"; return(View(model)); } RemoveHerbs(potion); model.CraftablePotions = potionRepository.GetCraftablePotions(allPotions, herbsByRarity, userName); int roll = rand.Next(1, 21); var advantage = model.Advantage; var mod = model.HerbalismMod; if (advantage == Advantage.Disadvantage) { roll = Math.Min(roll, rand.Next(1, 21)); } else if (advantage == Advantage.Advantage) { roll = Math.Max(roll, rand.Next(1, 21)); } model.Message = string.Format("You rolled {0} ({1} + {2}).", roll + mod, roll, mod); if (roll >= potion.DC) { model.Message += string.Format("\nCongrats! You have successfully brewed a {0}!", potion.PotionName); } else { model.Message += "\nSorry, you have failed to brew a potion."; } return(View(model)); }