package org.project.entity.players;

import org.project.entity.Entity;
import org.project.item.armors.LeatherArmor;
import org.project.item.weapons.Dagger;

public class Assassin extends Player {

    private boolean isHidden = false;
    private boolean nextAttackCritical = false;

    public Assassin(String name)
    {
        super(name, 150, 120, new Dagger(), new LeatherArmor());
    }

    @Override
    public int getBaseDamage()
    {
        return 10;
    }

    @Override
    public void specialAbility(Entity target)
    {
        if (this.getMp() < costSpecial)
        {
            System.out.println(YELLOW+"Not enough Mana for Vanish!"+RESET);
            return;
        }

        setIsHidden(true);
        setNextAttackCritical(true);
        this.setMp(this.getMp() - costSpecial);
        System.out.println("👻 " +PURPLE+ name + " has turned invisible!"+RESET);
        System.out.println("🎯 Next attack is guaranteed to be a Critical Hit!");
    }

    @Override
    public void heavyAttack(Entity target) {
        int baseDmg = getBaseDamage() * 2;
        int weaponDmg = (weapon != null) ? weapon.getDamage() : 0;
        int totalDmg = baseDmg + weaponDmg;
        if (getNextAttackCritical()) {
            totalDmg *= 2;
            System.out.println("⚡ Critical Hit! Damage doubled!");
            setNextAttackCritical(false);
        }


        if (this.getMp() < costHeavy) {
            System.out.println(YELLOW+"Not enough Mana for Heavy Attack!"+RESET);
            return;
        }
        this.setMp(this.getMp() - costHeavy);

        target.takeDamage(totalDmg);
        System.out.println("🔪 " + name + " (Assassin) used Heavy Attack! " + "( " + BLUE + costHeavy + RESET + " Mana)");
        System.out.println("💥 " + target.getClass().getSimpleName() + " took " + RED+totalDmg+RESET + " damage!");
    }

    @Override
    public void lightAttack(Entity target)
    {
        int baseDmg = getBaseDamage();
        int weaponDmg = (weapon != null) ? weapon.getDamage() : 0;
        int totalDmg = baseDmg + weaponDmg;
        if (getNextAttackCritical()) {
            totalDmg *= 2;
            System.out.println("⚡ Critical Hit! Damage doubled!");
            setNextAttackCritical(false);
        }

        target.takeDamage(totalDmg);
        System.out.println("️🗡️ " + name + " (Assassin) used Light Attack! " + "( " + BLUE+costLight+RESET + " Mana)");
        System.out.println("💥 " + target.getClass().getSimpleName() + " took " + RED+totalDmg+RESET + " damage!");
    }

    @Override
    public void heal(int health)
    {
        setHp(getHp() + health);
        if (this.getHp() > getMaxHP()) {
            setHp(getMaxHP());
        }
        System.out.println("💚" + name + " (Assassin) healed " + health + " HP!" );
    }
    @Override
    public void defend()
    {
        if (this.getMp() >= costDefend)
        {
            this.setMp(getMp() - costDefend);
            this.setDefending(true);
            System.out.println("🛡️" + name + " (Assassin) is defending!" + "( " + BLUE+costDefend+RESET + " Mana)");
        }
        else
        {
            System.out.println(YELLOW+"Not enough Mana!"+RESET);
        }
    }

    public boolean getIsHidden() {
        return isHidden;
    }

    public void setIsHidden(boolean hidden) {
        isHidden = hidden;
    }

    public boolean getNextAttackCritical() {
        return nextAttackCritical;
    }

    public void setNextAttackCritical(boolean nextAttackCritical) {
        this.nextAttackCritical = nextAttackCritical;
    }
}
