package org.project.entity.players;

import org.project.Colors;
import org.project.entity.Entity;
import org.project.item.armors.WizardArmor;
import org.project.item.weapons.Weapon;
import org.project.item.weapons.WizardWeapon;

public class Wizard extends Player{

    public Wizard(String name, Weapon weapon, WizardArmor armor) {
        super(name, 80, 80, weapon, armor,50 );
        super.setDamage(35);
        super.setMp(super.getMp() + armor.getBonus(this));
        super.setMaxMP(super.getMp() + armor.getBonus(this));
    }

    @Override
    public void levelUp() {
        if(super.getLevel() < 5) {
            addLevel();
            System.out.printf("You leveled up! " +Colors.ORANGE +"(" +Colors.RESET +"your level: " + Colors.LIGHTBLUE + "%d" + Colors.ORANGE +")\n" + Colors.RESET, super.getLevel());
            switch (getLevel())
            {
                case (2):
                {
                    super.setMaxDefense(super.getMaxDefense() + ((30*super.getMaxDefense()) / 100));
                    System.out.println("Your maximum defence is know 30% higher");
                    super.setMaxHP(super.getMaxHP() + ((10*super.getMaxHP()) / 100));
                    System.out.println("Your maximum HP is know 10% higher");
                    break;
                }
                case(3):
                {
                    WizardArmor wizardArmor = (WizardArmor) super.getArmor();
                    wizardArmor.setBonusPercent(2*wizardArmor.getBonusPercent());
                    System.out.println("Bonus percentage has doubled");
                    wizardArmor.setReflectPercent(wizardArmor.getReflectPercent() + ((30*wizardArmor.getReflectPercent()) / 100));
                    System.out.println("Reflect percentage increased");
                    break;
                }
                case(4):
                {
                    super.setMaxHP(super.getMaxMP() + ((30*super.getMaxMP()) / 100 ));
                    System.out.println("Your maximum HP is know 30% higher");
                    WizardWeapon wizardWeapon = (WizardWeapon) super.getWeapon();
                    wizardWeapon.setManaCost(wizardWeapon.getManaCost() - ((35* wizardWeapon.getManaCost()) / 100 ));
                    System.out.println("Your weapon mana cost decreased by 35%");
                    super.setDamage(super.getDamage() + ((50*super.getDamage()) / 100 ));
                    System.out.println("Your base damage is know 50% higher");
                    break;
                }
                case (5):
                {
                    super.setMaxMP(super.getMaxMP() + ((50*super.getMaxMP()) / 100 ));
                    System.out.println("Your maximum mana is know 50% higher");
                    super.setMaxHP(super.getMaxHP() + ((40*super.getMaxHP()) / 100 ));
                    System.out.println("Your maximum HP is know 40% higher");
                    super.setMaxDefense(super.getMaxDefense() + ((50*super.getMaxDefense()) / 100));
                    System.out.println("Your maximum defence is know 50% higher");
                    break;
                }
            }
        }
            super.setHp(super.getMaxHP());
            super.fillMana(super.getMaxMP());
            super.getArmor().repair();
            System.out.println();
            showInf();
    }



    public void takeDamage(Entity attacker ,int damage) {
        super.takeDamage(damage);
        WizardArmor w = (WizardArmor) super.getArmor();
        w.reflect(attacker, damage);
    }

    @Override
    public boolean heavyAttack(Entity target) {
        if(super.getMp() > super.getWeapon().getManaCost()) {
            super.setMp(super.getMp() - super.getWeapon().getManaCost());
            System.out.printf("%s (Wizard) performed a triple attack!\n", super.name);
            WizardWeapon wp = (WizardWeapon) super.getWeapon();
            target.takeDamage(wp.tripleAttack());
            return true;
        }
        System.out.println("You don't have enough " + Colors.BLUE + "Mana" + Colors.RESET + " for heavy attack.");
        return false;

    }

    @Override
    public boolean specialAbility(Entity target) {
        if(super.getMp() > 75) {
            super.setMp(super.getMp() - 75);
            System.out.printf("%s (Wizard) uses special ability.\n", super.name);
            WizardWeapon w = (WizardWeapon) super.getWeapon();
            target.takeDamage(4*w.getDamage());
            super.setHp(super.getHp() + ((6 * super.getMaxHP()) / 10));
            return true;
        }
        System.out.println("You don't have enough " + Colors.BLUE + "Mana" + Colors.RESET + " for your special ability.");
        return false;
    }

    @Override
    public void showInf() {
        WizardArmor w = (WizardArmor) super.getArmor();
        System.out.println("Your information:");
        System.out.printf("""
                level: %d
                HP: %d
                MP: %d
                Coin: %d
                Maximum defence: %d
                Special damage(in special attack): %d
                
                armor:
                durability: %d
                defensePercentage: %d
                Bonus percentage: %d
                Reflect percent: %d
                
                weapon:
                damage: %d
                mana cost: %d
 
                """, super.getLevel(), super.getHp(), super.getMp(), super.getCoin(), super.getMaxDefense(),
                4*super.getWeapon().getDamage(), w.getDurability(), w.getDefensePercentage(),
                w.getBonusPercent(), w.getReflectPercent(), super.getWeapon().getDamage(), super.getWeapon().getManaCost());
    }
}
