Esempio n. 1
0
        void GiveItem_Handler(Task t)
        {
            GiveItemArgs  args = (GiveItemArgs)t.Args;
            CharacterInfo ci   = t.Client.Character;

            // Instantiate the item
            Item item = _server.InstantiateItem(args.ItemTemplateID);

            // Log it
            string log = string.Format("Giving item template({0}) to Character ID: {1}. Reason: {2}, Context: {3}", args.ItemTemplateID, ci.ID, args.Reason, args.Context);

            LogInterface.Log(log, LogInterface.LogMessageType.Game);

            // Do autostacking
            if (item.ItemType == Item.Type.Stackable)
            {
                // Find all existing stacks with this model id
                Item[] stacks = ci.FindItemsByModel(item.Model);
                if (stacks.Length > 0)
                {
                    foreach (Item stack in stacks)
                    {
                        if (stack.StackSpace > 0)
                        {
                            // There is room in this stack, put items into this stack until full
                            int amountToAdd = Math.Min(stack.StackSpace, item.Quantity);

                            // Change this stacks quantity, save in the database, and send to the client
                            stack.AddQuantity(amountToAdd);
                            AddDBQuery(stack.UpdateDBString(), null, false);
                            if (item.Quantity > amountToAdd)
                            {
                                t.Client.SendPacket(new GiveItemPacket(stack));
                            }

                            // Remove the quantity from the new item
                            item.AddQuantity(-amountToAdd);
                            if (item.Quantity <= 0)
                            {
                                // All of the quantity has been distributed
                                // Tell the client about the loot with the last stack
                                t.Client.SendPacket(new ItemLootPacket(stack, args.Context));
                                return;
                            }
                        }
                    }
                }
            }

            // Find a slot for it
            item.Slot = ci.FindGeneralSlot();

            // Save it in the database
            string sql = item.WriteDBString(args.ItemTemplateID, ci.ID);

            t.Type    = Task.TaskType.GiveItem_Finish;
            args.Item = item;
            AddDBQuery(sql, t);
        }
Esempio n. 2
0
        void GiveItem_Finish_Handler(Task t)
        {
            GiveItemArgs args = (GiveItemArgs)t.Args;
            Item         item = args.Item;
            ulong        res  = (ulong)t.Query.Rows[0][0];

            item.ID = (uint)res;

            // Store it in the character
            t.Client.Character.AddItem(item);

            // Tell the client about it
            if (args.Reason == GiveItemArgs.TheReason.Loot)
            {
                t.Client.SendPacket(new ItemLootPacket(item, args.Context));
            }
            else
            {
                t.Client.SendPacket(new GiveItemPacket(item));
            }
        }