Пример #1
0
        /// <summary>
        /// Tries to distribute the given amount of the given Item over all available stacks and add the remainder to a free slot.
        /// Parts of the stack might have distributed over existing stacks, even if adding the remainder failed.
        /// </summary>
        /// <returns>InventoryError.OK in case that it could be added</returns>
        public InventoryError TryAddAmount(Item item, int amount, bool isNew,
                                           ItemReceptionType reception = ItemReceptionType.Receive)
        {
            int            amount1 = amount;
            InventoryError err     = InventoryError.OK;

            if (!this.Distribute(item.Template, ref amount1))
            {
                this.CheckUniqueness((IMountableItem)item, ref amount, ref err, isNew);
                if (err == InventoryError.OK)
                {
                    amount     -= amount1;
                    item.Amount = amount;
                    SimpleSlotId freeSlot = this.FindFreeSlot((IMountableItem)item, amount);
                    if (freeSlot.Slot == (int)byte.MaxValue)
                    {
                        return(InventoryError.BAG_FULL);
                    }
                    freeSlot.Container.AddUnchecked(freeSlot.Slot, item.Template, amount, isNew);
                }
            }
            else
            {
                amount     -= amount1;
                item.Amount = amount;
            }

            if (isNew)
            {
                this.OnAdded(item, item.Template, amount1 + amount, reception);
            }
            return(err);
        }
Пример #2
0
        /// <summary>
        /// Tries to add the given item to the given slot (make sure the slot is valid and not occupied).
        /// Fails if not all items of this stack can be added.
        /// </summary>
        /// <returns>InventoryError.OK in case that it worked</returns>
        public InventoryError TryAdd(int slot, Item item, bool isNew,
                                     ItemReceptionType reception = ItemReceptionType.Receive)
        {
            int            amount = item.Amount;
            InventoryError err    = this.CheckAdd(slot, (IMountableItem)item, amount);

            if (err == InventoryError.OK)
            {
                this.CheckUniqueness((IMountableItem)item, ref amount, ref err, isNew);
                if (err == InventoryError.OK && amount != item.Amount)
                {
                    err = InventoryError.CANT_CARRY_MORE_OF_THIS;
                }
                else
                {
                    this.AddUnchecked(slot, item, isNew);
                    if (isNew)
                    {
                        this.OnAdded(item, item.Template, amount, reception);
                    }
                }
            }

            return(err);
        }
Пример #3
0
        /// <summary>
        /// Tries to add an item with the given template and amount
        /// </summary>
        /// <param name="amount">Amount of items to be added: Will be set to the amount of Items that have actually been added.</param>
        /// <returns>The result (InventoryError.OK in case that it worked)</returns>
        public InventoryError TryAdd(ItemTemplate template, ref int amount,
                                     ItemReceptionType reception = ItemReceptionType.Receive)
        {
            int            amount1 = amount;
            InventoryError err     = InventoryError.OK;
            Item           obj     = (Item)null;

            if (!this.Distribute(template, ref amount1))
            {
                amount -= amount1;
                this.CheckUniqueness((IMountableItem)template, ref amount, ref err, true);
                if (err == InventoryError.OK)
                {
                    SimpleSlotId freeSlot = this.FindFreeSlot((IMountableItem)template, amount);
                    if (freeSlot.Slot == (int)byte.MaxValue)
                    {
                        return(this.FullError);
                    }
                    obj = freeSlot.Container.AddUnchecked(freeSlot.Slot, template, amount, true);
                }
            }

            this.OnAdded(obj, template, amount1 + (obj != null ? obj.Amount : 0), reception);
            return(err);
        }
