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, combatOptions {
    protected String name;
    Weapon weapon;
    Armor armor;
    private int hp;
    private int maxHP;
    private int mp;
    private int maxMP;
    private boolean defending = false;
    private double defendRate;
    private boolean isUsingSpecialAbility = false;

    public Player(String name, int hp, int mp, Weapon weapon, Armor armor) {
        this.name = name;
        this.hp = hp;
        this.mp = mp;

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

    @Override
    public void attack(Entity target, double multiplier) {
        double damage = multiplier * weapon.getDamage();
        if (target.isDefending()) {
            target.takeDamage( (int) (damage * (1 - getDefendRate())));
            target.setDefending(false);
        }
        else {
            target.takeDamage((int) damage);
        }
    };

    @Override
    public abstract void lightAttack(Entity target);

    @Override
    public abstract void heavyAttack(Entity target);

    @Override
    public void defend(){
        setDefending(true);
    };

    @Override
    public abstract void specialAbility(Entity target);


    @Override
    public void takeDamage(int damage) {

        int finalDamage = damage - armor.getDefense();
        setHP(getHP() - finalDamage);
    }

    @Override
    public void heal(int health) {
        setHP(getHP() + health);
    }


    public String getName() {
        return name;
    }

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

    @Override
    public void setHP(int hp) {
        this.hp = hp;
        if (this.hp > maxHP) {
            this.hp = maxHP;
        } else if (this.hp < 0) {
            this.hp = 0;
        }
    }

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

    @Override
    public void setMaxHP(int maxHP) {
        this.maxHP = maxHP;
    }


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

    @Override
    public void setMP(int mana) {
        mp = mana;
        if (mp > maxMP) {
            mp = maxMP;
        } else if (mp < 0) {
            mp = 0;
        }
    }


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

    @Override
    public void setMaxMP(int maxMP) {
        this.maxMP = maxMP;
    }

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

    public Armor getArmor() {
        return armor;
    }

    @Override
    public boolean isDefending() { return defending; }

    @Override
    public void setDefending(boolean defending) { this.defending = defending; }

    @Override
    public double getDefendRate() { return defendRate; }

    @Override
    public void setDefendRate(double defendRate) { this.defendRate = defendRate; }

    public boolean getUsingSpecialAbility() { return isUsingSpecialAbility; }

    public void setUsingSpecialAbility(boolean isUsingSpecialAbility) { this.isUsingSpecialAbility = isUsingSpecialAbility; }

}
