示例#1
0
        /// <summary>
        /// Retrieve all market orders created by <code>seller</code>
        /// </summary>
        public static List <MarketEntry> EntriesBySeller(Mobile seller)
        {
            List <MarketEntry> list   = new List <MarketEntry>();
            SQLiteDataReader   reader = ExecuteQuery("SELECT entryid,active,category,cost,description,itemserial FROM entries WHERE sellerserial = " + (int)seller.Serial);

            while (reader.Read())
            {
                IEntity     saleObject = World.FindEntity(reader.GetInt32(reader.GetOrdinal("itemserial")));
                MarketEntry entry      = new MarketEntry(seller);

                entry.Active      = reader.GetBoolean(reader.GetOrdinal("active"));
                entry.Category    = (Category)reader.GetInt32(reader.GetOrdinal("category"));
                entry.Description = reader.GetString(reader.GetOrdinal("description"));
                entry.TableId     = reader.GetInt32(reader.GetOrdinal("entryid"));

                if (saleObject != null)
                {
                    entry.SetSellItem(saleObject);
                }

                entry.ChangeCost(reader.GetInt32(reader.GetOrdinal("cost")), 0, 0);

                list.Add(entry);
            }

            reader.Close();

            return(list);
        }
示例#2
0
        /// <summary>
        /// Retrieve all market orders matching <code>category</code>
        /// </summary>
        public static List <MarketEntry> EntriesByCategory(Category category)
        {
            List <MarketEntry> list   = new List <MarketEntry>();
            SQLiteDataReader   reader = ExecuteQuery("SELECT entryid,cost,description,itemserial,sellerserial FROM entries WHERE active = 1 AND category = " + (int)category);

            while (reader.Read())
            {
                Mobile  seller     = World.FindMobile(reader.GetInt32(reader.GetOrdinal("sellerserial")));
                IEntity saleObject = World.FindEntity(reader.GetInt32(reader.GetOrdinal("itemserial")));

                if (seller == null || saleObject == null)
                {
                    continue;
                }

                MarketEntry entry = new MarketEntry(seller);
                entry.Category    = category;
                entry.Description = reader.GetString(reader.GetOrdinal("description"));
                entry.TableId     = reader.GetInt32(reader.GetOrdinal("entryid"));

                entry.ChangeCost(reader.GetInt32(reader.GetOrdinal("cost")), 0, 0);
                entry.SetSellItem(saleObject);

                list.Add(entry);
            }

            reader.Close();

            return(list);
        }
示例#3
0
        /// <summary>
        /// Updates the properties of a market order. If the entry's TableId property is 0, the order is added as new instead of updating.
        /// </summary>
        /// <param name="entry">MarketEntry with the new order properties</param>
        public static void UpdateOrder(Mobile seller, MarketEntry entry)
        {
            if (entry.TableId <= 0)
            {
                AddNewOrder(seller, entry);
                return;
            }

            if (String.IsNullOrEmpty(entry.Description))
            {
                IEntity entity = World.FindEntity(entry.ObjectSerial);
                entry.Description = (entity is Item ? ((Item)entity).Name : (entity is Mobile ? ((Mobile)entity).Name : "an object"));
            }

            SQLiteParameter[] paramSet = new SQLiteParameter[]
            {
                new SQLiteParameter("$cat", (int)entry.Category),
                new SQLiteParameter("$cost", entry.Cost),
                new SQLiteParameter("$desc", entry.Description.Substring(0, Math.Min(entry.Description.Length, 255)))
            };
            ExecuteNonQuery("UPDATE entries SET active=1,category=$cat,cost=$cost,description=$desc WHERE entryid = " + entry.TableId, paramSet);

            seller.SendGump(new PersonalMarketGump(seller));
            seller.SendMessage("Your order has been updated.");
        }
示例#4
0
        public static void AddNewOrder( Mobile seller, MarketEntry entry )
        {
            seller.SendMessage("Select the object for this order.");
            seller.BeginTarget(12, false, Server.Targeting.TargetFlags.None, new TargetCallback(
                delegate( Mobile from, object targeted )
                {
                    if( targeted is IEntity )
                    {
                        if( targeted is Mobile )
                        {
                            Mobile mob = (Mobile)targeted;

                            if( mob is BaseCreature && ((BaseCreature)mob).ControlMaster == from )
                                FinalizeNewOrder(seller, entry, mob);
                            else
                                from.SendMessage("You do not have the right to sell that.");
                        }
                        else if( targeted is Item )
                        {
                            Item item = (Item)targeted;

                            if( item.IsChildOf(from.Backpack) || item.RootParent == from )
                                FinalizeNewOrder(seller, entry, item);
                            else
                                from.SendMessage("You do not have the right to sell that.");
                        }
                    }
                    else
                    {
                        from.SendMessage("That is not a valid market entity.");
                    }
                }));
        }