Пример #4
0
        /// <summary>
        /// Tries to distribute the given item over all available stacks and add the remainder to a free slot.
        /// IMPORTANT:
        /// 1. The Item will be destroyed if it could successfully be distributed over existing stacks of Items.
        /// 2. If item.Container == null, parts of the item-stack might have distributed over other stacks of the same type
        /// but the remainder did not find a free slot or exceeded the max count of the item.
        /// item.Amount will hold the remaining amount.
        /// </summary>
        /// <returns>The result (InventoryError.OK in case that it worked)</returns>
        public InventoryError TryAdd(Item item, bool isNew, ItemReceptionType reception = ItemReceptionType.Receive)
        {
            int            amount1 = item.Amount;
            InventoryError err     = InventoryError.OK;
            int            amount2 = amount1;

            if (!this.Distribute(item.Template, ref amount2))
            {
                int amount3 = amount1 - amount2;
                item.Amount = amount3;
                this.CheckUniqueness((IMountableItem)item, ref amount3, ref err, isNew);
                if (err == InventoryError.OK)
                {
                    SimpleSlotId freeSlot = this.FindFreeSlot((IMountableItem)item, amount3);
                    if (freeSlot.Slot == (int)byte.MaxValue)
                    {
                        return(this.FullError);
                    }
                    freeSlot.Container.AddUnchecked(freeSlot.Slot, item, isNew);
                }
            }
            else
            {
                int num = amount1 - amount2;
                item.Amount = num;
            }

            if (isNew)
            {
                this.OnAdded(item, item.Template, amount2 + item.Amount, reception);
            }
            return(err);
        }
Пример #5
0
        /// <summary>
        /// Tries to distribute the given amount of the given Item over all available stacks and add the remainder to a free slot.
        /// Parts of the stack might have distributed over existing stacks, even if adding the remainder failed.
        /// </summary>
        /// <returns>InventoryError.OK in case that it could be added</returns>
        public InventoryError TryAddAmount(Item item, int amount, bool isNew, ItemReceptionType reception = ItemReceptionType.Receive)
        {
            var distributedAmount = amount;
            var err = InventoryError.OK;

            if (!Distribute(item.Template, ref distributedAmount))
            {
                CheckUniqueness(item, ref amount, ref err, isNew);
                if (err == InventoryError.OK)
                {
                    amount     -= distributedAmount;
                    item.Amount = amount;
                    var slotId = FindFreeSlot(item, amount);
                    if (slotId.Slot == INVALID_SLOT)
                    {
                        return(InventoryError.BAG_FULL);
                    }
                    slotId.Container.AddUnchecked(slotId.Slot, item.Template, amount, isNew);
                }
            }
            else
            {
                amount     -= distributedAmount;
                item.Amount = amount;
            }
            if (isNew)
            {
                OnAdded(item, item.Template, distributedAmount + amount, reception);
            }
            return(err);
        }
Пример #6
0
        /// <summary>
        /// Tries to add a new item with the given template and amount ot the given slot.
        /// Make sure the given targetSlot is valid before calling this method.
        /// </summary>
        /// <returns>The result (InventoryError.OK in case that it worked)</returns>
        public InventoryError TryAdd(ItemTemplate template, ref int amount, int slot,
                                     ItemReceptionType reception = ItemReceptionType.Receive)
        {
            if (this.m_Items[slot] != null)
            {
                LogManager.GetCurrentClassLogger().Warn("Tried to add Item {0} to {1} in occupied slot {2}",
                                                        (object)template, (object)this, (object)slot);
                return(InventoryError.ITEM_DOESNT_GO_TO_SLOT);
            }

            InventoryError err = InventoryError.OK;

            this.CheckUniqueness((IMountableItem)template, ref amount, ref err, true);
            if (err == InventoryError.OK)
            {
                IItemSlotHandler handler = this.GetHandler(slot);
                if (handler != null)
                {
                    err = InventoryError.OK;
                    handler.CheckAdd(slot, amount, (IMountableItem)template, ref err);
                    if (err != InventoryError.OK)
                    {
                        return(err);
                    }
                }

                this.OnAdded(this.AddUnchecked(slot, template, amount, true), template, amount, reception);
            }

            return(err);
        }
