package org.project.entity.enemies;

import org.project.entity.Entity;
import org.project.entity.players.Player;
import org.project.item.weapons.BoneDagger;
import org.project.item.weapons.DragonClaw;
import org.project.location.NarrativeConsole;

import java.util.Random;

public class Dragon extends Enemy {
    private Random random;

    public Dragon() {
        super("Dragon", 150, 100, new DragonClaw());
        this.random = new Random();
    }

    @Override
    public void attack(Entity target) {
        int chance = random.nextInt(100);

        if (chance > 40) {      //Fire breath chance 60%
            //Fire breath attack
            fireBreath(target);
        } else {
            //Normal claw attack
            normalAttack(target);
        }
    }

    private void normalAttack(Entity target) {
        int damage = 25;

        if (target instanceof Player) {
            Player player = (Player) target;
            if (player.isDefending()) {
                NarrativeConsole.printCombat("🐉 Dragon ignores your pathetic shield!");
                //Complete damage is done
            }
        }

        target.takeDamage(damage);
        NarrativeConsole.printCombat("🐉 Dragon strikes with its claw!");
        NarrativeConsole.printDamage("💥 " + damage + " damage dealt to " + getName(target) + "!");
    }

    private void fireBreath(Entity target) {
        int damage = 45;

        NarrativeConsole.printSpecial("🐉🐉🐉 DRAGON BREATHES FIRE! 🐉🐉🐉");
        NarrativeConsole.printSpecial("🔥🔥🔥 FIERY BREATH ENGULFS EVERYTHING! 🔥🔥🔥");

        if (target instanceof Player) {
            Player player = (Player) target;
            if (player.isDefending()) {
                NarrativeConsole.printSpecial("🛡️ Your shield MELTS under the dragon's breath!");
                NarrativeConsole.printSpecial("🔥 Defense is USELESS against this attack!");
                player.setDefending(false);  //The defense is invalid
            }
        }

        target.takeDamage(damage);
        NarrativeConsole.printDamage("💥 " + getName(target) + " takes " + damage + " MASSIVE damage!");
    }

    @Override
    public int getMaxHP() {
        return 150;
    }

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


}