示例#5
0
        public MarketDetailsGump(MarketEntry entry)
            : base(0, 0)
        {
            _entry = entry;

            AddPage(1);
            AddBackground(155, 65, 535, 355, 9250);
            AddLabel(380, 75, 1152, "Item Details");

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

            if (entity.Serial.IsItem)
            {
                AddItem(615, 85, ((Item)entity).ItemID, ((Item)entity).Hue);
            }

            AddAlphaRegion(170, 105, 415, 300);
            AddHtml(170, 105, 415, 300, String.Format("<basefont color=#{0:X6}>{1}</basefont>", 0xFFFFFF, GetDescription(entry)), false, true);

            AddButton(625, 275, 4023, 4025, GetButtonId(1, 0), GumpButtonType.Reply, 0);
            AddLabel(610, 295, 1152, "Purchase");

            AddButton(625, 340, 4020, 4022, GetButtonId(1, 1), GumpButtonType.Reply, 0);
            AddLabel(615, 360, 1152, "Go back");
        }
		public OrderManagementGump( MarketEntry entry )
			: base( 0, 0 )
		{
			_entry = entry;

			AddPage( 1 );
			AddBackground( 10, 10, 500, 430, 9250 );
			AddLabel( 170, 20, LabelHue, "Personal Market Management" );
			AddItem( 445, 30, 6226 );
			AddItem( 431, 53, 3826 );
			AddItem( 446, 62, 3820 );
			AddItem( 422, 45, 3822 );

			if( entry == null )
				AddLabel( 225, 40, LabelHue, "New Order" );
			else
				AddLabel( 215, 40, LabelHue, "Order Update" );

			AddLabel( 25, 80, LabelHue, "Item cost:" );

			int[] cost = new int[] { 0, 0, 0 };

			if( entry != null )
				cost = Curr.Compress( entry.Cost, 0, 0 );

			AddImageTiled( 30, 100, 80, 20, 3004 );
			AddTextEntry( 30, 100, 80, 20, 0, 1, Convert.ToString( cost[0] ) );
			AddLabel( 115, 100, LabelHue, "copper" );
			AddImageTiled( 30, 125, 80, 20, 3004 );
			AddTextEntry( 30, 125, 80, 20, 0, 2, Convert.ToString( cost[1] ) );
			AddLabel( 115, 125, LabelHue, "silver" );
			AddImageTiled( 30, 150, 80, 20, 3004 );
			AddTextEntry( 30, 150, 80, 20, 0, 3, Convert.ToString( cost[2] ) );
			AddLabel( 115, 150, LabelHue, "gold" );

			AddLabel( 275, 80, LabelHue, "Category:" );

			AddRadio( 310, 100, 9020, 9021, (entry == null ? false : entry.Category == Category.Armor), 1 );
			AddLabel( 335, 100, LabelHue, "Armor" );
			AddRadio( 310, 125, 9020, 9021, (entry == null ? false : entry.Category == Category.Clothing), 2 );
			AddLabel( 335, 125, LabelHue, "Clothing" );
			AddRadio( 310, 150, 9020, 9021, (entry == null ? true : entry.Category == Category.Misc), 3 );
			AddLabel( 335, 150, LabelHue, "Miscellaneous" );
			AddRadio( 310, 175, 9020, 9021, (entry == null ? false : entry.Category == Category.Resources), 4 );
			AddLabel( 335, 175, LabelHue, "Resources (commodities)" );
			AddRadio( 310, 200, 9020, 9021, (entry == null ? false : entry.Category == Category.SkillItems), 5 );
			AddLabel( 335, 200, LabelHue, "Skill Items (training aid)" );
			AddRadio( 310, 225, 9020, 9021, (entry == null ? false : entry.Category == Category.Weaponry), 6 );
			AddLabel( 335, 225, LabelHue, "Weaponry" );

			AddLabel( 25, 225, LabelHue, "Description:" );
			AddImageTiled( 25, 250, 355, 175, 3004 );
			AddTextEntry( 25, 250, 355, 175, 0, 4, (entry == null ? "" : entry.Description) );

			AddButton( 420, 265, 4023, 4025, GetButtonId( 1, 1 ), GumpButtonType.Reply, 0 );
			AddLabel( 395, 285, LabelHue, "Submit Order" );
			AddButton( 420, 335, 4017, 4019, GetButtonId( 1, 2 ), GumpButtonType.Reply, 0 );
			AddLabel( 395, 355, LabelHue, "Cancel Order" );
		}
示例#7
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());
                    }
                }
            }
        }
示例#8
0
        public static bool IsSold(MarketEntry entry)
        {
            SQLiteDataReader reader = ExecuteQuery("SELECT active FROM entries WHERE entryid=" + entry.TableId);
            bool             active = false;

            if (reader.Read())
            {
                active = reader.GetBoolean(reader.GetOrdinal("active"));
            }

            return(!active);
        }
