예제 #1
0
        // [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));
                }
            }
        }
예제 #2
0
        public Loot GetLoot(GridVector gridVector)
        {
            if (CellEmpty(gridVector))
            {
                return(null);
            }

            return(grid[gridVector.x, gridVector.y].loot);
        }
예제 #3
0
        // [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);
        }
예제 #4
0
        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);
        }
예제 #5
0
 /* [IsCellEmpty] - Returns true or false if given cell is empty */
 public bool CellEmpty(GridVector gridVector)
 {
     return(grid[gridVector.x, gridVector.y] == null);
 }
예제 #6
0
        /* [ClearCell] - Clears the contents of a given cell, returns that cell */
        public GridVector ClearCell(GridVector cell)
        {
            grid[cell.x, cell.y] = null;

            return(cell);
        }
예제 #7
0
 /* [GetStack] - gets stack (if there is one) at a specified GridVector */
 public InventorySlot GetStack(GridVector pos)
 {
     return(grid[pos.x, pos.y]);
 }