package org.project.entity.players;

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

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;
    private boolean isAlive;

    public int getBaseDamage() {
        return baseDamage;
    }

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

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

    public void heavyAttack(Entity target) {
        target.takeDamage(weapon.getDamage() + this.baseDamage + 7);
    }

    @Override
    public void takeDamage(int damage) {
        if (damage - armor.getDefense() > 0) {
            hp -= damage - armor.getDefense();
            if (hp <= 0) {
                getKilled();
            }
        }
    }

    @Override
    public void heal(int health) {
        hp += health;
        if (hp > maxHP) {
            hp = maxHP;
        }
        System.out.println("\u001B[32myou Healed yourself!\u001B[0m");
    }

    @Override
    public void fillMana(int mana) {
        mp += mana;
        if (mp > maxMP) {
            mp = maxMP;
            System.out.println("\u001B[33myour Mana got spilled.\u001B[0m");
        } else
            System.out.printf("\u001B[36m+%d Mana\u001B[0m\n", mana);
    }

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

    public boolean isAlive() {
        return isAlive;
    }

    public void getKilled() {
        isAlive = false;
        System.out.println("\u001B[31mYou died!\u001B[0m");
    }

    public boolean useMana(int mana) {
        if (mp - mana < 0)
            return false;
        else {
            mp -= mana;
            return true;
        }
    }
}