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 extends Entity {
    protected String name;
    protected Weapon weapon;
    protected Armor armor;

    public Player(String name, int hp, int mp, Weapon weapon, Armor armor) {

        super(name, hp, mp);

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

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

    @Override
    public void defend() {
       // TODO
        System.out.println(name + " is defending!");
    }


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

        if (finalDamage < 0) {
            finalDamage = 0;
        }

        hp -= finalDamage;

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


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

}
