示例#1
0
        public static void TryPurchase(Mobile m)
        {
            Dictionary <StoreEntry, int> cart = GetCart(m);
            int total = GetSubTotal(cart);

            if (cart == null || cart.Count == 0 || total == 0)
            {
                // Purchase failed due to your cart being empty.
                m.SendLocalizedMessage(1156842);
            }
            else if (total > GetCurrency(m, true))
            {
                if (m is PlayerMobile)
                {
                    BaseGump.SendGump(new NoFundsGump((PlayerMobile)m));
                }
            }
            else
            {
                int  subtotal = 0;
                bool fail     = false;

                List <StoreEntry> remove = new List <StoreEntry>();

                foreach (KeyValuePair <StoreEntry, int> entry in cart)
                {
                    for (int i = 0; i < entry.Value; i++)
                    {
                        if (!entry.Key.Construct(m))
                        {
                            fail = true;

                            try
                            {
                                using (StreamWriter op = File.AppendText("UltimaStoreError.log"))
                                {
                                    op.WriteLine("Bad Constructor: {0}", entry.Key.ItemType.Name);

                                    Utility.WriteConsoleColor(ConsoleColor.Red, "[Ultima Store]: Bad Constructor: {0}", entry.Key.ItemType.Name);
                                }
                            }
                            catch (Exception e)
                            {
                                Diagnostics.ExceptionLogging.LogException(e);
                            }
                        }
                        else
                        {
                            remove.Add(entry.Key);

                            subtotal += entry.Key.Cost;
                        }
                    }
                }

                if (subtotal > 0)
                {
                    DeductCurrency(m, subtotal);
                }

                PlayerProfile profile = GetProfile(m);

                foreach (StoreEntry entry in remove)
                {
                    profile.RemoveFromCart(entry);
                }

                if (fail)
                {
                    // Failed to process one of your items. Please check your cart and try again.
                    m.SendLocalizedMessage(1156853);
                }
            }
        }