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;
    }

    public void setDialogue() {
        dialogue[0][0] = "You open the chest and find a " + loot.name + "!\nBut your inventory is full...";
        dialogue[1][0] = "You open the chest and find a " + loot.name + "!\nYou obtain the " + loot.name + "!";
        dialogue[2][0] = "It's already empty...";
    }

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

    @Override
    public void interact() {
        if(this.opened) {
            startDialogue(this,2);
            return;
        }
        panel.playSE(3);
        if(!panel.player.canObtainItem(loot)) {
            startDialogue(this,0);
            return;
        }
        down1 = image2;
        opened = true;
        startDialogue(this,1);
    }

}
