public void addInventory(Inventory inv) { add(inv); inv.setBounds(x, y, 47, 42); if (last != count) { x += 50; last += 1; } else { x = 2; y += 50; last = 0; } setPreferredSize(new Dimension(82 * count, y + 30)); }
public void useItem(int y, int x) { // uses an item Item temp = inventory.itemAt(x, y); if (temp == null) return; else if (temp.itemID < 5) { // equips equipnent inventory.setItem(x, y, equipment.itemAt(0, temp.itemID)); equipment.setItem(0, temp.itemID, temp); calculateStats(); // recalculates player stats } else if (temp.itemID == 5) { // uses health potion inventory.setItem(x, y, null); healHealth((int) (80 + maxHealth * 0.2)); } else if (temp.itemID == 6) { // uses mana potion inventory.setItem(x, y, null); healMana((int) (80 + maxMana * 0.2)); } }
public void calculateStats() { // calculates stats based on equipped items if (equipment.itemAt(0, 0) != null) atk.damage = equipment.itemAt(0, 0).value1; if (equipment.itemAt(0, 1) != null) atkSpd = ((double) equipment.itemAt(0, 1).value1 / 100.0 + 1) * 0.8; if (equipment.itemAt(0, 2) != null) { armor = equipment.itemAt(0, 2).value1; maxHealth = 100 + equipment.itemAt(0, 2).value2; } if (equipment.itemAt(0, 3) != null) { armor += equipment.itemAt(0, 3).value1; maxMana = 100 + equipment.itemAt(0, 3).value2; } if (equipment.itemAt(0, 4) != null) { maxHealth += equipment.itemAt(0, 4).value1; atk.damage += equipment.itemAt(0, 4).value2; } }