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 int baseDamage ;

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

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


    @Override
    public void attack(Entity target) {
        target.takeDamage(weapon.getDamage());
    }

    @Override
    public void defend(Entity me ,  int damage) {
        me.heal(damage);



    }


    @Override
    public void takeDamage(int damage) {
        hp -= damage - armor.getDefense();
    }

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


    public String getName() {
        return name;
    }

    public int getHp() {
        return hp;
    }
    public void setHp(int newhp){
        hp = newhp ;
    }

    @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;
    }
    public abstract void  specialAttack(Entity target) ;
    public boolean IsLive ( )
    {
        if (getHp() <= 0 )
            return false ;
        else
        {
            return true ;
        }
    }
    public void LightAttack( Entity target , int base_damage)
    {
        target.takeDamage(base_damage);
    }
    public void UpGradeMaxHP ()
    {
        maxHP = maxHP + (maxHP*2/10) ;
    }
    public void UpGradeMaxMP ()
    {
        maxMP = maxMP + (maxMP*2/10) ;
    }
    public void freshFactors()
    {
        mp = maxMP ;
        hp = maxHP ;
    }

}