示例#9
0
        public static void AddNewOrder(Mobile seller, MarketEntry entry)
        {
            seller.SendMessage("Select the object for this order.");
            seller.BeginTarget(12, false, Server.Targeting.TargetFlags.None, new TargetCallback(
                                   delegate(Mobile from, object targeted)
            {
                if (targeted is IEntity)
                {
                    if (targeted is Mobile)
                    {
                        Mobile mob = (Mobile)targeted;

                        if (mob is BaseCreature && ((BaseCreature)mob).ControlMaster == from)
                        {
                            FinalizeNewOrder(seller, entry, mob);
                        }
                        else
                        {
                            from.SendMessage("You do not have the right to sell that.");
                        }
                    }
                    else if (targeted is Item)
                    {
                        Item item = (Item)targeted;

                        if (item.IsChildOf(from.Backpack) || item.RootParent == from)
                        {
                            FinalizeNewOrder(seller, entry, item);
                        }
                        else
                        {
                            from.SendMessage("You do not have the right to sell that.");
                        }
                    }
                }
                else
                {
                    from.SendMessage("That is not a valid market entity.");
                }
            }));
        }
示例#10
0
        public MarketDetailsGump( MarketEntry entry )
            : base(0, 0)
        {
            _entry = entry;

            AddPage(1);
            AddBackground(155, 65, 535, 355, 9250);
            AddLabel(380, 75, 1152, "Item Details");

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

            if( entity.Serial.IsItem )
                AddItem(615, 85, ((Item)entity).ItemID, ((Item)entity).Hue);

            AddAlphaRegion(170, 105, 415, 300);
            AddHtml(170, 105, 415, 300, String.Format("<basefont color=#{0:X6}>{1}</basefont>", 0xFFFFFF, GetDescription(entry)), false, true);

            AddButton(625, 275, 4023, 4025, GetButtonId(1, 0), GumpButtonType.Reply, 0);
            AddLabel(610, 295, 1152, "Purchase");

            AddButton(625, 340, 4020, 4022, GetButtonId(1, 1), GumpButtonType.Reply, 0);
            AddLabel(615, 360, 1152, "Go back");
        }
示例#11
0
        public override void OnResponse(Server.Network.NetState sender, RelayInfo info)
        {
            int val, type, index;

            DecodeButtonId(info.ButtonID, out val, out type, out index);

            if (val < 0)
            {
                return;
            }

            Mobile from = sender.Mobile;

            if (type == 1)
            {
                if (index == 1)
                {
                    bool newOrder = (_entry == null);

                    if (newOrder)
                    {
                        _entry = new MarketEntry(from);
                    }

                    _entry.Category = (Category)(info.Switches[0] - 1);

                    string cc = info.GetTextEntry(1).Text;
                    string cs = info.GetTextEntry(2).Text;
                    string cg = info.GetTextEntry(3).Text;

                    Regex rx = new Regex("[^0-9]");
                    cc = rx.Replace(cc, ""); cc.Trim();
                    cs = rx.Replace(cs, ""); cs.Trim();
                    cg = rx.Replace(cg, ""); cg.Trim();

                    int[] cost = new int[]
                    {
                        (String.IsNullOrEmpty(cc) ? 0 : Convert.ToInt32(cc)),
                        (String.IsNullOrEmpty(cs) ? 0 : Convert.ToInt32(cs)),
                        (String.IsNullOrEmpty(cg) ? 0 : Convert.ToInt32(cg))
                    };
                    _entry.ChangeCost(cost[0], cost[1], cost[2]);
                    _entry.Description = info.GetTextEntry(4).Text;

                    if (_entry.Cost < 10)
                    {
                        from.SendMessage("Please enter a price of at least 10 copper.");
                        from.SendGump(new OrderManagementGump(_entry));
                    }
                    else if (String.IsNullOrEmpty(_entry.Description))
                    {
                        from.SendMessage("Please enter a description for your order.");
                        from.SendGump(new OrderManagementGump(_entry));
                    }
                    else
                    {
                        if (newOrder)
                        {
                            Market.AddNewOrder(from, _entry);
                        }
                        else
                        {
                            Market.UpdateOrder(from, _entry);
                        }
                    }
                }
                else if (index == 2 && _entry != null)                  //cancel order
                {
                    Market.CloseOrder(_entry, false);
                }
            }
        }
