package de.miaurizius.jgame2d.entity.obstacle;

import de.miaurizius.jgame2d.core.GamePanel;
import de.miaurizius.jgame2d.core.enums.EntityType;
import de.miaurizius.jgame2d.core.enums.GameState;
import de.miaurizius.jgame2d.entity.Entity;

public class ChestObj extends Entity {

    GamePanel panel;

    public ChestObj(GamePanel panel) {
        super(panel);
        this.panel = panel;
        type = EntityType.OBSTACLE;
        name = "chest";

        image = initEntitySprites("objects/chest");
        image2 = initEntitySprites("objects/chest_opened");
        down1 = image;
        collision = true;

        solidArea.x = 4;
        solidArea.y = 16;
        solidArea.width = 40;
        solidArea.height = 32;
        solidAreaDefaultX = solidArea.x;
        solidAreaDefaultY = solidArea.y;
    }

    @Override
    public void setLoot(Entity loot) {
        this.loot = loot;
    }

    @Override
    public void interact() {
        panel.gameState = GameState.DIALOGUE;

        if(this.opened) {
            panel.ui.currentDialogue = "It's already empty...";
            return;
        }
        panel.playSE(3);
        StringBuilder sb = new StringBuilder();
        sb.append("You open the chest and find a ").append(loot.name).append("!");
        if(!panel.player.canObtainItem(loot)) {
            sb.append("\nBut your inventory is full...");
            panel.ui.currentDialogue = sb.toString();
            return;
        }
        sb.append("\nYou obtain the ").append(loot.name).append("!");
        down1 = image2;
        opened = true;
        panel.ui.currentDialogue = sb.toString();
    }

}
