package org.project.entity.players;

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


public abstract class Player extends Entity{

    protected final PlayerStats stats;
    protected String name;
    private int mp;
    private boolean defensing;
    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;
        defensing = 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(!isDefensing()){
            super.takeDamage(damage);
            System.out.println("Enemy's attack dealt " + damage + " damage to you!");
        }
        else {
            System.out.println("You blocked the attack!");
            defensing = false;
        }
    }

    public void defend() { setDefensing(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 PlayerStats getStats() {return stats;}

    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 giveGoblinKey() { goblinKey = true; }
    public void giveSkeletonKey() { skeletonKey = true; }
    public void giveVampireKey() { vampireKey = true; }

    public boolean isDefensing() { return defensing; }
    public void setDefensing(boolean defensing) {this.defensing = defensing; }

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