public bool Insert(ItemComponent item, Vector2i position) { var size = item.Orientation == Orientation.Vertical ? item.Size.Yx : item.Size; if (fits(position, size)) { for (int i = 0; i < size.X; i++) { for (int k = 0; k < size.Y; k++) { storage[position.X + i, position.Y + k] = item.GetHashCode(); } } items.Add(item.GetHashCode(), item); return true; } else { Logger.Log.AddLogEntry(LogLevel.Error, "Inventory", "Failed to insert inventory item '{0}' at position <{1},{2}> - position already in use!", item.Entity.Name, position.X, position.Y); } return false; }
public bool MoveBarItemToPosition(ItemComponent item, byte position) { if (inventoryBar[position] == null) { inventoryBar[GetPositionOfBarItem(item)] = null; inventoryBar[position] = item.GetHashCode(); if (MessageCreated != null) MessageCreated(new BarItemMovedMessage(item, position)); return true; } return false; }
public Vector2i GetPositionOfItem(ItemComponent item) { var hc = item.GetHashCode(); int x, y = 0; for (; y < storage.GetLength(0); y++) { x = 0; for (; x < storage.GetLength(1); x++) { if (storage[y, x] == hc) return new Vector2i(y, x); } } Logger.Log.AddLogEntry(LogLevel.Error, "Inventory", "Item does not exist in inventory!"); return new Vector2i(-1, -1); }
public byte GetPositionOfBarItem(ItemComponent item) { var hc = item.GetHashCode(); byte index = 0; while (index < inventoryBar.Length && inventoryBar[index] != hc) { index++; } return index; }