package de.miaurizius.jgame2d.entity.item;

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 KeyObj extends Entity {

    public KeyObj(GamePanel panel) {
        super(panel);
        name = "Normal Key";
        description = "[" + name + "]\nIt opens a door.";
        type = EntityType.ITEM;
        consumable = true;
        down1 = initEntitySprites("objects/key");

        price = 50;
        stackable = true;

        setDialogue();
    }

    public void setDialogue() {
        dialogue[0][0] = "What are you doing?\nThere is no door nearby.";
        dialogue[1][0] = "You used a " + name + "!\nThe door is now open.";
    }

    @Override
    public boolean use(Entity entity) {
        int objIndex = getDetected(entity, panel.obj, "door");
        if(objIndex == 999) {
            startDialogue(this,0);
            return false;
        }
        panel.playSE(3);
        panel.obj[panel.currentMap.getIndex()][objIndex] = null;
        startDialogue(this,1);
        return true;
    }

}
