package org.project.entity.players;

import org.project.entity.Entity;

public abstract class Player implements Entity {
    protected String name;
    protected int hp;
    protected int maxHP;
    protected int mp;
    protected int maxMP;
    protected boolean isDefending;

    public Player(String name, int hp, int mp, int maxHP,int maxMP) {
        this.name = name;
        this.hp = hp;
        this.mp = mp;
        this.maxMP = maxMP;
        this.maxHP = maxHP;
        this.isDefending = false;
    }


    @Override
    public String defend() {
        if (mp >= 6) {
            mp -= 6;
            isDefending = true;
            return name + " assumes defensive stance";
        }
        return "not enough mana to defend";
    }

    @Override
    public void takeDamage(int damage) {
        if (isDefending) {
            damage = damage / 2;
            isDefending = false;
        }
        hp -= damage;
        if (hp < 0) hp = 0;
    }

    @Override
    public void heal(int health) {
        hp += health;
        if (hp > maxHP) {
            hp = maxHP;
        }
    }

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

    @Override
    public void LightAttack(Entity target, int damage) {
        target.takeDamage(damage);
    }

    @Override
    public void HeavyAttack(Entity target, int damage) {
        if (mp >= 8) {
            target.takeDamage(damage);
            mp -= 8;
        }
    }


    public abstract void SpecialAbility(Entity target);

    @Override
    public boolean isAlive() {
        return hp > 0;
    }


    public String getName() {
        return name;
    }

    public int getHp() {
        return hp;
    }

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

    public int getMp() {
        return mp;
    }

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

}