示例#12
0
		public override void OnResponse( Server.Network.NetState sender, RelayInfo info )
		{
			int val, type, index;
			DecodeButtonId( info.ButtonID, out val, out type, out index );

			if( val < 0 )
				return;

			Mobile from = sender.Mobile;

			if( type == 1 )
			{
				if( index == 1 )
				{
					bool newOrder = (_entry == null);

					if( newOrder )
						_entry = new MarketEntry( from );

					_entry.Category = (Category)(info.Switches[0] - 1);

					string cc = info.GetTextEntry( 1 ).Text;
					string cs = info.GetTextEntry( 2 ).Text;
					string cg = info.GetTextEntry( 3 ).Text;

					Regex rx = new Regex( "[^0-9]" );
					cc = rx.Replace( cc, "" ); cc.Trim();
					cs = rx.Replace( cs, "" ); cs.Trim();
					cg = rx.Replace( cg, "" ); cg.Trim();

					int[] cost = new int[]
					{
						(String.IsNullOrEmpty( cc ) ? 0 : Convert.ToInt32( cc )),
						(String.IsNullOrEmpty( cs ) ? 0 : Convert.ToInt32( cs )),
						(String.IsNullOrEmpty( cg ) ? 0 : Convert.ToInt32( cg ))
					};
					_entry.ChangeCost( cost[0], cost[1], cost[2] );
					_entry.Description = info.GetTextEntry( 4 ).Text;

					if( _entry.Cost < 10 )
					{
						from.SendMessage( "Please enter a price of at least 10 copper." );
						from.SendGump( new OrderManagementGump( _entry ) );
					}
					else if( String.IsNullOrEmpty( _entry.Description ) )
					{
						from.SendMessage( "Please enter a description for your order." );
						from.SendGump( new OrderManagementGump( _entry ) );
					}
					else
					{
						if( newOrder )
							Market.AddNewOrder( from, _entry );
						else
							Market.UpdateOrder( from, _entry );
					}
				}
				else if( index == 2 && _entry != null ) //cancel order
				{
					Market.CloseOrder( _entry, false );
				}
			}
		}
示例#13
0
        public PersonalMarketGump(Mobile from, byte page)
            : base(0, 0)
        {
            selectedPage = page;

            AddPage(1);
            AddBackground(10, 10, 500, 430, 9250);
            AddLabel(170, 20, LabelHue, "Personal Market Management");
            AddItem(445, 30, 6226);
            AddItem(431, 53, 3826);
            AddItem(446, 62, 3820);
            AddItem(422, 45, 3822);

            AddLabel(30, 55, LabelHue, "Orders (active/total): " + Market.PrintOrderData(from));
            AddLabel(30, 80, LabelHue, "Total earnings to date: " + Market.PrintOrderEarnings(from));

            AddLabel(350, 145, LabelHue, "Create new order");
            AddButton(465, 145, 4011, 4013, GetButtonId(3, 1), GumpButtonType.Reply, 0);

            AddBackground(25, 180, 470, 245, 9350);
            AddLabel(225, 160, LabelHue, "My Orders");

            entries = Market.EntriesBySeller(from);

            for (int i = 0, y = 185, index = (page * 10); i < 10; i++, y += 22)
            {
                AddAlphaRegion(30, y, 355, 20);
                AddAlphaRegion(387, y, 85, 20);

                if (entries.Count >= (index + 1))
                {
                    MarketEntry entry = entries[index];

                    if (entry == null)
                    {
                        continue;
                    }

                    AddLabelCropped(30, y, 355, 20, (entry.Active ? LabelHue : InactiveLabelHue), entry.Description);

                    int[] cost = Currency.CurrencySystem.Compress(entry.Cost, 0, 0);
                    AddLabel(387, y, LabelHue, String.Format("{0}c, {1}s, {2}g", cost[0], cost[1], cost[2]));

                    if (entry.Active)
                    {
                        AddButton(478, (y + 5), 2103, 2104, GetButtonId(1, index), GumpButtonType.Reply, 0);
                    }

                    index++;
                }
            }

            if (page > 0)
            {
                AddButton(240, 405, 5603, 5607, GetButtonId(2, 1), GumpButtonType.Reply, 0);
            }
            if (entries.Count > ((page + 1) * 10))
            {
                AddButton(265, 405, 5601, 5605, GetButtonId(2, 2), GumpButtonType.Reply, 0);
            }
        }
示例#14
0
 /// <summary>
 /// Closes an order after being sold
 /// </summary>
 public static void CloseOrder(MarketEntry entry)
 {
     CloseOrder(entry, true);
 }
示例#15
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);
        }
示例#16
0
        /// <summary>
        /// Retrieve all market orders matching <code>category</code>
        /// </summary>
        public static List<MarketEntry> EntriesByCategory( Category category )
        {
            List<MarketEntry> list = new List<MarketEntry>();
            SQLiteDataReader reader = ExecuteQuery("SELECT entryid,cost,description,itemserial,sellerserial FROM entries WHERE active = 1 AND category = " + (int)category);

            while( reader.Read() )
            {
                Mobile seller = World.FindMobile(reader.GetInt32(reader.GetOrdinal("sellerserial")));
                IEntity saleObject = World.FindEntity(reader.GetInt32(reader.GetOrdinal("itemserial")));

                if( seller == null || saleObject == null )
                    continue;

                MarketEntry entry = new MarketEntry(seller);
                entry.Category = category;
                entry.Description = reader.GetString(reader.GetOrdinal("description"));
                entry.TableId = reader.GetInt32(reader.GetOrdinal("entryid"));

                entry.ChangeCost(reader.GetInt32(reader.GetOrdinal("cost")), 0, 0);
                entry.SetSellItem(saleObject);

                list.Add(entry);
            }

            reader.Close();

            return list;
        }
