/// <summary> /// Adds item to inventory and updates client. /// </summary> /// <param name="item"></param> /// <return>Index of the item.</return> public int Add(Item item, InventoryAddType addType) { var index = this.AddSilent(item); Send.ZC_ITEM_ADD(_character, item, index, addType); Send.ZC_OBJECT_PROPERTY(_character, ObjectProperty.PC.NowWeight); return(index); }
/// <summary> /// Adds item to inventory and updates client. /// </summary> /// <param name="item"></param> /// <param name="addType"></param> public void Add(Item item, InventoryAddType addType) { var left = this.FillStacks(item, addType, false); if (left > 0) { item.Amount = left; this.AddStack(item, addType, false); } Send.ZC_OBJECT_PROPERTY(_character, ObjectProperty.PC.NowWeight); }
/// <summary> /// Adds new items with given item id to inventory. /// </summary> /// <param name="itemId"></param> /// <param name="amount"></param> /// <param name="addType"></param> public void Add(int itemId, int amount, InventoryAddType addType) { while (amount > 0) { // Item caps Amount automatically. By using amount directly // either the entire amount is used for the new item, // or the max amount for it. This way we add new stacks until // amount is 0. var item = new Item(itemId, amount); this.Add(item, addType); amount -= item.Amount; } }
/// <summary> /// Adds given stack to inventory. /// </summary> /// <param name="item">Item to add to inventory.</param> /// <param name="silent">If true, client isn't updated.</param> private void AddStack(Item item, InventoryAddType addType, bool silent) { var cat = item.Data.Category; lock (_syncLock) { _items[cat].Add(item); _itemsWorldIndex[item.ObjectId] = item; if (!silent) { var categoryIndex = item.GetInventoryIndex(_items[cat].Count - 1); Send.ZC_ITEM_ADD(_character, item, categoryIndex, item.Amount, addType); } } }
/// <summary> /// Adds item to inventory and updates client. /// </summary> /// <param name="item"></param> /// <param name="addType"></param> public void Add(Item item, InventoryAddType addType) { var left = this.FillStacks(item, addType, false); if (left > 0) { item.Amount = left; this.AddStack(item, addType, false); } Send.ZC_OBJECT_PROPERTY(_character, PropertyId.PC.NowWeight); // Temp fix. The amounts on item stacks that items were added // to are sometimes wrong, a full updates fixes that. Maybe // ZC_ITEM_ADD needs an update. Send.ZC_ITEM_INVENTORY_DIVISION_LIST(_character); }
/// <summary> /// Filles stacks with item, returns the amount of items left. /// The item is not modified. /// </summary> /// <remarks> /// If no stacks are found, nothing happens, and the amount returned /// will be equal to item.Amount. /// </remarks> /// <param name="item">Item to fill existing stacks with.</param> /// <param name="silent">If true, client isn't updated.</param> private int FillStacks(Item item, InventoryAddType addType, bool silent) { // If item isn't stackable, we've got nothing to do here. if (!item.IsStackable) { return(item.Amount); } var itemId = item.Id; var amount = item.Amount; var cat = item.Data.Category; var stacks = this.GetStacks(cat, itemId); // Fill stacks foreach (var index in stacks) { lock (_syncLock) { var categoryItem = _items[cat][index]; var space = (categoryItem.Data.MaxStack - categoryItem.Amount); var add = Math.Min(amount, space); categoryItem.Amount += add; amount -= add; if (!silent) { var categoryIndex = categoryItem.GetInventoryIndex(index); // Use given add type if this was the last of it, // or NotNew if only some was just added to a stack. var adjustedAddType = (amount == 0 ? addType : InventoryAddType.NotNew); Send.ZC_ITEM_ADD(_character, categoryItem, categoryIndex, add, adjustedAddType); } } if (amount == 0) { break; } } return(amount); }