Пример #7
0
        /// <summary>
        /// Tries to add ONE new item with the given template to the given slot.
        /// Make sure the given targetSlot is valid before calling this method.
        /// </summary>
        public InventoryError TryAdd(ItemTemplate template, int targetSlot,
                                     ItemReceptionType reception = ItemReceptionType.Receive)
        {
            int amount = 1;

            return(this.TryAdd(template, ref amount, targetSlot, reception));
        }
Пример #8
0
        /// <summary>
        /// Tries to add a single new item with the given template to the given slot.
        /// Make sure the given targetSlot is valid before calling this method.
        /// </summary>
        public InventoryError TryAdd(ItemTemplate template, EquipmentSlot targetSlot,
                                     ItemReceptionType reception = ItemReceptionType.Receive)
        {
            int amount = 1;

            return(TryAdd(template, ref amount, (int)targetSlot, reception));
        }
Пример #9
0
 public virtual void OnAdded(Item item, ItemTemplate templ, int amount, ItemReceptionType reception = ItemReceptionType.Receive)
 {
     if (item == null || !item.IsBuyback)
     {
         // TODO: Sometimes we need to send this to the entire group
         ItemHandler.SendItemPushResult(Owner, item, templ, amount, reception);
     }
 }
Пример #10
0
 public virtual void OnAdded(Item item, ItemTemplate templ, int amount,
                             ItemReceptionType reception = ItemReceptionType.Receive)
 {
     if (item != null && item.IsBuyback)
     {
         return;
     }
     ItemHandler.SendItemPushResult(this.Owner, item, templ, amount, reception);
 }
Пример #11
0
        /// <summary>
        /// Tries to add an Item with the given template and amount ot the given slot.
        /// Make sure the given targetSlot is valid before calling this method.
        /// </summary>
        /// <returns>The result (InventoryError.OK in case that it worked)</returns>
        public InventoryError TryAdd(ItemId id, ref int amount, int targetSlot, ItemReceptionType reception = ItemReceptionType.Receive)
        {
            var templ = ItemMgr.GetTemplate(id);

            if (templ != null)
            {
                return(TryAdd(templ, ref amount, targetSlot, reception));
            }
            return(InventoryError.ITEM_NOT_FOUND);
        }
Пример #12
0
        /// <summary>
        /// Tries to add ONE new item with the given template to the given slot.
        /// Make sure the given targetSlot is valid before calling this method.
        /// </summary>
        /// <returns>The result (InventoryError.OK in case that it worked)</returns>
        public InventoryError TryAdd(Asda2ItemId id, InventorySlot targetSlot, ItemReceptionType reception = ItemReceptionType.Receive)
        {
            var templ = ItemMgr.GetTemplate(id);

            if (templ != null)
            {
                return(TryAdd(templ, (int)targetSlot, reception));
            }
            return(InventoryError.ITEM_NOT_FOUND);
        }
Пример #13
0
        /// <summary>
        /// Tries to add ONE new item with the given template to the given slot.
        /// Make sure the given targetSlot is valid before calling this method.
        /// </summary>
        /// <returns>The result (InventoryError.OK in case that it worked)</returns>
        public InventoryError TryAdd(ItemId id, int targetSlot, ItemReceptionType reception = ItemReceptionType.Receive)
        {
            var templ = ItemMgr.GetTemplate(id);

            if (templ != null)
            {
                return(TryAdd(templ, targetSlot, reception));
            }
            return(InventoryError.Invalid);
        }
Пример #14
0
        /// <summary>
        /// Tries to add an Item with the given template and amount ot the given slot.
        /// Make sure the given targetSlot is valid before calling this method.
        /// </summary>
        /// <returns>The result (InventoryError.OK in case that it worked)</returns>
        public InventoryError TryAdd(Asda2ItemId id, ref int amount, int targetSlot,
                                     ItemReceptionType reception = ItemReceptionType.Receive)
        {
            ItemTemplate template = ItemMgr.GetTemplate(id);

            if (template != null)
            {
                return(this.TryAdd(template, ref amount, targetSlot, reception));
            }
            return(InventoryError.ITEM_NOT_FOUND);
        }