示例#17
0
        private static void FinalizeNewOrder(Mobile seller, MarketEntry entry, IEntity saleEntity)
        {
            entry.SetSellItem(saleEntity);

            //do this to prevent a scenario where the market db is more up to date than the latest server save (market serials could be mismatched to server items, in that case)
            World.Save(false, true);

            if (saleEntity is Item)
            {
                ((Item)saleEntity).MoveToWorld(new Point3D(0, 0, 1), Map.Internal);
            }
            else if (saleEntity is Mobile)
            {
                ((Mobile)saleEntity).Internalize();
            }

            if (String.IsNullOrEmpty(entry.Description))
            {
                if (saleEntity is Item)
                {
                    Item i = saleEntity as Item;

                    if (String.IsNullOrEmpty(i.Name))
                    {
                        if ((i.ItemData.Flags & TileFlag.ArticleA) != 0)
                        {
                            entry.Description = "a " + i.ItemData.Name;
                        }
                        else if ((i.ItemData.Flags & TileFlag.ArticleAn) != 0)
                        {
                            entry.Description = "an " + i.ItemData.Name;
                        }
                        else
                        {
                            entry.Description = i.ItemData.Name;
                        }
                    }
                    else
                    {
                        entry.Description = i.Name;
                    }
                }
                else
                {
                    entry.Description = "a pet for sale by " + seller.Name;
                }
            }

            //add into the entries table
            SQLiteParameter[] paramSet = new SQLiteParameter[]
            {
                new SQLiteParameter("$category", (int)entry.Category),
                new SQLiteParameter("$cost", entry.Cost),
                new     SQLiteParameter("$desc", entry.Description.Substring(0, Math.Min(entry.Description.Length, 255))),
                new SQLiteParameter("$item", (int)saleEntity.Serial),
                new SQLiteParameter("$seller", (int)seller.Serial)
            };
            ExecuteNonQuery("INSERT INTO entries (category,cost,description,itemserial,sellerserial) " +
                            "VALUES ($category,$cost,$desc,$item,$seller)", paramSet);

            //add/update the seller detail table
            try
            {
                ExecuteNonQuery("INSERT INTO sellers (serial,totalorders) VALUES ($seller,1)", new SQLiteParameter[] { new SQLiteParameter("$seller", (int)seller.Serial) });
            }
            catch
            {
                ExecuteNonQuery("UPDATE sellers SET totalorders=totalorders+1 WHERE serial=$seller", new SQLiteParameter[] { new SQLiteParameter("$seller", (int)seller.Serial) });
            }

            seller.SendGump(new PersonalMarketGump(seller));
            seller.SendMessage("Your order has been added to the marketplace.");
        }
示例#18
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;
        }
示例#19
0
 /// <summary>
 /// Closes an order after being sold
 /// </summary>
 public static void CloseOrder( MarketEntry entry )
 {
     CloseOrder(entry, true);
 }
示例#20
0
        private string GetDescription(MarketEntry entry)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine(String.Format("Seller: {0}", (entry.Seller == null ? "(private)" : entry.Seller.RawName)));

            int[] cost = Curr.Compress(entry.Cost, 0, 0);
            sb.AppendLine(String.Format("Total cost: {0} copper, {1} silver, {2} gold", cost[0], cost[1], cost[2]));

            sb.AppendLine(String.Format("Seller's description: {0}", entry.Description));

            sb.AppendLine();
            sb.Append("<center>---------------</center>");
            sb.Append(String.Format("<center>{0} Details</center>", (entry.ObjectSerial.IsItem ? "Item" : "Mobile")));

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

            if (entity is Item)
            {
                Item item = (Item)entity;

                sb.AppendLine("Name: " + item.Name);

                if (item.Amount > 1)
                {
                    sb.AppendLine("Quantity: " + item.Amount);
                }

                if (item is BaseWeapon)
                {
                    BaseWeapon weap = (BaseWeapon)item;

                    if (weap.Crafter != null)
                    {
                        sb.AppendLine("Crafted by: " + weap.Crafter.RawName);
                    }

                    sb.AppendLine("Quality: " + weap.Quality);

                    if (weap.Identified)
                    {
                        sb.AppendLine("Durability: " + weap.DurabilityLevel);
                        sb.AppendLine("Accuracy level: " + weap.AccuracyLevel);
                        sb.AppendLine("Damage level: " + weap.DamageLevel);

                        if (weap.Slayer != SlayerName.None)
                        {
                            SlayerEntry se = SlayerGroup.GetEntryByName(weap.Slayer);

                            if (se != null)
                            {
                                sb.AppendLine("Slayer enhancement: " + se.Title);
                            }
                        }

                        if (weap.Slayer2 != SlayerName.None)
                        {
                            SlayerEntry se = SlayerGroup.GetEntryByName(weap.Slayer2);

                            if (se != null)
                            {
                                sb.AppendLine("Slayer enhancement: " + se.Title);
                            }
                        }
                    }
                    else
                    {
                        sb.AppendLine("<i>Unidentified</i>");
                    }
                }
            }
            else if (entity is Mobile)
            {
                Mobile mob = (Mobile)entity;

                sb.AppendLine("Name: " + mob.Name);

                if (mob is BaseCreature)
                {
                    BaseCreature bc = (BaseCreature)mob;

                    sb.AppendLine("Creature type: " + Util.SplitString(bc.GetType().ToString()));
                    sb.AppendLine("Minimum Taming required: " + bc.MinTameSkill.ToString("F2"));
                    sb.AppendLine("Follower Slots required: " + bc.ControlSlots);
                }
            }

            return(sb.ToString());
        }
