示例#1
0
        /// <summary>
        /// Handling the Drop action from the ItemPacket.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="item">The item packet.</param>
        public static void Handle(Entities.GameClient client, ItemPacket packet)
        {
            if (client.Booth != null)
            {
                return;
            }
            if (!client.Alive)
            {
                return;
            }
            if (client.Map.MapType == Enums.MapType.Shared)
            {
                return;
            }

            if (client.Inventory.ContainsByUID(packet.UID))
            {
                Maps.MapPoint Location = client.Map.CreateAvailableLocation <Data.GroundItem>(client.X, client.Y, 3);

                if (Location != null)
                {
                    Data.ItemInfo dropitem = client.Inventory.GetItemByUID(packet.UID);

                    if (dropitem != null)
                    {
                        if (!dropitem.IsValidOffItem())
                        {
                            using (var fmsg = Message.MessageCore.CreateSystem(client.Name, Core.MessageConst.NO_PERMISSION_ITEM))
                            {
                                client.Send(fmsg);
                            }
                            return;
                        }
                        client.Inventory.RemoveItemByUID(packet.UID);

                        Data.GroundItem ground = new Data.GroundItem(dropitem);
                        ground.PlayerDrop = true;
                        ground.DropType   = Enums.DropItemType.Item;
                        ground.X          = Location.X;
                        ground.Y          = Location.Y;
                        Location.Map.EnterMap(ground);
                        ground.TaskID = ProjectX_V3_Lib.Threading.DelayedTask.StartDelayedTask(
                            () => {
                            Location.Map.LeaveMap(ground);
                            ground.Screen.ClearScreen();
                        },
                            Core.TimeIntervals.DroppedItemRemove);
                        ground.Screen.UpdateScreen(null);
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Handles the AddItem subtype of the TradePacket.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="trade">The trade packet.</param>
        public static void Handle(Entities.GameClient client, TradePacket trade)
        {
            if (!client.Trade.Trading)
            {
                return;
            }
            if (!client.Trade.WindowOpen)
            {
                return;
            }

            uint itemuid = trade.TargetUID;

            if (client.Inventory.ContainsByUID(itemuid))
            {
                Data.ItemInfo item = client.Inventory[itemuid];

                if (!item.IsValidOffItem())
                {
                    using (var fmsg = Message.MessageCore.CreateSystem(client.Name, Core.MessageConst.NO_PERMISSION_ITEM))
                    {
                        client.Send(fmsg);
                    }
                    return;
                }

                if ((client.Trade.Partner.Inventory.Count + client.Trade.Items.Count) >= 40)
                {
                    using (var fmsg = Message.MessageCore.CreateSystem(client.Name, Core.MessageConst.TARGET_FULL_INVENTORY))
                    {
                        client.Send(fmsg);
                    }
                    return;
                }

                client.Trade.Items.Add(item);
                item.SendPacket(client.Trade.Partner, 2);
            }
        }
示例#3
0
        /// <summary>
        /// Handling the Sell action from the ItemPacket.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="item">The item packet.</param>
        public static void Handle(Entities.GameClient client, ItemPacket packet)
        {
            if (client.Booth != null)
            {
                return;
            }
            if (!client.Alive)
            {
                return;
            }

            Data.Shop shop;
            if (Core.Kernel.Shops.TryGetValue(packet.UID, out shop))
            {
                if (Core.Screen.GetDistance(shop.AssociatedNPC.X, shop.AssociatedNPC.Y, client.X, client.Y) >= Core.NumericConst.MaxNPCDistance)
                {
                    using (var fmsg = Packets.Message.MessageCore.CreateSystem(client.Name, Core.MessageConst.TOO_FAR_NPC))
                        client.Send(fmsg);
                    return;
                }
                Data.ItemInfo sellitem = client.Inventory.GetItemByUID(packet.Data1);
                if (!sellitem.IsValidOffItem())
                {
                    using (var fmsg = Message.MessageCore.CreateSystem(client.Name, Core.MessageConst.NO_PERMISSION_ITEM))
                    {
                        client.Send(fmsg);
                    }
                    return;
                }

                uint giveback = (uint)(sellitem.Price / 3);
                if (client.Inventory.RemoveItemByUID(packet.Data1) != null)
                {
                    client.Money += giveback;
                }
            }
        }