package org.project.entity.players;

import org.project.entity.Entity;
import org.project.item.armors.Armor;
import org.project.item.weapons.Weapon;

// TODO: UPDATE IMPLEMENTATION
public abstract class Player implements Entity {
    protected String name;
    Weapon weapon;
    Armor armor;
    private int hp;
    private int maxHP;
    private int mp;
    private int maxMP;
    private boolean isDefending = false;
    private boolean stunned;

    public Player(String name, int hp, int mp, Weapon weapon, Armor armor,int maxHP, int maxMP) {
        this.name = name;
        this.hp = hp;
        this.mp = mp;

        this.maxHP = maxHP;
        this.maxMP = maxMP;

        this.weapon = weapon;
        this.armor = armor;
    }

    public void lightAttack(Entity target){
        target.takeDamage(10);
    }

    public void heavyAttack(Entity target){
        target.takeDamage(weapon.getDamage());
        mp -= weapon.getManaCost();
    }

    @Override
    public void defend() {
        this.mp -= 5;
        isDefending = true;
        System.out.println("Defending...");
    }


    @Override
    public void takeDamage(int damage) {
        if (!isDefending) {
            hp -= damage - armor.getDefense();
        }
        else {
            System.out.println("Defended the attack.");
            isDefending = false;
        }

    }

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

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

    @Override
    public void stun() {
        stunned = true;
    }

    @Override
    public boolean isStunned() {
        return stunned;
    }

    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;
    }

    public Weapon getWeapon() {
        return weapon;
    }

    public Armor getArmor() {
        return armor;
    }

}