示例#21
0
        /// <summary>
        /// Updates the properties of a market order. If the entry's TableId property is 0, the order is added as new instead of updating.
        /// </summary>
        /// <param name="entry">MarketEntry with the new order properties</param>
        public static void UpdateOrder( Mobile seller, MarketEntry entry )
        {
            if( entry.TableId <= 0 )
            {
                AddNewOrder(seller, entry);
                return;
            }

            if( String.IsNullOrEmpty(entry.Description) )
            {
                IEntity entity = World.FindEntity(entry.ObjectSerial);
                entry.Description = (entity is Item ? ((Item)entity).Name : (entity is Mobile ? ((Mobile)entity).Name : "an object"));
            }

            SQLiteParameter[] paramSet = new SQLiteParameter[]
				{
					new SQLiteParameter( "$cat", (int)entry.Category ),
					new SQLiteParameter( "$cost", entry.Cost ),
					new SQLiteParameter( "$desc", entry.Description.Substring( 0, Math.Min( entry.Description.Length, 255 ) ) )
				};
            ExecuteNonQuery("UPDATE entries SET active=1,category=$cat,cost=$cost,description=$desc WHERE entryid = " + entry.TableId, paramSet);

            seller.SendGump(new PersonalMarketGump(seller));
            seller.SendMessage("Your order has been updated.");
        }
示例#22
0
        public static bool IsSold( MarketEntry entry )
        {
            SQLiteDataReader reader = ExecuteQuery("SELECT active FROM entries WHERE entryid=" + entry.TableId);
            bool active = false;

            if( reader.Read() )
                active = reader.GetBoolean(reader.GetOrdinal("active"));

            return !active;
        }
示例#23
0
        /// <summary>
        /// Retrieve all market orders created by <code>seller</code>
        /// </summary>
        public static List<MarketEntry> EntriesBySeller( Mobile seller )
        {
            List<MarketEntry> list = new List<MarketEntry>();
            SQLiteDataReader reader = ExecuteQuery("SELECT entryid,active,category,cost,description,itemserial FROM entries WHERE sellerserial = " + (int)seller.Serial);

            while( reader.Read() )
            {
                IEntity saleObject = World.FindEntity(reader.GetInt32(reader.GetOrdinal("itemserial")));
                MarketEntry entry = new MarketEntry(seller);

                entry.Active = reader.GetBoolean(reader.GetOrdinal("active"));
                entry.Category = (Category)reader.GetInt32(reader.GetOrdinal("category"));
                entry.Description = reader.GetString(reader.GetOrdinal("description"));
                entry.TableId = reader.GetInt32(reader.GetOrdinal("entryid"));

                if( saleObject != null )
                    entry.SetSellItem(saleObject);

                entry.ChangeCost(reader.GetInt32(reader.GetOrdinal("cost")), 0, 0);

                list.Add(entry);
            }

            reader.Close();

            return list;
        }
示例#24
0
        public OrderManagementGump(MarketEntry entry)
            : base(0, 0)
        {
            _entry = entry;

            AddPage(1);
            AddBackground(10, 10, 500, 430, 9250);
            AddLabel(170, 20, LabelHue, "Personal Market Management");
            AddItem(445, 30, 6226);
            AddItem(431, 53, 3826);
            AddItem(446, 62, 3820);
            AddItem(422, 45, 3822);

            if (entry == null)
            {
                AddLabel(225, 40, LabelHue, "New Order");
            }
            else
            {
                AddLabel(215, 40, LabelHue, "Order Update");
            }

            AddLabel(25, 80, LabelHue, "Item cost:");

            int[] cost = new int[] { 0, 0, 0 };

            if (entry != null)
            {
                cost = Curr.Compress(entry.Cost, 0, 0);
            }

            AddImageTiled(30, 100, 80, 20, 3004);
            AddTextEntry(30, 100, 80, 20, 0, 1, Convert.ToString(cost[0]));
            AddLabel(115, 100, LabelHue, "copper");
            AddImageTiled(30, 125, 80, 20, 3004);
            AddTextEntry(30, 125, 80, 20, 0, 2, Convert.ToString(cost[1]));
            AddLabel(115, 125, LabelHue, "silver");
            AddImageTiled(30, 150, 80, 20, 3004);
            AddTextEntry(30, 150, 80, 20, 0, 3, Convert.ToString(cost[2]));
            AddLabel(115, 150, LabelHue, "gold");

            AddLabel(275, 80, LabelHue, "Category:");

            AddRadio(310, 100, 9020, 9021, (entry == null ? false : entry.Category == Category.Armor), 1);
            AddLabel(335, 100, LabelHue, "Armor");
            AddRadio(310, 125, 9020, 9021, (entry == null ? false : entry.Category == Category.Clothing), 2);
            AddLabel(335, 125, LabelHue, "Clothing");
            AddRadio(310, 150, 9020, 9021, (entry == null ? true : entry.Category == Category.Misc), 3);
            AddLabel(335, 150, LabelHue, "Miscellaneous");
            AddRadio(310, 175, 9020, 9021, (entry == null ? false : entry.Category == Category.Resources), 4);
            AddLabel(335, 175, LabelHue, "Resources (commodities)");
            AddRadio(310, 200, 9020, 9021, (entry == null ? false : entry.Category == Category.SkillItems), 5);
            AddLabel(335, 200, LabelHue, "Skill Items (training aid)");
            AddRadio(310, 225, 9020, 9021, (entry == null ? false : entry.Category == Category.Weaponry), 6);
            AddLabel(335, 225, LabelHue, "Weaponry");

            AddLabel(25, 225, LabelHue, "Description:");
            AddImageTiled(25, 250, 355, 175, 3004);
            AddTextEntry(25, 250, 355, 175, 0, 4, (entry == null ? "" : entry.Description));

            AddButton(420, 265, 4023, 4025, GetButtonId(1, 1), GumpButtonType.Reply, 0);
            AddLabel(395, 285, LabelHue, "Submit Order");
            AddButton(420, 335, 4017, 4019, GetButtonId(1, 2), GumpButtonType.Reply, 0);
            AddLabel(395, 355, LabelHue, "Cancel Order");
        }
