示例#1
0
        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!");
            }
        }
示例#2
0
        public void printVendors()
        {
            var vendorsItems = new VendorItems().VendorItemsList;

            Console.WriteLine("Vendors: ");
            Console.WriteLine("_________________________");
            foreach (var item in vendorsItems)
            {
                Console.WriteLine(item);
            }
        }
示例#3
0
        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));
        }