Пример #1
0
        public int Compare(object x, object y)
        {
            ResourceTransaction rt1 = x as ResourceTransaction, rt2 = y as ResourceTransaction;

            if (rt1 == null && rt2 != null)
            {
                return(-1);
            }
            if (rt1 == null && rt2 == null)
            {
                return(0);
            }
            if (rt1 != null && rt2 == null)
            {
                return(1);
            }

            return(rt1.Date.CompareTo(rt2.Date));
        }
Пример #2
0
        public static double AddToPool(Mobile seller, Type type, int amount, bool truncateprice, Serial vendorid)
        {
            if (m_Resources[type] == null)
            {
                return(-1);
            }

            ResourceTransaction rt = new ResourceTransaction(TransactionType.Sale);

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

            double ret = ((ResourceData)m_Resources[type]).Add(seller, amount, truncateprice);

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

            ResourceLogger.Add(rt, seller);

            return(ret);
        }
Пример #3
0
        public static bool Add(ResourceTransaction rt, Mobile player)
        {
            if (!(m_History[player] is ArrayList))
            {
                LoadHistory(player);
            }

            int count = 0;

            foreach (ResourceTransaction r in (ArrayList)m_History[player])
            {
                if (r.TransactionID == rt.TransactionID && r.TransType == rt.TransType)
                {
                    break;
                }
                count++;
            }

            // fear not, this is just a sh!tload of casts and indexes
            if (count < ((ArrayList)m_History[player]).Count)
            {
                ((ResourceTransaction)((ArrayList)m_History[player])[count]).Amount += rt.Amount;
            }
            else
            {
                ((ArrayList)m_History[player]).Insert(0, rt);
            }
            if (((ArrayList)m_History[player]).Count > 50)
            {
                ((ArrayList)m_History[player]).RemoveRange(49, ((ArrayList)m_History[player]).Count - 50);
            }

            m_TransactionStack--;
            if (m_TransactionStack == 0)
            {
                m_TransID++;
            }

            // log
            if (m_LogLevel > 0)
            {
                try
                {
                    if (!Directory.Exists("Saves/ResourcePool"))
                    {
                        Directory.CreateDirectory("Saves/ResourcePool");
                    }
                    if (!Directory.Exists("Saves/ResourcePool/TransactionHistories"))
                    {
                        Directory.CreateDirectory("Saves/ResourcePool/TransactionHistories");
                    }

                    BinaryFileWriter writer = new BinaryFileWriter(new FileStream("Saves/ResourcePool/MasterHistory.dat", FileMode.Append, FileAccess.Write, FileShare.Read), true);
                    rt.Serialize(writer);
                    writer.Close();
                }
                catch (Exception e)
                {
                    LogHelper.LogException(e);
                    Console.WriteLine("ResourceLogger error: Failed to open MasterHistory.dat for writing.");
                    Console.WriteLine(e.ToString());
                }
            }

            return(true);
        }
Пример #4
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);
        }
Пример #5
0
		public static bool Add(ResourceTransaction rt, Mobile player)
		{
			if (!(m_History[player] is ArrayList))
				LoadHistory(player);

			int count = 0;
			foreach (ResourceTransaction r in (ArrayList)m_History[player])
			{
				if (r.TransactionID == rt.TransactionID && r.TransType == rt.TransType)
					break;
				count++;
			}
			
			// fear not, this is just a sh!tload of casts and indexes
			if (count < ((ArrayList)m_History[player]).Count)
				((ResourceTransaction)((ArrayList)m_History[player])[count]).Amount += rt.Amount;
			else
				((ArrayList)m_History[player]).Insert(0, rt);
			if (((ArrayList)m_History[player]).Count > 50)
				((ArrayList)m_History[player]).RemoveRange(49, ((ArrayList)m_History[player]).Count - 50);

			m_TransactionStack--;
			if (m_TransactionStack == 0)
				m_TransID++;
			
			// log
			if (m_LogLevel > 0)
			{
				try
				{
					if (!Directory.Exists("Saves/ResourcePool"))
						Directory.CreateDirectory("Saves/ResourcePool");
					if (!Directory.Exists("Saves/ResourcePool/TransactionHistories"))
						Directory.CreateDirectory("Saves/ResourcePool/TransactionHistories");
					
					BinaryFileWriter writer = new BinaryFileWriter(new FileStream("Saves/ResourcePool/MasterHistory.dat", FileMode.Append, FileAccess.Write, FileShare.Read), true);
					rt.Serialize(writer);
					writer.Close();
				}
				catch (Exception e)
				{
					LogHelper.LogException(e);
					Console.WriteLine("ResourceLogger error: Failed to open MasterHistory.dat for writing.");
					Console.WriteLine(e.ToString());
				}
			}

			return true;
		}
Пример #6
0
		public static double AddToPool(Mobile seller, Type type, int amount, bool truncateprice, Serial vendorid)
		{
			if (m_Resources[type] == null)
			{
				return -1;
			}

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

			double ret = ((ResourceData)m_Resources[type]).Add(seller, amount, truncateprice);

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

			ResourceLogger.Add(rt, seller);

			return ret;
		}
Пример #7
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;
		}