package org.project.entity.players;

import org.project.entity.Entity;
import org.project.entity.enemies.Enemy;


public abstract class Player extends Entity{

    protected final PlayerStats stats;
    protected String name;
    private int mp;
    private boolean defending;
    private int XP;
    private boolean skeletonKey;
    private boolean goblinKey;
    private boolean vampireKey;


    public Player(String name, PlayerStats stats) {
        super(stats.maxHP);
        this.name = name;
        this.mp = stats.maxMP;
        this.stats = stats;

        XP = 0;
        defending = false;
        goblinKey = false;
        skeletonKey = false;
        vampireKey = false;
    }

    public void lightAttack(Enemy target) {target.takeDamage(stats.lightAttackDamage);}

    public abstract void specialAbility(Enemy target);
    public abstract void heavyAttack(Enemy target);

    @Override
    public void takeDamage(int damage) {
        if(!isDefending()){
            super.takeDamage(damage);
            System.out.println("\u001B[31mEnemy's attack dealt " + damage + " damage to you!\u001B[0m");
        }
        else {
            System.out.println("You blocked the attack!");
            defending = false;
        }
    }

    public void defend() { setDefending(true); }

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

    public boolean reduceMana(int amount) {
        if(mp - amount >= 0) {
            mp -= amount;
            return true;
        }
        return false;
    }


    public int getHeavyAttackManaCost() {return stats.heavyAttackManaCost;}

    public int getDefendManaCost() {return stats.defendManaCost;}

    public int getHealManaCost() {return stats.healManaCost;}

    public int getSpecialAbilityManaCost() {return stats.specialAbilityManaCost;}

    public String getName() { return name; }

    public int getMp() { return mp; }

    public int getMaxMP() { return stats.maxMP; }

    public boolean hasGoblinKey() {return goblinKey;}
    public boolean hasSkeletonKey() {return skeletonKey;}
    public boolean hasVampireKey() {return vampireKey;}

    public void setGoblinKey(boolean value) { goblinKey = value; }
    public void setSkeletonKey(boolean value) { skeletonKey = value; }
    public void setVampireKey(boolean value) { vampireKey = value; }

    public boolean isDefending() { return defending; }
    public void setDefending(boolean value) {this.defending = value; }

    public int getXP() { return XP;}
    public void setXp(int amount) { XP = amount;}
    public void addXP(int amount) { XP += amount; }
}
