package org.project.entity.players;

import org.project.Colors;
import org.project.entity.Entity;
import org.project.entity.enemies.Enemy;
import org.project.item.armors.AssassineArmor;
import org.project.item.weapons.AssassineWeapon;

public class Assassin extends Player{



    public Assassin(String name, AssassineWeapon weapon, AssassineArmor armor) {
        super(name, 65, 120, weapon, armor, 70);
        super.setDamage(35);
    }

    @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() + ((20*super.getMaxHP()) / 100 ));
                    System.out.println("Your maximum HP is know 20% higher");
                    super.setDamage(super.getDamage() + ((20*super.getMaxHP()) / 100 ));
                    System.out.println("Your base damage is know 20% higher");
                    break;

                }
                case(3):
                {
                    AssassineArmor asA = (AssassineArmor) super.getArmor();
                    asA.setDodgeChance(asA.getDodgeChance() + asA.getDodgeChance()/2);
                    System.out.println("Your dodge chance is know " + asA.getDodgeChance());
                    asA.setMaxPercentage(2*asA.getMaxPercentage());
                    System.out.println("Your defend percentage is know " + asA.getDefensePercentage());
                    break;

                }
                case(4):
                {

                    super.setDamage(super.getDamage() + super.getDamage()/ 2);
                    System.out.println("Your base damage is know 50% higher");
                    AssassineWeapon aw = (AssassineWeapon) super.getWeapon();
                    aw.setBleedingRound(aw.getBleedingRound() + 1);
                    System.out.println("Bleed duration on the enemy increased to two rounds (up from one)");
                    aw.setBleedChance(2*aw.getBleedChance());
                    System.out.println("Your bleed chance is know " + aw.getBleedChance());
                    break;

                }
                case (5):
                {
                    super.setMaxHP(super.getMaxHP() + ((30*super.getMaxHP()) / 100 ));
                    System.out.println("Your maximum HP is know 20% higher");
                    super.setMaxMP(super.getMaxMP() + ((10*super.getMaxMP()) / 100 ));
                    System.out.println("Your maximum Mana is know 10% higher");
                    super.getWeapon().setDamage(super.getWeapon().getDamage() + ((30*super.getWeapon().getDamage()) / 100 ));
                    System.out.println("Your Weapon damage is know 30% higher");
                    super.setMaxDefense(super.getMaxDefense() + ((20*super.getMaxDefense()) / 100 ));
                    System.out.println("Your maximum defence is know 20% higher");
                    AssassineWeapon aw = (AssassineWeapon) super.getWeapon();
                    aw.setBleedingRound(aw.getBleedingRound() + 1);
                    System.out.println("Bleed duration on the enemy increased to three rounds (up from two)");
                    break;
                }
            }
            super.setHp(super.getMaxHP());
            super.fillMana(super.getMaxMP());
            super.getArmor().repair();
            System.out.println();
            showInf();
        }

    }


    @Override
    public boolean heavyAttack(Entity target) {
        if(super.getMp() >= super.getWeapon().getManaCost()) {
            super.setMp(super.getMp() - super.getWeapon().getManaCost());
            System.out.printf("%s (%s) uses heavy attack.\n", name, this.getClass().getSimpleName());
            target.takeDamage(super.getWeapon().getDamage());
            AssassineWeapon aw = (AssassineWeapon) super.getWeapon();
            aw.manaGain(this, aw.getDamage() / 4);
            if(target instanceof Enemy enemy)
            {
                enemy.setHaveBleed(aw.bleed());
                if(enemy.HaveBleed())
                {
                    enemy.setBleedingRound(aw.getBleedingRound());
                }
            }
            return true;
        }
        System.out.println("You don't have enough " + Colors.BLUE + "Mana" + Colors.RESET + " for heavy attack.");
        return false;
    }


    @Override
    public void takeDamage(int damage) {
        AssassineArmor asA = (AssassineArmor) super.getArmor();
        int defence = asA.getDefense(damage);
        if(defence == damage)
        {
            System.out.printf("%s (Assassin) dodged the attack.\n", super.name);
        }
        else {
            super.takeDamage(damage - defence);
        }
    }

    @Override
    public boolean specialAbility(Entity target) {
        if(super.getMp() >= 80) {
            super.setMp(super.getMp() - 80);
            System.out.printf("%s (Assassin) uses special ability.\n", super.name);
            System.out.println("Assassin dodged the " + Colors.RED +  "attack" + Colors.RESET);
            AssassineWeapon aw = (AssassineWeapon) super.getWeapon();
            System.out.printf("%s (Assassin) used Critical Strike!\n", super.name);
            target.takeDamage(aw.criticalHit());
            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() {
            AssassineArmor asA = (AssassineArmor) super.getArmor();
            AssassineWeapon aw = (AssassineWeapon) 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
                Dodge chance: %d
                
                Weapon:
                Damage: %d
                Mana cost: %d
                
                Bleed chance: %d
                Bleed damage: %d
                Bleeding round: %d
         
                Critical hit: %d
                
                """, super.getLevel(), super.getHp(), super.getMp(), super.getCoin(), super.getMaxDefense(),
                    super.getArmor().getDurability(), super.getArmor().getDefensePercentage(),
                    asA.getDodgeChance(), aw.getDamage(), aw.getManaCost() ,aw.getBleedChance(),
                    aw.getBleedDamage(), aw.getBleedingRound(), 3*aw.getDamage() );
    }
}
