public void setAt(int column, int row, MaterialStack stack) { if (column <= 3 && column >= 0 && row >= 0 && row <= 4) { contents[column, row] = stack; } }
public int[] getIndex(MaterialStack stack) { for(int x = 0; x < contents.GetLength(0); x++){ for (int y = 0; y < contents.GetLength(1); y++) { if(contents[x,y].getType().getId() == stack.getType().getId()){ return new int[] {x,y}; } } } return new int[]{-1, -1}; }
/// <summary> /// Adds materials to the inventory /// </summary> /// <param name="mat">The stack of materials to add</param> /// <returns>False if the gatherer would go over their carry capacity</returns> public bool AddMaterials(MaterialStack mat) { if (inventory.totalCount + mat.count > carryCapacity) { return(false); } else { inventory.AddMaterial(mat); } return(true); }
public int[] getIndex(MaterialStack stack) { for(int x = 0; x < contents.GetLength(0); x++){ for (int y = 0; y < contents.GetLength(1); y++) { if (contents[x, y] != null) { if (contents[x, y].getType().getId() == stack.getType().getId()) { return new int[] { x, y }; } } } } return new int[]{-1, -1}; }
/// <summary> /// Adds all the materials on the tile to the inventory /// </summary> /// <param name="tile">The tile to add from</param> /// <returns>False if the inventory is to large</returns> public bool CollectMaterialsFromTile(BaseTile tile) { while (tile.entityList.Count > 0) { MaterialStack stack = tile.entityList[0].GetStack(); if (!AddMaterials(stack.material, stack.count)) { int remaining = remainingCapacity; AddMaterials(stack.material, remaining); tile.entityList[0].Decrease(remaining); return(false); } tile.entityList.RemoveAt(0); if (remainingCapacity == 0) { return(false); } } return(true); }
public void Draw() { Screen.render(location, SideCraft.toolbarTile); for (int x = 0; x < boxes.Length; x++) { MaterialStack item = SideCraft.player.getInventory().getAt(x, 0); Screen.render(boxes[x], item.getType().getTexture()); if (x == currentIndex) { Screen.render(new Rectangle(boxes[x].X - 3, Y - 3, 35, 34), this.selectionBox); } if (item.getAmount() > 0) { Screen.renderString(SideCraft.font, SideCraft.player.getInventory().getAt(x, 0).getAmount().ToString(), new Vector2(boxes[x].Center.X + 5, boxes[x].Center.Y - 1), Color.White); } } }
public void add(MaterialStack stack) { for(int x = 0; x < contents.GetLength(0); x++){ for (int y = 0; y < contents.GetLength(1); y++) { if (contents[x, y] != null) { if (contents[x, y].getType() == stack.getType()) { if (contents[x, y].getAmount() < contents[x, y].getType().getMaxStackSize()) { int amount = contents[x, y].getType().getMaxStackSize() - contents[x, y].getAmount(); if (amount > stack.getAmount()) { contents[x, y].modifyAmount(stack.getAmount()); stack.modifyAmount(-1 * stack.getAmount()); } else { contents[x, y].modifyAmount(amount); stack.modifyAmount(-1 * amount); } if (stack.getAmount() == 0) { return; } } } } } } if (stack.getAmount() > 0) { for (int y = 0; y < contents.GetLength(0); y++) { for (int x = 0; x < contents.GetLength(1); x++) { if (contents[x, y] == null) { setAt(x, y, stack); return; } } } } }
public void setContents(MaterialStack[,] newc) { if (newc.GetLength(0) == contents.GetLength(0) && newc.GetLength(1) == contents.GetLength(1)) { this.contents = newc; } }
public PlayerInventory() { contents = new MaterialStack[COLUMNS, ROWS]; contents[0, 0] = new MaterialStack(new Stone(), 1); }
public void setAt(int column, int row, MaterialStack stack) { if (column < contents.GetLength(0) && row < contents.GetLength(1) && row > -1 && column > -1) { contents[column, row] = stack; } }
public PlayerInventory() { contents = new MaterialStack[COLUMNS, ROWS]; contents[0, 0] = new MaterialStack(Material.STONE, 5); }