Beispiel #1
0
        /// <summary>
        /// Create a new <see cref="Item"/> in the first available inventory bag index or stack.
        /// </summary>
        public void ItemCreate(Item2Entry itemEntry, uint count, ItemUpdateReason reason = ItemUpdateReason.NoReason, uint charges = 0)
        {
            if (itemEntry == null)
            {
                throw new ArgumentNullException();
            }

            Bag bag = GetBag(InventoryLocation.Inventory);

            Debug.Assert(bag != null);

            // update any existing stacks before creating new items
            if (itemEntry.MaxStackCount > 1)
            {
                foreach (Item item in bag.Where(i => i.Entry.Id == itemEntry.Id))
                {
                    if (count == 0u)
                    {
                        break;
                    }

                    if (item.StackCount == itemEntry.MaxStackCount)
                    {
                        continue;
                    }

                    uint newStackCount = Math.Min(item.StackCount + count, itemEntry.MaxStackCount);
                    count -= newStackCount - item.StackCount;
                    ItemStackCountUpdate(item, newStackCount);
                }
            }

            // create new stacks for the remaining count
            while (count > 0)
            {
                uint bagIndex = bag.GetFirstAvailableBagIndex();
                if (bagIndex == uint.MaxValue)
                {
                    return;
                }

                var item = new Item(characterId, itemEntry, Math.Min(count, itemEntry.MaxStackCount), charges);
                AddItem(item, InventoryLocation.Inventory, bagIndex);

                if (!player?.IsLoading ?? false)
                {
                    player.Session.EnqueueMessageEncrypted(new ServerItemAdd
                    {
                        InventoryItem = new InventoryItem
                        {
                            Item   = item.BuildNetworkItem(),
                            Reason = reason
                        }
                    });
                }

                count -= item.StackCount;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Create a new <see cref="Item"/> in the first available inventory bag index or stack.
        /// </summary>
        public void ItemCreate(uint itemId, uint count, ItemUpdateReason reason = ItemUpdateReason.NoReason, uint charges = 0)
        {
            Item2Entry itemEntry = GameTableManager.Instance.Item.GetEntry(itemId);

            if (itemEntry == null)
            {
                throw new ArgumentNullException();
            }

            ItemCreate(itemEntry, count, reason, charges);
        }
Beispiel #3
0
        /// <summary>
        /// Update <see cref="Item"/> with supplied stack count.
        /// </summary>
        private void ItemStackCountUpdate(Item item, uint stackCount, ItemUpdateReason reason = ItemUpdateReason.NoReason)
        {
            if (item == null)
            {
                throw new ArgumentNullException();
            }

            item.StackCount = stackCount;

            player.Session.EnqueueMessageEncrypted(new ServerItemStackCountUpdate
            {
                Guid       = item.Guid,
                StackCount = stackCount,
                Reason     = reason
            });
        }
Beispiel #4
0
        private Item ItemDelete(Bag bag, Item item, ItemUpdateReason reason)
        {
            bag.RemoveItem(item);
            if (!item.PendingCreate)
            {
                item.EnqueueDelete();
                deletedItems.Add(item);
            }

            player.Session.EnqueueMessageEncrypted(new ServerItemDelete
            {
                Guid   = item.Guid,
                Reason = reason
            });

            return(item);
        }
Beispiel #5
0
        /// <summary>
        /// Delete <see cref="Item"/> at supplied <see cref="ItemLocation"/>, this is called directly from a packet hander.
        /// </summary>
        public Item ItemDelete(ItemLocation from, ItemUpdateReason reason = ItemUpdateReason.Loot)
        {
            Bag srcBag = GetBag(from.Location);

            if (srcBag == null)
            {
                throw new InvalidPacketValueException();
            }

            Item srcItem = srcBag.GetItem(from.BagIndex);

            if (srcItem == null)
            {
                throw new InvalidPacketValueException();
            }

            return(ItemDelete(srcBag, srcItem, reason));
        }
Beispiel #6
0
        /// <summary>
        /// Remove <see cref="Item"/> from this player's inventory without deleting the item from the DB
        /// </summary>
        public void ItemRemove(Item srcItem, ItemUpdateReason reason = ItemUpdateReason.NoReason)
        {
            if (srcItem == null)
            {
                throw new InvalidPacketValueException("Item could not be found");
            }

            Bag srcBag = GetBag(srcItem.Location);

            if (srcBag == null)
            {
                throw new InvalidPacketValueException();
            }

            srcBag.RemoveItem(srcItem);
            srcItem.CharacterId = null;

            player.Session.EnqueueMessageEncrypted(new ServerItemDelete
            {
                Guid   = srcItem.Guid,
                Reason = reason
            });
        }
Beispiel #7
0
        /// <summary>
        /// Create a new <see cref="Item"/> from supplied <see cref="Spell4BaseEntry"/> in the first available <see cref="InventoryLocation.Ability"/> bag slot.
        /// </summary>
        public Item SpellCreate(Spell4BaseEntry spell4BaseEntry, ItemUpdateReason reason)
        {
            if (spell4BaseEntry == null)
            {
                throw new ArgumentNullException();
            }

            Bag bag = GetBag(InventoryLocation.Ability);

            Debug.Assert(bag != null);

            uint bagIndex = bag.GetFirstAvailableBagIndex();

            if (bagIndex == uint.MaxValue)
            {
                return(null);
            }

            var spell = new Item(characterId, spell4BaseEntry);

            AddItem(spell, InventoryLocation.Ability, bagIndex);

            if (!player?.IsLoading ?? false)
            {
                player.Session.EnqueueMessageEncrypted(new ServerItemAdd
                {
                    InventoryItem = new InventoryItem
                    {
                        Item   = spell.BuildNetworkItem(),
                        Reason = reason
                    }
                });
            }

            return(spell);
        }