package de.miaurizius.jgame2d.entity.npc;

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

import java.awt.*;
import java.util.Random;

public class OldManNPC extends Entity {

    public OldManNPC(GamePanel panel) {
        super(panel);
        type = EntityType.NPC;
        name = "oldman-npc";

        direction = Direction.DOWN;
        speed = 1;
        getImage();
        setDialogue();

        dialogueSet = -1;

        solidArea.x = 8;
        solidArea.y = 16;
        solidAreaDefaultX = solidArea.x;
        solidAreaDefaultY = solidArea.y;
        solidArea.width = 30;
        solidArea.height = 30;
    }

    public void setAction() {

//        if(onPath) {
//            searchPath(12, 9);
//            return;
//        }

        actionLock++;
        if(actionLock != 120) return; //lock action for x frames
        Random rand = new Random();
        int i = rand.nextInt(100)+1; //Generate number between 1 and 100
        if(i <= 25) direction = Direction.UP;
        if(i > 25 && i <= 50) direction = Direction.DOWN;
        if(i > 50 && i <= 75) direction = Direction.LEFT;
        if(i > 75) direction = Direction.RIGHT;
        actionLock = 0;

    }
    @Override
    public void speak() {
        super.facePlayer();
        super.startDialogue(this,super.dialogueSet);
        dialogueSet++;
        if(dialogue[dialogueSet][0] == null) dialogueSet = 0;
        // super.onPath = true;
    }

    // SETTING THINGS UP
    private void getImage()  {
        up1 = initEntitySprites("npc/oldman_up_1");
        up2 = initEntitySprites("npc/oldman_up_2");
        down1 = initEntitySprites("npc/oldman_down_1");
        down2 = initEntitySprites("npc/oldman_down_2");
        left1 = initEntitySprites("npc/oldman_left_1");
        left2 = initEntitySprites("npc/oldman_left_2");
        right1 = initEntitySprites("npc/oldman_right_1");
        right2 = initEntitySprites("npc/oldman_right_2");
    }
    private void setDialogue() {
        dialogue[0][0] = "Hello, lad.";
        dialogue[0][1] = "So you've come to this island to \nfind the treasure?";
        dialogue[0][2] = "I used to be a great wizard but now... \nI'm a bit too old for taking an \nadventure.";
        dialogue[0][3] = "Well, good luck on you.";
        dialogue[0][4] = "I heard drinking the water of the \nholy lake makes you feel fine again...";

        dialogue[1][0] = "If you become tired, reset at the water.";
        dialogue[1][1] = "However, the monsters reappear if you rest.\nI don't know why but that's how it works.";
        dialogue[1][2] = "In any case, don't push yourself too hard.";

        dialogue[2][0] = "I wonder how to open that door...";
    }
}
