package org.project.entity.players;


import org.project.entity.Entity;
import org.project.item.armors.KnightArmor;
import org.project.item.weapons.Sword;

public class Knight extends Player {

    public Knight() {
        super("Knight",100,90, new Sword(), new KnightArmor());
        setDefendRate(.9);
    }

    @Override
    public void lightAttack(Entity target) {
        super.lightAttack(target);
        if (((Sword) weapon).charge()){
            setAttackMultiplier(1.4);
            attack(target);
            setAttackMultiplier(1);
        } else {
            attack(target);
        }
    }

    @Override
    public void heavyAttack(Entity target) {
        super.heavyAttack(target);
        if (getMP() >= weapon.getManaCost()) {
            setAttackMultiplier(1.5);
            attack(target);
            setAttackMultiplier(1);
            setMP(getMP() - weapon.getManaCost());
        }
        else {
            System.out.println("Not enough MP");
            setSuccessfulAction(false);
        }
    }

    @Override
    public void defend() {
        if (getMP() >= 16) {
            super.defend();
            setMP(getMP() - 16);
        }
        else {
            System.out.println("Not enough MP");
            setSuccessfulAction(false);
        }
    }

    @Override
    public void specialAbility(Entity target) {
        if (getMP() >= 30) {
            setUsingSpecialAbility(true);
            setAttackMultiplier(2);
            attack(target);
            setAttackMultiplier(1);
            setMP(getMP() - 30);
        }
        else {
            System.out.println("Not enough MP");
            setUsingSpecialAbility(false);
        }
    }

    @Override
    public void heal(int health) {
        if (getMP() >= 10) {
            super.heal(health);
            setMP(getMP() - 10);
        }
        else  {
            System.out.println("Not enough MP");
            setSuccessfulAction(false);
        }
    }


    public void takeDamage(int damage, Entity attacker) {
        super.takeDamage(damage);
        if (!getArmor().checkBrake()) {
            int reflected = ((KnightArmor) armor).getReflectedDamage(damage);
            attacker.takeDamage(reflected);
        }
    }

}

