add dialogue setup and improve item handling in inventory

This commit is contained in:
2026-03-23 23:32:37 +01:00
parent e5b86cd778
commit b20f423348

View File

@@ -12,6 +12,7 @@ import de.miaurizius.jgame2d.entity.projectile.FireballObj;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.lang.reflect.InvocationTargetException;
public class Player extends Entity {
@@ -281,6 +282,7 @@ public class Player extends Entity {
attack = getAttack();
defense = getDefense();
panel.playSE(8);
setDialogue();
startDialogue(this,0);
}
public void selectItem() {
@@ -433,17 +435,21 @@ public class Player extends Entity {
}
public boolean canObtainItem(Entity item) {
int i = searchItemInInventory(item.name);
if(item.stackable) {
if(i != 999) {
inventory.get(i).amt++;
return true;
try {
if(item.stackable) {
if(i != 999) {
inventory.get(i).amt++;
return true;
} else if(inventory.size() != maxInvSize) {
inventory.add((Entity) Class.forName(item.getClass().getName()).getDeclaredConstructor(GamePanel.class).newInstance(panel));
return true;
}
} else if(inventory.size() != maxInvSize) {
inventory.add(item);
inventory.add((Entity) Class.forName(item.getClass().getName()).getDeclaredConstructor(GamePanel.class).newInstance(panel));
return true;
}
} else if(inventory.size() != maxInvSize) {
inventory.add(item);
return true;
} catch(ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
return false;
}