Esempio n. 1
0
        public void AddItem(uint[] itemId)
        {
            if (!IsSpaceForAdd(itemId[0], itemId.Length))
            {
                return;
            }

            //Update lists and db
            owner.QueuePacket(InventoryBeginChangePacket.BuildPacket(owner.actorId));
            owner.QueuePacket(InventorySetBeginPacket.BuildPacket(owner.actorId, inventoryCapacity, inventoryCode));

            int startPos = list.Count;

            //New item that spilled over
            for (int i = 0; i < itemId.Length; i++)
            {
                ItemData      gItem     = Server.GetItemGamedata(itemId[i]);
                InventoryItem addedItem = Database.AddItem(owner, itemId[i], 1, (byte)1, gItem.isExclusive ? (byte)0x3 : (byte)0x0, gItem.durability, inventoryCode);
                list.Add(addedItem);
            }

            SendInventoryPackets(startPos);

            owner.QueuePacket(InventorySetEndPacket.BuildPacket(owner.actorId));
            owner.QueuePacket(InventoryEndChangePacket.BuildPacket(owner.actorId));
        }
Esempio n. 2
0
        public void Equip(ushort slot, InventoryItem item)
        {
            if (slot >= list.Length)
            {
                return;
            }

            if (writeToDB)
            {
                Database.EquipItem(owner, slot, item.uniqueId);
            }

            owner.QueuePacket(InventoryBeginChangePacket.BuildPacket(owner.actorId));

            if (list[slot] != null)
            {
                normalInventory.RefreshItem(list[slot], item);
            }
            else
            {
                normalInventory.RefreshItem(item);
            }

            owner.QueuePacket(InventorySetBeginPacket.BuildPacket(owner.actorId, inventoryCapacity, inventoryCode));
            SendEquipmentPackets(slot, item);
            owner.QueuePacket(InventorySetEndPacket.BuildPacket(owner.actorId));

            owner.QueuePacket(InventoryEndChangePacket.BuildPacket(owner.actorId));

            list[slot] = item;
        }
Esempio n. 3
0
        public void Unequip(ushort slot)
        {
            if (slot >= list.Length)
            {
                return;
            }

            if (writeToDB)
            {
                Database.UnequipItem(owner, slot);
            }

            owner.QueuePacket(InventoryBeginChangePacket.BuildPacket(owner.actorId));

            normalInventory.RefreshItem(list[slot]);

            owner.QueuePacket(InventorySetBeginPacket.BuildPacket(owner.actorId, inventoryCapacity, inventoryCode));
            SendEquipmentPackets(slot, null);
            owner.QueuePacket(InventorySetEndPacket.BuildPacket(owner.actorId));

            owner.QueuePacket(InventoryEndChangePacket.BuildPacket(owner.actorId));

            list[slot] = null;
            owner.RecalculateStats();
        }
Esempio n. 4
0
        public void RemoveItemByUniqueId(ulong itemDBId)
        {
            ushort        slot     = 0;
            InventoryItem toDelete = null;

            foreach (InventoryItem item in list)
            {
                if (item.uniqueId == itemDBId)
                {
                    toDelete = item;
                    break;
                }
                slot++;
            }

            if (toDelete == null)
            {
                return;
            }

            int oldListSize = list.Count;

            list.RemoveAt(slot);
            Database.RemoveItem(owner, itemDBId, inventoryCode);

            //Realign slots
            for (int i = slot; i < list.Count; i++)
            {
                list[i].slot = (ushort)i;
            }

            owner.QueuePacket(InventoryBeginChangePacket.BuildPacket(owner.actorId));
            owner.QueuePacket(InventorySetBeginPacket.BuildPacket(owner.actorId, inventoryCapacity, inventoryCode));

            SendInventoryPackets(slot);
            SendInventoryRemovePackets(slot);
            if (slot != oldListSize - 1)
            {
                SendInventoryRemovePackets((ushort)(oldListSize - 1));
            }

            owner.QueuePacket(InventorySetEndPacket.BuildPacket(owner.actorId));

            if (inventoryCode == NORMAL)
            {
                owner.GetEquipment().SendFullEquipment(false);
            }

            owner.QueuePacket(InventoryEndChangePacket.BuildPacket(owner.actorId));
        }
