package org.project.entity.enemies;

import org.project.entity.Entity;

public abstract class Enemy implements Entity {
    protected boolean isDefending = false;
    private int hp;
    private int mp;
    private int maxHP = 50;
    private int maxMP = 50;

    public Enemy(int hp, int mp) {
        this.hp = hp;
        this.mp = mp;
    }

    @Override
    public void attack(Entity target)
    {
        target.takeDamage(2);
        System.out.println("Enemy is attacking ⚔️");
    }

    @Override
    public void defend()
    {
        if(getMp() >= 3)
        {
            this.setMp(this.getMp() - 3);
            System.out.println("Enemy is defending 🛡️");
            isDefending = true;
        }
        else System.out.println("Enemy does not have enough mp to defend");
    }

    @Override
    public void takeDamage(int damage) {
        if(isDefending == true) {
            damage = damage / 2;
            hp -= damage;
            isDefending = false;
            System.out.println("Enemy get a little damage !");
        }
        else
        {
            hp -= damage;
            if (hp < 0) hp = 0;
            System.out.println("The enemy get damage 🩸");
        }
    }

    @Override
    public void specialAbility(Entity target)
    {
        System.out.println("Enemy is using its special ability !");
    }

    @Override
    public void heal() {
        if(getMp() >= 6) {
            hp += 10;
            if (hp > maxHP) hp = maxHP;
        }
    }

    @Override
    public void fillMana(int mana) {
        mp += mana;
        if (mp > maxMP) {
            mp = maxMP;
        }
    }

    @Override
    public boolean isAlive() { return hp > 0; }

    @Override
    public int getMaxHP() { return maxHP; }

    @Override
    public int getMaxMP() { return maxMP;}

    public int getHp() { return hp; }

    public void setHp(int newHp) { this.hp = newHp; }

    public int getMp() { return mp; }

    public void setMp(int newMp) { this.mp = newMp; }

}
