package org.project.entity.enemies;

import org.project.entity.Entity;
import org.project.item.weapons.Weapon;

public abstract class Enemy implements Entity {
    protected Weapon weapon;
    protected String name;
    protected int hp;
    protected int mp;
    protected int maxHP;
    protected int maxMP;
    protected int xpReward;


    public Enemy(String name ,int hp, int mp, Weapon weapon , int xpReward) {
        this.hp = hp;
        this.mp = mp;
        this.maxHP = hp;
        this.maxMP = mp;
        this.name = name;
        this.xpReward = xpReward;
        this.weapon = weapon;
    }

    public abstract void specialAbility(Entity target);
    public abstract String geTKeyType();

    @Override
    public void attack(Entity target) {
        int damage = weapon.getDamage();
        target.takeDamage(damage);
        System.out.println("\u001B[31m" + this.name + " attacks for " + damage + " damage!\u001B[0m");
    }

    @Override
    public void defend() {
        System.out.println("\u001B[34m" + this.name + " is defending.\u001B[0m");
    }

    @Override
    public void heal(int health) {
        hp += health;
        if (hp > maxHP)   hp = maxHP;
    }

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

    @Override
    public void takeDamage(int damage) {
        hp -= damage;
        if (hp < 0) hp = 0;
        System.out.println("\u001B[31m" + name + " takes " +  damage + " damage!\u001B[0m");
    }

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

    public int getHp() {
        return hp;
    }

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

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

    public int getXpReward(){
        return xpReward;
    }

    public String getName(){
        return name;
    }

    public Weapon getWeapon(){
        return weapon;
    }
}
