/// <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; }
/// <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); }
public abstract bool AddItem(AStorageItem item, short targetSlot);
public abstract short[] GetSlots(AStorageItem item);
/// <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)); }
public override short[] GetSlots(AStorageItem item) { var type = (EquipType)Enum.Parse(typeof(EquipType), item.Template.EquipType); return new[] { (short)EnumExt.GetSlotByEquipType(type) }; }