added trading system

This commit is contained in:
2025-12-12 16:44:50 +01:00
parent eb2c435671
commit 580775bf30
2 changed files with 43 additions and 0 deletions

View File

@@ -462,7 +462,46 @@ public class UI {
} }
} }
private void tradeSell() { private void tradeSell() {
drawInventory(panel.player, true);
int x, y, width, height;
// HINT WINDOW
x = panel.tileSize*2;
y = panel.tileSize*9;
width = panel.tileSize*6;
height = panel.tileSize*2;
drawSubWindow(x, y, width, height);
graphics2d.drawString("[ESC] Back", x+panel.tileSize, y+60);
// PLAYER COINS
x = panel.tileSize*12;
drawSubWindow(x, y, width, height);
graphics2d.drawString("Your Coins: " + panel.player.coins, x+panel.tileSize, y+60);
// PRICE WINDOW
int itemIndex = getItemIndex(playerSlotCol, playerSlotRow);
if(itemIndex < panel.player.inventory.size()) {
x = (int)(panel.tileSize*15.5);
y = (int)(panel.tileSize*5.5);
width = (int)(panel.tileSize*2.5);
height = panel.tileSize;
drawSubWindow(x, y, width, height);
graphics2d.drawImage(coin, x+10, y+8, 32, 32, null);
String price = String.valueOf(panel.player.inventory.get(itemIndex).price/2);
graphics2d.drawString(price, getAlignedToRightX(price, panel.tileSize*18-20), y+34);
// SELL
if(!panel.keyH.spacePressed) return;
if(panel.player.inventory.get(itemIndex) == panel.player.currentWeapon || panel.player.inventory.get(itemIndex) == panel.player.currentShield) {
commandNum = 0;
tradeState = TradeState.SELECT;
panel.gameState = GameState.DIALOGUE;
currentDialogue = "You cannot sell an equipped item!";
return;
}
panel.player.inventory.remove(itemIndex);
panel.player.coins += Integer.parseInt(price);
}
} }
// UTILITY // UTILITY

View File

@@ -176,6 +176,10 @@ public class KeyHandler implements KeyListener {
npcInventory(code); npcInventory(code);
if(code == KeyEvent.VK_ESCAPE) panel.ui.tradeState = UI.TradeState.SELECT; if(code == KeyEvent.VK_ESCAPE) panel.ui.tradeState = UI.TradeState.SELECT;
} }
if(panel.ui.tradeState == UI.TradeState.SELL) {
playerInventory(code);
if(code == KeyEvent.VK_ESCAPE) panel.ui.tradeState = UI.TradeState.SELECT;
}
} }
// UTILITY // UTILITY