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 Weapon weapon;
    protected Armor armor;
    protected int hp;
    protected int maxHP;
    protected int mp;
    protected int maxMP;
    protected int fistDamage;
    protected boolean isDefending;
    protected boolean isalive;
    protected int Xp;




    public Player(String name, int hp, int mp, Weapon weapon, Armor armor , int fistDamage) {
        this.name = name;
        this.hp = hp;
        this.maxHP=hp;
        this.mp = mp;
        this.maxMP = mp;
        this.weapon = weapon;
        this.armor = armor;
        this.isDefending=false;
        this.fistDamage = fistDamage;
        this.isalive=true;
        this.Xp=0;

    }

    public abstract void specialAbility(Entity target);


    @Override
    public void lightattack(Entity target){
        System.out.println(name + " use light attak "  + "| Damge: " + fistDamage);
        target.takeDamage(fistDamage);

    }

    @Override
    public void heavyattack(Entity target){
        System.out.println(name + " use Heavy attak | Damage " + weapon.getDamage());
        target.takeDamage(weapon.getDamage());
        mp -= weapon.getManaCost();

    }

    @Override
    public void defend() {
        System.out.println("Defend mode is active now");
        mp -=12;
        isDefending =true;
    }


    @Override
    public void takeDamage(int damage) {

        if(isDefending){
            System.out.println("you have Defend this attak (half damage)" );
            damage /= 2;
            isDefending = false;
        }
        if(!armor.checkBreak()){
            System.out.println("you take " + (damage - armor.getDefense()) +
                    " Damage.  armor defend: " + armor.getDefense());
            hp -= damage - armor.getDefense();
            armor.use(this);
        }
        else {
            System.out.println("you take " + (damage - armor.getDefense()) + " Damage");
            hp -=damage;
        }

    }

    @Override
    public void healHp(int health) {
        System.out.println("you have got " + health + " Hp");
        mp -=14;
        hp += health;
        if (hp > maxHP) {
            hp = maxHP;
        }
    }

    @Override
    public void healMp(int mp) {
        System.out.println("you have got " + mp + " Mp");
        mp -=14;
        this.mp+= mp;
        if (this.mp > maxMP) {
            this.mp = maxMP;
        }
    }


    @Override
    public String toString(){
        return name+ " |Hp: " + hp +"/" + maxHP + " | Mp: " +mp +"/" + maxMP + "| Xp:" +this.Xp ;
    }


    @Override
    public void repair(){
        this.Xp +=1;
        this.maxHP +=5;
        this.maxMP +=5;
        this.hp = maxHP;
        this.mp += (maxMP / 4);
        armor.repair();
        System.out.println( "Repair: we full your Hp , repair your armor and give you some Mp");
    }

    public void setKing(){
        this.maxHP =1000;
        this.hp=maxHP;
        this.maxMP = 1000;
        this.mp = maxMP;
        armor.repair();
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public int getHp() {
        return hp;
    }

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

    @Override
    public int getMp() {
        return mp;
    }

    @Override
    public boolean getpossible(){ return true;}

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

    @Override
    public Weapon getWeapon() {
        return weapon;
    }

    @Override
    public Armor getArmor() {
        return armor;
    }

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

    // we should override this function but they are for enemies
    public void falsepossible(){}
    public void truepossible(){}
}
