package de.miaurizius.jgame2d.entity.monster;

import de.miaurizius.jgame2d.core.GamePanel;
import de.miaurizius.jgame2d.core.enums.EntityType;
import de.miaurizius.jgame2d.entity.Entity;
import de.miaurizius.jgame2d.entity.item.CoinObj;
import de.miaurizius.jgame2d.entity.item.HeartObj;
import de.miaurizius.jgame2d.entity.item.PotionObj;

import java.util.Random;

public class OrcMON extends Entity {

    public OrcMON(GamePanel panel) {
        super(panel);
        type = EntityType.MONSTER;
        name = "orc";
        defaultSpeed = 1;
        speed = defaultSpeed;
        maxLife = 10;
        life = maxLife;
        attack = 8;
        defense = 2;
        exp = 10;

        solidArea.x = 4;
        solidArea.y = 4;
        solidArea.width = 40;
        solidArea.height = 44;
        solidAreaDefaultX = solidArea.x;
        solidAreaDefaultY = solidArea.y;

        attackArea.width = panel.tileSize;
        attackArea.height = panel.tileSize;

        getImage();
        getAttackImage();
    }

    // INTERACTION
    public void setAction() {
        if(!onPath) checkStartChasing(panel.player, 10 ,100); else followPlayer();
        checkStopChasing(panel.player, 15, 100);
        setRandomDirection();
        if(!attacking) checkAttack(50, panel.tileSize*4, panel.tileSize);
    }
    public void damageReaction() {
        actionLock = 0;
        onPath = true;
    }
    public void checkDrop() {
        int i = new Random().nextInt(100)+1;
        if(i < 50) dropItem(new CoinObj(panel));
        if(i >= 50 && i < 75) dropItem(new HeartObj(panel));
        if(i >= 75 && i < 100) dropItem(new PotionObj(panel));
    }

    // SETTING THINGS UP
    public void getImage() {
        up1 = initEntitySprites("monster/orc_up_1");
        up2 = initEntitySprites("monster/orc_up_2");
        down1 = initEntitySprites("monster/orc_down_1");
        down2 = initEntitySprites("monster/orc_down_2");
        left1 = initEntitySprites("monster/orc_left_1");
        left2 = initEntitySprites("monster/orc_left_2");
        right1 = initEntitySprites("monster/orc_right_1");
        right2 = initEntitySprites("monster/orc_right_2");
    }
    public void getAttackImage() {
        attackUp1 = initEntitySprites("monster/orc_attack_up_1", panel.tileSize, panel.tileSize * 2);
        attackUp2 = initEntitySprites("monster/orc_attack_up_2", panel.tileSize, panel.tileSize * 2);
        attackDown1 = initEntitySprites("monster/orc_attack_down_1", panel.tileSize, panel.tileSize * 2);
        attackDown2 = initEntitySprites("monster/orc_attack_down_2", panel.tileSize, panel.tileSize * 2);
        attackLeft1 = initEntitySprites("monster/orc_attack_left_1", panel.tileSize*2, panel.tileSize);
        attackLeft2 = initEntitySprites("monster/orc_attack_left_2", panel.tileSize*2, panel.tileSize);
        attackRight1 = initEntitySprites("monster/orc_attack_right_1", panel.tileSize*2, panel.tileSize);
        attackRight2 = initEntitySprites("monster/orc_attack_right_2", panel.tileSize*2, panel.tileSize);
    }
}