Esempio n. 5
0
        public void RemoveItemAtSlot(ushort slot)
        {
            if (slot >= list.Count)
            {
                return;
            }

            int oldListSize = list.Count;

            list.RemoveAt((int)slot);
            Database.RemoveItem(owner, slot, inventoryCode);

            //Realign slots
            for (int i = slot; i < list.Count; i++)
            {
                list[i].slot = (ushort)i;
            }

            owner.QueuePacket(InventoryBeginChangePacket.BuildPacket(owner.actorId));
            owner.QueuePacket(InventorySetBeginPacket.BuildPacket(owner.actorId, inventoryCapacity, inventoryCode));

            SendInventoryPackets(slot);
            SendInventoryRemovePackets(slot);
            if (slot != oldListSize - 1)
            {
                SendInventoryRemovePackets((ushort)(oldListSize - 1));
            }

            owner.QueuePacket(InventorySetEndPacket.BuildPacket(owner.actorId));

            if (inventoryCode == NORMAL)
            {
                owner.GetEquipment().SendFullEquipment(false);
            }

            owner.QueuePacket(InventoryEndChangePacket.BuildPacket(owner.actorId));
        }
Esempio n. 6
0
        public void SetEquipment(ushort[] slots, ushort[] itemSlots)
        {
            if (slots.Length != itemSlots.Length)
            {
                return;
            }

            for (int i = 0; i < slots.Length; i++)
            {
                InventoryItem item = normalInventory.GetItemBySlot(itemSlots[i]);

                if (item == null)
                {
                    continue;
                }

                Database.EquipItem(owner, slots[i], item.uniqueId);
                list[slots[i]] = normalInventory.GetItemBySlot(itemSlots[i]);
            }

            owner.QueuePacket(InventoryBeginChangePacket.BuildPacket(owner.actorId));
            SendFullEquipment(false);
            owner.QueuePacket(InventoryEndChangePacket.BuildPacket(owner.actorId));
        }
Esempio n. 7
0
        public void RemoveItem(uint itemId, int quantity)
        {
            if (!HasItem(itemId, quantity))
            {
                return;
            }

            List <ushort>        slotsToUpdate  = new List <ushort>();
            List <InventoryItem> itemsToRemove  = new List <InventoryItem>();
            List <ushort>        slotsToRemove  = new List <ushort>();
            List <SubPacket>     AddItemPackets = new List <SubPacket>();

            //Remove as we go along
            int    quantityCount = quantity;
            ushort lowestSlot    = 0;

            for (int i = list.Count - 1; i >= 0; i--)
            {
                InventoryItem item = list[i];
                if (item.itemId == itemId)
                {
                    int oldQuantity = item.quantity;
                    //Stack nomnomed
                    if (item.quantity - quantityCount <= 0)
                    {
                        itemsToRemove.Add(item);
                        slotsToRemove.Add(item.slot);
                    }
                    else
                    {
                        slotsToUpdate.Add(item.slot);
                        item.quantity -= quantityCount; //Stack reduced
                    }

                    quantityCount -= oldQuantity;
                    lowestSlot     = item.slot;

                    if (quantityCount <= 0)
                    {
                        break;
                    }
                }
            }

            for (int i = 0; i < slotsToUpdate.Count; i++)
            {
                Database.SetQuantity(owner, slotsToUpdate[i], inventoryCode, list[slotsToUpdate[i]].quantity);
            }

            int oldListSize = list.Count;

            for (int i = 0; i < itemsToRemove.Count; i++)
            {
                Database.RemoveItem(owner, itemsToRemove[i].uniqueId, inventoryCode);
                list.Remove(itemsToRemove[i]);
            }

            //Realign slots
            for (int i = lowestSlot; i < list.Count; i++)
            {
                list[i].slot = (ushort)i;
            }

            //Added tail end items that need to be cleared for slot realignment
            for (int i = oldListSize - 1; i >= oldListSize - itemsToRemove.Count; i--)
            {
                if (!slotsToRemove.Contains((ushort)i))
                {
                    slotsToRemove.Add((ushort)i);
                }
            }

            owner.QueuePacket(InventoryBeginChangePacket.BuildPacket(owner.actorId));
            owner.QueuePacket(InventorySetBeginPacket.BuildPacket(owner.actorId, inventoryCapacity, inventoryCode));

            SendInventoryPackets(lowestSlot);
            SendInventoryRemovePackets(slotsToRemove);

            owner.QueuePacket(InventorySetEndPacket.BuildPacket(owner.actorId));

            if (inventoryCode == NORMAL)
            {
                owner.GetEquipment().SendFullEquipment(false);
            }

            owner.QueuePacket(InventoryEndChangePacket.BuildPacket(owner.actorId));
        }
