package org.project.entity;

import org.project.item.weapons.Weapon;

public abstract class Entity {

    protected String name;
    protected int hp;
    protected int maxHp;

    protected int mana;
    protected int maxMana;

    protected Weapon weapon;

    protected boolean isDefending;

    public Entity(String name, int hp, int mana, Weapon weapon) {

        this.name = name;

        this.hp = hp;
        this.maxHp = hp;

        this.mana = mana;
        this.maxMana = mana;

        this.weapon = weapon;

        this.isDefending = false;
    }

    public boolean useMana(int amount) {

        if (mana >= amount) {

            mana -= amount;
            return true;
        }

        return false;
    }

    public void takeDamage(int damage) {

        if (isDefending) {
            damage /= 2;
        }

        hp -= damage;

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

        System.out.println(name + " took " + damage + " damage.");
    }

    public void heal(int amount) {

        hp += amount;

        if (hp > maxHp) {
            hp = maxHp;
        }

        System.out.println(name + " healed for " + amount + " HP.");
    }

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

    public void defend() {

        isDefending = true;

        System.out.println(name + " is defending.");
    }

    public void resetDefending() {
        isDefending = false;
    }

    public String getName() {
        return name;
    }

    public int getHp() {
        return hp;
    }

    public void setHp(int hp) {
        this.hp = hp;
    }

    public int getMaxHp() {
        return maxHp;
    }

    public int getMana() {
        return mana;
    }

    public void setMana(int mana) {
        this.mana = mana;
    }

    public int getMaxMana() {
        return maxMana;
    }

    public Weapon getWeapon() {
        return weapon;
    }

    public void setWeapon(Weapon weapon) {
        this.weapon = weapon;
    }

    public boolean isDefending() {
        return isDefending;
    }

    public void setDefending(boolean defending) {
        isDefending = defending;
    }
}
