package org.project.entity.enemies;

import org.project.entity.Entity;

public abstract class Enemy implements Entity
{
    protected String name;

    protected int hp;
    protected int maxHP;
    protected int mp;
    protected int maxMP;
    protected boolean defending;

    public Enemy(String name, int maxHP, int maxMP)
    {
        this.name = name;
        this.maxHP = maxHP;
        this.hp = maxHP;
        this.maxMP = maxMP;
        this.mp = maxMP;
        this.defending = false;
    }

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

    @Override
    public int getHP() {return hp;}

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

    @Override
    public void setHP(int hp) {this.hp = Math.min(hp, maxHP);}

    @Override
    public int getMP() {return mp;}

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

    @Override
    public void setMP(int mp) {this.mp = Math.min(mp, maxMP);}

    @Override
    public void defend()
    {
        defending = true;
        System.out.println(name + " is defending and will reduce damage next turn.");
    }

    @Override
    public void takeDamage(int damage)
    {
        if (defending)
        {
            damage /= 2;
            System.out.println(name + " defended and reduced damage to " + damage);
            defending = false;
        }
        hp -= damage;
        if (hp < 0) hp = 0;
    }

    @Override
    public void attack(Entity target)
    {
        int damage = 8;
        System.out.println(name + " attacks for " + damage + " damage!");
        target.takeDamage(damage);
    }

    public String getName() {return name;}
}
