package org.project.entity.players;

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

// TODO: UPDATE IMPLEMENTATION
public class Knight extends Player {


    public Knight(String name,Sword weapon, KnightArmor armor) {
        //although hp is low but armor is wow.
        super(name, 60, 70, weapon, armor, 65);
        super.setDamage(40);
    }

    @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 (super.getLevel())
            {
                case (2):
                {

                    super.setMaxHP(super.getMaxHP() + ((15*super.getMaxHP()) / 100 ));
                    System.out.println("Your maximum HP is know 15% higher");
                    super.setMaxMP(super.getMaxMP() + ((10*super.getMaxMP()) / 100 ));
                    System.out.println("Your maximum Mana is know 10% higher");
                    break;
                }
                case(3):
                {
                    super.getArmor().setMaxDurability(super.getArmor().getMaxDurability() + ((10 * super.getArmor().getMaxDurability()) / 100));
                    System.out.println("Your armor's maximum durability is know 10% higher");
                    break;

                }
                case(4):
                {
                    super.setMaxHP(super.getMaxHP() + ((40*super.getMaxHP()) / 100 ));
                    System.out.println("Your maximum HP is know 40% higher");
                    Sword sword = (Sword) super.getWeapon();
                    sword.setSpecialDamage(sword.getSpecialDamage() + (10*sword.getSpecialDamage() / 100 ));
                    System.out.println("Your sword special damage is know 10% higher");
                    super.setDamage(super.getDamage() + ((20*super.getDamage()) / 100 ));
                    System.out.println("Your base damage is know 20% higher");
                    super.getWeapon().setManaCost(super.getWeapon().getManaCost() - ((10*super.getWeapon().getManaCost()) / 100 ));
                    System.out.println("Your weapon mana cost decreased by 10%");
                    break;
                }
                case (5):
                {
                    super.setMaxMP(super.getMaxMP() + ((20*super.getMaxMP()) / 100 ));
                    System.out.println("Your maximum mana is know 20% higher");
                    super.setMaxDefense(super.getMaxDefense() + ((20*super.getMaxDefense()) / 100 ));
                    System.out.println("Your maximum defence is know 20% higher");
                    super.getWeapon().setDamage(super.getWeapon().getDamage() + ((10*super.getWeapon().getDamage()) / 100 ));
                    System.out.println("Your sword damage is know 10% higher");
                    break;
                }
            }
        }
        super.setHp(super.getMaxHP());
        super.fillMana(super.getMaxMP());
        super.getArmor().repair();
        System.out.println();
        showInf();
    }

    @Override
    public boolean specialAbility(Entity target) {
        if(super.getMp() > 65) {
            super.setMp(super.getMp() - 65);
            System.out.printf("%s (Knight) uses special ability.\n", super.name);
            Sword sword = (Sword) super.getWeapon();
            target.takeDamage(sword.getSpecialDamage());
            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() {
        Sword sword = (Sword) super.getWeapon();
        System.out.println("Your information:");
        System.out.printf("""
                level: %d
                HP: %d
                MP: %d
                Coin: %d
                Maximum defence: %d
                
                
                armor:
                durability: %d
                defensePercentage: %d
                
                
                Sword:
                damage: %d
                mana cost: %d
                Special damage: %d
                
                """, super.getLevel(), super.getHp(), super.getMp(), super.getCoin(), super.getMaxDefense(),
                super.getArmor().getDurability(), super.getArmor().getDefensePercentage(),
                sword.getDamage(),sword.getManaCost() ,sword.getSpecialDamage());
    }


    //    @Override
//    public void defend(int damage) {
//
//        if(damage > 60)
//        {
//            int defense = (80 * damage) / 100;
//            this.takeDamage(damage - defense);
//            System.out.printf("You took " + Colors.BLUE + "%d" + Colors.RESET + "damage!" + Colors.YELLO + "(%d damage was defended)\n" + Colors.RESET, damage, damage - defense);
//        }
//        else
//        {
//            System.out.println("The enemy hit defended!");
//        }
//
//    }



//    @Override
//    public void takeDamage(int damage) {
//        super.takeDamage(damage);
//        System.out.printf("%s (Knight) took" + Colors.RED + "%d" + Colors.RESET +  "damage!\n",super.name, damage - armor.getDefense(damage) );
//    }


    // TODO: DESIGN KNIGHT'S WEAPON AND ARMOR AND IMPLEMENT THE CONSTRUCTOR

}