示例#25
0
        public MarketGump(Category category, byte page)
            : base(0, 0)
        {
            selectedCategory = category;
            selectedPage     = page;

            AddPage(1);
            AddBackground(10, 10, 780, 490, 9250);
            AddLabel(355, 20, LabelHue, "Player Market");

            AddAlphaRegion(25, 40, 125, 20);
            AddHtml(25, 40, 125, 20, String.Format("<basefont color=#{0:X6}><center>Category</center></basefont>", LabelColor32), false, false);
            AddAlphaRegion(155, 40, 535, 20);
            AddHtml(155, 40, 535, 20, String.Format("<basefont color=#{0:X6}><center>Item Description</center></basefont>", LabelColor32), false, false);
            AddAlphaRegion(695, 40, 80, 20);
            AddHtml(695, 40, 80, 20, String.Format("<basefont color=#{0:X6}><center>Cost</center></basefont>", LabelColor32), false, false);
            AddImageTiled(25, 60, 750, 4, 9151);

            string[] categories = Enum.GetNames(typeof(Category));

            for (int i = 0, y = 70; i < categories.Length; i++, y += 25)
            {
                AddAlphaRegion(45, y, 105, 20);

                if ((int)selectedCategory != i)
                {
                    AddButton(25, (y + 5), 5601, 5605, GetButtonId(1, i), GumpButtonType.Reply, 0);
                    AddLabel(45, y, LabelHue, Util.SplitString(categories[i]));
                }
                else
                {
                    AddImage(25, (y + 5), 5605);
                    AddHtml(45, y, 105, 20, String.Format("<basefont color=#{0:X6}>{1}</basefont>", LabelColor32, Util.SplitString(categories[i])), false, false);
                }
            }

            entries = Market.EntriesByCategory(selectedCategory);

            if (entries.Count > 0)
            {
                for (int i = 0, index = (selectedPage * 10), y = 65; i < 10 && index >= 0 && index < entries.Count; i++, index++, y += 40)
                {
                    MarketEntry entry = entries[index];

                    if (entry == null)
                    {
                        continue;
                    }

                    AddAlphaRegion(155, y, 535, 20);
                    AddLabelCropped(155, y, 535, 20, LabelHue, entry.Description);

                    int[] cost = Currency.CurrencySystem.Compress(entry.Cost, 0, 0);
                    AddAlphaRegion(695, y, 80, 20);
                    AddLabel(695, y, LabelHue, String.Format("{0}c, {1}s, {2}g", cost[0], cost[1], cost[2]));

                    AddButton(645, (y + 21), 5411, 5411, GetButtonId(2, index), GumpButtonType.Reply, 0);
                    AddButton(675, (y + 22), 2117, 2118, GetButtonId(3, index), GumpButtonType.Reply, 0);
                }
            }

            if (selectedPage > 0)
            {
                AddButton(380, 470, 5603, 5607, GetButtonId(4, 1), GumpButtonType.Reply, 0);
            }
            if (entries.Count > ((selectedPage + 1) * 10))
            {
                AddButton(405, 470, 5601, 5605, GetButtonId(4, 2), GumpButtonType.Reply, 0);
            }
        }
