public void BuyItem(Player player, string[] userInput, int quantity) { if (quantity == 0) { return; } string inputName = InputHelper.ParseInput(userInput); int index = -1; index = VendorCategory == VendorType.Healer ? VendorItems.FindIndex( f => f.Name == inputName || f.Name.Contains(inputName)) : VendorItems.FindIndex( f => f.Name == inputName || f.Name.Contains(userInput.Last())); if (index == -1) { OutputHelper.Display.StoreUserOutput( Settings.FormatFailureOutputText(), Settings.FormatDefaultBackground(), "The vendor doesn't have that available for sale!"); return; } IItem buyItem = VendorItems[index]; if (player.Gold >= buyItem.ItemValue && quantity > 0) { player.Gold -= buyItem.ItemValue; player.Inventory.Add(buyItem); VendorItems.RemoveAt(index); string purchaseString = $"You purchased {buyItem.Name} from the vendor for {buyItem.ItemValue} gold."; OutputHelper.Display.StoreUserOutput( Settings.FormatSuccessOutputText(), Settings.FormatDefaultBackground(), purchaseString); if (!(buyItem is IPotion || buyItem is Arrows)) { return; } if (VendorCategory == VendorType.Healer) { RepopulateHealerPotion(inputName); } else { RepopulateArrows(inputName); } quantity--; BuyItem(player, userInput, quantity); } else { OutputHelper.Display.StoreUserOutput( Settings.FormatFailureOutputText(), Settings.FormatDefaultBackground(), "You can't afford that!"); } }
public void printVendors() { var vendorsItems = new VendorItems().VendorItemsList; Console.WriteLine("Vendors: "); Console.WriteLine("_________________________"); foreach (var item in vendorsItems) { Console.WriteLine(item); } }
public async Task <IActionResult> Register(VendorItems VendorItems) { //var userWithSameEmail = _dbContext.ADMINMast.SingleOrDefault(u => u.EmailID == ADMINMast.EmailID); //if (userWithSameEmail != null) return BadRequest("User with this email already exists"); var VendorItemsObj = new VendorItems { vendorItemID = Guid.NewGuid(), Capacity = VendorItems.Capacity, ItemID = VendorItems.ItemID, PerPlateRate = VendorItems.PerPlateRate, PreferentialRating = VendorItems.PreferentialRating, VendorId = VendorItems.VendorId }; _dbContext.VendorItems.Add(VendorItemsObj); await _dbContext.SaveChangesAsync(); return(StatusCode(StatusCodes.Status201Created)); }