Пример #15
0
        /// <summary>
        /// Tries to add ONE new item with the given template to the given slot.
        /// Make sure the given targetSlot is valid before calling this method.
        /// </summary>
        /// <returns>The result (InventoryError.OK in case that it worked)</returns>
        public InventoryError TryAdd(Asda2ItemId id, int targetSlot,
                                     ItemReceptionType reception = ItemReceptionType.Receive)
        {
            ItemTemplate template = ItemMgr.GetTemplate(id);

            if (template != null)
            {
                return(this.TryAdd(template, targetSlot, reception));
            }
            return(InventoryError.Invalid);
        }
Пример #16
0
        /// <summary>
        /// Tries to add a new item with the given template and amount ot the given slot.
        /// Make sure the given targetSlot is valid before calling this method.
        /// If slot is occupied, method will find another unoccupied slot.
        /// </summary>
        /// <returns>The result (InventoryError.OK in case that it worked)</returns>
        public InventoryError TryAdd(Asda2ItemId id, ref int amount, InventorySlot targetSlot,
                                     ItemReceptionType reception = ItemReceptionType.Receive)
        {
            ItemTemplate template = ItemMgr.GetTemplate(id);

            if (template != null)
            {
                return(TryAdd(template, ref amount, (int)targetSlot, reception));
            }
            return(InventoryError.Invalid);
        }
Пример #17
0
 /// <summary>
 /// Tries to add a new item with the given id to a free slot.
 /// </summary>
 /// <returns>The result (InventoryError.OK in case that it worked)</returns>
 public InventoryError TryAdd(ItemTemplate templ, ItemReceptionType reception = ItemReceptionType.Receive)
 {
     if (templ != null)
     {
         var slotId = FindFreeSlot(templ, 1);
         if (slotId.Slot == INVALID_SLOT)
         {
             return(FullError);
         }
         return(slotId.Container.TryAdd(templ, slotId.Slot, reception));
     }
     return(InventoryError.Invalid);
 }
Пример #18
0
        /// <summary>
        /// Tries to add a new item with the given id to a free slot.
        /// </summary>
        /// <returns>The result (InventoryError.OK in case that it worked)</returns>
        public InventoryError TryAdd(ItemTemplate templ, ItemReceptionType reception = ItemReceptionType.Receive)
        {
            if (templ == null)
            {
                return(InventoryError.Invalid);
            }
            SimpleSlotId freeSlot = this.FindFreeSlot((IMountableItem)templ, 1);

            if (freeSlot.Slot == (int)byte.MaxValue)
            {
                return(this.FullError);
            }
            return(freeSlot.Container.TryAdd(templ, freeSlot.Slot, reception));
        }
Пример #19
0
        /// <summary>
        /// Tries to add an item with the given template and amount
        /// </summary>
        /// <param name="amount">Amount of items to be added: Will be set to the amount of Items that have actually been added.</param>
        /// <returns>The result (InventoryError.OK in case that it worked)</returns>
        public InventoryError TryAdd(ItemTemplate template, ref int amount, ItemReceptionType reception = ItemReceptionType.Receive)
        {
            var  distributedAmount = amount;
            var  err  = InventoryError.OK;
            Item item = null;

            if (!Distribute(template, ref distributedAmount))
            {
                amount -= distributedAmount;
                CheckUniqueness(template, ref amount, ref err, true);
                if (err == InventoryError.OK)
                {
                    var slotId = FindFreeSlot(template, amount);
                    if (slotId.Slot == INVALID_SLOT)
                    {
                        return(FullError);
                    }
                    item = slotId.Container.AddUnchecked(slotId.Slot, template, amount, true);
                }
            }

            OnAdded(item, template, distributedAmount + (item != null ? item.Amount : 0), reception);
            return(err);
        }
