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;
    protected boolean isDefending = false;
    private int hp;
    private int maxHP = 100;
    private int mp;
    private int maxMP = 100;
    private int xp;

    public Player(String name, int hp, int mp,int xp) {
        this.name = name;
        this.isDefending = isDefending;
        this.hp = hp;
        this.mp = mp;
        this.xp = xp;
    }

    public void gainXp(int amount) {
        setXp(this.xp += amount);
        System.out.println(getName() + " gained " + amount + " XP 🪙");
    }

    @Override
    public void attack(Entity target) {
        target.takeDamage(2);
        System.out.println(getName() + " is attacking ⚔️");
    }

    public void heavyAttack(Entity target) {
        if(getMp() >= 2) {
            target.takeDamage(4);
            System.out.println(getName() + "has heavy attack 💣");
            this.setMp(this.getMp() - 2);
        }
        else {
            System.out.println("You do not have enough mp to have heavy attack 😓");
        }
    }

    @Override
    public void defend() {
        if(getMp() >= 3) {
            this.setMp(this.getMp() - 3);
            System.out.println(getName() + " is defending 🛡️");
            isDefending = true;
        }
        else System.out.println("You do not have enough mp to defend 😓");
    }

    @Override
    public void takeDamage(int damage) {
        if(isDefending == true) {
            damage = damage / 2;
            hp -= damage;
            isDefending = false;
            System.out.println(getName() + " get a little damage !");
        }
        else
        {
            hp -= damage;
            if (hp < 0) hp = 0;
            System.out.println("Oh, the " + getName() + " get damage 🩸");
        }
    }

    @Override
    public void heal() {
        if(getMp() >= 6) {
            hp += 10;
            if (hp > maxHP) hp = maxHP;
        }
        else System.out.println("Unfortunately you dont have enough mp 😓");
    }

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

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

    @Override
    public void specialAbility(Entity target) {
        System.out.println(getName() + "is using special ability 😎");
    }

    public String getName() { return name; }

    public int getHp() { return hp; }

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

    public int getXp() { return xp; }

    public void setXp(int newXp) { this.xp = newXp; }

    @Override
    public int getMaxHP() { return maxHP; }

    public int getMp() { return mp; }

    public void setMp(int newMp) { mp = newMp; }

    @Override
    public int getMaxMP() { return maxMP; }

}
