示例#1
0
        public bool BuyItem(string itemNumber, int numberToBuy, SMCharacter smc)
        {
            // Check that there is an item with that number
            SMShopItem ssi = ShopInventory.FirstOrDefault(item => item.ItemNumber == int.Parse(itemNumber));

            // If the item isn't null continue
            if (ssi != null)
            {
                // check the player has enough money to pay for the item(s)
                // Get the total value
                int totalValue = numberToBuy * ssi.Cost;

                if (smc.Currency.CheckCurrency(totalValue))
                {
                    // remove the money from the character
                    smc.Currency.RemoveCurrency(totalValue);

                    // add the item to the character
                    while (numberToBuy > 0)
                    {
                        numberToBuy--;
                        smc.ReceiveItem(ssi.Item, true);
                    }

                    // Return that the item was bought.
                    return(true);
                }
                else // They don't have enough to buy the item
                {
                    smc.sendMessageToPlayer(this.Formatter.Italic("You don't have enough money for that (needed " + totalValue + ", you have " + smc.Currency.AmountOfCurrency + ")"));
                    return(false);
                }
            }
            else // Return that the item isn't valid...
            {
                smc.sendMessageToPlayer(this.Formatter.ListItem("The item you've specified isn't valid, please check and try again"));
                return(false);
            }
        }