Esempio n. 8
0
        public bool AddItem(uint itemId, int quantity, byte quality)
        {
            if (!IsSpaceForAdd(itemId, quantity))
            {
                return(false);
            }

            ItemData         gItem          = Server.GetItemGamedata(itemId);
            List <ushort>    slotsToUpdate  = new List <ushort>();
            List <SubPacket> addItemPackets = new List <SubPacket>();

            if (gItem == null)
            {
                Program.Log.Error("Inventory.AddItem: unable to find item %u", itemId);
                return(false);
            }

            //Check if item id exists
            int quantityCount = quantity;

            for (int i = 0; i < list.Count; i++)
            {
                InventoryItem item = list[i];
                if (item.itemId == itemId && item.quantity < gItem.maxStack)
                {
                    slotsToUpdate.Add(item.slot);
                    int oldQuantity = item.quantity;
                    item.quantity  = Math.Min(item.quantity + quantityCount, gItem.maxStack);
                    quantityCount -= (gItem.maxStack - oldQuantity);
                    if (quantityCount <= 0)
                    {
                        break;
                    }
                }
            }

            //If it's unique, abort
            //if (quantityCount > 0 && storedItem.isUnique)
            //      return ITEMERROR_UNIQUE;

            //If Inventory is full
            //if (quantityCount > 0 && isInventoryFull())
            //       return ITEMERROR_FULL;

            //Update lists and db
            owner.QueuePacket(InventoryBeginChangePacket.BuildPacket(owner.actorId));
            owner.QueuePacket(InventorySetBeginPacket.BuildPacket(owner.actorId, inventoryCapacity, inventoryCode));

            //These had their quantities Changed
            foreach (ushort slot in slotsToUpdate)
            {
                Database.SetQuantity(owner, slot, inventoryCode, list[slot].quantity);

                if (inventoryCode != CURRENCY && inventoryCode != KEYITEMS)
                {
                    SendInventoryPackets(list[slot]);
                }
            }

            //New item that spilled over
            while (quantityCount > 0)
            {
                InventoryItem addedItem = Database.AddItem(owner, itemId, Math.Min(quantityCount, gItem.maxStack), quality, gItem.isExclusive ? (byte)0x3 : (byte)0x0, gItem.durability, inventoryCode);


                list.Add(addedItem);

                if (inventoryCode != CURRENCY && inventoryCode != KEYITEMS)
                {
                    SendInventoryPackets(addedItem);
                }

                quantityCount -= gItem.maxStack;
            }

            if (inventoryCode == CURRENCY || inventoryCode == KEYITEMS)
            {
                SendFullInventory();
            }

            owner.QueuePacket(InventorySetEndPacket.BuildPacket(owner.actorId));
            owner.QueuePacket(InventoryEndChangePacket.BuildPacket(owner.actorId));
            return(true);
        }