Aura.Channel.World.Shops.PersonalShop.Buy C# (CSharp) Метод

Buy() публичный Метод

Attempts to buy the given item for buyer, returns true if successful.
public Buy ( Creature buyer, long itemEntityId, bool directBankTransaction ) : bool
buyer Aura.Channel.World.Entities.Creature
itemEntityId long
directBankTransaction bool
Результат bool
		public bool Buy(Creature buyer, long itemEntityId, bool directBankTransaction)
		{
			var item = this.Owner.Inventory.GetItem(a => a.PersonalShopPrice != 0 && a.Info.Pocket == this.Bag.OptionInfo.LinkedPocketId && a.EntityId == itemEntityId);
			if (item == null)
				return false;

			// As soon as you click buy the item is removed on the client,
			// it has to be readded if something goes wrong.

			// Check payment method
			if (directBankTransaction && !this.LicenseData.DirectBankAllowed)
			{
				Send.PersonalShopAddItem(buyer, item);
				Send.MsgBox(buyer, Localization.Get("This shop doesn't allow Direct Bank Transaction."));
				return false;
			}

			// Check for empty cursor
			if (buyer.Inventory.GetItemAt(Pocket.Cursor, 0, 0) != null)
			{
				Send.PersonalShopAddItem(buyer, item);
				Send.MsgBox(buyer, Localization.Get("Failed to buy item."));
				return false;
			}

			var gold = 0;
			var price = item.PersonalShopPrice;
			var cost = price;

			// Disable direct bank transaction if price is less than 50k
			if (directBankTransaction && price < 50000)
				directBankTransaction = false;

			// Check gold
			if (directBankTransaction)
			{
				gold = buyer.Client.Account.Bank.Gold;
				cost = cost + (int)(cost * 0.05f); // Fee
			}
			else
				gold = buyer.Inventory.Gold;

			if (gold < cost)
			{
				Send.PersonalShopAddItem(buyer, item);
				Send.MsgBox(buyer, Localization.Get("You don't have enough gold."));
				return false;
			}

			// Remove item from shop
			this.Owner.Inventory.Remove(item);
			Send.PersonalShopRemoveItem(this.Owner, item.EntityId, buyer.EntityId);
			this.ForAllCustomers(creature => Send.PersonalShopRemoveItem(creature, item.EntityId, buyer.EntityId));

			// Remove gold and give item
			if (directBankTransaction)
				buyer.Client.Account.Bank.RemoveGold(buyer, cost);
			else
				buyer.Inventory.RemoveGold(cost);
			buyer.Inventory.Add(new Item(item), Pocket.Cursor);

			// Notice to owner
			var msg = string.Format(Localization.Get("[{0}] was sold to [{1}]."), Localization.Get(item.Data.Name), buyer.Name);
			Send.Notice(this.Owner, msg);
			Send.SystemMessageFrom(this.Owner, Localization.Get("<PERSONALSHOP>"), msg);

			// Add gold to the license
			var fee = this.LicenseData.SalesFee;
			var revenue = (int)(price - price * fee);

			// Cap at limit
			var val = this.LicenseItem.MetaData1.GetInt("EVALUE") + revenue;
			val = Math.Min(this.LicenseData.Limit, val);

			this.LicenseItem.MetaData1.SetInt("EVALUE", val);
			Send.ItemUpdate(this.Owner, this.LicenseItem);

			return true;
		}