public IActionResult Herb(HerbingViewModel model) { if (!model.Static.HasValue) { model.Static = 0; } if (!model.SurvivalMod.HasValue) { model.SurvivalMod = 0; } if (model.Location == null || model.Rarity == null) { model.IsStatic = false; return(View(model)); } Location location = (Location)model.Location; Rarity rarity = (Rarity)model.Rarity; if (model.IsStatic) { int herbId; HerbCount herbCount; if (rarity == Rarity.Any) { foreach (Rarity r in Enum.GetValues(typeof(Rarity))) { if (r != Rarity.Any) { herbId = herbInfoRepository.GetHerbId(r, location); herbCount = herbCountRepository.GetHerb(herbId, User.Identity.Name); herbCount.Count += (int)model.Static; herbCountRepository.Update(herbCount); } } model.Message = string.Format("You have added {0} pieces of every {1} herb to your pouch!", model.Static, location); } else { herbId = herbInfoRepository.GetHerbId((Rarity)model.Rarity, location); herbCount = herbCountRepository.GetHerb(herbId, User.Identity.Name); herbCount.Count += (int)model.Static; herbCountRepository.Update(herbCount); model.Message = string.Format("You have added {0} pieces of {1} to your pouch!", model.Static, herbInfoRepository.GetHerbInfo(herbId).HerbName); } return(View(model)); } else { int roll = rand.Next(1, 21); var advantage = model.Advantage; var mod = model.SurvivalMod; 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)); } int herbId = 0; int amount = 0; switch (rarity) { case Rarity.Any: Rarity temp; if (roll + mod >= 10) { if (roll + mod >= 20) { temp = (Rarity)rand.Next(0, 4); } else if (roll + mod >= 16) { temp = (Rarity)rand.Next(0, 3); } else if (roll + mod >= 13) { temp = (Rarity)rand.Next(0, 2); } else { temp = Rarity.Common; } (herbId, amount) = Herb(temp, location); } break; case Rarity.VeryRare: if (roll + mod >= 20) { (herbId, amount) = Herb(rarity, location); } break; case Rarity.Rare: if (roll + mod >= 16) { (herbId, amount) = Herb(rarity, location); } break; case Rarity.Uncommon: if (roll + mod >= 13) { (herbId, amount) = Herb(rarity, location); } break; case Rarity.Common: if (roll + mod >= 10) { (herbId, amount) = Herb(rarity, location); } break; } model.Message = string.Format("You rolled {0} ({1} + {2}).", roll + mod, roll, mod); if (herbId == 0) { model.Message += "\nSorry, you failed."; } else { model.Message += string.Format("\nCongrats! You have added {0} pieces of {1} to your pouch!", amount, herbInfoRepository.GetHerbInfo(herbId).HerbName); } return(View(model)); } }
public IActionResult Herb() { var model = new HerbingViewModel(); return(View(model)); }