package org.project.entity.enemies;

import org.project.entity.Entity;
import org.project.item.weapons.BoneDagger;
import org.project.location.NarrativeConsole;

public class Skeleton extends Enemy {
    private boolean hasResurrected = false;

    public Skeleton() {
        super("Skeleton", 45, 25, new BoneDagger());
    }

    @Override
    public void attack(Entity target) {
        int damage = 10;

        target.takeDamage(damage);

        NarrativeConsole.printWarning("💀 Skeleton attacked " + getName(target) + "!");
        NarrativeConsole.printDamage("💥 Skeleton dealt " + damage + " damage to "
                + getName(target) + "!");
    }

    @Override
    public void takeDamage(int damage) {
        int newHp = getHp() - damage;

        if (newHp <= 0 && !hasResurrected) {
            //Resurrecting
            int resurrectedHp = getMaxHP() * 50 / 100;
            setHp(resurrectedHp);
            hasResurrected = true;

            NarrativeConsole.printSuccess("💀 Skeleton has been defeated...");
            NarrativeConsole.printSpecial("☠️ But Skeleton rises again! Resurrected with "
                    + resurrectedHp + " HP!");
            return;
        }

        setHp(newHp);
        if (getHp() < 0) setHp(0);

        NarrativeConsole.printDamage("💥 Skeleton took " + damage + " damage! HP: "
                + getHp() + "/" + getMaxHP());

        if (getHp() <= 0) {
            NarrativeConsole.printSuccess("☠️ Skeleton has been destroyed for good!");
        }
    }

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

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

    public boolean hasResurrected() {
        return hasResurrected;
    }

    public void setHasResurrected(boolean hasResurrected) {
        this.hasResurrected = hasResurrected;
    }
}