Пример #20
0
        /// <summary>
        /// Sends the Item's PushResult (required after adding items).
        /// </summary>
        public static void SendItemPushResult(Character owner, Item item, ItemTemplate templ, int amount, ItemReceptionType reception)
        {
            bool isStacked;
            int contSlot;
            uint propertySeed, randomPropid;
            if (item != null)
            {
                contSlot = item.Container.Slot;
                isStacked = item.Amount != amount; // item.Amount == amount means that it was not added to an existing stack
                propertySeed = item.PropertySeed;
                randomPropid = item.RandomPropertiesId;
            }
            else
            {
                contSlot = BaseInventory.INVALID_SLOT;
                isStacked = true;													// we did not have an item -> stacked
                propertySeed = 0;
                randomPropid = 0;
            }

            using (var packet = new RealmPacketOut(RealmServerOpCode.SMSG_ITEM_PUSH_RESULT, 45))
            {
                packet.Write(owner.EntityId);
                packet.Write((ulong)reception);

                //packet.Write(received ? 1 : 0);										// 0 = "You looted...", 1 = "You received..."
                //packet.Write(isNew ? 1 : 0);										// 0 = "You received/looted...", 1 = "You created..."

                packet.Write(1);													// log message
                packet.Write((byte)contSlot);
                packet.Write(isStacked ? -1 : item.Slot);
                packet.Write(templ.Id);
                packet.Write(propertySeed);
                packet.Write(randomPropid);
                packet.Write(amount);												// amount added
                packet.Write(owner.Inventory.GetAmount(templ.ItemId));				// amount of that type of item in inventory

                owner.Send(packet);
            }
        }
Пример #21
0
 /// <summary>
 /// Sends the Item's PushResult (required after adding items).
 /// </summary>
 public static void SendItemPushResult(Character owner, Item item, ItemTemplate templ, int amount, ItemReceptionType reception)
 {
     /*bool isStacked;
      * int contSlot;
      * uint propertySeed, randomPropid;
      * if (item != null)
      * {
      *      contSlot = item.Container.Slot;
      *      isStacked = item.Amount != amount; // item.Amount == amount means that it was not added to an existing stack
      *      propertySeed = item.PropertySeed;
      *      randomPropid = item.RandomPropertiesId;
      * }
      * else
      * {
      *      contSlot = BaseInventory.INVALID_SLOT;
      *      isStacked = true;													// we did not have an item -> stacked
      *      propertySeed = 0;
      *      randomPropid = 0;
      * }
      *
      * using (var packet = new RealmPacketOut(RealmServerOpCode.SMSG_ITEM_PUSH_RESULT, 45))
      * {
      *      packet.Write(owner.EntityId);
      *      packet.Write((ulong)reception);
      *
      *      //packet.Write(received ? 1 : 0);										// 0 = "You looted...", 1 = "You received..."
      *      //packet.Write(isNew ? 1 : 0);										// 0 = "You received/looted...", 1 = "You created..."
      *
      *      packet.Write(1);													// log message
      *      packet.Write((byte)contSlot);
      *      packet.Write(isStacked ? -1 : item.Slot);
      *      packet.Write(templ.Id);
      *      packet.Write(propertySeed);
      *      packet.Write(randomPropid);
      *      packet.Write(amount);												// amount added
      *      packet.Write(owner.Inventory.GetAmount(templ.ItemId));				// amount of that type of item in inventory
      *
      *      owner.Send(packet);
      * }*/
 }
Пример #22
0
 /// <summary>
 /// Sends the Item's PushResult (required after adding items).
 /// </summary>
 public static void SendItemPushResult(Character owner, Item item, ItemTemplate templ, int amount,
                                       ItemReceptionType reception)
 {
 }
Пример #23
0
 /// <summary>Tries to add the item to a free slot in this srcCont</summary>
 /// <returns>whether the item could be added</returns>
 public virtual InventoryError TryAdd(Item item, bool isNew,
                                      ItemReceptionType reception = ItemReceptionType.Receive)
 {
     return(this.m_inventory.TryAdd(this.FindFreeSlot(), item, isNew, reception));
 }
