// [Remove] - Remove a Loot item from inventory public Inventory Remove(Loot loot, int quantity = 1) { GridVector vStack = FindAnyStack(loot); if (quantity <= 0 || vStack == null) { return(this); } else { int x = vStack.x; int y = vStack.y; if ((grid[x, y].amount - quantity) > 0) { grid[x, y].amount -= quantity; return(this); } else { int removed = grid[x, y].amount; grid[x, y] = null; quantity -= removed; return(Remove(loot, quantity)); } } }
public Loot GetLoot(GridVector gridVector) { if (CellEmpty(gridVector)) { return(null); } return(grid[gridVector.x, gridVector.y].loot); }
// [Add] - Add a Loot item to inventory with an optional quantity. Returns the added Loot object. public Inventory Add(Loot loot, int quantity = 1) { GridVector vStack = FindFreeStack(loot); GridVector vEmpty = FindEmptyCell(); int stackLimit = loot.StackLimit; if ((vEmpty == null && vStack == null) || (Quantity(loot) >= loot.InventoryLimit)) { return(this); } if (vStack != null) { int x = vStack.x; int y = vStack.y; if ((grid[x, y].amount + quantity) <= stackLimit) { grid[x, y].amount += quantity; return(this); } else { int added = (stackLimit - grid[x, y].amount); grid[x, y].amount += added; quantity -= added; return(Add(loot, quantity)); } } else if (vEmpty != null) { int x = vEmpty.x; int y = vEmpty.y; if (quantity <= stackLimit) { grid[x, y] = new InventorySlot(loot, quantity); return(this); } else { int added = stackLimit; grid[x, y] = new InventorySlot(loot, added); quantity -= added; return(Add(loot, quantity)); } } return(this); }
public InventorySlot MoveStack(GridVector from, Inventory toInventory, GridVector to) { InventorySlot originStack = GetStack(from); InventorySlot destinationStack; if (!toInventory.CellEmpty(to)) { destinationStack = toInventory.GetStack(to); grid[from.x, from.y] = destinationStack; } else { ClearCell(from); } toInventory.Contents[to.x, to.y] = originStack; return(originStack); }
/* [IsCellEmpty] - Returns true or false if given cell is empty */ public bool CellEmpty(GridVector gridVector) { return(grid[gridVector.x, gridVector.y] == null); }
/* [ClearCell] - Clears the contents of a given cell, returns that cell */ public GridVector ClearCell(GridVector cell) { grid[cell.x, cell.y] = null; return(cell); }
/* [GetStack] - gets stack (if there is one) at a specified GridVector */ public InventorySlot GetStack(GridVector pos) { return(grid[pos.x, pos.y]); }