/// <summary>
        /// Get available slots for item
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public override short[] GetSlots(AStorageItem item)
        {
            var slots = new List<short>();
            var counter = item.Count;

            for (short i = 0; i < StorageItems.Length; i++)
            {
                if (StorageItems[i] == null)
                {
                    slots.Add(i);
                    break;
                }

                if (item.Template.MaxStack == 0 || item.ItemId != StorageItems[i].ItemId ||
                    StorageItems[i].Count >= item.Template.MaxStack) continue;
                counter -= (short)(item.Template.MaxStack - StorageItems[i].Count);
                slots.Add(i);

                if (counter <= 0)
                    break;
            }

            if (item.Template.MaxStack != 0 && counter > 0)
                return null;

            return slots.ToArray();
        }
        public override bool AddItem(AStorageItem item, short targetSlot)
        {
            short[] slot = GetSlots(item);

            if (!IsSlotValid(targetSlot))
                return false;

            if (slot.Length == 1)
            {
                if (!IsSlotValid(targetSlot) || StorageItems[targetSlot] != null)
                    return false;

                StorageItems[targetSlot] = item;
            }
            return true;
        }
        /// <summary>
        /// Add item in storage
        /// </summary>
        /// <param name="item"></param>
        /// <param name="targetSlot"></param>
        /// <returns></returns>
        public override bool AddItem(AStorageItem item, short targetSlot)
        {
            short[] targetSlots = null;
            if (targetSlot == -1)
            {
                var sl = GetSlots(item);
                if (sl != null && sl.Length > 0)
                    targetSlots = sl;
            }
            else
                targetSlots = new[] { targetSlot };

            if (targetSlots == null || !targetSlots.All(IsSlotValid))
                return false;

            int initialCount = item.Count;

            foreach (short slot in targetSlots)
            {
                if (StorageItems[slot] != null)
                {
                    short avail = (short)(StorageItems[slot].Template.MaxStack - StorageItems[slot].Count);
                    if (avail >= initialCount)
                    {
                        StorageItems[slot].Count += initialCount;
                        break;
                    }

                    StorageItems[slot].Count = (short)StorageItems[slot].Template.MaxStack;
                    initialCount -= avail;
                }
                else
                {
                    StorageItems[slot] = item;
                }
            }

            return true;
        }
Exemple #4
0
 /// <summary>
 /// Get slot id by item
 /// </summary>
 /// <param name="item">Storage item</param>
 /// <returns></returns>
 public short GetSlotOfItem(AStorageItem item)
 {
     return (short)Array.IndexOf(StorageItems, item);
 }
Exemple #5
0
 public abstract bool AddItem(AStorageItem item, short targetSlot);
Exemple #6
0
 public abstract short[] GetSlots(AStorageItem item);
Exemple #7
0
 /// <summary>
 /// Get slot id by item
 /// </summary>
 /// <param name="item">Storage item</param>
 /// <returns></returns>
 public short GetSlotOfItem(AStorageItem item)
 {
     return((short)Array.IndexOf(StorageItems, item));
 }
Exemple #8
0
 public abstract bool AddItem(AStorageItem item, short targetSlot);
Exemple #9
0
 public abstract short[] GetSlots(AStorageItem item);
        public override short[] GetSlots(AStorageItem item)
        {
            var type = (EquipType)Enum.Parse(typeof(EquipType), item.Template.EquipType);

            return new[] { (short)EnumExt.GetSlotByEquipType(type) };
        }