Пример #24
0
 /// <summary>
 /// Tries to add the given item to the corresponding slot: The offset of this inventory + the given slot
 /// </summary>
 /// <returns>whether the item could be added</returns>
 public virtual InventoryError TryAdd(int slot, Item item, bool isNew,
                                      ItemReceptionType reception = ItemReceptionType.Receive)
 {
     return(this.m_inventory.TryAdd(slot, item, isNew, reception));
 }
Пример #25
0
 public override InventoryError TryAdd(Item item, bool isNew, ItemReceptionType reception = ItemReceptionType.Receive)
 {
     return(AddBuyBackItem(item, isNew));
 }
Пример #26
0
		public override InventoryError TryAdd(Item item, bool isNew, ItemReceptionType reception = ItemReceptionType.Receive)
		{
			return AddBuyBackItem(item, isNew);
		}
Пример #27
0
		/// <summary>
		/// Tries to add the item to a free slot in this srcCont
		/// </summary>
		/// <returns>whether the item could be added</returns>
		public virtual InventoryError TryAdd(Item item, bool isNew, ItemReceptionType reception = ItemReceptionType.Receive)
		{
			return m_inventory.TryAdd(FindFreeSlot(), item, isNew, reception);
		}
Пример #28
0
		/// <summary>
		/// Tries to add the given item to the corresponding slot: The offset of this inventory + the given slot
		/// </summary>
		/// <returns>whether the item could be added</returns>
		public virtual InventoryError TryAdd(int slot, Item item, bool isNew, ItemReceptionType reception = ItemReceptionType.Receive)
		{
			return m_inventory.TryAdd(slot, item, isNew, reception);
		}
Пример #29
0
 public override InventoryError TryAdd(int slot, Item item, bool isNew,
                                       ItemReceptionType reception = ItemReceptionType.Receive)
 {
     return(this.AddBuyBackItem(slot, item, isNew));
 }
Пример #30
0
        /// <summary>
        /// Tries to add a new item with the given template and amount ot the given slot.
        /// Make sure the given targetSlot is valid before calling this method.
        /// </summary>
        /// <returns>The result (InventoryError.OK in case that it worked)</returns>
        public InventoryError TryAdd(ItemTemplate template, ref int amount, int slot, ItemReceptionType reception = ItemReceptionType.Receive)
        {
            if (m_Items[slot] != null)
            {
                LogManager.GetCurrentClassLogger().Warn("Tried to add Item {0} to {1} in occupied slot {2}", template, this, slot);
                return(InventoryError.ITEM_DOESNT_GO_TO_SLOT);
            }

            var err = InventoryError.OK;

            CheckUniqueness(template, ref amount, ref err, true);
            if (err == InventoryError.OK)
            {
                var handler = GetHandler(slot);
                if (handler != null)
                {
                    err = InventoryError.OK;
                    handler.CheckAdd(slot, amount, template, ref err);
                    if (err != InventoryError.OK)
                    {
                        return(err);
                    }
                }

                var item = AddUnchecked(slot, template, amount, true);
                OnAdded(item, template, amount, reception);
            }
            return(err);
        }
Пример #31
0
 /// <summary>
 /// Tries to add a new item with the given id to a free slot.
 /// </summary>
 /// <returns>The result (InventoryError.OK in case that it worked)</returns>
 public InventoryError TryAdd(ItemId id, ItemReceptionType reception = ItemReceptionType.Receive)
 {
     return(TryAdd(ItemMgr.GetTemplate(id), reception));
 }
Пример #32
0
 /// <summary>
 /// Tries to add a new item with the given template and amount
 /// </summary>
 /// <returns>The result (InventoryError.OK in case that it worked)</returns>
 public InventoryError TryAdd(uint templId, ref int amount, ItemReceptionType reception = ItemReceptionType.Receive)
 {
     return(TryAdd((ItemId)templId, ref amount, reception));
 }