package org.project.entity.enemies;

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

public abstract class Enemy extends Entity {

    protected Weapon weapon;
    protected boolean isDefending;

    public Enemy(String name, int maxHP, int maxMP, Weapon weapon) {
        super(name, maxHP, maxMP);

        this.weapon = weapon;
        this.isDefending = false;
    }

    @Override
    public void attack(Entity target) {


        int manaCost = weapon.getManaCost();

        if (mp < manaCost) {
            System.out.println(name + " tried to attack but does not have enough MP!");
            return;
        }


        mp -= manaCost;

        System.out.println(
                name + " attacks " + target.getName() +
                        " with " + weapon.getClass().getSimpleName() + "!"
        );


        weapon.use(target);
    }

    @Override
    public void defend() {
        isDefending = true;
        System.out.println(name + " is defending!");
    }

    @Override
    public void takeDamage(int damage) {

        if (damage <= 0) return;


        if (isDefending) {
            damage /= 2;
            isDefending = false;
            System.out.println(name + " defended and reduced the damage!");
        }

        hp -= damage;
        if (hp < 0) hp = 0;

        System.out.println(
                name + " took " + damage + " damage. (" + hp + "/" + maxHP + ")"
        );
    }


    public Weapon getWeapon() {
        return weapon;
    }
}
