Exemple #1
0
        /// <summary>
        /// Returns a string represenation of the lifetime market earnings from orders created by <code>seller</code>
        /// </summary>
        public static string PrintOrderEarnings(Mobile seller)
        {
            int copper = 0, silver = 0, gold = 0;

            SQLiteDataReader reader = ExecuteQuery("SELECT earnings FROM sellers WHERE serial = $seller", new SQLiteParameter[] { new SQLiteParameter("$seller", (int)seller.Serial) });

            if (reader != null)
            {
                if (reader.Read())
                {
                    copper = reader.GetInt32(reader.GetOrdinal("earnings"));
                }

                reader.Close();
            }

            if (copper >= 100)
            {
                int[] compressed = Curr.Compress(copper, 0, 0);
                copper = compressed[0];
                silver = compressed[1];
                gold   = compressed[2];
            }

            return(String.Format("{0}c, {1}s, {2}g", copper, silver, gold));
        }
Exemple #2
0
        protected override void OnAmountChange(int oldValue)
        {
            oldValue = CurrencySystem.ConvertTo(CurrencyType, CurrencyType.Gold, oldValue);
            int newValue = CurrencySystem.ConvertTo(CurrencyType, CurrencyType.Gold, this.Amount);

            UpdateTotal(this, TotalType.Gold, newValue - oldValue);
        }
Exemple #3
0
        /// <summary>
        /// Closes an order. If wasSold=false, the order is deleted from the entries table history.
        /// </summary>
        /// <param name="entry"></param>
        /// <param name="wasSold"></param>
        public static void CloseOrder(MarketEntry entry, bool wasSold)
        {
            ExecuteNonQuery("UPDATE entries SET active = 0 WHERE entryid = " + entry.TableId);

            if (wasSold)
            {
                ExecuteNonQuery("UPDATE sellers SET earnings = earnings + " + entry.Cost + " WHERE serial = " + (int)entry.Seller.Serial);
                Container cont = entry.Seller.FindBankNoCreate();

                if (cont != null)
                {
                    int[] coins = Curr.Compress(entry.Cost, 0, 0);
                    cont.DropItem(new Gold(coins[2]));
                    cont.DropItem(new Silver(coins[1]));
                    cont.DropItem(new Copper(coins[0]));
                }
                else
                {
                    ExceptionManager.LogException("Market", new Exception(String.Format("Unable to find bank for seller {0}.", LogManager.Format(entry.Seller))));
                }
            }
            else
            {
                ExecuteNonQuery("DELETE FROM entries WHERE entryid = " + entry.TableId);
                ExecuteNonQuery("UPDATE sellers SET totalorders = totalorders-1 WHERE serial = " + (int)entry.Seller.Serial);

                IEntity entity = World.FindEntity(entry.ObjectSerial);

                if (entity != null)
                {
                    if (entity.Serial.IsItem)
                    {
                        Container cont = entry.Seller.FindBankNoCreate();

                        if (cont == null)
                        {
                            cont = entry.Seller.Backpack;
                        }

                        if (cont == null)
                        {
                            ((Item)entity).MoveToWorld(entry.Seller.Location, entry.Seller.Map);
                        }
                        else
                        {
                            cont.DropItem((Item)entity);
                            entry.Seller.SendMessage("Your item has been returned to your {0}.", (cont is BankBox ? "bank box" : "backpack"));
                        }
                    }
                    else if (entity.Serial.IsMobile)
                    {
                        ((Mobile)entity).MoveToWorld(entry.Seller.Location, entry.Seller.Map);
                        ((Mobile)entity).PlaySound(((Mobile)entity).GetIdleSound());
                    }
                }
            }
        }
Exemple #4
0
        public override int GetTotal(TotalType type)
        {
            int baseTotal = base.GetTotal(type);

            if (type == TotalType.Gold)
            {
                baseTotal += CurrencySystem.ConvertTo(CurrencyType, CurrencyType.Gold, this.Amount);
            }

            return(baseTotal);
        }
Exemple #5
0
        public static bool BuyItem(Mobile buyer, MarketEntry entry)
        {
            if (buyer == null || !buyer.Alive)
            {
                buyer.SendMessage("You cannot purchase a market order while knocked out.");
            }
            else if (buyer == entry.Seller)
            {
                buyer.SendMessage("You cannot purchase something from yourself.");
            }
            else
            {
                IEntity entity = World.FindEntity(entry.ObjectSerial);

                if (entity == null || IsSold(entry))
                {
                    buyer.SendMessage("The order has expired.");
                }
                else
                {
                    Type[]    coinTypes      = new Type[] { Curr.typeofCopper, Curr.typeofSilver, Curr.typeofGold };
                    int[]     compressedCost = Curr.Compress(entry.Cost, 0, 0);
                    Container cont           = buyer.FindBankNoCreate();

                    if (cont != null && cont.ConsumeTotal(coinTypes, compressedCost) == -1)
                    {
                        if (entity is Item)
                        {
                            Item item = (Item)entity;
                            cont = buyer.Backpack;

                            if (cont != null && !cont.TryDropItem(buyer, item, false))
                            {
                                item.MoveToWorld(buyer.Location, buyer.Map);
                            }

                            CloseOrder(entry);

                            if (buyer.HasGump(typeof(MarketGump)))
                            {
                                buyer.CloseGump(typeof(MarketGump));
                                buyer.SendGump(new MarketGump(entry.Category, 0));
                            }

                            return(true);
                        }
                        else if (entity is Mobile)
                        {
                            Mobile mob = (Mobile)entity;
                            mob.Direction = (Direction)Utility.Random(8);
                            mob.MoveToWorld(buyer.Location, buyer.Map);
                            mob.PlaySound(mob.GetIdleSound());

                            if (mob is BaseCreature)
                            {
                                ((BaseCreature)mob).SetControlMaster(buyer);
                            }

                            CloseOrder(entry);

                            if (buyer.HasGump(typeof(MarketGump)))
                            {
                                buyer.CloseGump(typeof(MarketGump));
                                buyer.SendGump(new MarketGump(entry.Category, 0));
                            }

                            return(true);
                        }
                    }
                    else
                    {
                        buyer.SendMessage("You cannot afford that item.");
                    }
                }
            }

            return(false);
        }