예제 #1
0
        /// <summary>
        /// Remove from bag the specified amount of the item ID
        /// </summary>
        /// <param name="itemID">The item ID to look for and remove</param>
        /// <param name="amount">How many to be removed</param>
        public bool RemoveFromBag(uint itemID, uint amount)
        {
            Slot s = Slots.Find(x => x.ItemID == itemID);

            if (s != null)
            {
                if (s.ItemAmount < amount)
                {
                    return(false);
                }
                if (Encyclopedia.SearchStackID(s.ItemID))
                {
                    s.ItemAmount -= amount;
                    if (s.ItemAmount <= 0)
                    {
                        Slots.Remove(s);
                        FreeSlots++;
                        //OnBagUpdate();
                    }
                    return(true);
                }
                else
                {
                    return(RemoveNonStackableItem(s, amount));
                }
            }
            return(false);
        }
예제 #2
0
 /// <summary>
 /// Remove from bag one unit of the Slot
 /// DEPRECEATED NOT USE YET PLEASE
 /// </summary>
 /// <param name="itemID">The slot to look for and remove</param>
 public void RemoveFromBag(Slot slot)
 {
     if (Encyclopedia.SearchStackID(slot.ItemID))
     {
         if (--slot.ItemAmount <= 0)
         {
             Slots.Remove(slot);
             FreeSlots++;
             //OnBagUpdate();
         }
     }
     else
     {
         RemoveNonStackableItem(slot, 1);
     }
 }
예제 #3
0
        /// <summary>
        /// Remove from bag the specified amount of the index
        /// </summary>
        /// <param name="index">The index to look for and remove</param>
        /// <param name="amount">How many to be removed</param>
        public void RemoveFromBag(int index, uint amount)
        {
            Slot s = Slots.ElementAt(index);

            if (index < Slots.Count)
            {
                if (Encyclopedia.SearchStackID(s.ItemID))
                {
                    s.ItemAmount -= amount;
                    if (s.ItemAmount <= 0)
                    {
                        Slots.RemoveAt(index);
                        FreeSlots++;
                        //OnBagUpdate();
                    }
                }
                else
                {
                    RemoveNonStackableItem(s, amount);
                }
            }
        }
예제 #4
0
        /// <summary>
        /// This function add a item to the bag.
        /// It look for space and if there is some item that can be 'stacked' with space to do that.
        /// Then, if the item is stackable and it will overflow the max of items, then will calculate how many left and look for more space
        /// If there is more space, then it will recursivly add a new item in case the item overflow 2x the limite of max
        /// If is a non-stackable then will only add to the list if can be added
        /// See also <seealso cref="CanAddMore"/>
        /// </summary>
        /// <param name="itemID">The item ID to be added</param>
        /// <param name="amount">The amount of that item</param>
        /// <returns></returns>
        public virtual bool AddToBag(Slot slot)
        {
            if (slot == null)
            {
                return(false);
            }
            Slot playerSlot = Slots.Find(x => x.ItemID == slot.ItemID && x.ItemAmount < MaxStack && Encyclopedia.SearchStackID(x.ItemID));

            if (playerSlot != null)
            {
                if (playerSlot.ItemAmount + slot.ItemAmount > MaxStack)
                {
                    uint offset = playerSlot.ItemAmount + slot.ItemAmount - MaxStack;
                    playerSlot.ItemAmount = MaxStack;
                    slot.ItemAmount       = offset;
                    if (Slots.Count < MaxSlots)
                    {
                        FreeSlots--;
                        AddToBag(slot);
                        //OnBagUpdate();
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    playerSlot.ItemAmount += slot.ItemAmount;
                    slot.ItemAmount        = 0;
                    //OnBagUpdate();
                    return(true);
                }
            }
            else if (CanAddMore())
            {
                Slots.Add(new Slot(slot.ItemID, slot.ItemAmount));
                slot.ItemAmount = 0;
                //OnBagUpdate();
                return(true);
            }
            else
            {
                return(false);
            }
        }