コード例 #1
0
        public static bool SellOff(Type type, int amount, Serial vendorid, Mobile player)
        {
            if (((ResourceData)m_Resources[type]).TotalCount < amount)
            {
                return(false);
            }

            ResourceTransaction rt = new ResourceTransaction(TransactionType.Purchase);

            rt.Amount   = amount;
            rt.Price    = ((ResourceData)m_Resources[type]).ResalePrice;
            rt.ResName  = ((ResourceData)m_Resources[type]).Name;
            rt.VendorID = vendorid;

            ResourceConsignment[] topay = ((ResourceData)m_Resources[type]).Remove(amount);

            rt.NewAmount = ((ResourceData)m_Resources[type]).TotalCount;

            foreach (ResourceConsignment rc in topay)
            {
                if (rc.Seller == null || rc.Seller.Deleted)
                {
                    BountySystem.BountyKeeper.LBFund += (int)(rc.Amount * rc.Price * m_PaymentFactor);
                    continue;
                }

                // do this here instead of when writing check so player may know how much is waiting
                ResourceTransaction rtpay = new ResourceTransaction(TransactionType.Payment);
                rtpay.Amount   = rc.Amount;
                rtpay.Price    = rc.Price * m_PaymentFactor;
                rtpay.ResName  = ((ResourceData)m_Resources[type]).Name;
                rtpay.VendorID = vendorid;
                ResourceLogger.Add(rtpay, rc.Seller);

                if (m_Debts[rc.Seller] == null)
                {
                    m_Debts[rc.Seller] = (double)rc.Amount * rc.Price * m_PaymentFactor;
                }
                else
                {
                    m_Debts[rc.Seller] = (double)rc.Amount * rc.Price * m_PaymentFactor + (double)m_Debts[rc.Seller];
                }
            }

            Mobile[] keys = new Mobile[m_Debts.Count];
            m_Debts.Keys.CopyTo(keys, 0);
            foreach (Mobile m in keys)
            {
                double payment = (double)m_Debts[m];
                if (payment > 1)
                {
                    Container bank = m.BankBox;

                    PaymentCheck check = (PaymentCheck)bank.FindItemByType(typeof(PaymentCheck), false);
                    if (check != null)
                    {
                        check.Worth += (int)payment;
                        m_Debts[m]   = (double)m_Debts[m] - (int)payment;
                    }
                    else
                    {
                        check = new PaymentCheck((int)payment);
                        if (bank.Items.Count < 125)
                        {
                            check.SetLastMoved();
                            bank.DropItem(check);
                            m_Debts[m] = (double)m_Debts[m] - (int)payment;
                        }
                    }
                }
                if ((double)m_Debts[m] <= 0)
                {
                    m_Debts.Remove(m);
                }
            }

            ResourceLogger.Add(rt, player);

            return(true);
        }
コード例 #2
0
		public static bool SellOff(Type type, int amount, Serial vendorid, Mobile player)
		{
			if (((ResourceData)m_Resources[type]).TotalCount < amount)
			{
				return false;
			}

			ResourceTransaction rt = new ResourceTransaction(TransactionType.Purchase);
			rt.Amount = amount;
			rt.Price = ((ResourceData)m_Resources[type]).ResalePrice;
			rt.ResName = ((ResourceData)m_Resources[type]).Name;
			rt.VendorID = vendorid;

			ResourceConsignment[] topay = ((ResourceData)m_Resources[type]).Remove(amount);
			
			rt.NewAmount = ((ResourceData)m_Resources[type]).TotalCount;

			foreach (ResourceConsignment rc in topay)
			{
				if (rc.Seller == null || rc.Seller.Deleted)
				{
					BountySystem.BountyKeeper.LBFund += (int)(rc.Amount * rc.Price * m_PaymentFactor);
					continue;
				}

				// do this here instead of when writing check so player may know how much is waiting
				ResourceTransaction rtpay = new ResourceTransaction(TransactionType.Payment);
				rtpay.Amount = rc.Amount;
				rtpay.Price = rc.Price * m_PaymentFactor;
				rtpay.ResName = ((ResourceData)m_Resources[type]).Name;
				rtpay.VendorID = vendorid;
				ResourceLogger.Add(rtpay, rc.Seller);

				if (m_Debts[rc.Seller] == null)
					m_Debts[rc.Seller] = (double)rc.Amount * rc.Price * m_PaymentFactor;
				else
					m_Debts[rc.Seller] = (double)rc.Amount * rc.Price * m_PaymentFactor + (double)m_Debts[rc.Seller];
			}

			Mobile[] keys = new Mobile[m_Debts.Count];
			m_Debts.Keys.CopyTo(keys, 0);
			foreach (Mobile m in keys)
			{
				double payment = (double)m_Debts[m];
				if (payment > 1)
				{
					Container bank = m.BankBox;

					PaymentCheck check = (PaymentCheck)bank.FindItemByType(typeof(PaymentCheck), false);
					if (check != null)
					{
						check.Worth += (int)payment;
						m_Debts[m] = (double)m_Debts[m] - (int)payment;
					}
					else
					{
						check = new PaymentCheck((int)payment);
						if (bank.Items.Count < 125)
						{
							check.SetLastMoved();
							bank.DropItem(check);
							m_Debts[m] = (double)m_Debts[m] - (int)payment;
						}
					}
				}
				if ((double)m_Debts[m] <= 0)
					m_Debts.Remove(m);
			}

			ResourceLogger.Add(rt, player);

			return true;
		}