package org.project.entity.enemies;

import org.project.entity.Entity;
import org.project.entity.players.Knight;
import org.project.entity.players.Player;
import org.project.item.weapons.Weapon;


public abstract class Enemy  implements Entity {
    Weapon weapon;
    private int hp;
    private int maxHP;
    private int mp;
    private int maxMP;
    private boolean defending = false;
    private double defendRate;

    public Enemy(int hp, int mp, Weapon weapon) {
        this.hp = hp;
        this.mp = mp;
        this.weapon = weapon;
    }
    //implement this in Main
    private boolean checkTargetAbility(Player target) {
        if (target instanceof Knight) {
            boolean check = target.getUsingSpecialAbility();
            return check;
        }
        return false;
    }

    @Override
    public  void attack(Entity target, double multiplier) {
        if (checkTargetAbility((Player) target)){
            System.out.println("target is using special ability");
            return;
        }
        double damage = multiplier * weapon.getDamage();
        if (target.isDefending()) {
            target.takeDamage( (int) (damage * (1 - target.getDefendRate())));
            target.setDefending(false);
        }
        else {
            target.takeDamage((int) damage);
        }
    }

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

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

    @Override
    public void takeDamage(int damage) {
        setHP(getHP() - damage);
    }

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

    @Override
    public void setHP(int hp) {
        this.hp = hp;
    }

    @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 mp) {
        this.mp = mp;
    }

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

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

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

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