示例#26
0
        private string GetDescription( MarketEntry entry )
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine(String.Format("Seller: {0}", (entry.Seller == null ? "(private)" : entry.Seller.RawName)));

            int[] cost = Curr.Compress(entry.Cost, 0, 0);
            sb.AppendLine(String.Format("Total cost: {0} copper, {1} silver, {2} gold", cost[0], cost[1], cost[2]));

            sb.AppendLine(String.Format("Seller's description: {0}", entry.Description));

            sb.AppendLine();
            sb.Append("<center>---------------</center>");
            sb.Append(String.Format("<center>{0} Details</center>", (entry.ObjectSerial.IsItem ? "Item" : "Mobile")));

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

            if( entity is Item )
            {
                Item item = (Item)entity;

                sb.AppendLine("Name: " + item.Name);

                if( item.Amount > 1 )
                    sb.AppendLine("Quantity: " + item.Amount);

                if( item is BaseWeapon )
                {
                    BaseWeapon weap = (BaseWeapon)item;

                    if( weap.Crafter != null )
                        sb.AppendLine("Crafted by: " + weap.Crafter.RawName);

                    sb.AppendLine("Quality: " + weap.Quality);

                    if( weap.Identified )
                    {
                        sb.AppendLine("Durability: " + weap.DurabilityLevel);
                        sb.AppendLine("Accuracy level: " + weap.AccuracyLevel);
                        sb.AppendLine("Damage level: " + weap.DamageLevel);

                        if( weap.Slayer != SlayerName.None )
                        {
                            SlayerEntry se = SlayerGroup.GetEntryByName(weap.Slayer);

                            if( se != null )
                                sb.AppendLine("Slayer enhancement: " + se.Title);
                        }

                        if( weap.Slayer2 != SlayerName.None )
                        {
                            SlayerEntry se = SlayerGroup.GetEntryByName(weap.Slayer2);

                            if( se != null )
                                sb.AppendLine("Slayer enhancement: " + se.Title);
                        }
                    }
                    else
                    {
                        sb.AppendLine("<i>Unidentified</i>");
                    }
                }
            }
            else if( entity is Mobile )
            {
                Mobile mob = (Mobile)entity;

                sb.AppendLine("Name: " + mob.Name);

                if( mob is BaseCreature )
                {
                    BaseCreature bc = (BaseCreature)mob;

                    sb.AppendLine("Creature type: " + Util.SplitString(bc.GetType().ToString()));
                    sb.AppendLine("Minimum Taming required: " + bc.MinTameSkill.ToString("F2"));
                    sb.AppendLine("Follower Slots required: " + bc.ControlSlots);
                }
            }

            return sb.ToString();
        }
示例#27
0
        private static void FinalizeNewOrder( Mobile seller, MarketEntry entry, IEntity saleEntity )
        {
            entry.SetSellItem(saleEntity);

            //do this to prevent a scenario where the market db is more up to date than the latest server save (market serials could be mismatched to server items, in that case)
            World.Save(false, true);

            if( saleEntity is Item )
                ((Item)saleEntity).MoveToWorld(new Point3D(0, 0, 1), Map.Internal);
            else if( saleEntity is Mobile )
                ((Mobile)saleEntity).Internalize();

            if( String.IsNullOrEmpty(entry.Description) )
            {
                if( saleEntity is Item )
                {
                    Item i = saleEntity as Item;

                    if( String.IsNullOrEmpty(i.Name) )
                    {
                        if( (i.ItemData.Flags & TileFlag.ArticleA) != 0 )
                            entry.Description = "a " + i.ItemData.Name;
                        else if( (i.ItemData.Flags & TileFlag.ArticleAn) != 0 )
                            entry.Description = "an " + i.ItemData.Name;
                        else
                            entry.Description = i.ItemData.Name;
                    }
                    else
                    {
                        entry.Description = i.Name;
                    }
                }
                else
                {
                    entry.Description = "a pet for sale by " + seller.Name;
                }
            }

            //add into the entries table
            SQLiteParameter[] paramSet = new SQLiteParameter[]
				{
					new SQLiteParameter( "$category", (int)entry.Category ),
					new SQLiteParameter( "$cost", entry.Cost ),
					new	SQLiteParameter( "$desc", entry.Description.Substring( 0, Math.Min( entry.Description.Length, 255 ) ) ),
					new SQLiteParameter( "$item", (int)saleEntity.Serial ),
					new SQLiteParameter( "$seller", (int)seller.Serial )
				};
            ExecuteNonQuery("INSERT INTO entries (category,cost,description,itemserial,sellerserial) " +
                "VALUES ($category,$cost,$desc,$item,$seller)", paramSet);

            //add/update the seller detail table
            try
            {
                ExecuteNonQuery("INSERT INTO sellers (serial,totalorders) VALUES ($seller,1)", new SQLiteParameter[] { new SQLiteParameter("$seller", (int)seller.Serial) });
            }
            catch
            {
                ExecuteNonQuery("UPDATE sellers SET totalorders=totalorders+1 WHERE serial=$seller", new SQLiteParameter[] { new SQLiteParameter("$seller", (int)seller.Serial) });
            }

            seller.SendGump(new PersonalMarketGump(seller));
            seller.SendMessage("Your order has been added to the marketplace.");
        }
示例#28
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());
                    }
                }
            }
        }