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

    private final int spriteScale = 5;

    public SkeletonLordMON(GamePanel panel) {
        super(panel);
        type = EntityType.MONSTER;
        name = "Skeleton Lord";
        defaultSpeed = 1;
        speed = defaultSpeed;
        maxLife = 50;
        life = maxLife;
        attack = 10;
        defense = 2;
        exp = 50;
        knockbackVal = 5;

        int size = panel.tileSize*spriteScale;
        solidArea.x = 48;
        solidArea.y = 48;
        solidArea.width = size-48*2;
        solidArea.height = size-48;
        solidAreaDefaultX = solidArea.x;
        solidAreaDefaultY = solidArea.y;

        attackArea.width = 170;
        attackArea.height = 170;

        getImage();
        getAttackImage();
    }

    // INTERACTION
    public void setAction() {
        if(!rage && life < maxLife/2) {
            rage = true;
            getImage();
            getAttackImage();
            defaultSpeed++;
            speed = defaultSpeed;
            attack *= 2;
        }
        if(dTile(panel.player) < 10) moveTowardPlayer(60); else setRandomDirection(120);
        if(!attacking) checkAttack(60, panel.tileSize*7, panel.tileSize*5);
    }
    public void damageReaction() {
        actionLock = 0;
    }
    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() {
        if(rage) {
            up1 = initEntitySprites("monster/skeletonlord_phase2_up_1", panel.tileSize * spriteScale, panel.tileSize * spriteScale);
            up2 = initEntitySprites("monster/skeletonlord_phase2_up_2", panel.tileSize * spriteScale, panel.tileSize * spriteScale);
            down1 = initEntitySprites("monster/skeletonlord_phase2_down_1", panel.tileSize * spriteScale, panel.tileSize * spriteScale);
            down2 = initEntitySprites("monster/skeletonlord_phase2_down_2", panel.tileSize * spriteScale, panel.tileSize * spriteScale);
            left1 = initEntitySprites("monster/skeletonlord_phase2_left_1", panel.tileSize * spriteScale, panel.tileSize * spriteScale);
            left2 = initEntitySprites("monster/skeletonlord_phase2_left_2", panel.tileSize * spriteScale, panel.tileSize * spriteScale);
            right1 = initEntitySprites("monster/skeletonlord_phase2_right_1", panel.tileSize * spriteScale, panel.tileSize * spriteScale);
            right2 = initEntitySprites("monster/skeletonlord_phase2_right_2", panel.tileSize * spriteScale, panel.tileSize * spriteScale);
            return;
        }
        up1 = initEntitySprites("monster/skeletonlord_up_1", panel.tileSize * spriteScale, panel.tileSize * spriteScale);
        up2 = initEntitySprites("monster/skeletonlord_up_2", panel.tileSize * spriteScale, panel.tileSize * spriteScale);
        down1 = initEntitySprites("monster/skeletonlord_down_1", panel.tileSize * spriteScale, panel.tileSize * spriteScale);
        down2 = initEntitySprites("monster/skeletonlord_down_2", panel.tileSize * spriteScale, panel.tileSize * spriteScale);
        left1 = initEntitySprites("monster/skeletonlord_left_1", panel.tileSize * spriteScale, panel.tileSize * spriteScale);
        left2 = initEntitySprites("monster/skeletonlord_left_2", panel.tileSize * spriteScale, panel.tileSize * spriteScale);
        right1 = initEntitySprites("monster/skeletonlord_right_1", panel.tileSize * spriteScale, panel.tileSize * spriteScale);
        right2 = initEntitySprites("monster/skeletonlord_right_2", panel.tileSize * spriteScale, panel.tileSize * spriteScale);
    }
    public void getAttackImage() {
        if(rage) {
            attackUp1 = initEntitySprites("monster/skeletonlord_phase2_attack_up_1", panel.tileSize * spriteScale, panel.tileSize * 2 * spriteScale);
            attackUp2 = initEntitySprites("monster/skeletonlord_phase2_attack_up_2", panel.tileSize * spriteScale, panel.tileSize * 2 * spriteScale);
            attackDown1 = initEntitySprites("monster/skeletonlord_phase2_attack_down_1", panel.tileSize * spriteScale, panel.tileSize * 2 * spriteScale);
            attackDown2 = initEntitySprites("monster/skeletonlord_phase2_attack_down_2", panel.tileSize * spriteScale, panel.tileSize * 2 * spriteScale);
            attackLeft1 = initEntitySprites("monster/skeletonlord_phase2_attack_left_1", panel.tileSize*2*spriteScale, panel.tileSize*spriteScale);
            attackLeft2 = initEntitySprites("monster/skeletonlord_phase2_attack_left_2", panel.tileSize*2*spriteScale, panel.tileSize*spriteScale);
            attackRight1 = initEntitySprites("monster/skeletonlord_phase2_attack_right_1", panel.tileSize*2*spriteScale, panel.tileSize*spriteScale);
            attackRight2 = initEntitySprites("monster/skeletonlord_phase2_attack_right_2", panel.tileSize*2*spriteScale, panel.tileSize*spriteScale);
            return;
        }
        attackUp1 = initEntitySprites("monster/skeletonlord_attack_up_1", panel.tileSize * spriteScale, panel.tileSize * 2 * spriteScale);
        attackUp2 = initEntitySprites("monster/skeletonlord_attack_up_2", panel.tileSize * spriteScale, panel.tileSize * 2 * spriteScale);
        attackDown1 = initEntitySprites("monster/skeletonlord_attack_down_1", panel.tileSize * spriteScale, panel.tileSize * 2 * spriteScale);
        attackDown2 = initEntitySprites("monster/skeletonlord_attack_down_2", panel.tileSize * spriteScale, panel.tileSize * 2 * spriteScale);
        attackLeft1 = initEntitySprites("monster/skeletonlord_attack_left_1", panel.tileSize*2*spriteScale, panel.tileSize*spriteScale);
        attackLeft2 = initEntitySprites("monster/skeletonlord_attack_left_2", panel.tileSize*2*spriteScale, panel.tileSize*spriteScale);
        attackRight1 = initEntitySprites("monster/skeletonlord_attack_right_1", panel.tileSize*2*spriteScale, panel.tileSize*spriteScale);
        attackRight2 = initEntitySprites("monster/skeletonlord_attack_right_2", panel.tileSize*2*spriteScale, panel.tileSize*spriteScale);
    }

}
