import { world, Scoreboard } from "@minecraft/server";
import { ActionFormData } from "@minecraft/server-ui";

//missao 1 = mostrar espada para Silho => novice
//missao 2 = mostrar armadura para Silho  => novice1

//missao 3 = mostrar 5 polvoras para Kile  => novice2

//missao 4 = Derrotar o Zumbi Necromante  => novice3

//missao 5 = Defender a vila de Alana  => adventure

//missao 6 = Fertilizar a planta de karlos => adventure2

//missao 7 = Entregar pergaminho para Nord => adventure3

//missao 8 = mostrar crânios de esqueleto para Ossos Secos => adventure4
//missao 9 = Derrotar o Zumbi Necromante  => adventure4

//missao 10 = mostrar Ajudantes para Silho => master

//missao 11 = Juntar pérolas do pantano => master2
//missao 12 = Derrotar a Abominação do Pântano  => master2

//missao 13 = Devolver todos os discos para os Bardos  => hero
//missao 14 = mostrar espada para Silho
//missao 15 = mostrar espada para Silho
//missao 16 = mostrar espada para Silho
//missao 17 = mostrar espada para Silho
//missao 18 = mostrar espada para Silho


// Ícones padrão para botões de diálogo (você pode expandir bastante)
const ICONES_BOTOES = {
    // Ações genéricas
    aceitar:        "textures/ui/permissions_visitor_hand.png",
    sim:            "textures/ui/check.png",
    nao:            "textures/ui/cancel.png",
    ok:             "textures/ui/icon_steve.png",          // ou algo neutro
    contratar:      "textures/ui/icon_multiplayer.png",
    entregar:       "textures/ui/book.png",
    mostrar:        "textures/ui/pergaminhos/icon_pergaminho.png",

    // Ícones temáticos por item/ação
    espada:         "textures/items/diamond_sword.png",
    armadura:       "textures/items/diamond_chestplate.png",
    polvora:        "textures/items/gunpowder.png",
    alma_arvore:    "textures/items/well/alma_da_arvore_item.png",
    fertilizante:   "textures/items/well/fertilizante_mistico.png",
    pergaminho:     "textures/items/book_written.png",
    cabecas:        "textures/items/skull.png",
    gelo_arcaico:   "textures/items/well/gelo_arcaico_item.png",
    disco:          "textures/items/record_otherside.png",
    flauta:         "textures/items/well/flauta_do_deserto.png",
    amuleto:        "textures/items/well/amuleto_de_farao_item.png",
    chave:          "textures/items/tripwire_hook.png",

    // Subquests – ícones por missão (exemplos)
    erva_gato:      "textures/items/itens_misticos/erva_gato.png",
    relogio:        "textures/items/clock_item.png",
    concha_nautilus:"textures/items/nautilus.png",
    chifre_cabra:   "textures/items/goat_horn.png",
    papagaio:       "textures/ui/pergaminhos/icones_submissoes/parrot.png",
    strider:        "textures/ui/pergaminhos/icones_submissoes/strider.png",
    sapo:           "textures/ui/pergaminhos/icones_submissoes/sapo.png",
    bolo:           "textures/items/cake.png",
    ovo_sniffer:    "textures/items/ovo_sniffer.png",
    esporos:        "textures/blocks/spore_blossom.png",
    // ... adicione mais conforme necessário
};

export function Missoes_NPC() {

// =============================================
// ÍCONES PADRÃO PARA BOTÕES
// =============================================
const ICONES_BOTOES = {
    cancelar: "textures/ui/realms_red_x.png",
    ainda_nao: "textures/ui/permissions_visitor_hand.png",
    entendi: "textures/ui/realms_slot_check.png",
    okay: "textures/ui/permissions_visitor_hand.png",
    quest1: "textures/items/wood_sword.png",
    quest2: "textures/ui/pergaminhos/icones_missoes/armadura_couro.png",
    quest3: "textures/items/gunpowder.png",
	quest4: "textures/ui/strength_effect.png",
	recompensaquest4: "textures/items/Fertilizante_Mistico.png",
	quest5: "textures/blocks/well_planta_stage_2.png",
	recompensaquest5: "textures/items/Literatura_dos_Arqueologos.png",
	quest6: "textures/items/Literatura_dos_Arqueologos.png",
	quest7: "textures/ui/pergaminhos/icones_missoes/cabecas_ossos.png",
	quest8: "textures/ui/tutorial_menu/geometry.arqueiro.png",
	quest9: "textures/items/flauta_do_deserto.png",
	discos_bardos: "textures/ui/pergaminhos/icones_missoes/discos.png",
	quest11: "textures/items/Chave_Hilda.png",
	quest12: "textures/items/Gema_Cristalina.png",
	recompensaquest12: "textures/items/Chave_Hilda.png",
	questfinal: "textures/items/Amuleto_de_Farao.png"
};

// =============================================
// FUNÇÕES AUXILIARES
// =============================================
function tocarSomEAnimacao(player, som = "npc.homem.dialogue.adulto") {
    player.runCommand(`playsound ${som} @p[r=5]`);
    const anims = ["dialogo1", "dialogo2", "dialogo3", "dialogo4"];
    const anim = anims[Math.floor(Math.random() * 4)];
    player.runCommand(`playanimation @e[type=!player,r=5] animation.humanoid.custom.well.${anim}`);
}

function mostrarDialogoComIcones(player, target, corpoTranslate, botoesTranslate, botoesIconesKeys, callback) {
    const form = new ActionFormData()
        .title("wellforced:renderentidade")
        .body({ rawtext: [{ translate: corpoTranslate }] });

    botoesTranslate.forEach((texto, i) => {
        const iconeKey = botoesIconesKeys[i] || "ok";
        const icone = ICONES_BOTOES[iconeKey] || "textures/ui/icon_steve.png";
        form.button({ rawtext: [{ translate: texto }] }, icone);
    });

    form.button("", ICONES_BOTOES.cancelar); // X de fechar
    form.button("", target.id);

    form.show(player).then(r => {
        if (r.canceled) return;
        callback(r.selection);
    });
}

function runComandos(entity, comandos) {
    comandos.forEach(cmd => {
        try {
            entity.runCommand(cmd);
        } catch (e) {
            console.warn(`Erro ao executar: ${cmd} → ${e}`);
        }
    });
}

// =============================================
// NPC: SILPHO
// =============================================
world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;
    if (!player?.runCommand || target?.typeId !== "npc:silpho") return;

    tocarSomEAnimacao(player);

    const scores = {
        m1: world.scoreboard.getObjective("missaowell1")?.getScore(player) ?? 0,
        m2: world.scoreboard.getObjective("missaowell2")?.getScore(player) ?? 0,
        m3: world.scoreboard.getObjective("missaowell3")?.getScore(player) ?? 0,
        m10: world.scoreboard.getObjective("missaowell10")?.getScore(player) ?? 0,
        m17: world.scoreboard.getObjective("missaowell17")?.getScore(player) ?? 0
    };

    const ESPADAS = ["iron_sword", "wooden_sword", "golden_sword", "diamond_sword", "netherite_sword"];
    const ARMADURAS = [
        "chainmail_chestplate", "diamond_chestplate", "golden_chestplate", "iron_chestplate", "leather_chestplate", "netherite_chestplate",
        "chainmail_boots", "diamond_boots", "golden_boots", "iron_boots", "leather_boots", "netherite_boots",
        "chainmail_helmet", "diamond_helmet", "golden_helmet", "iron_helmet", "leather_helmet", "netherite_helmet",
        "chainmail_leggings", "diamond_leggings", "golden_leggings", "iron_leggings", "leather_leggings", "netherite_leggings"
    ];

    // Verificação de tag para garantir o progresso correto
    if (scores.m1 === 1 && !player.getTags().includes("novice")) {
        player.runCommand("tag @s add novice"); // Garante tag inicial se resetou
    } else if (scores.m2 === 1 && !player.getTags().includes("novice1")) {
        player.runCommand("tag @s add novice1");
    } else if (scores.m3 === 1 && !player.getTags().includes("novice2")) {
        player.runCommand("tag @s add novice2");
    } else if (scores.m10 === 1 && !player.getTags().includes("master")) {
        player.runCommand("tag @s add master");
    } else if (scores.m17 === 1 && !player.getTags().includes("hero4")) {
        player.runCommand("tag @s add hero4");
    }

    if (scores.m1 === 1) {
        mostrarDialogoComIcones(player, target, "dialogo.silpho.espada",
            ["botao.subquest.mostrar", "botao.silpho.espada.nao"],
            ["quest1", "ainda_nao", "cancelar"],
            sel => {
                if (sel !== 0) return;
                ESPADAS.forEach(item => {
                    runComandos(player, [
                        `tag @s [hasitem={item=${item}},tag=novice,c=1,r=5] add novice1`,
                        `tag @s [hasitem={item=${item}},tag=novice1,c=1,r=5] remove novice`,
                        `titleraw @s [hasitem={item=${item}},tag=novice1,c=1,r=5] title {"rawtext":[{"translate":"missao.atualizacao.titulo"}]}`,
                        `titleraw @s [hasitem={item=${item}},tag=novice1,c=1,r=5] subtitle {"rawtext":[{"translate":"missao.atualizacao.subtitulo"}]}`,
                        `execute as @s [hasitem={item=${item}},tag=novice1,c=1,r=8] run tellraw @a {"rawtext":[{"selector":"@a[r=5,c=1]"},{"translate":"missao.concluida.mensagem.publica.espada"}]}`
                    ]);
                });
                runComandos(player, [
                    "playsound missioncomplete @s[tag=novice1] ~ ~ ~",
                    "scoreboard players set @s [tag=novice1] missaowell1 3",
                    "scoreboard players set @s [tag=novice1] missaowell2 1"
                ]);
            });
        return;
    }

    if (scores.m2 === 1) {
        mostrarDialogoComIcones(player, target, "dialogo.silpho.armadura",
            ["botao.subquest.mostrar", "botao.silpho.espada.nao"],
            ["quest2", "ainda_nao", "cancelar"],
            sel => {
                if (sel !== 0) return;
                ARMADURAS.forEach(item => {
                    runComandos(player, [
                        `tag @s [hasitem={item=${item}},tag=novice1,c=1,r=5] add novice2`,
                        `tag @s [hasitem={item=${item}},tag=novice2,c=1,r=5] remove novice1`,
                        `titleraw @s [hasitem={item=${item}},tag=novice2,c=1,r=5] title {"rawtext":[{"translate":"missao.atualizacao.titulo"}]}`,
                        `titleraw @s [hasitem={item=${item}},tag=novice2,c=1,r=5] subtitle {"rawtext":[{"translate":"missao.atualizacao.subtitulo"}]}`,
                        `execute as @s [hasitem={item=${item}},tag=novice2,c=1,r=5] run tellraw @a {"rawtext":[{"selector":"@a[r=5,c=1]"},{"translate":"missao.concluida.mensagem.publica.armadura"}]}`
                    ]);
                });
                runComandos(player, [
                    "playsound missioncomplete @s[tag=novice2] ~ ~ ~",
                    "scoreboard players set @s [tag=novice2] missaowell2 3",
                    "scoreboard players set @s [tag=novice2] missaowell3 1"
                ]);
            });
        return;
    }

    if (scores.m3 === 1) {
        mostrarDialogoComIcones(player, target, "dialogo.silpho.encaminhado.kile",
            ["opcoes.contratar", "opcoes.ok"],
            ["entendi", "okay"],
            () => {});
        return;
    }

    if (scores.m10 === 1) {
        mostrarDialogoComIcones(player, target, "dialogo.silpho.guerreiros",
            ["botao.subquest.mostrar", "botao.silpho.espada.nao"],
            ["quest8", "ainda_nao", "cancelar"],
            sel => {
                if (sel !== 0) return;
                runComandos(player, [
                    "execute as @e[family=ajudante,c=3,r=10] run tag @p[tag=master,r=8,c=1] add master1",
                    "execute as @e[family=ajudante,c=3,r=10] run tag @p[tag=master,r=8,c=1] remove master",
                    "scoreboard players add @s[tag=master1,r=8,c=1] perolas 0",
                    'titleraw @s[tag=master1,r=8,c=1] title {"rawtext":[{"translate":"missao.atualizacao.titulo"}]}',
                    'titleraw @s[tag=master1,r=8,c=1] subtitle {"rawtext":[{"translate":"missao.atualizacao.subtitulo"}]}',
                    'execute as @s[tag=master1,r=8,c=1] run tellraw @a {"rawtext":[{"selector":"@a[r=5,c=1]"},{"translate":"missao.concluida.mensagem.publica.tesouros"}]}',
                    "playsound missioncomplete @s[tag=master1,r=10] ~ ~ ~",
                    "scoreboard players set @s[tag=master1] missaowell10 3",
                    "scoreboard players set @s[tag=master1] missaowell11 1"
                ]);
            });
        return;
    }

    if (scores.m17 === 1) {
        mostrarDialogoComIcones(player, target, "dialogo.silpho.finale",
            ["botao.subquest.mostrar", "botao.silpho.espada.nao"],
            ["questfinal", "ainda_nao", "cancelar"],
            sel => {
                if (sel !== 0) return;
                runComandos(player, [
                    "tag @s [hasitem={item=well:amuleto_de_farao_item},tag=hero4,r=5] add boss4",
                    "execute as @s [hasitem={item=well:amuleto_de_farao_item}] run summon well:amuleto_farao ~ ~1 ~ ~ ~ vazio Amuleto",
                    "tag @s [tag=hero4,r=5] remove hero4",
                    "music play orgao.monster 1 1 loop",
                    "clear @s [hasitem={item=well:amuleto_de_farao_item},tag=boss4,c=1,r=10] well:amuleto_de_farao_item",
                    'titleraw @s[tag=boss4,r=5,c=1] title {"rawtext":[{"translate":"missao.atualizacao.titulo"}]}',
                    'titleraw @s[tag=boss4,r=5,c=1] subtitle {"rawtext":[{"translate":"missao.atualizacao.subtitulo"}]}',
                    'execute as @s[tag=boss4,r=5,c=1] run tellraw @a {"rawtext":[{"selector":"@a[r=5,c=1]"},{"translate":"missao.concluida.mensagem.publica.finale"}]}',
                    "playsound missioncomplete @s[tag=boss4,r=5,c=1] ~ ~ ~",
                    "scoreboard players set @s[tag=boss4] missaowell17 3",
                    "scoreboard players set @s[tag=boss4] missaowell18 1"
                ]);
            });
        return;
    }

    // Diálogo genérico
    mostrarDialogoComIcones(player, target, "dialogo.silpho.generico",
        ["opcoes.contratar", "opcoes.ok"],
        ["entendi", "okay"],
        () => {});
});

// =============================================
// NPC: KILE
// =============================================
world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;
    if (!player?.runCommand || target?.typeId !== "npc:kile") return;

    tocarSomEAnimacao(player);

    const score3 = world.scoreboard.getObjective("missaowell3")?.getScore(player) ?? 0;
    const score4 = world.scoreboard.getObjective("missaowell4")?.getScore(player) ?? 0;

    if (score3 === 1 && !player.getTags().includes("novice2")) {
        player.runCommand("tag @s add novice2"); // Garante tag para m3 ativa
    }

    if (score3 === 1) {
        mostrarDialogoComIcones(player, target, "dialogo.kile.polvoras",
            ["botao.subquest.mostrar", "botao.silpho.espada.nao"],
            ["quest3", "ainda_nao", "cancelar"],
            sel => {
                if (sel !== 0) return;
                const cond = "hasitem={item=gunpowder,quantity=5..}";
                runComandos(player, [
                    `tag @s[${cond},tag=novice2,r=5,c=1] add novice3`,
                    `tag @s[${cond},tag=novice3,r=5,c=1] remove novice2`,
                    `give @s[${cond},c=1,r=10] well:alma_da_arvore_item 1 0`,
                    `clear @s[${cond},tag=novice3,c=1,r=10] gunpowder 0 5`,
                    `titleraw @s[tag=novice3,r=5,c=1] title {"rawtext":[{"translate":"missao.atualizacao.titulo"}]}`,
                    `titleraw @s[tag=novice3,r=5,c=1] subtitle {"rawtext":[{"translate":"missao.atualizacao.subtitulo"}]}`,
                    `execute as @s[tag=novice3,r=5,c=1] run tellraw @a {"rawtext":[{"selector":"@a[r=5,c=1]"},{"translate":"missao.concluida.mensagem.publica.polvoras"}]}`,
                    "playsound missioncomplete @s[tag=novice3,r=5,c=1] ~ ~ ~",
                    "scoreboard players set @s[tag=novice3] missaowell3 3",
                    "scoreboard players set @s[tag=novice3] missaowell4 1"
                ]);
            });
        return;
    }

    if (score4 === 1) {
        mostrarDialogoComIcones(player, target, "dialogo.kile.alma_da_arvore",
            ["opcoes.contratar", "opcoes.ok"],
            ["entendi", "okay"],
            () => {});
        return;
    }

    mostrarDialogoComIcones(player, target, "dialogo.kile.generico",
        ["opcoes.contratar", "opcoes.ok"],
        ["entendi", "okay"],
        () => {});
});

// =============================================
// NPC: ALANA
// =============================================
world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;
    if (!player?.runCommand || target?.typeId !== "npc:alana") return;

    tocarSomEAnimacao(player, "npc.mulher.dialogue.adulta");

    player.runCommand("scoreboard players add @s horda 0");

    const selva = world.scoreboard.getObjective("Selva")?.getScore(player) ?? 0;
    const horda = world.scoreboard.getObjective("horda")?.getScore(player) ?? 0;
    const mw6 = world.scoreboard.getObjective("missaowell6")?.getScore(player) ?? 0;

    if (mw6 === 0 && selva === 1 && horda <= 7) {
        mostrarDialogoComIcones(player, target, "dialogo.alana.defesa_cidade_jungle",
            ["opcoes.ok", "botao.silpho.espada.nao"],
            ["quest4", "ainda_nao", "cancelar"],
            sel => {
                if (sel !== 0) return;
                const cmds = [];
                for (let i = 0; i < 6; i++) cmds.push("execute as @s[r=10,tag=adventure,scores={Selva=1}] run summon skeleton_horse ~ ~10 ~");
                for (let i = 0; i < 8; i++) cmds.push("execute as @s[r=10,tag=adventure,scores={Selva=1}] run summon well:skeleton_ataque ~ ~10 ~");
                cmds.push(
                    "scoreboard players add @s[tag=adventure,scores={Selva=1}] horda 0",
                    "scoreboard players add @s[tag=adventure,scores={Selva=1}] horda_iniciada 0",
                    "replaceitem entity @e[type=well:skeleton_ataque] slot.armor.head 0 iron_helmet",
                    "summon lightning_bolt ~ ~10 ~",
                    "playsound horda @a[r=20] ~ ~ ~",
                    "spawnpoint @s[r=10]",
                    "spreadplayers ~10 ~ 0 20 @e[r=50,type=!player,family=!npc,type=!npc:alana]",
                    "ride @e[type=well:skeleton_ataque,r=50] summon_ride skeleton_horse no_ride_change",
                    "ride @e[type=well:skeleton_ataque,r=50] summon_ride skeleton_horse reassign_rides"//,
                    //"summon skeleton_horse ~ ~10 ~ minecraft:set_trap"
                );
                runComandos(player, cmds);
            });
        return;
    }

    if (horda >= 8) {
        mostrarDialogoComIcones(player, target, "dialogo.alana.fertilizante_mistico",
            ["receber.recompensa", "botao.silpho.espada.nao"],
            ["recompensaquest4", "ainda_nao", "cancelar"],
            sel => {
                if (sel !== 0) return;
                runComandos(player, [
                    "tag @s[r=5,c=1,tag=adventure,scores={Selva=1,horda=8..}] add adventure1",
                    "give @s[r=5,c=1,tag=adventure,scores={Selva=1,horda=8..}] well:fertilizante_mistico 1 0",
                    "tag @s[r=5,c=1,tag=adventure,scores={Selva=1,horda=8..}] remove adventure",
                    "execute as @s[r=5,c=1,scores={Selva=1,horda=8..}] run kill @e[family=undead,r=60]",
                    'titleraw @s[r=5,c=1,tag=adventure1,scores={Selva=1,horda=8..}] title {"rawtext":[{"translate":"missao.atualizacao.titulo"}]}',
                    'titleraw @s[r=5,c=1,tag=adventure1,scores={Selva=1,horda=8..}] subtitle {"rawtext":[{"translate":"missao.atualizacao.subtitulo"}]}',
                    'execute as @s[r=5,c=1,tag=adventure1,scores={Selva=1,horda=8..}] run tellraw @a {"rawtext":[{"selector":"@a[r=5,c=1]"},{"translate":"missao.concluida.mensagem.publica.defesa_cidade_jungle"}]}',
                    "stopsound @s[r=5,c=1,tag=adventure1,scores={Selva=1,horda=8..}] horda",
                    "playsound missioncomplete @s[r=5,c=1,tag=adventure1,scores={Selva=1,horda=8..}] ~ ~ ~",
                    "scoreboard players set @s[r=10,tag=adventure1,scores={horda=8..}] horda 0",
                    "scoreboard players set @s[tag=adventure1] missaowell5 3",
                    "scoreboard players set @s[tag=adventure1] missaowell6 1"
                ]);
            });
        return;
    }

    if (mw6 === 1) {
        mostrarDialogoComIcones(player, target, "dialogo.alana.agradecimento",
            ["botao.dialogo.alana.sim", "opcoes.contratar"],
            ["entendi", "okay"],
            () => {});
        return;
    }

    mostrarDialogoComIcones(player, target, "dialogo.alana.generico",
        ["opcoes.contratar", "opcoes.ok"],
        ["entendi", "okay"],
        () => {});
});

// =============================================
// NPC: KARLOS
// =============================================
world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;
    if (!player?.runCommand || target?.typeId !== "npc:karlos") return;

    tocarSomEAnimacao(player, "npc.homem.dialogue.velho");

    const mw6 = world.scoreboard.getObjective("missaowell6")?.getScore(player) ?? 0;
    const fertilizante = world.scoreboard.getObjective("fertilizante")?.getScore(player) ?? 0;

    if (mw6 === 1 && fertilizante < 1) {
        mostrarDialogoComIcones(player, target, "dialogo.carlos.fertilizante_mistico1",
            ["botao.subquest.mostrar", "botao.silpho.espada.nao"],
            ["quest5", "ainda_nao", "cancelar"],
            () => {});
        return;
    }

    if (fertilizante >= 1) {
        mostrarDialogoComIcones(player, target, "dialogo.carlos.fertilizante_mistico2",
            ["receber.recompensa", "botao.silpho.espada.nao"],
            ["recompensaquest5", "ainda_nao", "cancelar"],
            sel => {
                if (sel !== 0) return;
                runComandos(player, [
                    "tag @s[scores={fertilizante=1},tag=adventure1,r=5,c=1] add adventure2",
                    "tag @s[scores={fertilizante=1},tag=adventure1,r=5,c=1] remove adventure1",
                    "give @s[scores={fertilizante=1},tag=adventure2,r=20,c=1] well:literatura_dos_arqueologos 1 0",
                    'titleraw @s[tag=adventure2,scores={fertilizante=1..2},r=5,c=1] title {"rawtext":[{"translate":"missao.atualizacao.titulo"}]}',
                    'titleraw @s[tag=adventure2,scores={fertilizante=1..2},r=5,c=1] subtitle {"rawtext":[{"translate":"missao.atualizacao.subtitulo"}]}',
                    "playsound missioncomplete @s[tag=adventure2,scores={fertilizante=1..2},r=5,c=1] ~ ~ ~",
                    'execute as @s[tag=adventure2,scores={fertilizante=1..2},r=5,c=1] run tellraw @a {"rawtext":[{"selector":"@a[r=5,c=1]"},{"translate":"missao.concluida.mensagem.publica.fertilizante_mistico"}]}',
                    "scoreboard players set @s[scores={fertilizante=1..},tag=adventure2,r=5,c=1] fertilizante 3",
                    "scoreboard players set @s[tag=adventure2] missaowell6 3",
                    "scoreboard players set @s[tag=adventure2] missaowell7 1"
                ]);
            });
        return;
    }

    mostrarDialogoComIcones(player, target, "dialogo.carlos.fertilizante_mistico1",
        ["opcoes.contratar", "opcoes.ok"],
        ["entendi", "okay"],
        () => {});
});

// =============================================
// NPC: NORD
// =============================================
world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;
    if (!player?.runCommand || target?.typeId !== "npc:nord") return;

    tocarSomEAnimacao(player, "npc.homem.dialogue.velho");

    const mw7 = world.scoreboard.getObjective("missaowell7")?.getScore(player) ?? 0;
    const mw8 = world.scoreboard.getObjective("missaowell8")?.getScore(player) ?? 0;

    if (mw7 === 1 && !player.getTags().includes("adventure2")) {
        player.runCommand("tag @s add adventure2");
    }

    if (mw7 === 1) {
        mostrarDialogoComIcones(player, target, "dialogo.nord.pergaminho",
            ["botao.subquest.mostrar", "botao.silpho.espada.nao"],
            ["quest6", "ainda_nao", "cancelar"],
            sel => {
                if (sel !== 0) return;
                runComandos(player, [
                    "tag @s[hasitem={item=well:literatura_dos_arqueologos},tag=adventure2,r=5,c=1] add adventure3",
                    "tag @s[hasitem={item=well:literatura_dos_arqueologos},tag=adventure2,r=5,c=1] remove adventure2",
                    'titleraw @s[hasitem={item=well:literatura_dos_arqueologos},tag=adventure3,r=10,c=1] title {"rawtext":[{"translate":"missao.atualizacao.titulo"}]}',
                    'titleraw @s[hasitem={item=well:literatura_dos_arqueologos},tag=adventure3,r=10,c=1] subtitle {"rawtext":[{"translate":"missao.atualizacao.subtitulo"}]}',
                    'execute as @s[hasitem={item=well:literatura_dos_arqueologos},tag=adventure3,r=10,c=1] run tellraw @a {"rawtext":[{"selector":"@a[r=5,c=1]"},{"translate":"missao.concluida.mensagem.publica.pergaminho"}]}',
                    "playsound missioncomplete @s[tag=adventure3,r=5,c=1] ~ ~ ~",
                    "clear @a[hasitem={item=well:literatura_dos_arqueologos},tag=adventure3,r=10,c=1] well:literatura_dos_arqueologos",
                    "scoreboard players set @s[tag=adventure3] missaowell7 3",
                    "scoreboard players set @s[tag=adventure3] missaowell8 1"
                ]);
            });
        return;
    }

    if (mw8 >= 1) {
        mostrarDialogoComIcones(player, target, "dialogo.nord.pergaminho.devolvido",
            ["botao.dialogo.alana.sim", "opcoes.contratar"],
            ["entendi", "okay"],
            () => {});
        return;
    }

    mostrarDialogoComIcones(player, target, "dialogo.nord.generico",
        ["opcoes.contratar", "opcoes.ok"],
        ["entendi", "okay"],
        () => {});
});

// =============================================
// NPC: OSSOS SECOS
// =============================================
world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;
    if (!player?.runCommand || target?.typeId !== "npc:ossos_secos") return;

    tocarSomEAnimacao(player, "mob.endermen.idle");

    const mw8 = world.scoreboard.getObjective("missaowell8")?.getScore(player) ?? 0;
    const mw9 = world.scoreboard.getObjective("missaowell9")?.getScore(player) ?? 0;

    if (mw8 === 1 && !player.getTags().includes("adventure3")) {
        player.runCommand("tag @s add adventure3");
    }

    if (mw8 === 1) {
        mostrarDialogoComIcones(player, target, "dialogo.ossos_secos.cabecas",
            ["botao.subquest.mostrar", "botao.silpho.espada.nao"],
            ["quest7", "ainda_nao", "cancelar"],
            sel => {
                if (sel !== 0) return;
                runComandos(player, [
                    "tag @s[hasitem={item=skull,quantity=5..,data=0},tag=adventure3,r=8,c=1] add adventure4",
                    "tag @s[hasitem={item=skull,quantity=5..,data=0},tag=adventure3,r=8,c=1] remove adventure3",
                    "give @s[hasitem={item=skull,quantity=5..,data=0},tag=adventure4,r=8,c=1] well:gelo_arcaico_item 1 0",
                    "give @s[hasitem={item=skull,quantity=5..,data=0},tag=adventure4,r=8,c=1] filled_map 1 7",
                    'titleraw @s[hasitem={item=skull,quantity=5..,data=0},tag=adventure4,r=8,c=1] title {"rawtext":[{"translate":"missao.atualizacao.titulo"}]}',
                    'titleraw @s[hasitem={item=skull,quantity=5..,data=0},tag=adventure4,r=8,c=1] subtitle {"rawtext":[{"translate":"missao.atualizacao.subtitulo"}]}',
                    'execute as @s[hasitem={item=skull,quantity=5..,data=0},tag=adventure4,r=8,c=1] run tellraw @a {"rawtext":[{"selector":"@a[r=5,c=1]"},{"translate":"missao.concluida.mensagem.publica.gelo_arcaico"}]}',
                    "playsound missioncomplete @s[tag=adventure4,r=8] ~ ~ ~",
                    "clear @a[hasitem={item=skull,quantity=5..,data=0},tag=adventure4,r=5,c=1] skull 0 5",
                    "scoreboard players set @s[tag=adventure4] missaowell8 3",
                    "scoreboard players set @s[tag=adventure4] missaowell9 1"
                ]);
            });
        return;
    }

    if (mw9 >= 1) {
        mostrarDialogoComIcones(player, target, "dialogo.ossos_secos.cabecas.entregues",
            ["botao.dialogo.alana.sim", "opcoes.contratar"],
            ["entendi", "okay"],
            () => {});
        return;
    }

    mostrarDialogoComIcones(player, target, "dialogo.ossos.generico",
        ["opcoes.contratar", "opcoes.ok"],
        ["entendi", "okay"],
        () => {});
});

// =============================================
// BARDO MESTRE
// =============================================
world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;
    if (!player?.runCommand || target?.typeId !== "npc:bardo_mestre") return;
    tocarSomEAnimacao(player);

    const discos = [1,2,3,4,5].map(n => 
        world.scoreboard.getObjective(`discos${n}`)?.getScore(player) ?? 0
    );
    const mw13 = world.scoreboard.getObjective("missaowell13")?.getScore(player) ?? 0;
    const mw14 = world.scoreboard.getObjective("missaowell14")?.getScore(player) ?? 0;

    const todosDiscosEntregues = discos.every(score => score >= 2); // ← ALTERADO (era >=1)

    if (mw13 === 1) {
        if (todosDiscosEntregues) {
            mostrarDialogoComIcones(player, target, "dialogo.bardo.mestre",
                ["receber.recompensa", "botao.silpho.espada.nao"],
                ["quest9", "ainda_nao", "cancelar"],
                sel => {
                    if (sel !== 0) return;
                    runComandos(player, [
                        "tag @s[scores={discos1=2..,discos2=2..,discos3=2..,discos4=2..,discos5=2..},tag=hero,r=8] add hero1", // ← ALTERADO (era 1..)
                        "scoreboard players set @s[scores={discos1=2..,discos2=2..,discos3=2..,discos4=2..,discos5=2..},tag=hero,r=8] discos_completo 1",
                        "tag @s[scores={discos_completo=1},r=8] remove hero",
                        'titleraw @s[scores={discos_completo=1},r=8] title {"rawtext":[{"translate":"missao.atualizacao.titulo"}]}',
                        'titleraw @s[scores={discos_completo=1},r=8] subtitle {"rawtext":[{"translate":"missao.atualizacao.subtitulo"}]}',
                        'execute as @s[scores={discos_completo=1},r=8] run tellraw @a {"rawtext":[{"selector":"@a[r=5,c=1]"},{"translate":"missao.concluida.mensagem.publica.discos_dos_bardos"}]}',
                        "playsound missioncomplete @s[scores={discos_completo=1},r=8] ~ ~ ~",
                        "give @s[scores={discos_completo=1},r=8] well:flauta_do_deserto 1 0",
                        "execute as @s[scores={discos_completo=1},r=8] run playsound bardos.felizes @s ~ ~ ~",
                        "execute as @s[scores={discos_completo=1},r=8] run playanimation @e[family=bardos] animation.piglin.celebrate_hunt_special i 80",
                        "scoreboard players set @s[tag=hero1] missaowell13 3",
                        "scoreboard players set @s[tag=hero1] discos1 0",
                        "scoreboard players set @s[tag=hero1] discos2 0",
                        "scoreboard players set @s[tag=hero1] discos3 0",
                        "scoreboard players set @s[tag=hero1] discos4 0",
                        "scoreboard players set @s[tag=hero1] discos5 0",
                        "scoreboard players set @s[tag=hero1] missaowell14 1"
                    ]);
                });
        } else {
            mostrarDialogoComIcones(player, target, "dialogo.bardo.mestre",
                ["opcoes.contratar", "opcoes.ok"],
                ["entendi", "okay"],
                () => {});
        }
        return;
    }

    if (mw14 === 1) {
        mostrarDialogoComIcones(player, target, "dialogo.bardo.mestre.flauta",
            ["opcoes.contratar", "opcoes.ok"],
            ["entendi", "okay"],
            sel => {
                if (sel === 0) {
                    runComandos(player, [
                        "execute as @s[scores={discos_completo=1},r=8] run playsound bardos.felizes @s ~ ~ ~",
                        "execute as @s[scores={discos_completo=1},r=8] run playanimation @e[family=bardos] animation.piglin.celebrate_hunt_special i 80",
                        "scoreboard players set @s missaowell14 3",
                        "scoreboard players set @s missaowell15 1"
                    ]);
                }
            });
        return;
    }

    mostrarDialogoComIcones(player, target, "dialogo.bardo.mestre",
        ["opcoes.contratar", "opcoes.ok"],
        ["entendi", "okay"],
        () => {});
});

// =============================================
// BARDO 1
// =============================================
world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;
    if (!player?.runCommand || target?.typeId !== "npc:bardo1") return;

    tocarSomEAnimacao(player);

    const scoreDisco = world.scoreboard.getObjective("discos1")?.getScore(player) ?? 0;
    const scoreMissao = world.scoreboard.getObjective("missaowell13")?.getScore(player) ?? 0;

    if (scoreDisco === 0 && scoreMissao === 1) {
        mostrarDialogoComIcones(
            player,
            target,
            "dialogo.bardo1.disco",
            ["botao.subquest.sim", "bardo.button.nao"],
            ["discos_bardos", "ainda_nao"],
            sel => {
                if (sel !== 0) return;

                runComandos(player, [
                    "scoreboard players set @s [hasitem={item=well:disco1},tag=hero,r=5,c=1] discos1 2",
                    "titleraw @s [hasitem={item=well:disco1},tag=hero,r=5,c=1] title {\"rawtext\":[{\"translate\":\"missao.atualizacao.titulo\"}]}",
                    "titleraw @s [hasitem={item=well:disco1},tag=hero,r=5,c=1] subtitle {\"rawtext\":[{\"translate\":\"bardo.disco.entregue.name\"}]}",
                    "execute as @s [hasitem={item=well:disco1},tag=hero,r=5,c=1] run tellraw @a {\"rawtext\":[{\"selector\":\"@a[r=5,c=1]\"},{\"translate\":\"um.disco.devolvido\"}]}",
                    "playsound missioncomplete @s [tag=hero,scores={discos1=2}] ~ ~ ~",
                    "execute as @s [hasitem={item=well:disco1},tag=hero,r=5,c=1] run event entity @e[type=npc:bardo1,r=10] bardo_feliz",
                    "execute as @s [hasitem={item=well:disco1},tag=hero,r=5,c=1] run event entity @e[type=npc:bardo1,r=10] bardo1",
                    "clear @s [tag=hero,hasitem={item=well:disco1}] well:disco1 0 1",
                    "scoreboard players set @s [scores={discos1=2..},tag=hero] discos2 1"
                ]);
            }
        );
        return;
    }

    if (scoreDisco >= 2 && scoreMissao === 1) {
        mostrarDialogoComIcones(
            player,
            target,
            "dialogo.bardo.feliz",
            ["botao.dialogo.alana.sim", "opcoes.contratar"],
            ["entendi", "okay"],
            () => {}
        );
        return;
    }

    mostrarDialogoComIcones(
        player,
        target,
        "dialogo.bardo1.disco",
        ["opcoes.contratar", "opcoes.ok"],
        ["entendi", "okay"],
        () => {}
    );
});

// =============================================
// BARDO 2
// =============================================
world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;
    if (!player?.runCommand || target?.typeId !== "npc:bardo2") return;

    tocarSomEAnimacao(player);

    const scoreDisco = world.scoreboard.getObjective("discos2")?.getScore(player) ?? 0;
    const scoreMissao = world.scoreboard.getObjective("missaowell13")?.getScore(player) ?? 0;

    if (scoreDisco === 1 && scoreMissao === 1) {
        mostrarDialogoComIcones(
            player,
            target,
            "dialogo.bardo2.disco",
            ["botao.subquest.sim", "bardo.button.nao"],
            ["discos_bardos", "ainda_nao"],
            sel => {
                if (sel !== 0) return;

                runComandos(player, [
                    "scoreboard players set @s [hasitem={item=well:disco2},tag=hero,r=5,c=1] discos2 2",
                    "titleraw @s [hasitem={item=well:disco2},tag=hero,r=5,c=1] title {\"rawtext\":[{\"translate\":\"missao.atualizacao.titulo\"}]}",
                    "titleraw @s [hasitem={item=well:disco2},tag=hero,r=5,c=1] subtitle {\"rawtext\":[{\"translate\":\"bardo.disco.entregue.name\"}]}",
                    "execute as @s [hasitem={item=well:disco2},tag=hero,r=5,c=1] run tellraw @a {\"rawtext\":[{\"selector\":\"@a[r=5,c=1]\"},{\"translate\":\"um.disco.devolvido\"}]}",
                    "playsound missioncomplete @s [tag=hero,scores={discos2=2}] ~ ~ ~",
                    "execute as @s [hasitem={item=well:disco2},tag=hero,r=5,c=1] run event entity @e[type=npc:bardo2,r=10] bardo_feliz",
                    "execute as @s [hasitem={item=well:disco2},tag=hero,r=5,c=1] run event entity @e[type=npc:bardo2,r=10] bardo2",
                    "clear @s [tag=hero,hasitem={item=well:disco2}] well:disco2 0 1",
                    "scoreboard players set @s [scores={discos2=2..},tag=hero] discos3 1"
                ]);
            }
        );
        return;
    }

    if (scoreDisco >= 2 && scoreMissao === 1) {
        mostrarDialogoComIcones(
            player,
            target,
            "dialogo.bardo.feliz",
            ["botao.dialogo.alana.sim", "opcoes.contratar"],
            ["entendi", "okay"],
            () => {}
        );
        return;
    }

    mostrarDialogoComIcones(
        player,
        target,
        "dialogo.bardo2.disco",
        ["opcoes.contratar", "opcoes.ok"],
        ["entendi", "okay"],
        () => {}
    );
});

// =============================================
// BARDO 3
// =============================================
world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;
    if (!player?.runCommand || target?.typeId !== "npc:bardo3") return;

    tocarSomEAnimacao(player);

    const scoreDisco = world.scoreboard.getObjective("discos3")?.getScore(player) ?? 0;
    const scoreMissao = world.scoreboard.getObjective("missaowell13")?.getScore(player) ?? 0;

    if (scoreDisco === 1 && scoreMissao === 1) {
        mostrarDialogoComIcones(
            player,
            target,
            "dialogo.bardo3.disco",
            ["botao.subquest.sim", "bardo.button.nao"],
            ["discos_bardos", "ainda_nao"],
            sel => {
                if (sel !== 0) return;

                runComandos(player, [
                    "scoreboard players set @s [hasitem={item=well:disco3},tag=hero,r=5,c=1] discos3 2",
                    "titleraw @s [hasitem={item=well:disco3},tag=hero,r=5,c=1] title {\"rawtext\":[{\"translate\":\"missao.atualizacao.titulo\"}]}",
                    "titleraw @s [hasitem={item=well:disco3},tag=hero,r=5,c=1] subtitle {\"rawtext\":[{\"translate\":\"bardo.disco.entregue.name\"}]}",
                    "execute as @s [hasitem={item=well:disco3},tag=hero,r=5,c=1] run tellraw @a {\"rawtext\":[{\"selector\":\"@a[r=5,c=1]\"},{\"translate\":\"um.disco.devolvido\"}]}",
                    "playsound missioncomplete @s [tag=hero,scores={discos3=2}] ~ ~ ~",
                    "execute as @s [hasitem={item=well:disco3},tag=hero,r=5,c=1] run event entity @e[type=npc:bardo3,r=10] bardo_feliz",
                    "execute as @s [hasitem={item=well:disco3},tag=hero,r=5,c=1] run event entity @e[type=npc:bardo3,r=10] bardo3",
                    "clear @s [tag=hero,hasitem={item=well:disco3}] well:disco3 0 1",
                    "scoreboard players set @s [scores={discos3=2..},tag=hero] discos4 1"
                ]);
            }
        );
        return;
    }

    if (scoreDisco >= 2 && scoreMissao === 1) {
        mostrarDialogoComIcones(
            player,
            target,
            "dialogo.bardo.feliz",
            ["botao.dialogo.alana.sim", "opcoes.contratar"],
            ["entendi", "okay"],
            () => {}
        );
        return;
    }

    mostrarDialogoComIcones(
        player,
        target,
        "dialogo.bardo3.disco",
        ["opcoes.contratar", "opcoes.ok"],
        ["entendi", "okay"],
        () => {}
    );
});

// =============================================
// BARDO 4
// =============================================
world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;
    if (!player?.runCommand || target?.typeId !== "npc:bardo4") return;

    tocarSomEAnimacao(player);

    const scoreDisco = world.scoreboard.getObjective("discos4")?.getScore(player) ?? 0;
    const scoreMissao = world.scoreboard.getObjective("missaowell13")?.getScore(player) ?? 0;

    if (scoreDisco === 1 && scoreMissao === 1) {
        mostrarDialogoComIcones(
            player,
            target,
            "dialogo.bardo4.disco",
            ["botao.subquest.sim", "bardo.button.nao"],
            ["discos_bardos", "ainda_nao"],
            sel => {
                if (sel !== 0) return;

                runComandos(player, [
                    "scoreboard players set @s [hasitem={item=well:disco4},tag=hero,r=5,c=1] discos4 2",
                    "titleraw @s [hasitem={item=well:disco4},tag=hero,r=5,c=1] title {\"rawtext\":[{\"translate\":\"missao.atualizacao.titulo\"}]}",
                    "titleraw @s [hasitem={item=well:disco4},tag=hero,r=5,c=1] subtitle {\"rawtext\":[{\"translate\":\"bardo.disco.entregue.name\"}]}",
                    "execute as @s [hasitem={item=well:disco4},tag=hero,r=5,c=1] run tellraw @a {\"rawtext\":[{\"selector\":\"@a[r=5,c=1]\"},{\"translate\":\"um.disco.devolvido\"}]}",
                    "playsound missioncomplete @s [tag=hero,scores={discos4=2}] ~ ~ ~",
                    "execute as @s [hasitem={item=well:disco4},tag=hero,r=5,c=1] run event entity @e[type=npc:bardo4,r=10] bardo_feliz",
                    "execute as @s [hasitem={item=well:disco4},tag=hero,r=5,c=1] run event entity @e[type=npc:bardo4,r=10] bardo4",
                    "clear @s [tag=hero,hasitem={item=well:disco4}] well:disco4 0 1",
                    "scoreboard players set @s [scores={discos4=2..},tag=hero] discos5 1"
                ]);
            }
        );
        return;
    }

    if (scoreDisco >= 2 && scoreMissao === 1) {
        mostrarDialogoComIcones(
            player,
            target,
            "dialogo.bardo.feliz",
            ["botao.dialogo.alana.sim", "opcoes.contratar"],
            ["entendi", "okay"],
            () => {}
        );
        return;
    }

    mostrarDialogoComIcones(
        player,
        target,
        "dialogo.bardo4.disco",
        ["opcoes.contratar", "opcoes.ok"],
        ["entendi", "okay"],
        () => {}
    );
});

// =============================================
// BARDO 5 (último)
// =============================================
world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;
    if (!player?.runCommand || target?.typeId !== "npc:bardo5") return;

    tocarSomEAnimacao(player);

    const scoreDisco = world.scoreboard.getObjective("discos5")?.getScore(player) ?? 0;
    const scoreMissao = world.scoreboard.getObjective("missaowell13")?.getScore(player) ?? 0;

    if (scoreDisco === 1 && scoreMissao === 1) {
        mostrarDialogoComIcones(
            player,
            target,
            "dialogo.bardo5.disco",
            ["botao.subquest.sim", "bardo.button.nao"],
            ["discos_bardos", "ainda_nao"],
            sel => {
                if (sel !== 0) return;

                runComandos(player, [
                    "scoreboard players set @s [hasitem={item=well:disco5},tag=hero,r=5,c=1] discos5 2",
                    "titleraw @s [hasitem={item=well:disco5},tag=hero,r=5,c=1] title {\"rawtext\":[{\"translate\":\"missao.atualizacao.titulo\"}]}",
                    "titleraw @s [hasitem={item=well:disco5},tag=hero,r=5,c=1] subtitle {\"rawtext\":[{\"translate\":\"bardo.disco.entregue.name\"}]}",
                    "execute as @s [hasitem={item=well:disco5},tag=hero,r=5,c=1] run tellraw @a {\"rawtext\":[{\"selector\":\"@a[r=5,c=1]\"},{\"translate\":\"um.disco.devolvido\"}]}",
                    "playsound missioncomplete @s [tag=hero,scores={discos5=2}] ~ ~ ~",
                    "execute as @s [hasitem={item=well:disco5},tag=hero,r=5,c=1] run event entity @e[type=npc:bardo5,r=10] bardo_feliz",
                    "execute as @s [hasitem={item=well:disco5},tag=hero,r=5,c=1] run event entity @e[type=npc:bardo5,r=10] bardo5",
                    "clear @s [tag=hero,hasitem={item=well:disco5}] well:disco5 0 1"
                    // Sem liberar próximo se for o último
                ]);
            }
        );
        return;
    }

    if (scoreDisco >= 2 && scoreMissao === 1) {
        mostrarDialogoComIcones(
            player,
            target,
            "dialogo.bardo.feliz",
            ["botao.dialogo.alana.sim", "opcoes.contratar"],
            ["entendi", "okay"],
            () => {}
        );
        return;
    }

    mostrarDialogoComIcones(
        player,
        target,
        "dialogo.bardo5.disco",
        ["opcoes.contratar", "opcoes.ok"],
        ["entendi", "okay"],
        () => {}
    );
});

// =============================================
// NPC: HILDA
// =============================================
world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;
    if (!player?.runCommand || target?.typeId !== "npc:hilda") return;

    tocarSomEAnimacao(player, "npc.mulher.dialogue.jovem");

    const obj0 = world.scoreboard.getObjective("missaowell15");
    const obj1 = world.scoreboard.getObjective("missaowell16");
    const score0 = obj0?.getScore(player) ?? 0;
    const score1 = obj1?.getScore(player) ?? 0;

    // Missão ativa (score0 === 3 && score1 === 1) → diálogo de ajudar/entregar
    if (score0 === 3 && score1 === 1) {
        mostrarDialogoComIcones(
            player,
            target,
            "dialogo.hilda.flauta_obtida",
            ["dialogo.hilda.ajudar.sim", "opcoes.contratar"],
            ["quest11", "okay"],  // quest11 = ícone da chave Hilda, okay = check neutro
            sel => {
                if (sel !== 0) return;  // só prossegue se clicou no botão "sim" (posição 0)

                runComandos(player, [
                    "tag @s [hasitem={item=well:chave_hilda, quantity=1..}, tag=hero3, scores={chave=3}, r=10] add hero4",
                    "tag @s [hasitem={item=well:chave_hilda, quantity=1..}, tag=hero3, scores={chave=3}, r=10] remove hero3",
                    "give @s [tag=hero4, hasitem={item=well:chave_hilda, quantity=1}, scores={chave=3}, r=10] well:amuleto_de_farao_item 1 0",
                    "clear @s [hasitem={item=well:chave_hilda, quantity=1}, tag=hero4, scores={chave=3}, r=10] well:chave_hilda",
                    "clear @s [hasitem={item=well:flauta_do_deserto, quantity=1..}, tag=hero4, scores={chave=3}, r=10] well:flauta_do_deserto",
                    "titleraw @s [tag=hero4, scores={chave=3}, r=10, c=1] title {\"rawtext\":[{\"translate\":\"missao.atualizacao.titulo\"}]}",
                    "titleraw @s [tag=hero4, scores={chave=3}, r=10, c=1] subtitle {\"rawtext\":[{\"translate\":\"missao.atualizacao.subtitulo\"}]}",
                    "execute as @s [tag=hero4, scores={chave=3}, r=5, c=1] run tellraw @a {\"rawtext\":[{\"selector\":\"@a[r=5,c=1]\"},{\"translate\":\"missao.concluida.mensagem.amuleto_de_farao\"}]}",
                    "playsound missioncomplete @s [tag=hero4, r=5, c=1] ~ ~ ~",
                    "scoreboard players set @s [tag=hero4] missaowell16 3",
                    "scoreboard players set @s [tag=hero4] missaowell17 1"
                ]);
            }
        );
        return;
    }
	
	if (score0 === 0 && score1 === 1) {
        mostrarDialogoComIcones(
            player,
            target,
            "dialogo.hilda.flauta_obtida",
            ["dialogo.hilda.ajudar.sim", "opcoes.contratar"],
            ["entendi", "okay"],  // quest11 = ícone da chave Hilda, okay = check neutro
            sel => {
                if (sel !== 0) return;  // só prossegue se clicou no botão "sim" (posição 0)

                runComandos(player, [
                    ""
                ]);
            }
        );
        return;
    }

    // Caso padrão (nenhuma missão ativa ou condição não atendida) → diálogo genérico
    mostrarDialogoComIcones(
        player,
        target,
        "dialogo.hilda.flauta",
        ["opcoes.contratar", "opcoes.ok"],
        ["entendi", "okay"],
        () => {}
    );
});


// =============================================
// NPC: LUNDON
// =============================================
world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;
    if (!player?.runCommand || target?.typeId !== "npc:lundon") return;
    tocarSomEAnimacao(player, "npc.homem.dialogue.velho");
    const mw15 = world.scoreboard.getObjective("missaowell15")?.getScore(player) ?? 0;
    const mw16 = world.scoreboard.getObjective("missaowell16")?.getScore(player) ?? 0;
    if (mw15 === 1 && !player.getTags().includes("hero2")) {
        //player.runCommand("tag @s add hero2");
    }
    if (mw15 === 0 && mw16 === 1) {
        mostrarDialogoComIcones(player, target, "dialogo.chaveiro.chave",
            ["botao.subquest.sim", "botao.silpho.espada.nao"],
            ["quest12", "ainda_nao", "cancelar"],
            sel => {
                if (sel !== 0) return;
                runComandos(player, [
                    "scoreboard players add @p [hasitem={item=well:gema_cristalina,quantity=1..},scores={chave=0},tag=hero2,r=10] chave 1",
                    "tag @s [hasitem={item=well:gema_cristalina,quantity=1..},scores={chave=1},tag=hero2,r=10] add hero3",
                    "tag @s [hasitem={item=well:gema_cristalina,quantity=1..},scores={chave=1},tag=hero2,r=10] remove hero2",
                    "clear @p [hasitem={item=well:gema_cristalina,quantity=1..},tag=hero3,r=10] well:gema_cristalina",
                    "give @p [scores={chave=1},tag=hero3,r=10] well:chave_hilda 1 0",
                    'titleraw @p [tag=hero3,scores={chave=1},r=10,c=1] title {"rawtext":[{"translate":"missao.atualizacao.titulo"}]}',
                    'titleraw @p [tag=hero3,scores={chave=1},r=10,c=1] subtitle {"rawtext":[{"translate":"missao.atualizacao.subtitulo"}]}',
                    'execute as @p [tag=hero3,scores={chave=1},r=5,c=1] run tellraw @a {"rawtext":[{"selector":"@a[r=5,c=1]"},{"translate":"missao.concluida.mensagem.gema_cristalina"}]}',
                    "playsound missioncomplete @p [tag=hero3,scores={chave=1},r=5,c=1] ~ ~ ~",
                    "scoreboard players set @p [tag=hero3,scores={chave=1},r=5,c=1] chave 3",
                    "scoreboard players set @s [tag=hero3] missaowell15 3",
                    "scoreboard players set @s [tag=hero3] missaowell16 1"
                ]);
            });
        return;
    }
    if (mw16 === 1) {
        mostrarDialogoComIcones(player, target, "dialogo.chaveiro.gema_cristalina_obtida",
            ["receber.recompensa", "opcoes.ok"],
            ["recompensaquest12", "okay"],
            () => {});
        return;
    }
    mostrarDialogoComIcones(player, target, "dialogo.lundon.generico",
        ["opcoes.contratar", "opcoes.ok"],
        ["entendi", "okay"],
        () => {});
});


///SUBQUESTS HUMANOS
world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;

    if (!player || !player.runCommand) return;
    if (target.typeId !== "well:npc25") return;

    const obj0 = world.scoreboard.getObjective("subquest_5");
	const obj1 = world.scoreboard.getObjective("mineiracao"); //mineiracao=100
	
    const score0 = obj0?.getScore(player);
	const score1 = obj1?.getScore(player);
	
	//player.runCommand("playsound npc.homem.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.adulto @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.jovem @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.velho @p [r=5]");
    
    //player.runCommand("playsound npc.mulher.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.velha @p [r=5]");
    player.runCommand("playsound npc.mulher.dialogue.adulta @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.jovem @p [r=5]");
    //player.runCommand("effect @e[type=!player,r=5] slowness 20 60 true");
  
    const chance = Math.random();
        if (chance < 0.25) {
          player.runCommand("playanimation @e[type=!player,r=5] animation.humanoid.custom.well.dialogo1");
        } else if (chance < 0.5) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo2");
        } else if (chance < 0.75) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo3");
        } else {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo4");
        }
    
	//DIALOGO DA MISSAO
    if (score0 === 0 && score1 >= 100) {
        const nina1 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eNina')
            .body({"rawtext": [{"translate": "dialogo.5.subquest"}]})
            .button({"rawtext": [{"translate": "botao.subquest.aceitar"}]}, "textures/ui/permissions_visitor_hand.png")
            .button({"rawtext": [{"translate": "botao.subquest.sim"}]}, "textures/items/itens_misticos/erva_gato.png")
			.button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina1.show(player).then(result => {
        if (result.canceled) return;
        switch (result.selection) {
            case 0:
                player.runCommand("tag @s [r=5, scores={subquest_5=0, mineiracao=100..}] add subquest5");
                player.runCommand("tag @s [r=5, scores={subquest_5=0, mineiracao=100..}] remove subquest0");
                player.runCommand("titleraw @s [r=5, scores={subquest_5=0, mineiracao=100..}] title {\"rawtext\":[{ \"translate\":\"subquest.aceitou.titulo\" }]}");
                player.runCommand("titleraw @s [r=5, scores={subquest_5=0, mineiracao=100..}] subtitle {\"rawtext\":[{ \"translate\":\"subquest.aceitou.subtitulo\" }]}");
                player.runCommand("tag @s [r=5, scores={subquest_5=0, mineiracao=100..}] remove subquest1");
                player.runCommand("tag @s [r=5, scores={subquest_5=0, mineiracao=100..}] remove subquest3");
                player.runCommand("tag @s [r=5, scores={subquest_5=0, mineiracao=100..}] remove subquest4");
                player.runCommand("tag @s [r=5, scores={subquest_5=0, mineiracao=100..}] remove subquest2");
                player.runCommand("tag @s [r=5, scores={subquest_5=0, mineiracao=100..}] remove subquest6");
                player.runCommand("tag @s [r=5, scores={subquest_5=0, mineiracao=100..}] remove subquest7");
                player.runCommand("tag @s [r=5, scores={subquest_5=0, mineiracao=100..}] remove subquest8");
                player.runCommand("tag @s [r=5, scores={subquest_5=0, mineiracao=100..}] remove subquest9");
                player.runCommand("tag @s [r=5, scores={subquest_5=0, mineiracao=100..}] remove subquest10");
                player.runCommand("tag @s [r=5, scores={subquest_5=0, mineiracao=100..}] remove subquest11");
                player.runCommand("tag @s [r=5, scores={subquest_5=0, mineiracao=100..}] remove subquest12");
                player.runCommand("tag @s [r=5, scores={subquest_5=0, mineiracao=100..}] remove subquest13");
                player.runCommand("tag @s [r=5, scores={subquest_5=0, mineiracao=100..}] remove subquest14");
                player.runCommand("tag @s [r=5, scores={subquest_5=0, mineiracao=100..}] remove subquest15");
                player.runCommand("tag @s [r=5, scores={subquest_5=0, mineiracao=100..}] remove subquest16");
                player.runCommand("tag @s [r=5, scores={subquest_5=0, mineiracao=100..}] remove subquest17");
                player.runCommand("tag @s [r=5, scores={subquest_5=0, mineiracao=100..}] remove subquest18");
                player.runCommand("tag @s [r=5, scores={subquest_5=0, mineiracao=100..}] remove subquest19");
                player.runCommand("tag @s [r=5, scores={subquest_5=0, mineiracao=100..}] remove subquest20");
                player.runCommand("tag @s [r=5, scores={subquest_5=0, mineiracao=100..}] remove subquest21");
                player.runCommand("tag @s [r=5, scores={subquest_5=0, mineiracao=100..}] remove subquest22");
                player.runCommand("tag @s [r=5, scores={subquest_5=0, mineiracao=100..}] remove subquest23");
                player.runCommand("tag @s [r=5, scores={subquest_5=0, mineiracao=100..}] remove subquest24");
                player.runCommand("tag @s [r=5, scores={subquest_5=0, mineiracao=100..}] remove subquest25");
                player.runCommand("tag @s [r=5, scores={subquest_5=0, mineiracao=100..}] remove subquest26");
                player.runCommand("tag @s [r=5, scores={subquest_5=0, mineiracao=100..}] remove subquest27");
                player.runCommand("tag @s [r=5, scores={subquest_5=0, mineiracao=100..}] remove subquest28");
                player.runCommand("tag @s [r=5, scores={subquest_5=0, mineiracao=100..}] remove subquest29");
                player.runCommand("tag @s [r=5, scores={subquest_5=0, mineiracao=100..}] remove subquest30");
				
				
                break;
            
			case 1:
                player.runCommand("give @p [r=5, scores={subquest_5=0}, hasitem={item=well:erva_de_gato, quantity=1..}] well:orbe_evolutiva 1 0");
                player.runCommand("give @p [r=5, scores={subquest_5=0}, hasitem={item=well:erva_de_gato, quantity=1..}] well:container_coracao 1 0");
                player.runCommand("tag @p [r=5, scores={subquest_5=0}, hasitem={item=well:erva_de_gato, quantity=1..}] remove subquest5");
                player.runCommand("scoreboard players add @p [r=5, scores={subquest_5=0}, hasitem={item=well:erva_de_gato, quantity=1..}] subquest_5 1");
                player.runCommand("clear @p [r=5, scores={subquest_5=1..}, hasitem={item=well:erva_de_gato, quantity=1..}] well:erva_de_gato 0 10");
                player.runCommand("titleraw @p [r=5, scores={subquest_5=1}, c=1] title {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_5=1}, c=1] subtitle {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.subtitulo\" }]}");
                player.runCommand("execute as @p [r=5, scores={subquest_5=1}, c=1] run tellraw @a {\"rawtext\":[{\"selector\": \"@a[r=5,c=1]\"},{ \"translate\":\"subquest.concluida.mensagem.publica.5\" }]}");
                player.runCommand("playsound missioncomplete @p [r=5, scores={subquest_5=1}, c=1] ~ ~ ~");
                player.runCommand("scoreboard players set @p [r=5, scores={subquest_5=1}] subquest_5 2");
                player.runCommand("tag @p [r=5, scores={subquest_5=2}] add subquest0");
				
				
                break;
            
			case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DE REQUISITOS
	if (score0 === 0 && score1 < 100) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eNina')
            .body({"rawtext": [{"translate": "dialogo.subquest5.requisitos"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DA MISSAO CUMPRIDA
	if (score0 >= 1) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eNina')
            .body({"rawtext": [{"translate": "dialogo.subquest5.cumprida"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
});

world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;

    if (!player || !player.runCommand) return;
    if (target.typeId !== "well:npc30") return;

    const obj0 = world.scoreboard.getObjective("subquest_2");
	const obj1 = world.scoreboard.getObjective("coleta_madeira"); //mineiracao=50
	
    const score0 = obj0?.getScore(player);
	const score1 = obj1?.getScore(player);
	
	//player.runCommand("playsound npc.homem.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.adulto @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.jovem @p [r=5]");
    player.runCommand("playsound npc.homem.dialogue.velho @p [r=5]");
    
    //player.runCommand("playsound npc.mulher.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.velha @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.adulta @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.jovem @p [r=5]");
    //player.runCommand("effect @e[type=!player,r=5] slowness 20 60 true");
  
    const chance = Math.random();
        if (chance < 0.25) {
          player.runCommand("playanimation @e[type=!player,r=5] animation.humanoid.custom.well.dialogo1");
        } else if (chance < 0.5) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo2");
        } else if (chance < 0.75) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo3");
        } else {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo4");
        }
    
	//DIALOGO DA MISSAO
    if (score0 === 0 && score1 >= 50) {
        const nina1 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eTristan')
            .body({"rawtext": [{"translate": "dialogo.2.subquest"}]})
			
            .button({"rawtext": [{"translate": "botao.subquest.aceitar"}]}, "textures/ui/permissions_visitor_hand.png")
            .button({"rawtext": [{"translate": "botao.subquest.sim"}]}, "textures/items/clock_item.png")
			.button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina1.show(player).then(result => {
        if (result.canceled) return;
        switch (result.selection) {
            case 0:
                player.runCommand("tag @p [r=5, scores={subquest_2=0, coleta_madeira=50..}] remove subquest0");
                player.runCommand("tag @p [r=5, scores={subquest_2=0, coleta_madeira=50..}] add subquest2");
                player.runCommand("titleraw @p [r=5, scores={subquest_2=0, coleta_madeira=50..}] title {\"rawtext\":[{ \"translate\":\"subquest.aceitou.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_2=0, coleta_madeira=50..}] subtitle {\"rawtext\":[{ \"translate\":\"subquest.aceitou.subtitulo\" }]}");
                player.runCommand("tag @p [r=5, scores={subquest_2=0, coleta_madeira=50..}] remove subquest1");
                player.runCommand("tag @p [r=5, scores={subquest_2=0, coleta_madeira=50..}] remove subquest3");
                player.runCommand("tag @p [r=5, scores={subquest_2=0, coleta_madeira=50..}] remove subquest4");
                player.runCommand("tag @p [r=5, scores={subquest_2=0, coleta_madeira=50..}] remove subquest5");
                player.runCommand("tag @p [r=5, scores={subquest_2=0, coleta_madeira=50..}] remove subquest6");
                player.runCommand("tag @p [r=5, scores={subquest_2=0, coleta_madeira=50..}] remove subquest7");
                player.runCommand("tag @p [r=5, scores={subquest_2=0, coleta_madeira=50..}] remove subquest8");
                player.runCommand("tag @p [r=5, scores={subquest_2=0, coleta_madeira=50..}] remove subquest9");
                player.runCommand("tag @p [r=5, scores={subquest_2=0, coleta_madeira=50..}] remove subquest10");
                player.runCommand("tag @p [r=5, scores={subquest_2=0, coleta_madeira=50..}] remove subquest11");
                player.runCommand("tag @p [r=5, scores={subquest_2=0, coleta_madeira=50..}] remove subquest12");
                player.runCommand("tag @p [r=5, scores={subquest_2=0, coleta_madeira=50..}] remove subquest13");
                player.runCommand("tag @p [r=5, scores={subquest_2=0, coleta_madeira=50..}] remove subquest14");
                player.runCommand("tag @p [r=5, scores={subquest_2=0, coleta_madeira=50..}] remove subquest15");
                player.runCommand("tag @p [r=5, scores={subquest_2=0, coleta_madeira=50..}] remove subquest16");
                player.runCommand("tag @p [r=5, scores={subquest_2=0, coleta_madeira=50..}] remove subquest17");
                player.runCommand("tag @p [r=5, scores={subquest_2=0, coleta_madeira=50..}] remove subquest18");
                player.runCommand("tag @p [r=5, scores={subquest_2=0, coleta_madeira=50..}] remove subquest19");
                player.runCommand("tag @p [r=5, scores={subquest_2=0, coleta_madeira=50..}] remove subquest20");
                player.runCommand("tag @p [r=5, scores={subquest_2=0, coleta_madeira=50..}] remove subquest21");
                player.runCommand("tag @p [r=5, scores={subquest_2=0, coleta_madeira=50..}] remove subquest22");
                player.runCommand("tag @p [r=5, scores={subquest_2=0, coleta_madeira=50..}] remove subquest23");
                player.runCommand("tag @p [r=5, scores={subquest_2=0, coleta_madeira=50..}] remove subquest24");
                player.runCommand("tag @p [r=5, scores={subquest_2=0, coleta_madeira=50..}] remove subquest25");
                player.runCommand("tag @p [r=5, scores={subquest_2=0, coleta_madeira=50..}] remove subquest26");
                player.runCommand("tag @p [r=5, scores={subquest_2=0, coleta_madeira=50..}] remove subquest27");
                player.runCommand("tag @p [r=5, scores={subquest_2=0, coleta_madeira=50..}] remove subquest28");
                player.runCommand("tag @p [r=5, scores={subquest_2=0, coleta_madeira=50..}] remove subquest29");
                player.runCommand("tag @p [r=5, scores={subquest_2=0, coleta_madeira=50..}] remove subquest30");
				
				
                break;
            
			case 1:
                player.runCommand("give @p [r=5, scores={subquest_2=0}, hasitem={item=clock, quantity=1..}] well:orbe_evolutiva 1 0 ");
                player.runCommand("give @p [r=5, scores={subquest_2=0}, hasitem={item=clock, quantity=1..}] well:container_coracao 1 0 "); 
                player.runCommand("tag @p [r=5, scores={subquest_2=0}, hasitem={item=clock, quantity=1..}] remove subquest2");
                player.runCommand("scoreboard players add @p [r=5, scores={subquest_2=0}, hasitem={item=clock, quantity=1..}] subquest_2 1");
                player.runCommand("clear @p [r=5, scores={subquest_2=1..}, hasitem={item=clock, quantity=1..}] clock 0 10");
                player.runCommand("titleraw @p [r=5, scores={subquest_2=1}, c=1] title {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_2=1}, c=1] subtitle {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.subtitulo\" }]}");
                player.runCommand("execute as @p [r=5, scores={subquest_2=1}, c=1] run tellraw @a {\"rawtext\":[{\"selector\": \"@a[r=5,c=1]\"},{ \"translate\":\"subquest.concluida.mensagem.publica.2\" }]}");
                player.runCommand("playsound missioncomplete @p [r=5, scores={subquest_2=1}, c=1] ~ ~ ~");
                player.runCommand("scoreboard players set @p [r=5, scores={subquest_2=1}] subquest_2 2");
                player.runCommand("tag @p [r=5, scores={subquest_2=2}] add subquest0");
                				
				
                break;
            
			case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DE REQUISITOS
	if (score0 === 0 && score1 < 50) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eTristan')
            .body({"rawtext": [{"translate": "dialogo.subquest2.requisitos"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DA MISSAO CUMPRIDA
	if (score0 >= 1) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eTristan')
            .body({"rawtext": [{"translate": "dialogo.subquest2.cumprida"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
});

world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;

    if (!player || !player.runCommand) return;
    if (target.typeId !== "well:npc21") return;

    const obj0 = world.scoreboard.getObjective("subquest_3");
	const obj1 = world.scoreboard.getObjective("mineiracao"); //mineiracao=40
	
    

    const score0 = obj0?.getScore(player);
	const score1 = obj1?.getScore(player);
	
	//player.runCommand("playsound npc.homem.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.adulto @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.jovem @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.velho @p [r=5]");
    
    //player.runCommand("playsound npc.mulher.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.velha @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.adulta @p [r=5]");
    player.runCommand("playsound npc.mulher.dialogue.jovem @p [r=5]");
    //player.runCommand("effect @e[type=!player,r=5] slowness 20 60 true");
  
    const chance = Math.random();
        if (chance < 0.25) {
          player.runCommand("playanimation @e[type=!player,r=5] animation.humanoid.custom.well.dialogo1");
        } else if (chance < 0.5) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo2");
        } else if (chance < 0.75) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo3");
        } else {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo4");
        }
    
	//DIALOGO DA MISSAO
    if (score0 === 0 && score1 >= 40) {
        const nina1 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eJhenifer')
            .body({"rawtext": [{"translate": "dialogo.3.subquest"}]})
            .button({"rawtext": [{"translate": "botao.subquest.aceitar"}]}, "textures/ui/permissions_visitor_hand.png")
            .button({"rawtext": [{"translate": "botao.subquest.sim"}]}, "textures/items/nautilus.png")
			.button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina1.show(player).then(result => {
        if (result.canceled) return;
        switch (result.selection) {
            case 0:
                player.runCommand("tag @p [r=5, scores={subquest_3=0, mineiracao=40..}] remove subquest0");
                player.runCommand("tag @p [r=5, scores={subquest_3=0, mineiracao=40..}] add subquest3");
                player.runCommand("titleraw @p [r=5, scores={subquest_3=0, mineiracao=40..}] title {\"rawtext\":[{ \"translate\":\"subquest.aceitou.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_3=0, mineiracao=40..}] subtitle {\"rawtext\":[{ \"translate\":\"subquest.aceitou.subtitulo\" }]}");
                player.runCommand("tag @p [r=5, scores={subquest_3=0, mineiracao=40..}] remove subquest1");
                player.runCommand("tag @p [r=5, scores={subquest_3=0, mineiracao=40..}] remove subquest2");
                player.runCommand("tag @p [r=5, scores={subquest_3=0, mineiracao=40..}] remove subquest4");
                player.runCommand("tag @p [r=5, scores={subquest_3=0, mineiracao=40..}] remove subquest5");
                player.runCommand("tag @p [r=5, scores={subquest_3=0, mineiracao=40..}] remove subquest6");
                player.runCommand("tag @p [r=5, scores={subquest_3=0, mineiracao=40..}] remove subquest7");
                player.runCommand("tag @p [r=5, scores={subquest_3=0, mineiracao=40..}] remove subquest8");
                player.runCommand("tag @p [r=5, scores={subquest_3=0, mineiracao=40..}] remove subquest9");
                player.runCommand("tag @p [r=5, scores={subquest_3=0, mineiracao=40..}] remove subquest10");
                player.runCommand("tag @p [r=5, scores={subquest_3=0, mineiracao=40..}] remove subquest11");
                player.runCommand("tag @p [r=5, scores={subquest_3=0, mineiracao=40..}] remove subquest12");
                player.runCommand("tag @p [r=5, scores={subquest_3=0, mineiracao=40..}] remove subquest13");
                player.runCommand("tag @p [r=5, scores={subquest_3=0, mineiracao=40..}] remove subquest14");
                player.runCommand("tag @p [r=5, scores={subquest_3=0, mineiracao=40..}] remove subquest15");
                player.runCommand("tag @p [r=5, scores={subquest_3=0, mineiracao=40..}] remove subquest16");
                player.runCommand("tag @p [r=5, scores={subquest_3=0, mineiracao=40..}] remove subquest17");
                player.runCommand("tag @p [r=5, scores={subquest_3=0, mineiracao=40..}] remove subquest18");
                player.runCommand("tag @p [r=5, scores={subquest_3=0, mineiracao=40..}] remove subquest19");
                player.runCommand("tag @p [r=5, scores={subquest_3=0, mineiracao=40..}] remove subquest20");
                player.runCommand("tag @p [r=5, scores={subquest_3=0, mineiracao=40..}] remove subquest21");
                player.runCommand("tag @p [r=5, scores={subquest_3=0, mineiracao=40..}] remove subquest22");
                player.runCommand("tag @p [r=5, scores={subquest_3=0, mineiracao=40..}] remove subquest23");
                player.runCommand("tag @p [r=5, scores={subquest_3=0, mineiracao=40..}] remove subquest24");
                player.runCommand("tag @p [r=5, scores={subquest_3=0, mineiracao=40..}] remove subquest25");
                player.runCommand("tag @p [r=5, scores={subquest_3=0, mineiracao=40..}] remove subquest26");
                player.runCommand("tag @p [r=5, scores={subquest_3=0, mineiracao=40..}] remove subquest27");
                player.runCommand("tag @p [r=5, scores={subquest_3=0, mineiracao=40..}] remove subquest28");
                player.runCommand("tag @p [r=5, scores={subquest_3=0, mineiracao=40..}] remove subquest29");
                player.runCommand("tag @p [r=5, scores={subquest_3=0, mineiracao=40..}] remove subquest30");
				
				
                break;
            
			case 1:
                player.runCommand("give @p [r=5, scores={subquest_3=0}, hasitem={item=nautilus_shell, quantity=1..}] well:orbe_evolutiva 1 0");
                player.runCommand("give @p [r=5, scores={subquest_3=0}, hasitem={item=nautilus_shell, quantity=1..}] well:container_coracao 1 0"); 
                player.runCommand("tag @p [r=5, scores={subquest_3=0}, hasitem={item=nautilus_shell, quantity=1..}] remove subquest3");
                player.runCommand("scoreboard players add @p [r=5, scores={subquest_3=0}, hasitem={item=nautilus_shell, quantity=1..}] subquest_3 1");
                player.runCommand("clear @p [r=5, scores={subquest_3=1..}, hasitem={item=nautilus_shell, quantity=1..}] nautilus_shell 0 10");
                player.runCommand("titleraw @p [r=5, scores={subquest_3=1}, c=1] title {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_3=1}, c=1] subtitle {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.subtitulo\" }]}");
                player.runCommand("execute as @p [r=5, scores={subquest_3=1}, c=1] run tellraw @a {\"rawtext\":[{\"selector\": \"@a[r=5,c=1]\"},{ \"translate\":\"subquest.concluida.mensagem.publica.3\" }]}");
                player.runCommand("playsound missioncomplete @p [r=5, scores={subquest_3=1}, c=1] ~ ~ ~");
                player.runCommand("scoreboard players set @p [r=5, scores={subquest_3=1}] subquest_3 2");
                player.runCommand("tag @p [r=5, scores={subquest_3=2}] add subquest0");
                				
				
                break;
            
			case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DE REQUISITOS
	if (score0 === 0 && score1 < 40) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eJhenifer')
            .body({"rawtext": [{"translate": "dialogo.subquest3.requisitos"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DA MISSAO CUMPRIDA
	if (score0 >= 1) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eJhenifer')
            .body({"rawtext": [{"translate": "dialogo.subquest3.cumprida"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
});

world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;

    if (!player || !player.runCommand) return;
    if (target.typeId !== "well:npc27") return;

    const obj0 = world.scoreboard.getObjective("subquest_7");
	const obj1 = world.scoreboard.getObjective("pescaria"); //pescaria=40
	
    

    const score0 = obj0?.getScore(player);
	const score1 = obj1?.getScore(player);
	
	//player.runCommand("playsound npc.homem.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.adulto @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.jovem @p [r=5]");
    player.runCommand("playsound npc.homem.dialogue.velho @p [r=5]");
    
    //player.runCommand("playsound npc.mulher.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.velha @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.adulta @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.jovem @p [r=5]");
    //player.runCommand("effect @e[type=!player,r=5] slowness 20 60 true");
  
    const chance = Math.random();
        if (chance < 0.25) {
          player.runCommand("playanimation @e[type=!player,r=5] animation.humanoid.custom.well.dialogo1");
        } else if (chance < 0.5) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo2");
        } else if (chance < 0.75) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo3");
        } else {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo4");
        }
    
	//DIALOGO DA MISSAO
    if (score0 === 0 && score1 >= 40) {
        const nina1 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eVitor')
            .body({"rawtext": [{"translate": "dialogo.7.subquest"}]})
            .button({"rawtext": [{"translate": "botao.subquest.aceitar"}]}, "textures/ui/permissions_visitor_hand.png")
            .button({"rawtext": [{"translate": "botao.subquest.sim"}]}, "textures/items/goat_horn.png")
			.button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina1.show(player).then(result => {
        if (result.canceled) return;
        switch (result.selection) {
            case 0:
                player.runCommand("tag @p [r=5, scores={subquest_7=0, pescaria=40..}] remove subquest0");
                player.runCommand("tag @p [r=5, scores={subquest_7=0, pescaria=40..}] add subquest7");
                player.runCommand("titleraw @p [r=5, scores={subquest_7=0, pescaria=40..}] title {\"rawtext\":[{ \"translate\":\"subquest.aceitou.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_7=0, pescaria=40..}] subtitle {\"rawtext\":[{ \"translate\":\"subquest.aceitou.subtitulo\" }]}");
                player.runCommand("tag @p [r=5, scores={subquest_7=0, pescaria=40..}] remove subquest1");
                player.runCommand("tag @p [r=5, scores={subquest_7=0, pescaria=40..}] remove subquest2");
                player.runCommand("tag @p [r=5, scores={subquest_7=0, pescaria=40..}] remove subquest4");
                player.runCommand("tag @p [r=5, scores={subquest_7=0, pescaria=40..}] remove subquest5");
                player.runCommand("tag @p [r=5, scores={subquest_7=0, pescaria=40..}] remove subquest6");
                player.runCommand("tag @p [r=5, scores={subquest_7=0, pescaria=40..}] remove subquest13");
                player.runCommand("tag @p [r=5, scores={subquest_7=0, pescaria=40..}] remove subquest8");
                player.runCommand("tag @p [r=5, scores={subquest_7=0, pescaria=40..}] remove subquest9");
                player.runCommand("tag @p [r=5, scores={subquest_7=0, pescaria=40..}] remove subquest10");
                player.runCommand("tag @p [r=5, scores={subquest_7=0, pescaria=40..}] remove subquest11");
                player.runCommand("tag @p [r=5, scores={subquest_7=0, pescaria=40..}] remove subquest12");
                player.runCommand("tag @p [r=5, scores={subquest_7=0, pescaria=40..}] remove subquest3");
                player.runCommand("tag @p [r=5, scores={subquest_7=0, pescaria=40..}] remove subquest14");
                player.runCommand("tag @p [r=5, scores={subquest_7=0, pescaria=40..}] remove subquest15");
                player.runCommand("tag @p [r=5, scores={subquest_7=0, pescaria=40..}] remove subquest16");
                player.runCommand("tag @p [r=5, scores={subquest_7=0, pescaria=40..}] remove subquest17");
                player.runCommand("tag @p [r=5, scores={subquest_7=0, pescaria=40..}] remove subquest18");
                player.runCommand("tag @p [r=5, scores={subquest_7=0, pescaria=40..}] remove subquest19");
                player.runCommand("tag @p [r=5, scores={subquest_7=0, pescaria=40..}] remove subquest20");
                player.runCommand("tag @p [r=5, scores={subquest_7=0, pescaria=40..}] remove subquest21");
                player.runCommand("tag @p [r=5, scores={subquest_7=0, pescaria=40..}] remove subquest22");
                player.runCommand("tag @p [r=5, scores={subquest_7=0, pescaria=40..}] remove subquest23");
                player.runCommand("tag @p [r=5, scores={subquest_7=0, pescaria=40..}] remove subquest24");
                player.runCommand("tag @p [r=5, scores={subquest_7=0, pescaria=40..}] remove subquest25");
                player.runCommand("tag @p [r=5, scores={subquest_7=0, pescaria=40..}] remove subquest26");
                player.runCommand("tag @p [r=5, scores={subquest_7=0, pescaria=40..}] remove subquest27");
                player.runCommand("tag @p [r=5, scores={subquest_7=0, pescaria=40..}] remove subquest28");
                player.runCommand("tag @p [r=5, scores={subquest_7=0, pescaria=40..}] remove subquest29");
                player.runCommand("tag @p [r=5, scores={subquest_7=0, pescaria=40..}] remove subquest30");
				
				
                break;
            
			case 1:
                player.runCommand("give @p [r=5, scores={subquest_7=0}, hasitem={item=goat_horn, quantity=1..}] well:orbe_evolutiva 1 0 ");
                player.runCommand("give @p [r=5, scores={subquest_7=0}, hasitem={item=goat_horn, quantity=1..}] well:container_coracao 1 0 "); 
                player.runCommand("tag @p [r=5, scores={subquest_7=0}, hasitem={item=goat_horn, quantity=1..}] remove subquest7");
                player.runCommand("scoreboard players add @p [r=5, scores={subquest_7=0}, hasitem={item=goat_horn, quantity=1..}] subquest_7 1");
                player.runCommand("clear @p [r=5, scores={subquest_7=1}, hasitem={item=goat_horn, quantity=1..}] goat_horn 0 10");
                player.runCommand("titleraw @p [r=5, scores={subquest_7=1}, c=1] title {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_7=1}, c=1] subtitle {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.subtitulo\" }]}");
                player.runCommand("execute as @p [r=5, scores={subquest_7=1}, c=1] run tellraw @a {\"rawtext\":[{\"selector\": \"@a[r=5,c=1]\"},{ \"translate\":\"subquest.concluida.mensagem.publica.7\" }]}");
                player.runCommand("playsound missioncomplete @p [r=5, scores={subquest_7=1}, c=1] ~ ~ ~");
                player.runCommand("scoreboard players set @p [r=5, scores={subquest_7=1}] subquest_7 2");
                player.runCommand("tag @p [r=5, scores={subquest_7=2}] add subquest0");
                				
				
                break;
            
			case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DE REQUISITOS
	if (score0 === 0 && score1 < 40) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eVitor')
            .body({"rawtext": [{"translate": "dialogo.subquest7.requisitos"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DA MISSAO CUMPRIDA
	if (score0 >= 1) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eVitor')
            .body({"rawtext": [{"translate": "dialogo.subquest7.cumprida"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
});

world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;

    if (!player || !player.runCommand) return;
    if (target.typeId !== "well:npc22") return;

    const obj0 = world.scoreboard.getObjective("subquest_13");
	const obj1 = world.scoreboard.getObjective("pescaria"); //pescaria=80
	
    

    const score0 = obj0?.getScore(player);
	const score1 = obj1?.getScore(player);
	
	//player.runCommand("playsound npc.homem.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.adulto @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.jovem @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.velho @p [r=5]");
    
    //player.runCommand("playsound npc.mulher.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.velha @p [r=5]");
    player.runCommand("playsound npc.mulher.dialogue.adulta @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.jovem @p [r=5]");
    //player.runCommand("effect @e[type=!player,r=5] slowness 20 60 true");
  
    const chance = Math.random();
        if (chance < 0.25) {
          player.runCommand("playanimation @e[type=!player,r=5] animation.humanoid.custom.well.dialogo1");
        } else if (chance < 0.5) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo2");
        } else if (chance < 0.75) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo3");
        } else {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo4");
        }
    
	//DIALOGO DA MISSAO
    if (score0 === 0 && score1 >= 80) {
        const nina1 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eDayse')
            .body({"rawtext": [{"translate": "dialogo.13.subquest"}]})
            .button({"rawtext": [{"translate": "botao.subquest.aceitar"}]}, "textures/ui/permissions_visitor_hand.png")
            .button({"rawtext": [{"translate": "botao.subquest.mostrar"}]}, "textures/ui/pergaminhos/icones_submissoes/parrot.png")
			.button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina1.show(player).then(result => {
        if (result.canceled) return;
        switch (result.selection) {
            case 0:
                player.runCommand("tag @p [r=5, scores={subquest_13=0, pescaria=80..}] remove subquest0");
                player.runCommand("tag @p [r=5, scores={subquest_13=0, pescaria=80..}] add subquest13");
                player.runCommand("titleraw @p [r=5, scores={subquest_13=0, pescaria=80..}] title {\"rawtext\":[{ \"translate\":\"subquest.aceitou.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_13=0, pescaria=80..}] subtitle {\"rawtext\":[{ \"translate\":\"subquest.aceitou.subtitulo\" }]}");
                player.runCommand("tag @p [r=5, scores={subquest_13=0, pescaria=80..}] remove subquest1");
                player.runCommand("tag @p [r=5, scores={subquest_13=0, pescaria=80..}] remove subquest2");
                player.runCommand("tag @p [r=5, scores={subquest_13=0, pescaria=80..}] remove subquest4");
                player.runCommand("tag @p [r=5, scores={subquest_13=0, pescaria=80..}] remove subquest5");
                player.runCommand("tag @p [r=5, scores={subquest_13=0, pescaria=80..}] remove subquest6");
                player.runCommand("tag @p [r=5, scores={subquest_13=0, pescaria=80..}] remove subquest7");
                player.runCommand("tag @p [r=5, scores={subquest_13=0, pescaria=80..}] remove subquest8");
                player.runCommand("tag @p [r=5, scores={subquest_13=0, pescaria=80..}] remove subquest9");
                player.runCommand("tag @p [r=5, scores={subquest_13=0, pescaria=80..}] remove subquest10");
                player.runCommand("tag @p [r=5, scores={subquest_13=0, pescaria=80..}] remove subquest11");
                player.runCommand("tag @p [r=5, scores={subquest_13=0, pescaria=80..}] remove subquest12");
                player.runCommand("tag @p [r=5, scores={subquest_13=0, pescaria=80..}] remove subquest3");
                player.runCommand("tag @p [r=5, scores={subquest_13=0, pescaria=80..}] remove subquest14");
                player.runCommand("tag @p [r=5, scores={subquest_13=0, pescaria=80..}] remove subquest15");
                player.runCommand("tag @p [r=5, scores={subquest_13=0, pescaria=80..}] remove subquest16");
                player.runCommand("tag @p [r=5, scores={subquest_13=0, pescaria=80..}] remove subquest17");
                player.runCommand("tag @p [r=5, scores={subquest_13=0, pescaria=80..}] remove subquest18");
                player.runCommand("tag @p [r=5, scores={subquest_13=0, pescaria=80..}] remove subquest19");
                player.runCommand("tag @p [r=5, scores={subquest_13=0, pescaria=80..}] remove subquest20");
                player.runCommand("tag @p [r=5, scores={subquest_13=0, pescaria=80..}] remove subquest21");
                player.runCommand("tag @p [r=5, scores={subquest_13=0, pescaria=80..}] remove subquest22");
                player.runCommand("tag @p [r=5, scores={subquest_13=0, pescaria=80..}] remove subquest23");
                player.runCommand("tag @p [r=5, scores={subquest_13=0, pescaria=80..}] remove subquest24");
                player.runCommand("tag @p [r=5, scores={subquest_13=0, pescaria=80..}] remove subquest25");
                player.runCommand("tag @p [r=5, scores={subquest_13=0, pescaria=80..}] remove subquest26");
                player.runCommand("tag @p [r=5, scores={subquest_13=0, pescaria=80..}] remove subquest27");
                player.runCommand("tag @p [r=5, scores={subquest_13=0, pescaria=80..}] remove subquest28");
                player.runCommand("tag @p [r=5, scores={subquest_13=0, pescaria=80..}] remove subquest29");
                player.runCommand("tag @p [r=5, scores={subquest_13=0, pescaria=80..}] remove subquest30");
				
				
                break;
            
			case 1:
                // recompensas
                player.runCommand("execute as @e[type=parrot,r=10] run give @p[r=5,scores={subquest_13=0}] well:orbe_evolutiva 1 0");
                player.runCommand("execute as @e[type=parrot,r=10] run give @p[r=5,scores={subquest_13=0}] well:container_coracao 1 0");
            
                // ❌ LINHA BUGADA REMOVIDA (tinha type=parrot no @p)
            
                // progresso da quest
                player.runCommand("execute as @e[type=parrot,c=5,r=10] run scoreboard players add @p[r=5,scores={subquest_13=0}] subquest_13 1");
            
                // mensagens
                player.runCommand("titleraw @p[r=5,scores={subquest_13=1},c=1] title {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.titulo\" }]}");
                player.runCommand("titleraw @p[r=5,scores={subquest_13=1},c=1] subtitle {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.subtitulo\" }]}");
                player.runCommand("execute as @p[r=5,scores={subquest_13=1},c=1] run tellraw @a {\"rawtext\":[{\"selector\":\"@a[r=5,c=1]\"},{\"translate\":\"subquest.concluida.mensagem.publica.13\"}]}");
                player.runCommand("playsound missioncomplete @p[r=5,scores={subquest_13=1},c=1] ~ ~ ~");
            
                // 🦜 SUMIR COM O PAPAGAIO (FIX REAL)
                player.runCommand("tag @e[type=parrot,r=20] add quest13_parrot");
                player.runCommand("execute as @e[tag=quest13_parrot] run tp @s ~ -100 ~");
                player.runCommand("kill @e[tag=quest13_parrot]");
            
                // finalizar quest
                player.runCommand("scoreboard players set @p[r=5,scores={subquest_13=1}] subquest_13 2");
                player.runCommand("tag @p[r=5,scores={subquest_13=2}] add subquest0");
            
                break;

			case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DE REQUISITOS
	if (score0 === 0 && score1 < 80) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eDayse')
            .body({"rawtext": [{"translate": "dialogo.subquest13.requisitos"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DA MISSAO CUMPRIDA
	if (score0 >= 1) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eDayse')
            .body({"rawtext": [{"translate": "dialogo.subquest13.cumprida"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
});


world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;

    if (!player || !player.runCommand) return;
    if (target.typeId !== "well:npc28") return;

    const obj0 = world.scoreboard.getObjective("subquest_14");
	const obj1 = world.scoreboard.getObjective("coleta_madeira"); //coleta_madeira=100
	
    

    const score0 = obj0?.getScore(player);
	const score1 = obj1?.getScore(player);
	
	//player.runCommand("playsound npc.homem.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.adulto @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.jovem @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.velho @p [r=5]");
    
    //player.runCommand("playsound npc.mulher.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.velha @p [r=5]");
    player.runCommand("playsound npc.mulher.dialogue.adulta @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.jovem @p [r=5]");
    //player.runCommand("effect @e[type=!player,r=5] slowness 20 60 true");
  
    const chance = Math.random();
        if (chance < 0.25) {
          player.runCommand("playanimation @e[type=!player,r=5] animation.humanoid.custom.well.dialogo1");
        } else if (chance < 0.5) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo2");
        } else if (chance < 0.75) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo3");
        } else {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo4");
        }
    
	//DIALOGO DA MISSAO
    if (score0 === 0 && score1 >= 100) {
        const nina1 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eLarissa')
            .body({"rawtext": [{"translate": "dialogo.14.subquest"}]})
            .button({"rawtext": [{"translate": "botao.subquest.aceitar"}]}, "textures/ui/permissions_visitor_hand.png")
            .button({"rawtext": [{"translate": "botao.subquest.mostrar"}]}, "textures/ui/pergaminhos/icones_submissoes/strider.png")
			.button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina1.show(player).then(result => {
        if (result.canceled) return;
        switch (result.selection) {
            case 0:
                player.runCommand("tag @p [r=5, scores={subquest_14=0, coleta_madeira=100..}] remove subquest0");
                player.runCommand("tag @p [r=5, scores={subquest_14=0, coleta_madeira=100..}] add subquest14");
                player.runCommand("titleraw @p [r=5, scores={subquest_14=0, coleta_madeira=100..}] title {\"rawtext\":[{ \"translate\":\"subquest.aceitou.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_14=0, coleta_madeira=100..}] subtitle {\"rawtext\":[{ \"translate\":\"subquest.aceitou.subtitulo\" }]}");
                player.runCommand("tag @p [r=5, scores={subquest_14=0, coleta_madeira=100..}] remove subquest1");
                player.runCommand("tag @p [r=5, scores={subquest_14=0, coleta_madeira=100..}] remove subquest2");
                player.runCommand("tag @p [r=5, scores={subquest_14=0, coleta_madeira=100..}] remove subquest4");
                player.runCommand("tag @p [r=5, scores={subquest_14=0, coleta_madeira=100..}] remove subquest5");
                player.runCommand("tag @p [r=5, scores={subquest_14=0, coleta_madeira=100..}] remove subquest6");
                player.runCommand("tag @p [r=5, scores={subquest_14=0, coleta_madeira=100..}] remove subquest7");
                player.runCommand("tag @p [r=5, scores={subquest_14=0, coleta_madeira=100..}] remove subquest8");
                player.runCommand("tag @p [r=5, scores={subquest_14=0, coleta_madeira=100..}] remove subquest9");
                player.runCommand("tag @p [r=5, scores={subquest_14=0, coleta_madeira=100..}] remove subquest10");
                player.runCommand("tag @p [r=5, scores={subquest_14=0, coleta_madeira=100..}] remove subquest11");
                player.runCommand("tag @p [r=5, scores={subquest_14=0, coleta_madeira=100..}] remove subquest12");
                player.runCommand("tag @p [r=5, scores={subquest_14=0, coleta_madeira=100..}] remove subquest3");
                player.runCommand("tag @p [r=5, scores={subquest_14=0, coleta_madeira=100..}] remove subquest13");
                player.runCommand("tag @p [r=5, scores={subquest_14=0, coleta_madeira=100..}] remove subquest15");
                player.runCommand("tag @p [r=5, scores={subquest_14=0, coleta_madeira=100..}] remove subquest16");
                player.runCommand("tag @p [r=5, scores={subquest_14=0, coleta_madeira=100..}] remove subquest17");
                player.runCommand("tag @p [r=5, scores={subquest_14=0, coleta_madeira=100..}] remove subquest18");
                player.runCommand("tag @p [r=5, scores={subquest_14=0, coleta_madeira=100..}] remove subquest19");
                player.runCommand("tag @p [r=5, scores={subquest_14=0, coleta_madeira=100..}] remove subquest20");
                player.runCommand("tag @p [r=5, scores={subquest_14=0, coleta_madeira=100..}] remove subquest21");
                player.runCommand("tag @p [r=5, scores={subquest_14=0, coleta_madeira=100..}] remove subquest22");
                player.runCommand("tag @p [r=5, scores={subquest_14=0, coleta_madeira=100..}] remove subquest23");
                player.runCommand("tag @p [r=5, scores={subquest_14=0, coleta_madeira=100..}] remove subquest24");
                player.runCommand("tag @p [r=5, scores={subquest_14=0, coleta_madeira=100..}] remove subquest25");
                player.runCommand("tag @p [r=5, scores={subquest_14=0, coleta_madeira=100..}] remove subquest26");
                player.runCommand("tag @p [r=5, scores={subquest_14=0, coleta_madeira=100..}] remove subquest27");
                player.runCommand("tag @p [r=5, scores={subquest_14=0, coleta_madeira=100..}] remove subquest28");
                player.runCommand("tag @p [r=5, scores={subquest_14=0, coleta_madeira=100..}] remove subquest29");
                player.runCommand("tag @p [r=5, scores={subquest_14=0, coleta_madeira=100..}] remove subquest30");
				
				
                break;
            
			case 1:
                    // recompensas
                    player.runCommand("execute as @e[type=strider,r=10] run give @p[r=5,scores={subquest_14=0}] well:orbe_evolutiva 1 0");
                    player.runCommand("execute as @e[type=strider,r=10] run give @p[r=5,scores={subquest_14=0}] well:container_coracao 1 0");
                
                    // ❌ linha inválida removida (type=strider no @p)
                
                    // progresso da quest
                    player.runCommand("execute as @e[type=strider,r=10] run scoreboard players add @p[r=5,scores={subquest_14=0}] subquest_14 1");
                
                    // mensagens
                    player.runCommand("titleraw @p[r=5,scores={subquest_14=1},c=1] title {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.titulo\" }]}");
                    player.runCommand("titleraw @p[r=5,scores={subquest_14=1},c=1] subtitle {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.subtitulo\" }]}");
                    player.runCommand("execute as @p[r=5,scores={subquest_14=1},c=1] run tellraw @a {\"rawtext\":[{\"selector\":\"@a[r=5,c=1]\"},{\"translate\":\"subquest.concluida.mensagem.publica.14\"}]}");
                    player.runCommand("playsound missioncomplete @p[r=5,scores={subquest_14=1},c=1] ~ ~ ~");
                
                    // 🐛 dispara evento no strider corretamente
                    player.runCommand("execute as @e[type=strider,r=20] run event entity @s add_contagem");
                
                    // finalizar quest
                    player.runCommand("scoreboard players set @p[r=5,scores={subquest_14=1}] subquest_14 2");
                    player.runCommand("tag @p[r=5,scores={subquest_14=2}] add subquest0");
                
                break;

            
			case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DE REQUISITOS
	if (score0 === 0 && score1 < 100) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eLarissa')
            .body({"rawtext": [{"translate": "dialogo.subquest14.requisitos"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DA MISSAO CUMPRIDA
	if (score0 >= 1) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eLarissa')
            .body({"rawtext": [{"translate": "dialogo.subquest14.cumprida"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
});

world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;

    if (!player || !player.runCommand) return;
    if (target.typeId !== "well:npc26") return;

    const obj0 = world.scoreboard.getObjective("subquest_15");
	const obj1 = world.scoreboard.getObjective("coleta_madeira"); //coleta_madeira=200
	
    

    const score0 = obj0?.getScore(player);
	const score1 = obj1?.getScore(player);
	
	//player.runCommand("playsound npc.homem.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.adulto @p [r=5]");
    player.runCommand("playsound npc.homem.dialogue.jovem @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.velho @p [r=5]");
    
    //player.runCommand("playsound npc.mulher.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.velha @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.adulta @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.jovem @p [r=5]");
    //player.runCommand("effect @e[type=!player,r=5] slowness 20 60 true");
  
    const chance = Math.random();
        if (chance < 0.25) {
          player.runCommand("playanimation @e[type=!player,r=5] animation.humanoid.custom.well.dialogo1");
        } else if (chance < 0.5) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo2");
        } else if (chance < 0.75) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo3");
        } else {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo4");
        }
    
	//DIALOGO DA MISSAO
    if (score0 === 0 && score1 >= 200) {
        const nina1 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eYago')
            .body({"rawtext": [{"translate": "dialogo.15.subquest"}]})
            .button({"rawtext": [{"translate": "botao.subquest.aceitar"}]}, "textures/ui/permissions_visitor_hand.png")
            .button({"rawtext": [{"translate": "botao.subquest.mostrar"}]}, "textures/ui/pergaminhos/icones_submissoes/sapo.png")
			.button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina1.show(player).then(result => {
        if (result.canceled) return;
        switch (result.selection) {
            case 0:
                player.runCommand("tag @p [r=5, scores={subquest_15=0, coleta_madeira=200..}] remove subquest0");
                player.runCommand("tag @p [r=5, scores={subquest_15=0, coleta_madeira=200..}] add subquest15");
                player.runCommand("titleraw @p [r=5, scores={subquest_15=0, coleta_madeira=200..}] title {\"rawtext\":[{ \"translate\":\"subquest.aceitou.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_15=0, coleta_madeira=200..}] subtitle {\"rawtext\":[{ \"translate\":\"subquest.aceitou.subtitulo\" }]}");
                player.runCommand("tag @p [r=5, scores={subquest_15=0, coleta_madeira=200..}] remove subquest1");
                player.runCommand("tag @p [r=5, scores={subquest_15=0, coleta_madeira=200..}] remove subquest2");
                player.runCommand("tag @p [r=5, scores={subquest_15=0, coleta_madeira=200..}] remove subquest4");
                player.runCommand("tag @p [r=5, scores={subquest_15=0, coleta_madeira=200..}] remove subquest5");
                player.runCommand("tag @p [r=5, scores={subquest_15=0, coleta_madeira=200..}] remove subquest6");
                player.runCommand("tag @p [r=5, scores={subquest_15=0, coleta_madeira=200..}] remove subquest7");
                player.runCommand("tag @p [r=5, scores={subquest_15=0, coleta_madeira=200..}] remove subquest8");
                player.runCommand("tag @p [r=5, scores={subquest_15=0, coleta_madeira=200..}] remove subquest9");
                player.runCommand("tag @p [r=5, scores={subquest_15=0, coleta_madeira=200..}] remove subquest10");
                player.runCommand("tag @p [r=5, scores={subquest_15=0, coleta_madeira=200..}] remove subquest11");
                player.runCommand("tag @p [r=5, scores={subquest_15=0, coleta_madeira=200..}] remove subquest12");
                player.runCommand("tag @p [r=5, scores={subquest_15=0, coleta_madeira=200..}] remove subquest3");
                player.runCommand("tag @p [r=5, scores={subquest_15=0, coleta_madeira=200..}] remove subquest14");
                player.runCommand("tag @p [r=5, scores={subquest_15=0, coleta_madeira=200..}] remove subquest13");
                player.runCommand("tag @p [r=5, scores={subquest_15=0, coleta_madeira=200..}] remove subquest16");
                player.runCommand("tag @p [r=5, scores={subquest_15=0, coleta_madeira=200..}] remove subquest17");
                player.runCommand("tag @p [r=5, scores={subquest_15=0, coleta_madeira=200..}] remove subquest18");
                player.runCommand("tag @p [r=5, scores={subquest_15=0, coleta_madeira=200..}] remove subquest19");
                player.runCommand("tag @p [r=5, scores={subquest_15=0, coleta_madeira=200..}] remove subquest20");
                player.runCommand("tag @p [r=5, scores={subquest_15=0, coleta_madeira=200..}] remove subquest21");
                player.runCommand("tag @p [r=5, scores={subquest_15=0, coleta_madeira=200..}] remove subquest22");
                player.runCommand("tag @p [r=5, scores={subquest_15=0, coleta_madeira=200..}] remove subquest23");
                player.runCommand("tag @p [r=5, scores={subquest_15=0, coleta_madeira=200..}] remove subquest24");
                player.runCommand("tag @p [r=5, scores={subquest_15=0, coleta_madeira=200..}] remove subquest25");
                player.runCommand("tag @p [r=5, scores={subquest_15=0, coleta_madeira=200..}] remove subquest26");
                player.runCommand("tag @p [r=5, scores={subquest_15=0, coleta_madeira=200..}] remove subquest27");
                player.runCommand("tag @p [r=5, scores={subquest_15=0, coleta_madeira=200..}] remove subquest28");
                player.runCommand("tag @p [r=5, scores={subquest_15=0, coleta_madeira=200..}] remove subquest29");
                player.runCommand("tag @p [r=5, scores={subquest_15=0, coleta_madeira=200..}] remove subquest30");
				
				
                break;
            
			case 1:
                // recompensas
                player.runCommand("execute as @e[type=frog,r=10] run give @p[r=5,scores={subquest_15=0}] well:orbe_evolutiva 1 0");
                player.runCommand("execute as @e[type=frog,r=10] run give @p[r=5,scores={subquest_15=0}] well:container_coracao 1 0");
            
                // ❌ removida linha inválida com @p[type=frog]
            
                // progresso da quest
                player.runCommand("execute as @e[type=frog,r=10] run scoreboard players add @p[r=5,scores={subquest_15=0}] subquest_15 1");
            
                // mensagens
                player.runCommand("titleraw @p[r=5,scores={subquest_15=1},c=1] title {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.titulo\" }]}");
                player.runCommand("titleraw @p[r=5,scores={subquest_15=1},c=1] subtitle {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.subtitulo\" }]}");
                player.runCommand("execute as @p[r=5,scores={subquest_15=1},c=1] run tellraw @a {\"rawtext\":[{\"selector\":\"@a[r=5,c=1]\"},{\"translate\":\"subquest.concluida.mensagem.publica.15\"}]}");
                player.runCommand("playsound missioncomplete @p[r=5,scores={subquest_15=1},c=1] ~ ~ ~");
            
                // 🐸 dispara evento no frog corretamente
                player.runCommand("execute as @e[type=frog,r=20] run event entity @s add_contagem");
            
                // finalizar quest
                player.runCommand("scoreboard players set @p[r=5,scores={subquest_15=1}] subquest_15 2");
                player.runCommand("tag @p[r=5,scores={subquest_15=2}] add subquest0");
            
            break;

            
			case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DE REQUISITOS
	if (score0 === 0 && score1 < 200) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eYago')
            .body({"rawtext": [{"translate": "dialogo.subquest15.requisitos"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DA MISSAO CUMPRIDA
	if (score0 >= 1) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eYago')
            .body({"rawtext": [{"translate": "dialogo.subquest15.cumprida"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
});

world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;

    if (!player || !player.runCommand) return;
    if (target.typeId !== "well:npc29") return;

    const obj0 = world.scoreboard.getObjective("subquest_21");
	const obj1 = world.scoreboard.getObjective("agricultura"); //agricultura=80
	
    

    const score0 = obj0?.getScore(player);
	const score1 = obj1?.getScore(player);
	
	//player.runCommand("playsound npc.homem.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.adulto @p [r=5]");
    player.runCommand("playsound npc.homem.dialogue.jovem @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.velho @p [r=5]");
    
    //player.runCommand("playsound npc.mulher.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.velha @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.adulta @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.jovem @p [r=5]");
    //player.runCommand("effect @e[type=!player,r=5] slowness 20 60 true");
  
    const chance = Math.random();
        if (chance < 0.25) {
          player.runCommand("playanimation @e[type=!player,r=5] animation.humanoid.custom.well.dialogo1");
        } else if (chance < 0.5) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo2");
        } else if (chance < 0.75) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo3");
        } else {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo4");
        }
    
	//DIALOGO DA MISSAO
    if (score0 === 0 && score1 >= 80) {
        const nina1 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eOlligard')
            .body({"rawtext": [{"translate": "dialogo.21.subquest"}]})
            .button({"rawtext": [{"translate": "botao.subquest.aceitar"}]}, "textures/ui/permissions_visitor_hand.png")
            .button({"rawtext": [{"translate": "botao.subquest.sim"}]}, "textures/ui/pergaminhos/icones_submissoes/cake.png")
			.button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina1.show(player).then(result => {
        if (result.canceled) return;
        switch (result.selection) {
            case 0:
                player.runCommand("tag @p [r=5, scores={subquest_21=0, agricultura=80..}] remove subquest0");
                player.runCommand("tag @p [r=5, scores={subquest_21=0, agricultura=80..}] add subquest21");
                player.runCommand("titleraw @p [r=5, scores={subquest_21=0, agricultura=80..}] title {\"rawtext\":[{ \"translate\":\"subquest.aceitou.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_21=0, agricultura=80..}] subtitle {\"rawtext\":[{ \"translate\":\"subquest.aceitou.subtitulo\" }]}");
                player.runCommand("tag @p [r=5, scores={subquest_21=0, agricultura=80..}] remove subquest1");
                player.runCommand("tag @p [r=5, scores={subquest_21=0, agricultura=80..}] remove subquest3");
                player.runCommand("tag @p [r=5, scores={subquest_21=0, agricultura=80..}] remove subquest4");
                player.runCommand("tag @p [r=5, scores={subquest_21=0, agricultura=80..}] remove subquest2");
                player.runCommand("tag @p [r=5, scores={subquest_21=0, agricultura=80..}] remove subquest6");
                player.runCommand("tag @p [r=5, scores={subquest_21=0, agricultura=80..}] remove subquest7");
                player.runCommand("tag @p [r=5, scores={subquest_21=0, agricultura=80..}] remove subquest8");
                player.runCommand("tag @p [r=5, scores={subquest_21=0, agricultura=80..}] remove subquest9");
                player.runCommand("tag @p [r=5, scores={subquest_21=0, agricultura=80..}] remove subquest10");
                player.runCommand("tag @p [r=5, scores={subquest_21=0, agricultura=80..}] remove subquest11");
                player.runCommand("tag @p [r=5, scores={subquest_21=0, agricultura=80..}] remove subquest12");
                player.runCommand("tag @p [r=5, scores={subquest_21=0, agricultura=80..}] remove subquest13");
                player.runCommand("tag @p [r=5, scores={subquest_21=0, agricultura=80..}] remove subquest14");
                player.runCommand("tag @p [r=5, scores={subquest_21=0, agricultura=80..}] remove subquest15");
                player.runCommand("tag @p [r=5, scores={subquest_21=0, agricultura=80..}] remove subquest16");
                player.runCommand("tag @p [r=5, scores={subquest_21=0, agricultura=80..}] remove subquest17");
                player.runCommand("tag @p [r=5, scores={subquest_21=0, agricultura=80..}] remove subquest18");
                player.runCommand("tag @p [r=5, scores={subquest_21=0, agricultura=80..}] remove subquest19");
                player.runCommand("tag @p [r=5, scores={subquest_21=0, agricultura=80..}] remove subquest20");
                player.runCommand("tag @p [r=5, scores={subquest_21=0, agricultura=80..}] remove subquest5");
                player.runCommand("tag @p [r=5, scores={subquest_21=0, agricultura=80..}] remove subquest22");
                player.runCommand("tag @p [r=5, scores={subquest_21=0, agricultura=80..}] remove subquest23");
                player.runCommand("tag @p [r=5, scores={subquest_21=0, agricultura=80..}] remove subquest24");
                player.runCommand("tag @p [r=5, scores={subquest_21=0, agricultura=80..}] remove subquest25");
                player.runCommand("tag @p [r=5, scores={subquest_21=0, agricultura=80..}] remove subquest26");
                player.runCommand("tag @p [r=5, scores={subquest_21=0, agricultura=80..}] remove subquest27");
                player.runCommand("tag @p [r=5, scores={subquest_21=0, agricultura=80..}] remove subquest28");
                player.runCommand("tag @p [r=5, scores={subquest_21=0, agricultura=80..}] remove subquest29");
                player.runCommand("tag @p [r=5, scores={subquest_21=0, agricultura=80..}] remove subquest30");
				
				
                break;
            
			case 1:
                player.runCommand("execute as @e [r=10, scores={subquest_21=0}] run give @p [r=5, scores={bolo_aniversario=1}] well:orbe_evolutiva 1 0 ");
                player.runCommand("execute as @e [r=10, scores={subquest_21=0}] run give @p [r=5, scores={bolo_aniversario=1}] well:container_coracao 1 0 ");
                player.runCommand("execute as @e [r=10, scores={subquest_21=0}] run tag @p [r=10, scores={bolo_aniversario=1}] remove subquest21");  
                player.runCommand("scoreboard players add @p [r=5, scores={subquest_21=0, bolo_aniversario=1..}] subquest_21 1");
                player.runCommand("scoreboard players set @p [r=5, scores={subquest_21=1, bolo_aniversario=1}] bolo_aniversario 2");
                player.runCommand("titleraw @p [r=5, scores={subquest_21=1}, c=1] title {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_21=1}, c=1] subtitle {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.subtitulo\" }]}");
                player.runCommand("execute as @p [r=5, scores={subquest_21=1}, c=1] run tellraw @a {\"rawtext\":[{\"selector\": \"@a[r=5,c=1]\"},{ \"translate\":\"subquest.concluida.mensagem.publica.21\" }]}");
                player.runCommand("playsound missioncomplete @p [r=5, scores={subquest_21=1}, c=1] ~ ~ ~");
                player.runCommand("scoreboard players set @p [r=5, scores={subquest_21=1}] subquest_21 2");
                player.runCommand("tag @p [r=5, scores={subquest_21=2}] add subquest0");
				
                break;
            
			case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DE REQUISITOS
	if (score0 === 0 && score1 < 80) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eOlligard')
            .body({"rawtext": [{"translate": "dialogo.subquest21.requisitos"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DA MISSAO CUMPRIDA
	if (score0 >= 1) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eOlligard')
            .body({"rawtext": [{"translate": "dialogo.subquest21.cumprida"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
});

world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;

    if (!player || !player.runCommand) return;
    if (target.typeId !== "well:npc24") return;

    const obj0 = world.scoreboard.getObjective("subquest_18");
	const obj1 = world.scoreboard.getObjective("agricultura"); //agricultura=150
	
    

    const score0 = obj0?.getScore(player);
	const score1 = obj1?.getScore(player);
	
	//player.runCommand("playsound npc.homem.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.adulto @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.jovem @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.velho @p [r=5]");
    
    //player.runCommand("playsound npc.mulher.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.velha @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.adulta @p [r=5]");
    player.runCommand("playsound npc.mulher.dialogue.jovem @p [r=5]");
    //player.runCommand("effect @e[type=!player,r=5] slowness 20 60 true");
  
    const chance = Math.random();
        if (chance < 0.25) {
          player.runCommand("playanimation @e[type=!player,r=5] animation.humanoid.custom.well.dialogo1");
        } else if (chance < 0.5) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo2");
        } else if (chance < 0.75) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo3");
        } else {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo4");
        }
    
	//DIALOGO DA MISSAO
    if (score0 === 0 && score1 >= 150) {
        const nina1 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eLinda')
            .body({"rawtext": [{"translate": "dialogo.18.subquest"}]})
            .button({"rawtext": [{"translate": "botao.subquest.aceitar"}]}, "textures/ui/permissions_visitor_hand.png")
            .button({"rawtext": [{"translate": "botao.subquest.sim"}]}, "textures/ui/pergaminhos/icones_submissoes/ovo.png")
			.button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina1.show(player).then(result => {
        if (result.canceled) return;
        switch (result.selection) {
            case 0:
                player.runCommand("tag @p [r=5, scores={subquest_18=0, agricultura=150..}] remove subquest0");
                player.runCommand("tag @p [r=5, scores={subquest_18=0, agricultura=150..}] add subquest18");
                player.runCommand("titleraw @p [r=5, scores={subquest_18=0, agricultura=150..}] title {\"rawtext\":[{ \"translate\":\"subquest.aceitou.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_18=0, agricultura=150..}] subtitle {\"rawtext\":[{ \"translate\":\"subquest.aceitou.subtitulo\" }]}");
                player.runCommand("tag @p [r=5, scores={subquest_18=0, agricultura=150..}] remove subquest1");
                player.runCommand("tag @p [r=5, scores={subquest_18=0, agricultura=150..}] remove subquest2");
                player.runCommand("tag @p [r=5, scores={subquest_18=0, agricultura=150..}] remove subquest4");
                player.runCommand("tag @p [r=5, scores={subquest_18=0, agricultura=150..}] remove subquest5");
                player.runCommand("tag @p [r=5, scores={subquest_18=0, agricultura=150..}] remove subquest6");
                player.runCommand("tag @p [r=5, scores={subquest_18=0, agricultura=150..}] remove subquest7");
                player.runCommand("tag @p [r=5, scores={subquest_18=0, agricultura=150..}] remove subquest8");
                player.runCommand("tag @p [r=5, scores={subquest_18=0, agricultura=150..}] remove subquest9");
                player.runCommand("tag @p [r=5, scores={subquest_18=0, agricultura=150..}] remove subquest10");
                player.runCommand("tag @p [r=5, scores={subquest_18=0, agricultura=150..}] remove subquest11");
                player.runCommand("tag @p [r=5, scores={subquest_18=0, agricultura=150..}] remove subquest12");
                player.runCommand("tag @p [r=5, scores={subquest_18=0, agricultura=150..}] remove subquest3");
                player.runCommand("tag @p [r=5, scores={subquest_18=0, agricultura=150..}] remove subquest14");
                player.runCommand("tag @p [r=5, scores={subquest_18=0, agricultura=150..}] remove subquest15");
                player.runCommand("tag @p [r=5, scores={subquest_18=0, agricultura=150..}] remove subquest16");
                player.runCommand("tag @p [r=5, scores={subquest_18=0, agricultura=150..}] remove subquest17");
                player.runCommand("tag @p [r=5, scores={subquest_18=0, agricultura=150..}] remove subquest13");
                player.runCommand("tag @p [r=5, scores={subquest_18=0, agricultura=150..}] remove subquest19");
                player.runCommand("tag @p [r=5, scores={subquest_18=0, agricultura=150..}] remove subquest20");
                player.runCommand("tag @p [r=5, scores={subquest_18=0, agricultura=150..}] remove subquest21");
                player.runCommand("tag @p [r=5, scores={subquest_18=0, agricultura=150..}] remove subquest22");
                player.runCommand("tag @p [r=5, scores={subquest_18=0, agricultura=150..}] remove subquest23");
                player.runCommand("tag @p [r=5, scores={subquest_18=0, agricultura=150..}] remove subquest24");
                player.runCommand("tag @p [r=5, scores={subquest_18=0, agricultura=150..}] remove subquest25");
                player.runCommand("tag @p [r=5, scores={subquest_18=0, agricultura=150..}] remove subquest26");
                player.runCommand("tag @p [r=5, scores={subquest_18=0, agricultura=150..}] remove subquest27");
                player.runCommand("tag @p [r=5, scores={subquest_18=0, agricultura=150..}] remove subquest28");
                player.runCommand("tag @p [r=5, scores={subquest_18=0, agricultura=150..}] remove subquest29");
                player.runCommand("tag @p [r=5, scores={subquest_18=0, agricultura=150..}] remove subquest30");
				
				
                break;
            
			case 1:
                player.runCommand("execute as @e [r=10, scores={subquest_18=0}] run give @p [r=5, scores={ovo_sniffer=1}] well:orbe_evolutiva 1 0 ");
                player.runCommand("execute as @e [r=10, scores={subquest_18=0}] run give @p [r=5, scores={ovo_sniffer=1}] well:container_coracao 1 0 ");
                player.runCommand("execute as @e [r=10, scores={subquest_18=0}] run tag @p [r=10, scores={ovo_sniffer=1}] remove subquest21");  
                player.runCommand("scoreboard players add @p [r=5, scores={subquest_18=0, ovo_sniffer=1..}] subquest_18 1");
                player.runCommand("scoreboard players set @p [r=5, scores={subquest_18=1, ovo_sniffer=1}] ovo_sniffer 2");
                player.runCommand("titleraw @p [r=5, scores={subquest_18=1}, c=1] title {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_18=1}, c=1] subtitle {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.subtitulo\" }]}");
                player.runCommand("execute as @p [r=5, scores={subquest_18=1}, c=1] run tellraw @a {\"rawtext\":[{\"selector\": \"@a[r=5,c=1]\"},{ \"translate\":\"subquest.concluida.mensagem.publica.18\" }]}");
                player.runCommand("playsound missioncomplete @p [r=5, scores={subquest_18=1}, c=1] ~ ~ ~");
                player.runCommand("scoreboard players set @p [r=5, scores={subquest_18=1}] subquest_18 2");
                player.runCommand("tag @p [r=5, scores={subquest_18=2}] add subquest0");
				
                break;
            
			case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DE REQUISITOS
	if (score0 === 0 && score1 < 150) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eLinda')
            .body({"rawtext": [{"translate": "dialogo.subquest18.requisitos"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DA MISSAO CUMPRIDA
	if (score0 >= 1) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eLinda')
            .body({"rawtext": [{"translate": "dialogo.subquest18.cumprida"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
});

world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;

    if (!player || !player.runCommand) return;
    if (target.typeId !== "well:npc23") return;

    const obj0 = world.scoreboard.getObjective("subquest_19");
	const obj1 = world.scoreboard.getObjective("agricultura"); //agricultura=30
	
    

    const score0 = obj0?.getScore(player);
	const score1 = obj1?.getScore(player);
	
	//player.runCommand("playsound npc.homem.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.adulto @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.jovem @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.velho @p [r=5]");
    
    //player.runCommand("playsound npc.mulher.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.velha @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.adulta @p [r=5]");
    player.runCommand("playsound npc.mulher.dialogue.jovem @p [r=5]");
    //player.runCommand("effect @e[type=!player,r=5] slowness 20 60 true");
  
    const chance = Math.random();
        if (chance < 0.25) {
          player.runCommand("playanimation @e[type=!player,r=5] animation.humanoid.custom.well.dialogo1");
        } else if (chance < 0.5) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo2");
        } else if (chance < 0.75) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo3");
        } else {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo4");
        }
    
	//DIALOGO DA MISSAO
    if (score0 === 0 && score1 >= 30) {
        const nina1 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eMilly')
            .body({"rawtext": [{"translate": "dialogo.19.subquest"}]})
            .button({"rawtext": [{"translate": "botao.subquest.aceitar"}]}, "textures/ui/permissions_visitor_hand.png")
            .button({"rawtext": [{"translate": "botao.subquest.sim"}]}, "textures/ui/pergaminhos/icones_submissoes/spore_blossom.png")
			.button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina1.show(player).then(result => {
        if (result.canceled) return;
        switch (result.selection) {
            case 0:
                player.runCommand("tag @p [r=5, scores={subquest_19=0, agricultura=30..}] remove subquest0");
                player.runCommand("tag @p [r=5, scores={subquest_19=0, agricultura=30..}] add subquest19");
                player.runCommand("titleraw @p [r=5, scores={subquest_19=0, agricultura=30..}] title {\"rawtext\":[{ \"translate\":\"subquest.aceitou.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_19=0, agricultura=30..}] subtitle {\"rawtext\":[{ \"translate\":\"subquest.aceitou.subtitulo\" }]}");
                player.runCommand("tag @p [r=5, scores={subquest_19=0, agricultura=30..}] remove subquest1");
                player.runCommand("tag @p [r=5, scores={subquest_19=0, agricultura=30..}] remove subquest2");
                player.runCommand("tag @p [r=5, scores={subquest_19=0, agricultura=30..}] remove subquest4");
                player.runCommand("tag @p [r=5, scores={subquest_19=0, agricultura=30..}] remove subquest5");
                player.runCommand("tag @p [r=5, scores={subquest_19=0, agricultura=30..}] remove subquest6");
                player.runCommand("tag @p [r=5, scores={subquest_19=0, agricultura=30..}] remove subquest7");
                player.runCommand("tag @p [r=5, scores={subquest_19=0, agricultura=30..}] remove subquest8");
                player.runCommand("tag @p [r=5, scores={subquest_19=0, agricultura=30..}] remove subquest9");
                player.runCommand("tag @p [r=5, scores={subquest_19=0, agricultura=30..}] remove subquest10");
                player.runCommand("tag @p [r=5, scores={subquest_19=0, agricultura=30..}] remove subquest11");
                player.runCommand("tag @p [r=5, scores={subquest_19=0, agricultura=30..}] remove subquest12");
                player.runCommand("tag @p [r=5, scores={subquest_19=0, agricultura=30..}] remove subquest3");
                player.runCommand("tag @p [r=5, scores={subquest_19=0, agricultura=30..}] remove subquest14");
                player.runCommand("tag @p [r=5, scores={subquest_19=0, agricultura=30..}] remove subquest15");
                player.runCommand("tag @p [r=5, scores={subquest_19=0, agricultura=30..}] remove subquest16");
                player.runCommand("tag @p [r=5, scores={subquest_19=0, agricultura=30..}] remove subquest17");
                player.runCommand("tag @p [r=5, scores={subquest_19=0, agricultura=30..}] remove subquest13");
                player.runCommand("tag @p [r=5, scores={subquest_19=0, agricultura=30..}] remove subquest18");
                player.runCommand("tag @p [r=5, scores={subquest_19=0, agricultura=30..}] remove subquest20");
                player.runCommand("tag @p [r=5, scores={subquest_19=0, agricultura=30..}] remove subquest21");
                player.runCommand("tag @p [r=5, scores={subquest_19=0, agricultura=30..}] remove subquest22");
                player.runCommand("tag @p [r=5, scores={subquest_19=0, agricultura=30..}] remove subquest23");
                player.runCommand("tag @p [r=5, scores={subquest_19=0, agricultura=30..}] remove subquest24");
                player.runCommand("tag @p [r=5, scores={subquest_19=0, agricultura=30..}] remove subquest25");
                player.runCommand("tag @p [r=5, scores={subquest_19=0, agricultura=30..}] remove subquest26");
                player.runCommand("tag @p [r=5, scores={subquest_19=0, agricultura=30..}] remove subquest27");
                player.runCommand("tag @p [r=5, scores={subquest_19=0, agricultura=30..}] remove subquest28");
                player.runCommand("tag @p [r=5, scores={subquest_19=0, agricultura=30..}] remove subquest29");
                player.runCommand("tag @p [r=5, scores={subquest_19=0, agricultura=30..}] remove subquest30");
				
				
                break;
            
			case 1:
                player.runCommand("give @p [r=5, scores={subquest_19=0, esporos=1}] well:orbe_evolutiva 1 0 ");
                player.runCommand("give @p [r=5, scores={subquest_19=0, esporos=1}] well:container_coracao 1 0 ");
                player.runCommand("tag @p [r=10, scores={subquest_19=0, esporos=1}] remove subquest19");  
                player.runCommand("scoreboard players add @p [r=5, scores={subquest_19=0, esporos=1..}] subquest_19 1");
                player.runCommand("scoreboard players set @p [r=5, scores={subquest_19=1, esporos=1}] esporos 2");
                player.runCommand("titleraw @p [r=5, scores={subquest_19=1}, c=1] title {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_19=1}, c=1] subtitle {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.subtitulo\" }]}");
                player.runCommand("execute as @p [r=5, scores={subquest_19=1}, c=1] run tellraw @a {\"rawtext\":[{\"selector\": \"@a[r=5,c=1]\"},{ \"translate\":\"subquest.concluida.mensagem.publica.19\" }]}");
                player.runCommand("playsound missioncomplete @p [r=5, scores={subquest_19=1}, c=1] ~ ~ ~");
                player.runCommand("scoreboard players set @p [r=5, scores={subquest_19=1}] subquest_19 2");
                player.runCommand("tag @p [r=5, scores={subquest_19=2}] add subquest0");
				player.runCommand("execute as @p [r=5, scores={subquest_19=2}, c=1] run setblock 6 70 33 air");
				
                break;
            
			case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DE REQUISITOS
	if (score0 === 0 && score1 < 30) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eMilly')
            .body({"rawtext": [{"translate": "dialogo.subquest19.requisitos"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DA MISSAO CUMPRIDA
	if (score0 >= 1) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eMilly')
            .body({"rawtext": [{"translate": "dialogo.subquest19.cumprida"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
});


///SUBQUESTS ELFOS
world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;

    if (!player || !player.runCommand) return;
    if (target.typeId !== "well:npc1") return;

    const obj0 = world.scoreboard.getObjective("subquest_4");
	const obj1 = world.scoreboard.getObjective("agricultura"); //agricultura=200
	
    

    const score0 = obj0?.getScore(player);
	const score1 = obj1?.getScore(player);
	
	//player.runCommand("playsound npc.homem.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.adulto @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.jovem @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.velho @p [r=5]");
    
    //player.runCommand("playsound npc.mulher.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.velha @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.adulta @p [r=5]");
    player.runCommand("playsound npc.mulher.dialogue.jovem @p [r=5]");
    //player.runCommand("effect @e[type=!player,r=5] slowness 20 60 true");
  
    const chance = Math.random();
        if (chance < 0.25) {
          player.runCommand("playanimation @e[type=!player,r=5] animation.humanoid.custom.well.dialogo1");
        } else if (chance < 0.5) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo2");
        } else if (chance < 0.75) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo3");
        } else {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo4");
        }
    
	//DIALOGO DA MISSAO
    if (score0 === 0 && score1 >= 200) {
        const nina1 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eHilly')
            .body({"rawtext": [{"translate": "dialogo.4.subquest"}]})
            .button({"rawtext": [{"translate": "botao.subquest.aceitar"}]}, "textures/ui/permissions_visitor_hand.png")
            .button({"rawtext": [{"translate": "botao.subquest.sim"}]}, "textures/ui/pergaminhos/icones_submissoes/bucket_axolotl.png")
			.button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina1.show(player).then(result => {
        if (result.canceled) return;
        switch (result.selection) {
            case 0:
                player.runCommand("tag @p [r=5, scores={subquest_4=0, agricultura=200..}] remove subquest0");
                player.runCommand("tag @p [r=5, scores={subquest_4=0, agricultura=200..}] add subquest4");
                player.runCommand("titleraw @p [r=5, scores={subquest_4=0, agricultura=200..}] title {\"rawtext\":[{ \"translate\":\"subquest.aceitou.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_4=0, agricultura=200..}] subtitle {\"rawtext\":[{ \"translate\":\"subquest.aceitou.subtitulo\" }]}");
                player.runCommand("tag @p [r=5, scores={subquest_4=0, agricultura=200..}] remove subquest1");
                player.runCommand("tag @p [r=5, scores={subquest_4=0, agricultura=200..}] remove subquest2");
                player.runCommand("tag @p [r=5, scores={subquest_4=0, agricultura=200..}] remove subquest20");
                player.runCommand("tag @p [r=5, scores={subquest_4=0, agricultura=200..}] remove subquest5");
                player.runCommand("tag @p [r=5, scores={subquest_4=0, agricultura=200..}] remove subquest6");
                player.runCommand("tag @p [r=5, scores={subquest_4=0, agricultura=200..}] remove subquest7");
                player.runCommand("tag @p [r=5, scores={subquest_4=0, agricultura=200..}] remove subquest8");
                player.runCommand("tag @p [r=5, scores={subquest_4=0, agricultura=200..}] remove subquest9");
                player.runCommand("tag @p [r=5, scores={subquest_4=0, agricultura=200..}] remove subquest10");
                player.runCommand("tag @p [r=5, scores={subquest_4=0, agricultura=200..}] remove subquest11");
                player.runCommand("tag @p [r=5, scores={subquest_4=0, agricultura=200..}] remove subquest12");
                player.runCommand("tag @p [r=5, scores={subquest_4=0, agricultura=200..}] remove subquest3");
                player.runCommand("tag @p [r=5, scores={subquest_4=0, agricultura=200..}] remove subquest13");
                player.runCommand("tag @p [r=5, scores={subquest_4=0, agricultura=200..}] remove subquest15");
                player.runCommand("tag @p [r=5, scores={subquest_4=0, agricultura=200..}] remove subquest16");
                player.runCommand("tag @p [r=5, scores={subquest_4=0, agricultura=200..}] remove subquest17");
                player.runCommand("tag @p [r=5, scores={subquest_4=0, agricultura=200..}] remove subquest18");
                player.runCommand("tag @p [r=5, scores={subquest_4=0, agricultura=200..}] remove subquest19");
                player.runCommand("tag @p [r=5, scores={subquest_4=0, agricultura=200..}] remove subquest14");
                player.runCommand("tag @p [r=5, scores={subquest_4=0, agricultura=200..}] remove subquest21");
                player.runCommand("tag @p [r=5, scores={subquest_4=0, agricultura=200..}] remove subquest22");
                player.runCommand("tag @p [r=5, scores={subquest_4=0, agricultura=200..}] remove subquest23");
                player.runCommand("tag @p [r=5, scores={subquest_4=0, agricultura=200..}] remove subquest24");
                player.runCommand("tag @p [r=5, scores={subquest_4=0, agricultura=200..}] remove subquest25");
                player.runCommand("tag @p [r=5, scores={subquest_4=0, agricultura=200..}] remove subquest26");
                player.runCommand("tag @p [r=5, scores={subquest_4=0, agricultura=200..}] remove subquest27");
                player.runCommand("tag @p [r=5, scores={subquest_4=0, agricultura=200..}] remove subquest28");
                player.runCommand("tag @p [r=5, scores={subquest_4=0, agricultura=200..}] remove subquest29");
                player.runCommand("tag @p [r=5, scores={subquest_4=0, agricultura=200..}] remove subquest30");
				
				
                break;
            
			case 1:
                player.runCommand("give @p [r=5, scores={subquest_4=0}, hasitem={item=axolotl_bucket, quantity=1..}] well:orbe_evolutiva 1 0 ");
                player.runCommand("give @p [r=5, scores={subquest_4=0}, hasitem={item=axolotl_bucket, quantity=1..}] well:container_coracao 1 0 "); 
                player.runCommand("tag @p [r=5, scores={subquest_4=0}, hasitem={item=axolotl_bucket, quantity=1..}] remove subquest4"); 
                player.runCommand("scoreboard players add @p [r=5, scores={subquest_4=0}, hasitem={item=axolotl_bucket, quantity=1..}] subquest_4 1");
                player.runCommand("clear @p [r=5, scores={subquest_4=1..}, hasitem={item=axolotl_bucket, quantity=1..}] axolotl_bucket 0 10");
                player.runCommand("titleraw @p [r=5, scores={subquest_4=1}, c=1] title {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_4=1}, c=1] subtitle {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.subtitulo\" }]}");
                player.runCommand("execute as @p [r=5, scores={subquest_4=1}, c=1] run tellraw @a {\"rawtext\":[{\"selector\": \"@a[r=5,c=1]\"},{ \"translate\":\"subquest.concluida.mensagem.publica.4\" }]}");
                player.runCommand("playsound missioncomplete @p [r=5, scores={subquest_4=1}, c=1] ~ ~ ~");
                player.runCommand("scoreboard players set @p [r=5, scores={subquest_4=1}] subquest_4 2");
                player.runCommand("tag @p [r=5, scores={subquest_4=2}] add subquest0");
				
                break;
            
			case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DE REQUISITOS
	if (score0 === 0 && score1 < 200) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eHilly')
            .body({"rawtext": [{"translate": "dialogo.subquest4.requisitos"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DA MISSAO CUMPRIDA
	if (score0 >= 1) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eHilly')
            .body({"rawtext": [{"translate": "dialogo.subquest4.cumprida"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
});

world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;

    if (!player || !player.runCommand) return;
    if (target.typeId !== "well:npc2") return;

    const obj0 = world.scoreboard.getObjective("subquest_1");
	const obj1 = world.scoreboard.getObjective("pescaria"); //agricultura=200
	
    

    const score0 = obj0?.getScore(player);
	const score1 = obj1?.getScore(player);
	
	//player.runCommand("playsound npc.homem.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.adulto @p [r=5]");
    player.runCommand("playsound npc.homem.dialogue.jovem @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.velho @p [r=5]");
    
    //player.runCommand("playsound npc.mulher.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.velha @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.adulta @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.jovem @p [r=5]");
    //player.runCommand("effect @e[type=!player,r=5] slowness 20 60 true");
  
    const chance = Math.random();
        if (chance < 0.25) {
          player.runCommand("playanimation @e[type=!player,r=5] animation.humanoid.custom.well.dialogo1");
        } else if (chance < 0.5) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo2");
        } else if (chance < 0.75) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo3");
        } else {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo4");
        }
    
	//DIALOGO DA MISSAO
    if (score0 === 0 && score1 >= 200) {
        const nina1 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eFabricio')
            .body({"rawtext": [{"translate": "dialogo.1.subquest"}]})
            .button({"rawtext": [{"translate": "botao.subquest.aceitar"}]}, "textures/ui/permissions_visitor_hand.png")
            .button({"rawtext": [{"translate": "botao.subquest.sim"}]}, "textures/ui/pergaminhos/icones_submissoes/beetroot_soup.png")
			.button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina1.show(player).then(result => {
        if (result.canceled) return;
        switch (result.selection) {
            case 0:
                player.runCommand("tag @p [r=5, scores={subquest_1=0, pescaria=200..}] remove subquest0");
                player.runCommand("tag @p [r=5, scores={subquest_1=0, pescaria=200..}] add subquest1");
                player.runCommand("titleraw @p [r=5, scores={subquest_1=0, pescaria=200..}] title {\"rawtext\":[{ \"translate\":\"subquest.aceitou.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_1=0, pescaria=200..}] subtitle {\"rawtext\":[{ \"translate\":\"subquest.aceitou.subtitulo\" }]}");
                player.runCommand("tag @p [r=5, scores={subquest_1=0, pescaria=200..}] remove subquest5");
                player.runCommand("tag @p [r=5, scores={subquest_1=0, pescaria=200..}] remove subquest2");
                player.runCommand("tag @p [r=5, scores={subquest_1=0, pescaria=200..}] remove subquest4");
                player.runCommand("tag @p [r=5, scores={subquest_1=0, pescaria=200..}] remove subquest13");
                player.runCommand("tag @p [r=5, scores={subquest_1=0, pescaria=200..}] remove subquest6");
                player.runCommand("tag @p [r=5, scores={subquest_1=0, pescaria=200..}] remove subquest7");
                player.runCommand("tag @p [r=5, scores={subquest_1=0, pescaria=200..}] remove subquest8");
                player.runCommand("tag @p [r=5, scores={subquest_1=0, pescaria=200..}] remove subquest9");
                player.runCommand("tag @p [r=5, scores={subquest_1=0, pescaria=200..}] remove subquest10");
                player.runCommand("tag @p [r=5, scores={subquest_1=0, pescaria=200..}] remove subquest11");
                player.runCommand("tag @p [r=5, scores={subquest_1=0, pescaria=200..}] remove subquest12");
                player.runCommand("tag @p [r=5, scores={subquest_1=0, pescaria=200..}] remove subquest3");
                player.runCommand("tag @p [r=5, scores={subquest_1=0, pescaria=200..}] remove subquest14");
                player.runCommand("tag @p [r=5, scores={subquest_1=0, pescaria=200..}] remove subquest15");
                player.runCommand("tag @p [r=5, scores={subquest_1=0, pescaria=200..}] remove subquest16");
                player.runCommand("tag @p [r=5, scores={subquest_1=0, pescaria=200..}] remove subquest17");
                player.runCommand("tag @p [r=5, scores={subquest_1=0, pescaria=200..}] remove subquest18");
                player.runCommand("tag @p [r=5, scores={subquest_1=0, pescaria=200..}] remove subquest19");
                player.runCommand("tag @p [r=5, scores={subquest_1=0, pescaria=200..}] remove subquest20");
                player.runCommand("tag @p [r=5, scores={subquest_1=0, pescaria=200..}] remove subquest21");
                player.runCommand("tag @p [r=5, scores={subquest_1=0, pescaria=200..}] remove subquest22");
                player.runCommand("tag @p [r=5, scores={subquest_1=0, pescaria=200..}] remove subquest23");
                player.runCommand("tag @p [r=5, scores={subquest_1=0, pescaria=200..}] remove subquest24");
                player.runCommand("tag @p [r=5, scores={subquest_1=0, pescaria=200..}] remove subquest25");
                player.runCommand("tag @p [r=5, scores={subquest_1=0, pescaria=200..}] remove subquest26");
                player.runCommand("tag @p [r=5, scores={subquest_1=0, pescaria=200..}] remove subquest27");
                player.runCommand("tag @p [r=5, scores={subquest_1=0, pescaria=200..}] remove subquest28");
                player.runCommand("tag @p [r=5, scores={subquest_1=0, pescaria=200..}] remove subquest29");
                player.runCommand("tag @p [r=5, scores={subquest_1=0, pescaria=200..}] remove subquest30");
				
				
                break;
            
			case 1:
                player.runCommand("give @p [r=5, scores={subquest_1=0}, hasitem={item=beetroot_soup, quantity=1..}] well:orbe_evolutiva 1 0 ");
                player.runCommand("give @p [r=5, scores={subquest_1=0}, hasitem={item=beetroot_soup, quantity=1..}] well:container_coracao 1 0 "); 
                player.runCommand("tag @p [r=5, scores={subquest_1=0}, hasitem={item=beetroot_soup, quantity=1..}] remove subquest1"); 
                player.runCommand("scoreboard players add @p [r=5, scores={subquest_1=0}, hasitem={item=beetroot_soup, quantity=1..}] subquest_1 1");
                player.runCommand("clear @p [r=5, scores={subquest_1=1..}, hasitem={item=beetroot_soup, quantity=1..}] beetroot_soup 0 10");
                player.runCommand("titleraw @p [r=5, scores={subquest_1=1}, c=1] title {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_1=1}, c=1] subtitle {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.subtitulo\" }]}");
                player.runCommand("execute as @p [r=5, scores={subquest_1=1}, c=1] run tellraw @a {\"rawtext\":[{\"selector\": \"@a[r=5,c=1]\"},{ \"translate\":\"subquest.concluida.mensagem.publica.1\" }]}");
                player.runCommand("playsound missioncomplete @p [r=5, scores={subquest_1=1}, c=1] ~ ~ ~");
                player.runCommand("scoreboard players set @p [r=5, scores={subquest_1=1}] subquest_1 2");
                player.runCommand("tag @p [r=5, scores={subquest_1=2}] add subquest0");
				
                break;
            
			case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DE REQUISITOS
	if (score0 === 0 && score1 < 200) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eFabricio')
            .body({"rawtext": [{"translate": "dialogo.subquest1.requisitos"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DA MISSAO CUMPRIDA
	if (score0 >= 1) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eFabricio')
            .body({"rawtext": [{"translate": "dialogo.subquest1.cumprida"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
});

world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;

    if (!player || !player.runCommand) return;
    if (target.typeId !== "well:npc4") return;

    const obj0 = world.scoreboard.getObjective("subquest_30");
	const obj1 = world.scoreboard.getObjective("coleta_madeira"); //agricultura=400
	
    

    const score0 = obj0?.getScore(player);
	const score1 = obj1?.getScore(player);
	
	//player.runCommand("playsound npc.homem.dialogue.crianca @p [r=5]");
    player.runCommand("playsound npc.homem.dialogue.adulto @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.jovem @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.velho @p [r=5]");
    
    //player.runCommand("playsound npc.mulher.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.velha @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.adulta @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.jovem @p [r=5]");
    //player.runCommand("effect @e[type=!player,r=5] slowness 20 60 true");
  
    const chance = Math.random();
        if (chance < 0.25) {
          player.runCommand("playanimation @e[type=!player,r=5] animation.humanoid.custom.well.dialogo1");
        } else if (chance < 0.5) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo2");
        } else if (chance < 0.75) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo3");
        } else {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo4");
        }
    
	//DIALOGO DA MISSAO
    if (score0 === 0 && score1 >= 400) {
        const nina1 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eJoseph')
            .body({"rawtext": [{"translate": "dialogo.30.subquest"}]})
            .button({"rawtext": [{"translate": "botao.subquest.aceitar"}]}, "textures/ui/permissions_visitor_hand.png")
            .button({"rawtext": [{"translate": "botao.subquest.sim"}]}, "textures/ui/pergaminhos/icones_submissoes/fish_pufferfish_raw.png")
			.button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina1.show(player).then(result => {
        if (result.canceled) return;
        switch (result.selection) {
            case 0:
                player.runCommand("tag @p [r=5, scores={subquest_30=0, coleta_madeira=400..}] remove subquest0");
                player.runCommand("tag @p [r=5, scores={subquest_30=0, coleta_madeira=400..}] add subquest30");
                player.runCommand("titleraw @p [r=5, scores={subquest_30=0, coleta_madeira=400..}] title {\"rawtext\":[{ \"translate\":\"subquest.aceitou.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_30=0, coleta_madeira=400..}] subtitle {\"rawtext\":[{ \"translate\":\"subquest.aceitou.subtitulo\" }]}");
                player.runCommand("tag @p [r=5, scores={subquest_30=0, coleta_madeira=400..}] remove subquest5");
                player.runCommand("tag @p [r=5, scores={subquest_30=0, coleta_madeira=400..}] remove subquest2");
                player.runCommand("tag @p [r=5, scores={subquest_30=0, coleta_madeira=400..}] remove subquest4");
                player.runCommand("tag @p [r=5, scores={subquest_30=0, coleta_madeira=400..}] remove subquest13");
                player.runCommand("tag @p [r=5, scores={subquest_30=0, coleta_madeira=400..}] remove subquest1");
                player.runCommand("tag @p [r=5, scores={subquest_30=0, coleta_madeira=400..}] remove subquest7");
                player.runCommand("tag @p [r=5, scores={subquest_30=0, coleta_madeira=400..}] remove subquest8");
                player.runCommand("tag @p [r=5, scores={subquest_30=0, coleta_madeira=400..}] remove subquest9");
                player.runCommand("tag @p [r=5, scores={subquest_30=0, coleta_madeira=400..}] remove subquest10");
                player.runCommand("tag @p [r=5, scores={subquest_30=0, coleta_madeira=400..}] remove subquest11");
                player.runCommand("tag @p [r=5, scores={subquest_30=0, coleta_madeira=400..}] remove subquest12");
                player.runCommand("tag @p [r=5, scores={subquest_30=0, coleta_madeira=400..}] remove subquest3");
                player.runCommand("tag @p [r=5, scores={subquest_30=0, coleta_madeira=400..}] remove subquest14");
                player.runCommand("tag @p [r=5, scores={subquest_30=0, coleta_madeira=400..}] remove subquest15");
                player.runCommand("tag @p [r=5, scores={subquest_30=0, coleta_madeira=400..}] remove subquest16");
                player.runCommand("tag @p [r=5, scores={subquest_30=0, coleta_madeira=400..}] remove subquest17");
                player.runCommand("tag @p [r=5, scores={subquest_30=0, coleta_madeira=400..}] remove subquest18");
                player.runCommand("tag @p [r=5, scores={subquest_30=0, coleta_madeira=400..}] remove subquest19");
                player.runCommand("tag @p [r=5, scores={subquest_30=0, coleta_madeira=400..}] remove subquest20");
                player.runCommand("tag @p [r=5, scores={subquest_30=0, coleta_madeira=400..}] remove subquest21");
                player.runCommand("tag @p [r=5, scores={subquest_30=0, coleta_madeira=400..}] remove subquest22");
                player.runCommand("tag @p [r=5, scores={subquest_30=0, coleta_madeira=400..}] remove subquest23");
                player.runCommand("tag @p [r=5, scores={subquest_30=0, coleta_madeira=400..}] remove subquest24");
                player.runCommand("tag @p [r=5, scores={subquest_30=0, coleta_madeira=400..}] remove subquest25");
                player.runCommand("tag @p [r=5, scores={subquest_30=0, coleta_madeira=400..}] remove subquest26");
                player.runCommand("tag @p [r=5, scores={subquest_30=0, coleta_madeira=400..}] remove subquest27");
                player.runCommand("tag @p [r=5, scores={subquest_30=0, coleta_madeira=400..}] remove subquest28");
                player.runCommand("tag @p [r=5, scores={subquest_30=0, coleta_madeira=400..}] remove subquest29");
                player.runCommand("tag @p [r=5, scores={subquest_30=0, coleta_madeira=400..}] remove subquest6");
				
				
                break;
            
			case 1:
                player.runCommand("give @p [r=5, scores={subquest_30=0}, hasitem={item=pufferfish, quantity=1..}] well:orbe_evolutiva 1 0 ");
                player.runCommand("give @p [r=5, scores={subquest_30=0}, hasitem={item=pufferfish, quantity=1..}] well:container_coracao 1 0 "); 
                player.runCommand("tag @p [r=5, scores={subquest_30=0}, hasitem={item=pufferfish, quantity=1..}] remove subquest30"); 
                player.runCommand("scoreboard players add @p [r=5, scores={subquest_30=0}, hasitem={item=pufferfish, quantity=1..}] subquest_30 1");
                player.runCommand("clear @p [r=5, scores={subquest_30=1..}, hasitem={item=pufferfish, quantity=1..}] pufferfish 0 10");
                player.runCommand("titleraw @p [r=5, scores={subquest_30=1}, c=1] title {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_30=1}, c=1] subtitle {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.subtitulo\" }]}");
                player.runCommand("execute as @p [r=5, scores={subquest_30=1}, c=1] run tellraw @a {\"rawtext\":[{\"selector\": \"@a[r=5,c=1]\"},{ \"translate\":\"subquest.concluida.mensagem.publica.30\" }]}");
                player.runCommand("playsound missioncomplete @p [r=5, scores={subquest_30=1}, c=1] ~ ~ ~");
                player.runCommand("scoreboard players set @p [r=5, scores={subquest_30=1}] subquest_30 2");
                player.runCommand("tag @p [r=5, scores={subquest_30=2}] add subquest0");
				
                break;
            
			case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DE REQUISITOS
	if (score0 === 0 && score1 < 400) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eJoseph')
            .body({"rawtext": [{"translate": "dialogo.subquest30.requisitos"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DA MISSAO CUMPRIDA
	if (score0 >= 1) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eJoseph')
            .body({"rawtext": [{"translate": "dialogo.subquest30.cumprida"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
});

world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;

    if (!player || !player.runCommand) return;
    if (target.typeId !== "well:npc3") return;

    const obj0 = world.scoreboard.getObjective("subquest_6");
	const obj1 = world.scoreboard.getObjective("mineiracao"); //mineiracao=100
	
    

    const score0 = obj0?.getScore(player);
	const score1 = obj1?.getScore(player);
	
	//player.runCommand("playsound npc.homem.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.adulto @p [r=5]");
    player.runCommand("playsound npc.homem.dialogue.jovem @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.velho @p [r=5]");
    
    //player.runCommand("playsound npc.mulher.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.velha @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.adulta @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.jovem @p [r=5]");
    //player.runCommand("effect @e[type=!player,r=5] slowness 20 60 true");
  
    const chance = Math.random();
        if (chance < 0.25) {
          player.runCommand("playanimation @e[type=!player,r=5] animation.humanoid.custom.well.dialogo1");
        } else if (chance < 0.5) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo2");
        } else if (chance < 0.75) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo3");
        } else {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo4");
        }
    
	//DIALOGO DA MISSAO
    if (score0 === 0 && score1 >= 100) {
        const nina1 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eKayo')
            .body({"rawtext": [{"translate": "dialogo.6.subquest"}]})
            .button({"rawtext": [{"translate": "botao.subquest.aceitar"}]}, "textures/ui/permissions_visitor_hand.png")
            .button({"rawtext": [{"translate": "botao.subquest.sim"}]}, "textures/ui/pergaminhos/icones_submissoes/fungos_nether.png")
			.button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina1.show(player).then(result => {
        if (result.canceled) return;
        switch (result.selection) {
            case 0:
                player.runCommand("tag @p [r=5, scores={subquest_6=0, mineiracao=100..}] remove subquest0");
                player.runCommand("tag @p [r=5, scores={subquest_6=0, mineiracao=100..}] add subquest6");
                player.runCommand("titleraw @p [r=5, scores={subquest_6=0, mineiracao=100..}] title {\"rawtext\":[{ \"translate\":\"subquest.aceitou.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_6=0, mineiracao=100..}] subtitle {\"rawtext\":[{ \"translate\":\"subquest.aceitou.subtitulo\" }]}");
                player.runCommand("tag @p [r=5, scores={subquest_6=0, mineiracao=100..}] remove subquest5");
                player.runCommand("tag @p [r=5, scores={subquest_6=0, mineiracao=100..}] remove subquest2");
                player.runCommand("tag @p [r=5, scores={subquest_6=0, mineiracao=100..}] remove subquest4");
                player.runCommand("tag @p [r=5, scores={subquest_6=0, mineiracao=100..}] remove subquest13");
                player.runCommand("tag @p [r=5, scores={subquest_6=0, mineiracao=100..}] remove subquest1");
                player.runCommand("tag @p [r=5, scores={subquest_6=0, mineiracao=100..}] remove subquest7");
                player.runCommand("tag @p [r=5, scores={subquest_6=0, mineiracao=100..}] remove subquest8");
                player.runCommand("tag @p [r=5, scores={subquest_6=0, mineiracao=100..}] remove subquest9");
                player.runCommand("tag @p [r=5, scores={subquest_6=0, mineiracao=100..}] remove subquest10");
                player.runCommand("tag @p [r=5, scores={subquest_6=0, mineiracao=100..}] remove subquest11");
                player.runCommand("tag @p [r=5, scores={subquest_6=0, mineiracao=100..}] remove subquest12");
                player.runCommand("tag @p [r=5, scores={subquest_6=0, mineiracao=100..}] remove subquest3");
                player.runCommand("tag @p [r=5, scores={subquest_6=0, mineiracao=100..}] remove subquest14");
                player.runCommand("tag @p [r=5, scores={subquest_6=0, mineiracao=100..}] remove subquest15");
                player.runCommand("tag @p [r=5, scores={subquest_6=0, mineiracao=100..}] remove subquest16");
                player.runCommand("tag @p [r=5, scores={subquest_6=0, mineiracao=100..}] remove subquest17");
                player.runCommand("tag @p [r=5, scores={subquest_6=0, mineiracao=100..}] remove subquest18");
                player.runCommand("tag @p [r=5, scores={subquest_6=0, mineiracao=100..}] remove subquest19");
                player.runCommand("tag @p [r=5, scores={subquest_6=0, mineiracao=100..}] remove subquest20");
                player.runCommand("tag @p [r=5, scores={subquest_6=0, mineiracao=100..}] remove subquest21");
                player.runCommand("tag @p [r=5, scores={subquest_6=0, mineiracao=100..}] remove subquest22");
                player.runCommand("tag @p [r=5, scores={subquest_6=0, mineiracao=100..}] remove subquest23");
                player.runCommand("tag @p [r=5, scores={subquest_6=0, mineiracao=100..}] remove subquest24");
                player.runCommand("tag @p [r=5, scores={subquest_6=0, mineiracao=100..}] remove subquest25");
                player.runCommand("tag @p [r=5, scores={subquest_6=0, mineiracao=100..}] remove subquest26");
                player.runCommand("tag @p [r=5, scores={subquest_6=0, mineiracao=100..}] remove subquest27");
                player.runCommand("tag @p [r=5, scores={subquest_6=0, mineiracao=100..}] remove subquest28");
                player.runCommand("tag @p [r=5, scores={subquest_6=0, mineiracao=100..}] remove subquest29");
                player.runCommand("tag @p [r=5, scores={subquest_6=0, mineiracao=100..}] remove subquest30");
				
				
                break;
            
			case 1:
                player.runCommand("give @p [r=5, scores={subquest_6=0}, hasitem={item=brown_mushroom, item=red_mushroom, item=crimson_fungus, item=warped_fungus, quantity=1..}] well:orbe_evolutiva 1 0 ");
                player.runCommand("give @p [r=5, scores={subquest_6=0}, hasitem={item=brown_mushroom, item=red_mushroom, item=crimson_fungus, item=warped_fungus, quantity=1..}] well:container_coracao 1 0 "); 
                player.runCommand("tag @p [r=5, scores={subquest_6=0}, hasitem={item=brown_mushroom, item=red_mushroom, item=crimson_fungus, item=warped_fungus, quantity=1..}] remove subquest6"); 
                player.runCommand("scoreboard players add @p [r=5, scores={subquest_6=0}, hasitem={item=brown_mushroom, item=red_mushroom, item=crimson_fungus, item=warped_fungus, quantity=1..}] subquest_6 1");
                player.runCommand("clear @p [r=5, scores={subquest_6=0}, hasitem={item=brown_mushroom, quantity=1..}] brown_mushroom 0 10");
                player.runCommand("clear @p [r=5, scores={subquest_6=0}, hasitem={item=item=red_mushroom, quantity=1..}] red_mushroom 0 10");
                player.runCommand("clear @p [r=5, scores={subquest_6=0}, hasitem={item=crimson_fungus, quantity=1..}] crimson_fungus 0 10");
                player.runCommand("clear @p [r=5, scores={subquest_6=0}, hasitem={item=warped_fungus, quantity=1..}] warped_fungus 0 10");
                player.runCommand("titleraw @p [r=5, scores={subquest_6=1}, c=1] title {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_6=1}, c=1] subtitle {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.subtitulo\" }]}");
                player.runCommand("execute as @p [r=5, scores={subquest_6=1}, c=1] run tellraw @a {\"rawtext\":[{\"selector\": \"@a[r=5,c=1]\"},{ \"translate\":\"subquest.concluida.mensagem.publica.6\" }]}");
                player.runCommand("playsound missioncomplete @p [r=5, scores={subquest_6=1}, c=1] ~ ~ ~");
                player.runCommand("scoreboard players set @p [r=5, scores={subquest_6=1}] subquest_6 2");
                player.runCommand("tag @p [r=5, scores={subquest_6=2}] add subquest0");
				
                break;
            
			case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DE REQUISITOS
	if (score0 === 0 && score1 < 100) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eKayo')
            .body({"rawtext": [{"translate": "dialogo.subquest6.requisitos"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DA MISSAO CUMPRIDA
	if (score0 >= 1) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eKayo')
            .body({"rawtext": [{"translate": "dialogo.subquest6.cumprida"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
});

world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;

    if (!player || !player.runCommand) return;
    if (target.typeId !== "well:npc5") return;

    const obj0 = world.scoreboard.getObjective("subquest_8");
	const obj1 = world.scoreboard.getObjective("coleta_madeira"); //coleta_madeira=300
	
    

    const score0 = obj0?.getScore(player);
	const score1 = obj1?.getScore(player);
	
	//player.runCommand("playsound npc.homem.dialogue.crianca @p [r=5]");
    player.runCommand("playsound npc.homem.dialogue.adulto @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.jovem @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.velho @p [r=5]");
    
    //player.runCommand("playsound npc.mulher.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.velha @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.adulta @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.jovem @p [r=5]");
    //player.runCommand("effect @e[type=!player,r=5] slowness 20 60 true");
  
    const chance = Math.random();
        if (chance < 0.25) {
          player.runCommand("playanimation @e[type=!player,r=5] animation.humanoid.custom.well.dialogo1");
        } else if (chance < 0.5) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo2");
        } else if (chance < 0.75) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo3");
        } else {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo4");
        }
    
	//DIALOGO DA MISSAO
    if (score0 === 0 && score1 >= 300) {
        const nina1 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eFrodon')
            .body({"rawtext": [{"translate": "dialogo.8.subquest"}]})
            .button({"rawtext": [{"translate": "botao.subquest.aceitar"}]}, "textures/ui/permissions_visitor_hand.png")
            .button({"rawtext": [{"translate": "botao.subquest.sim"}]}, "textures/ui/pergaminhos/icones_submissoes/slimeball.png")
			.button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina1.show(player).then(result => {
        if (result.canceled) return;
        switch (result.selection) {
            case 0:
                player.runCommand("tag @p [r=5, scores={subquest_8=0, coleta_madeira=300..}] remove subquest0");
                player.runCommand("tag @p [r=5, scores={subquest_8=0, coleta_madeira=300..}] add subquest8");
                player.runCommand("titleraw @p [r=5, scores={subquest_8=0, coleta_madeira=300..}] title {\"rawtext\":[{ \"translate\":\"subquest.aceitou.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_8=0, coleta_madeira=300..}] subtitle {\"rawtext\":[{ \"translate\":\"subquest.aceitou.subtitulo\" }]}");
                player.runCommand("tag @p [r=5, scores={subquest_8=0, coleta_madeira=300..}] remove subquest5");
                player.runCommand("tag @p [r=5, scores={subquest_8=0, coleta_madeira=300..}] remove subquest2");
                player.runCommand("tag @p [r=5, scores={subquest_8=0, coleta_madeira=300..}] remove subquest4");
                player.runCommand("tag @p [r=5, scores={subquest_8=0, coleta_madeira=300..}] remove subquest13");
                player.runCommand("tag @p [r=5, scores={subquest_8=0, coleta_madeira=300..}] remove subquest1");
                player.runCommand("tag @p [r=5, scores={subquest_8=0, coleta_madeira=300..}] remove subquest7");
                player.runCommand("tag @p [r=5, scores={subquest_8=0, coleta_madeira=300..}] remove subquest6");
                player.runCommand("tag @p [r=5, scores={subquest_8=0, coleta_madeira=300..}] remove subquest9");
                player.runCommand("tag @p [r=5, scores={subquest_8=0, coleta_madeira=300..}] remove subquest10");
                player.runCommand("tag @p [r=5, scores={subquest_8=0, coleta_madeira=300..}] remove subquest11");
                player.runCommand("tag @p [r=5, scores={subquest_8=0, coleta_madeira=300..}] remove subquest12");
                player.runCommand("tag @p [r=5, scores={subquest_8=0, coleta_madeira=300..}] remove subquest3");
                player.runCommand("tag @p [r=5, scores={subquest_8=0, coleta_madeira=300..}] remove subquest14");
                player.runCommand("tag @p [r=5, scores={subquest_8=0, coleta_madeira=300..}] remove subquest15");
                player.runCommand("tag @p [r=5, scores={subquest_8=0, coleta_madeira=300..}] remove subquest16");
                player.runCommand("tag @p [r=5, scores={subquest_8=0, coleta_madeira=300..}] remove subquest17");
                player.runCommand("tag @p [r=5, scores={subquest_8=0, coleta_madeira=300..}] remove subquest18");
                player.runCommand("tag @p [r=5, scores={subquest_8=0, coleta_madeira=300..}] remove subquest19");
                player.runCommand("tag @p [r=5, scores={subquest_8=0, coleta_madeira=300..}] remove subquest20");
                player.runCommand("tag @p [r=5, scores={subquest_8=0, coleta_madeira=300..}] remove subquest21");
                player.runCommand("tag @p [r=5, scores={subquest_8=0, coleta_madeira=300..}] remove subquest22");
                player.runCommand("tag @p [r=5, scores={subquest_8=0, coleta_madeira=300..}] remove subquest23");
                player.runCommand("tag @p [r=5, scores={subquest_8=0, coleta_madeira=300..}] remove subquest24");
                player.runCommand("tag @p [r=5, scores={subquest_8=0, coleta_madeira=300..}] remove subquest25");
                player.runCommand("tag @p [r=5, scores={subquest_8=0, coleta_madeira=300..}] remove subquest26");
                player.runCommand("tag @p [r=5, scores={subquest_8=0, coleta_madeira=300..}] remove subquest27");
                player.runCommand("tag @p [r=5, scores={subquest_8=0, coleta_madeira=300..}] remove subquest28");
                player.runCommand("tag @p [r=5, scores={subquest_8=0, coleta_madeira=300..}] remove subquest29");
                player.runCommand("tag @p [r=5, scores={subquest_8=0, coleta_madeira=300..}] remove subquest30");
                				
				
                break;
            
			case 1:
                player.runCommand("give @p [r=5, scores={subquest_8=0}, hasitem={item=slime_ball, quantity=50..}] well:orbe_evolutiva 1 0 ");
                player.runCommand("give @p [r=5, scores={subquest_8=0}, hasitem={item=slime_ball, quantity=50..}] well:container_coracao 1 0 "); 
                player.runCommand("tag @p [r=5, scores={subquest_8=0}, hasitem={item=slime_ball, quantity=50..}] remove subquest8"); 
                player.runCommand("scoreboard players add @p [r=5, scores={subquest_8=0}, hasitem={item=slime_ball, quantity=50..}] subquest_8 1");
                player.runCommand("clear @p [r=5, scores={subquest_8=1}, hasitem={item=slime_ball, quantity=50..}] slime_ball 0 70");
                player.runCommand("titleraw @p [r=5, scores={subquest_8=1}, c=1] title {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_8=1}, c=1] subtitle {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.subtitulo\" }]}");
                player.runCommand("execute as @p [r=5, scores={subquest_8=1}, c=1] run tellraw @a {\"rawtext\":[{\"selector\": \"@a[r=5,c=1]\"},{ \"translate\":\"subquest.concluida.mensagem.publica.8\" }]}");
                player.runCommand("playsound missioncomplete @p [r=5, scores={subquest_8=1}, c=1] ~ ~ ~");
                player.runCommand("scoreboard players set @p [r=5, scores={subquest_8=1}] subquest_8 2");
                player.runCommand("tag @p [r=5, scores={subquest_8=2}] add subquest0");
                				
                break;
            
			case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DE REQUISITOS
	if (score0 === 0 && score1 < 300) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eFrodon')
            .body({"rawtext": [{"translate": "dialogo.subquest8.requisitos"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DA MISSAO CUMPRIDA
	if (score0 >= 1) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eFrodon')
            .body({"rawtext": [{"translate": "dialogo.subquest8.cumprida"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
});

world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;

    if (!player || !player.runCommand) return;
    if (target.typeId !== "well:npc6") return;

    const obj0 = world.scoreboard.getObjective("subquest_9");
	const obj1 = world.scoreboard.getObjective("mineiracao"); //mineiracao=200
	
    

    const score0 = obj0?.getScore(player);
	const score1 = obj1?.getScore(player);
	
	//player.runCommand("playsound npc.homem.dialogue.crianca @p [r=5]");
    player.runCommand("playsound npc.homem.dialogue.adulto @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.jovem @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.velho @p [r=5]");
    
    //player.runCommand("playsound npc.mulher.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.velha @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.adulta @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.jovem @p [r=5]");
    //player.runCommand("effect @e[type=!player,r=5] slowness 20 60 true");
  
    const chance = Math.random();
        if (chance < 0.25) {
          player.runCommand("playanimation @e[type=!player,r=5] animation.humanoid.custom.well.dialogo1");
        } else if (chance < 0.5) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo2");
        } else if (chance < 0.75) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo3");
        } else {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo4");
        }
    
	//DIALOGO DA MISSAO
    if (score0 === 0 && score1 >= 200) {
        const nina1 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eGuillard')
            .body({"rawtext": [{"translate": "dialogo.9.subquest"}]})
            .button({"rawtext": [{"translate": "botao.subquest.aceitar"}]}, "textures/ui/permissions_visitor_hand.png")
            .button({"rawtext": [{"translate": "botao.subquest.sim"}]}, "textures/ui/pergaminhos/icones_submissoes/cabeca_dragao.png")
			.button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina1.show(player).then(result => {
        if (result.canceled) return;
        switch (result.selection) {
            case 0:
                player.runCommand("tag @p [r=5, scores={subquest_9=0, mineiracao=200..}] remove subquest0");
                player.runCommand("tag @p [r=5, scores={subquest_9=0, mineiracao=200..}] add subquest9");
                player.runCommand("titleraw @p [r=5, scores={subquest_9=0, mineiracao=200..}] title {\"rawtext\":[{ \"translate\":\"subquest.aceitou.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_9=0, mineiracao=200..}] subtitle {\"rawtext\":[{ \"translate\":\"subquest.aceitou.subtitulo\" }]}");
                player.runCommand("tag @p [r=5, scores={subquest_9=0, mineiracao=200..}] remove subquest5");
                player.runCommand("tag @p [r=5, scores={subquest_9=0, mineiracao=200..}] remove subquest2");
                player.runCommand("tag @p [r=5, scores={subquest_9=0, mineiracao=200..}] remove subquest4");
                player.runCommand("tag @p [r=5, scores={subquest_9=0, mineiracao=200..}] remove subquest13");
                player.runCommand("tag @p [r=5, scores={subquest_9=0, mineiracao=200..}] remove subquest1");
                player.runCommand("tag @p [r=5, scores={subquest_9=0, mineiracao=200..}] remove subquest7");
                player.runCommand("tag @p [r=5, scores={subquest_9=0, mineiracao=200..}] remove subquest6");
                player.runCommand("tag @p [r=5, scores={subquest_9=0, mineiracao=200..}] remove subquest8");
                player.runCommand("tag @p [r=5, scores={subquest_9=0, mineiracao=200..}] remove subquest10");
                player.runCommand("tag @p [r=5, scores={subquest_9=0, mineiracao=200..}] remove subquest11");
                player.runCommand("tag @p [r=5, scores={subquest_9=0, mineiracao=200..}] remove subquest12");
                player.runCommand("tag @p [r=5, scores={subquest_9=0, mineiracao=200..}] remove subquest3");
                player.runCommand("tag @p [r=5, scores={subquest_9=0, mineiracao=200..}] remove subquest14");
                player.runCommand("tag @p [r=5, scores={subquest_9=0, mineiracao=200..}] remove subquest15");
                player.runCommand("tag @p [r=5, scores={subquest_9=0, mineiracao=200..}] remove subquest16");
                player.runCommand("tag @p [r=5, scores={subquest_9=0, mineiracao=200..}] remove subquest17");
                player.runCommand("tag @p [r=5, scores={subquest_9=0, mineiracao=200..}] remove subquest18");
                player.runCommand("tag @p [r=5, scores={subquest_9=0, mineiracao=200..}] remove subquest19");
                player.runCommand("tag @p [r=5, scores={subquest_9=0, mineiracao=200..}] remove subquest20");
                player.runCommand("tag @p [r=5, scores={subquest_9=0, mineiracao=200..}] remove subquest21");
                player.runCommand("tag @p [r=5, scores={subquest_9=0, mineiracao=200..}] remove subquest22");
                player.runCommand("tag @p [r=5, scores={subquest_9=0, mineiracao=200..}] remove subquest23");
                player.runCommand("tag @p [r=5, scores={subquest_9=0, mineiracao=200..}] remove subquest24");
                player.runCommand("tag @p [r=5, scores={subquest_9=0, mineiracao=200..}] remove subquest25");
                player.runCommand("tag @p [r=5, scores={subquest_9=0, mineiracao=200..}] remove subquest26");
                player.runCommand("tag @p [r=5, scores={subquest_9=0, mineiracao=200..}] remove subquest27");
                player.runCommand("tag @p [r=5, scores={subquest_9=0, mineiracao=200..}] remove subquest28");
                player.runCommand("tag @p [r=5, scores={subquest_9=0, mineiracao=200..}] remove subquest29");
                player.runCommand("tag @p [r=5, scores={subquest_9=0, mineiracao=200..}] remove subquest30");
				
                break;
            
			case 1:
                player.runCommand("give @p [r=5, scores={subquest_9=0}, hasitem ={ location = slot.armor.head, item=skull, data= 5}] well:orbe_evolutiva 1 0 ");
                player.runCommand("give @p [r=5, scores={subquest_9=0}, hasitem ={ location = slot.armor.head, item=skull, data= 5}] well:container_coracao 1 0 "); 
                player.runCommand("tag @p [r=5, scores={subquest_9=0}, hasitem ={ location = slot.armor.head, item=skull, data= 5}] remove subquest9");
                player.runCommand("scoreboard players add @p [r=5, scores={subquest_9=0}, hasitem ={ location = slot.armor.head, item=skull, data= 5}] subquest_9 1");
                player.runCommand("clear @p [r=5, scores={subquest_9=0}, hasitem ={ location = slot.armor.head, item=skull, data= 5}] skull 5 1");
                player.runCommand("titleraw @p [r=5, scores={subquest_9=1}, c=1] title {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_9=1}, c=1] subtitle {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.subtitulo\" }]}");
                player.runCommand("execute as @p [r=5, scores={subquest_9=1}, c=1] run tellraw @a {\"rawtext\":[{\"selector\": \"@a[r=5,c=1]\"},{ \"translate\":\"subquest.concluida.mensagem.publica.9\" }]}");
                player.runCommand("playsound missioncomplete @p [r=5, scores={subquest_9=1}, c=1] ~ ~ ~");
                player.runCommand("scoreboard players set @p [r=5, scores={subquest_9=1}] subquest_9 2");
                player.runCommand("tag @p [r=5, scores={subquest_9=2}] add subquest0");
                
				break;
            
			case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DE REQUISITOS
	if (score0 === 0 && score1 < 200) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eGuillard')
            .body({"rawtext": [{"translate": "dialogo.subquest9.requisitos"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DA MISSAO CUMPRIDA
	if (score0 >= 1) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eGuillard')
            .body({"rawtext": [{"translate": "dialogo.subquest9.cumprida"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
});

world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;

    if (!player || !player.runCommand) return;
    if (target.typeId !== "well:npc7") return;

    const obj0 = world.scoreboard.getObjective("subquest_10");
	const obj1 = world.scoreboard.getObjective("agricultura"); //mineiracao=650
	
    

    const score0 = obj0?.getScore(player);
	const score1 = obj1?.getScore(player);
	
	//player.runCommand("playsound npc.homem.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.adulto @p [r=5]");
    player.runCommand("playsound npc.homem.dialogue.jovem @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.velho @p [r=5]");
    
    //player.runCommand("playsound npc.mulher.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.velha @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.adulta @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.jovem @p [r=5]");
    //player.runCommand("effect @e[type=!player,r=5] slowness 20 60 true");
  
    const chance = Math.random();
        if (chance < 0.25) {
          player.runCommand("playanimation @e[type=!player,r=5] animation.humanoid.custom.well.dialogo1");
        } else if (chance < 0.5) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo2");
        } else if (chance < 0.75) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo3");
        } else {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo4");
        }
    
	//DIALOGO DA MISSAO
    if (score0 === 0 && score1 >= 650) {
        const nina1 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eZacky')
            .body({"rawtext": [{"translate": "dialogo.10.subquest"}]})
            .button({"rawtext": [{"translate": "botao.subquest.aceitar"}]}, "textures/ui/permissions_visitor_hand.png")
            .button({"rawtext": [{"translate": "botao.subquest.mostrar"}]}, "textures/ui/pergaminhos/icones_submissoes/vaca.png")
			.button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina1.show(player).then(result => {
        if (result.canceled) return;
        switch (result.selection) {
            case 0:
                player.runCommand("tag @p [r=5, scores={subquest_10=0, agricultura=650..}] remove subquest0");
                player.runCommand("tag @p [r=5, scores={subquest_10=0, agricultura=650..}] add subquest10");
                player.runCommand("titleraw @p [r=5, scores={subquest_10=0, agricultura=650..}] title {\"rawtext\":[{ \"translate\":\"subquest.aceitou.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_10=0, agricultura=650..}] subtitle {\"rawtext\":[{ \"translate\":\"subquest.aceitou.subtitulo\" }]}");
                player.runCommand("tag @p [r=5, scores={subquest_10=0, agricultura=650..}] remove subquest5");
                player.runCommand("tag @p [r=5, scores={subquest_10=0, agricultura=650..}] remove subquest2");
                player.runCommand("tag @p [r=5, scores={subquest_10=0, agricultura=650..}] remove subquest4");
                player.runCommand("tag @p [r=5, scores={subquest_10=0, agricultura=650..}] remove subquest13");
                player.runCommand("tag @p [r=5, scores={subquest_10=0, agricultura=650..}] remove subquest1");
                player.runCommand("tag @p [r=5, scores={subquest_10=0, agricultura=650..}] remove subquest7");
                player.runCommand("tag @p [r=5, scores={subquest_10=0, agricultura=650..}] remove subquest6");
                player.runCommand("tag @p [r=5, scores={subquest_10=0, agricultura=650..}] remove subquest8");
                player.runCommand("tag @p [r=5, scores={subquest_10=0, agricultura=650..}] remove subquest9");
                player.runCommand("tag @p [r=5, scores={subquest_10=0, agricultura=650..}] remove subquest11");
                player.runCommand("tag @p [r=5, scores={subquest_10=0, agricultura=650..}] remove subquest12");
                player.runCommand("tag @p [r=5, scores={subquest_10=0, agricultura=650..}] remove subquest3");
                player.runCommand("tag @p [r=5, scores={subquest_10=0, agricultura=650..}] remove subquest14");
                player.runCommand("tag @p [r=5, scores={subquest_10=0, agricultura=650..}] remove subquest15");
                player.runCommand("tag @p [r=5, scores={subquest_10=0, agricultura=650..}] remove subquest16");
                player.runCommand("tag @p [r=5, scores={subquest_10=0, agricultura=650..}] remove subquest17");
                player.runCommand("tag @p [r=5, scores={subquest_10=0, agricultura=650..}] remove subquest18");
                player.runCommand("tag @p [r=5, scores={subquest_10=0, agricultura=650..}] remove subquest19");
                player.runCommand("tag @p [r=5, scores={subquest_10=0, agricultura=650..}] remove subquest20");
                player.runCommand("tag @p [r=5, scores={subquest_10=0, agricultura=650..}] remove subquest21");
                player.runCommand("tag @p [r=5, scores={subquest_10=0, agricultura=650..}] remove subquest22");
                player.runCommand("tag @p [r=5, scores={subquest_10=0, agricultura=650..}] remove subquest23");
                player.runCommand("tag @p [r=5, scores={subquest_10=0, agricultura=650..}] remove subquest24");
                player.runCommand("tag @p [r=5, scores={subquest_10=0, agricultura=650..}] remove subquest25");
                player.runCommand("tag @p [r=5, scores={subquest_10=0, agricultura=650..}] remove subquest26");
                player.runCommand("tag @p [r=5, scores={subquest_10=0, agricultura=650..}] remove subquest27");
                player.runCommand("tag @p [r=5, scores={subquest_10=0, agricultura=650..}] remove subquest28");
                player.runCommand("tag @p [r=5, scores={subquest_10=0, agricultura=650..}] remove subquest29");
                player.runCommand("tag @p [r=5, scores={subquest_10=0, agricultura=650..}] remove subquest30");
				
                break;
            
			case 1:
                // recompensas
                player.runCommand("execute as @e[type=mooshroom,r=10] run give @p[r=5,scores={subquest_10=0}] well:orbe_evolutiva 1 0");
                player.runCommand("execute as @e[type=mooshroom,r=10] run give @p[r=5,scores={subquest_10=0}] well:container_coracao 1 0");
            
                // ❌ removida linha inválida com @p[type=mooshroom]
            
                // progresso da quest
                player.runCommand("execute as @e[type=mooshroom,c=3,r=10] run scoreboard players add @p[r=5,scores={subquest_10=0}] subquest_10 1");
            
                // mensagens
                player.runCommand("titleraw @p[r=5,scores={subquest_10=1},c=1] title {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.titulo\" }]}");
                player.runCommand("titleraw @p[r=5,scores={subquest_10=1},c=1] subtitle {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.subtitulo\" }]}");
                player.runCommand("execute as @p[r=5,scores={subquest_10=1},c=1] run tellraw @a {\"rawtext\":[{\"selector\":\"@a[r=5,c=1]\"},{\"translate\":\"subquest.concluida.mensagem.publica.10\"}]}");
                player.runCommand("playsound missioncomplete @p[r=5,scores={subquest_10=1},c=1] ~ ~ ~");
            
                // finalização da quest
                player.runCommand("tag @p[r=5,scores={subquest_10=1},c=1] remove subquest10");
                player.runCommand("scoreboard players set @p[r=5,scores={subquest_10=1}] subquest_10 2");
                player.runCommand("tag @p[r=5,scores={subquest_10=2}] add subquest0");
            
            break;

            
			case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DE REQUISITOS
	if (score0 === 0 && score1 < 650) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eZacky')
            .body({"rawtext": [{"translate": "dialogo.subquest10.requisitos"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DA MISSAO CUMPRIDA
	if (score0 >= 1) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eZacky')
            .body({"rawtext": [{"translate": "dialogo.subquest10.cumprida"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
});

world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;

    if (!player || !player.runCommand) return;
    if (target.typeId !== "well:npc8") return;

    const obj0 = world.scoreboard.getObjective("subquest_11");
	const obj1 = world.scoreboard.getObjective("agricultura"); //mineiracao=700
	
    

    const score0 = obj0?.getScore(player);
	const score1 = obj1?.getScore(player);
	
	//player.runCommand("playsound npc.homem.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.adulto @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.jovem @p [r=5]");
    player.runCommand("playsound npc.homem.dialogue.velho @p [r=5]");
    
    //player.runCommand("playsound npc.mulher.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.velha @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.adulta @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.jovem @p [r=5]");
    //player.runCommand("effect @e[type=!player,r=5] slowness 20 60 true");
  
    const chance = Math.random();
        if (chance < 0.25) {
          player.runCommand("playanimation @e[type=!player,r=5] animation.humanoid.custom.well.dialogo1");
        } else if (chance < 0.5) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo2");
        } else if (chance < 0.75) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo3");
        } else {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo4");
        }
    
	//DIALOGO DA MISSAO
    if (score0 === 0 && score1 >= 700) {
        const nina1 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eSheeron')
            .body({"rawtext": [{"translate": "dialogo.11.subquest"}]})
            .button({"rawtext": [{"translate": "botao.subquest.aceitar"}]}, "textures/ui/permissions_visitor_hand.png")
            .button({"rawtext": [{"translate": "botao.subquest.sim"}]}, "textures/ui/pergaminhos/icones_submissoes/plantas_ancestrais.png")
			.button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina1.show(player).then(result => {
        if (result.canceled) return;
        switch (result.selection) {
            case 0:
                player.runCommand("tag @p [r=5, scores={subquest_11=0, agricultura=700..}] remove subquest0");
                player.runCommand("tag @p [r=5, scores={subquest_11=0, agricultura=700..}] add subquest11");
                player.runCommand("titleraw @p [r=5, scores={subquest_11=0, agricultura=700..}] title {\"rawtext\":[{ \"translate\":\"subquest.aceitou.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_11=0, agricultura=700..}] subtitle {\"rawtext\":[{ \"translate\":\"subquest.aceitou.subtitulo\" }]}");
                player.runCommand("tag @p [r=5, scores={subquest_11=0, agricultura=700..}] remove subquest1");
                player.runCommand("tag @p [r=5, scores={subquest_11=0, agricultura=700..}] remove subquest2");
                player.runCommand("tag @p [r=5, scores={subquest_11=0, agricultura=700..}] remove subquest4");
                player.runCommand("tag @p [r=5, scores={subquest_11=0, agricultura=700..}] remove subquest5");
                player.runCommand("tag @p [r=5, scores={subquest_11=0, agricultura=700..}] remove subquest6");
                player.runCommand("tag @p [r=5, scores={subquest_11=0, agricultura=700..}] remove subquest7");
                player.runCommand("tag @p [r=5, scores={subquest_11=0, agricultura=700..}] remove subquest8");
                player.runCommand("tag @p [r=5, scores={subquest_11=0, agricultura=700..}] remove subquest9");
                player.runCommand("tag @p [r=5, scores={subquest_11=0, agricultura=700..}] remove subquest10");
                player.runCommand("tag @p [r=5, scores={subquest_11=0, agricultura=700..}] remove subquest19");
                player.runCommand("tag @p [r=5, scores={subquest_11=0, agricultura=700..}] remove subquest12");
                player.runCommand("tag @p [r=5, scores={subquest_11=0, agricultura=700..}] remove subquest3");
                player.runCommand("tag @p [r=5, scores={subquest_11=0, agricultura=700..}] remove subquest14");
                player.runCommand("tag @p [r=5, scores={subquest_11=0, agricultura=700..}] remove subquest15");
                player.runCommand("tag @p [r=5, scores={subquest_11=0, agricultura=700..}] remove subquest16");
                player.runCommand("tag @p [r=5, scores={subquest_11=0, agricultura=700..}] remove subquest17");
                player.runCommand("tag @p [r=5, scores={subquest_11=0, agricultura=700..}] remove subquest13");
                player.runCommand("tag @p [r=5, scores={subquest_11=0, agricultura=700..}] remove subquest18");
                player.runCommand("tag @p [r=5, scores={subquest_11=0, agricultura=700..}] remove subquest20");
                player.runCommand("tag @p [r=5, scores={subquest_11=0, agricultura=700..}] remove subquest21");
                player.runCommand("tag @p [r=5, scores={subquest_11=0, agricultura=700..}] remove subquest22");
                player.runCommand("tag @p [r=5, scores={subquest_11=0, agricultura=700..}] remove subquest23");
                player.runCommand("tag @p [r=5, scores={subquest_11=0, agricultura=700..}] remove subquest24");
                player.runCommand("tag @p [r=5, scores={subquest_11=0, agricultura=700..}] remove subquest25");
                player.runCommand("tag @p [r=5, scores={subquest_11=0, agricultura=700..}] remove subquest26");
                player.runCommand("tag @p [r=5, scores={subquest_11=0, agricultura=700..}] remove subquest27");
                player.runCommand("tag @p [r=5, scores={subquest_11=0, agricultura=700..}] remove subquest28");
                player.runCommand("tag @p [r=5, scores={subquest_11=0, agricultura=700..}] remove subquest29");
                player.runCommand("tag @p [r=5, scores={subquest_11=0, agricultura=700..}] remove subquest30");
				
                break;
            
			case 1:
                player.runCommand("give @p [r=5, scores={subquest_11=0, flores_plantacao_sniffer_final=1}] well:orbe_evolutiva 1 0 ");
                player.runCommand("give @p [r=5, scores={subquest_11=0, flores_plantacao_sniffer_final=1}] well:container_coracao 1 0 ");
                player.runCommand("tag @p [r=10, scores={subquest_11=0, flores_plantacao_sniffer_final=1}] remove subquest11");  
                player.runCommand("scoreboard players add @p [r=5, scores={subquest_11=0, flores_plantacao_sniffer_final=1..}] subquest_11 1");
                player.runCommand("scoreboard players set @p [r=5, scores={subquest_11=1, flores_plantacao_sniffer_final=1}] flores_plantacao_sniffer_final 2");
                player.runCommand("titleraw @p [r=5, scores={subquest_11=1}, c=1] title {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_11=1}, c=1] subtitle {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.subtitulo\" }]}");
                player.runCommand("execute as @p [r=5, scores={subquest_11=1}, c=1] run tellraw @a {\"rawtext\":[{\"selector\": \"@a[r=5,c=1]\"},{ \"translate\":\"subquest.concluida.mensagem.publica.11\" }]}");
                player.runCommand("playsound missioncomplete @p [r=5, scores={subquest_11=1}, c=1] ~ ~ ~");
                player.runCommand("scoreboard players set @p [r=5, scores={subquest_11=1}] subquest_11 2");
                player.runCommand("tag @p [r=5, scores={subquest_11=2}] add subquest0");
                
				break;
            
			case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DE REQUISITOS
	if (score0 === 0 && score1 < 700) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eSheeron')
            .body({"rawtext": [{"translate": "dialogo.subquest11.requisitos"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DA MISSAO CUMPRIDA
	if (score0 >= 1) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eSheeron')
            .body({"rawtext": [{"translate": "dialogo.subquest11.cumprida"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
});

world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;

    if (!player || !player.runCommand) return;
    if (target.typeId !== "well:npc9") return;

    const obj0 = world.scoreboard.getObjective("subquest_12");
	const obj1 = world.scoreboard.getObjective("pescaria"); //pescaria=550
	
    

    const score0 = obj0?.getScore(player);
	const score1 = obj1?.getScore(player);
	
	//player.runCommand("playsound npc.homem.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.adulto @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.jovem @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.velho @p [r=5]");
    
    //player.runCommand("playsound npc.mulher.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.velha @p [r=5]");
    player.runCommand("playsound npc.mulher.dialogue.adulta @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.jovem @p [r=5]");
    //player.runCommand("effect @e[type=!player,r=5] slowness 20 60 true");
  
    const chance = Math.random();
        if (chance < 0.25) {
          player.runCommand("playanimation @e[type=!player,r=5] animation.humanoid.custom.well.dialogo1");
        } else if (chance < 0.5) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo2");
        } else if (chance < 0.75) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo3");
        } else {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo4");
        }
    
	//DIALOGO DA MISSAO
    if (score0 === 0 && score1 >= 550) {
        const nina1 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eYasminne')
            .body({"rawtext": [{"translate": "dialogo.12.subquest"}]})
            .button({"rawtext": [{"translate": "botao.subquest.aceitar"}]}, "textures/ui/permissions_visitor_hand.png")
            .button({"rawtext": [{"translate": "botao.subquest.sim"}]}, "textures/ui/pergaminhos/icones_submissoes/coral_cerebro.png")
			.button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina1.show(player).then(result => {
        if (result.canceled) return;
        switch (result.selection) {
            case 0:
                player.runCommand("tag @p [r=5, scores={subquest_12=0, pescaria=550..}] remove subquest0");
                player.runCommand("tag @p [r=5, scores={subquest_12=0, pescaria=550..}] add subquest12");
                player.runCommand("titleraw @p [r=5, scores={subquest_12=0, pescaria=550..}] title {\"rawtext\":[{ \"translate\":\"subquest.aceitou.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_12=0, pescaria=550..}] subtitle {\"rawtext\":[{ \"translate\":\"subquest.aceitou.subtitulo\" }]}");
                player.runCommand("tag @p [r=5, scores={subquest_12=0, pescaria=550..}] remove subquest1");
                player.runCommand("tag @p [r=5, scores={subquest_12=0, pescaria=550..}] remove subquest3");
                player.runCommand("tag @p [r=5, scores={subquest_12=0, pescaria=550..}] remove subquest4");
                player.runCommand("tag @p [r=5, scores={subquest_12=0, pescaria=550..}] remove subquest2");
                player.runCommand("tag @p [r=5, scores={subquest_12=0, pescaria=550..}] remove subquest6");
                player.runCommand("tag @p [r=5, scores={subquest_12=0, pescaria=550..}] remove subquest7");
                player.runCommand("tag @p [r=5, scores={subquest_12=0, pescaria=550..}] remove subquest8");
                player.runCommand("tag @p [r=5, scores={subquest_12=0, pescaria=550..}] remove subquest9");
                player.runCommand("tag @p [r=5, scores={subquest_12=0, pescaria=550..}] remove subquest10");
                player.runCommand("tag @p [r=5, scores={subquest_12=0, pescaria=550..}] remove subquest11");
                player.runCommand("tag @p [r=5, scores={subquest_12=0, pescaria=550..}] remove subquest21");
                player.runCommand("tag @p [r=5, scores={subquest_12=0, pescaria=550..}] remove subquest13");
                player.runCommand("tag @p [r=5, scores={subquest_12=0, pescaria=550..}] remove subquest14");
                player.runCommand("tag @p [r=5, scores={subquest_12=0, pescaria=550..}] remove subquest15");
                player.runCommand("tag @p [r=5, scores={subquest_12=0, pescaria=550..}] remove subquest16");
                player.runCommand("tag @p [r=5, scores={subquest_12=0, pescaria=550..}] remove subquest17");
                player.runCommand("tag @p [r=5, scores={subquest_12=0, pescaria=550..}] remove subquest18");
                player.runCommand("tag @p [r=5, scores={subquest_12=0, pescaria=550..}] remove subquest19");
                player.runCommand("tag @p [r=5, scores={subquest_12=0, pescaria=550..}] remove subquest20");
                player.runCommand("tag @p [r=5, scores={subquest_12=0, pescaria=550..}] remove subquest5");
                player.runCommand("tag @p [r=5, scores={subquest_12=0, pescaria=550..}] remove subquest22");
                player.runCommand("tag @p [r=5, scores={subquest_12=0, pescaria=550..}] remove subquest23");
                player.runCommand("tag @p [r=5, scores={subquest_12=0, pescaria=550..}] remove subquest24");
                player.runCommand("tag @p [r=5, scores={subquest_12=0, pescaria=550..}] remove subquest25");
                player.runCommand("tag @p [r=5, scores={subquest_12=0, pescaria=550..}] remove subquest26");
                player.runCommand("tag @p [r=5, scores={subquest_12=0, pescaria=550..}] remove subquest27");
                player.runCommand("tag @p [r=5, scores={subquest_12=0, pescaria=550..}] remove subquest28");
                player.runCommand("tag @p [r=5, scores={subquest_12=0, pescaria=550..}] remove subquest29");
                player.runCommand("tag @p [r=5, scores={subquest_12=0, pescaria=550..}] remove subquest30");
				
                break;
            
			case 1:
                player.runCommand("execute as @e [r=10, scores={subquest_12=0}] run give @p [r=5, scores={coral_elfo=1}] well:orbe_evolutiva 1 0 ");
                player.runCommand("execute as @e [r=10, scores={subquest_12=0}] run give @p [r=5, scores={coral_elfo=1}] well:container_coracao 1 0 ");
                player.runCommand("execute as @e [r=10, scores={subquest_12=0}] run tag @p [r=10, scores={coral_elfo=1}] remove subquest12");  
                player.runCommand("scoreboard players add @p [r=5, scores={subquest_12=0, coral_elfo=1..}] subquest_12 1");
                player.runCommand("scoreboard players set @p [r=5, scores={subquest_12=1, coral_elfo=1}] coral_elfo 2");
                player.runCommand("titleraw @p [r=5, scores={subquest_12=1}, c=1] title {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_12=1}, c=1] subtitle {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.subtitulo\" }]}");
                player.runCommand("execute as @p [r=5, scores={subquest_12=1}, c=1] run tellraw @a {\"rawtext\":[{\"selector\": \"@a[r=5,c=1]\"},{ \"translate\":\"subquest.concluida.mensagem.publica.12\" }]}");
                player.runCommand("playsound missioncomplete @p [r=5, scores={subquest_12=1}, c=1] ~ ~ ~");
                player.runCommand("scoreboard players set @p [r=5, scores={subquest_12=1}] subquest_12 2");
                player.runCommand("tag @p [r=5, scores={subquest_12=2}] add subquest0");
                
				break;
            
			case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DE REQUISITOS
	if (score0 === 0 && score1 < 550) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eYasminne')
            .body({"rawtext": [{"translate": "dialogo.subquest12.requisitos"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DA MISSAO CUMPRIDA
	if (score0 >= 1) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eYasminne')
            .body({"rawtext": [{"translate": "dialogo.subquest12.cumprida"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
});

world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;

    if (!player || !player.runCommand) return;
    if (target.typeId !== "well:npc10") return;

    const obj0 = world.scoreboard.getObjective("subquest_20");
	const obj1 = world.scoreboard.getObjective("pescaria"); //pescaria=650
	
    

    const score0 = obj0?.getScore(player);
	const score1 = obj1?.getScore(player);
	
	//player.runCommand("playsound npc.homem.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.adulto @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.jovem @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.velho @p [r=5]");
    
    //player.runCommand("playsound npc.mulher.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.velha @p [r=5]");
    player.runCommand("playsound npc.mulher.dialogue.adulta @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.jovem @p [r=5]");
    //player.runCommand("effect @e[type=!player,r=5] slowness 20 60 true");
  
    const chance = Math.random();
        if (chance < 0.25) {
          player.runCommand("playanimation @e[type=!player,r=5] animation.humanoid.custom.well.dialogo1");
        } else if (chance < 0.5) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo2");
        } else if (chance < 0.75) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo3");
        } else {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo4");
        }
    
	//DIALOGO DA MISSAO
    if (score0 === 0 && score1 >= 650) {
        const nina1 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eSunny')
            .body({"rawtext": [{"translate": "dialogo.20.subquest"}]})
            .button({"rawtext": [{"translate": "botao.subquest.aceitar"}]}, "textures/ui/permissions_visitor_hand.png")
            .button({"rawtext": [{"translate": "botao.subquest.sim"}]}, "textures/ui/pergaminhos/icones_submissoes/para_raios.png")
			.button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina1.show(player).then(result => {
        if (result.canceled) return;
        switch (result.selection) {
            case 0:
                player.runCommand("tag @p [r=5, scores={subquest_20=0, pescaria=650..}] remove subquest0");
                player.runCommand("tag @p [r=5, scores={subquest_20=0, pescaria=650..}] add subquest20");
                player.runCommand("titleraw @p [r=5, scores={subquest_20=0, pescaria=650..}] title {\"rawtext\":[{ \"translate\":\"subquest.aceitou.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_20=0, pescaria=650..}] subtitle {\"rawtext\":[{ \"translate\":\"subquest.aceitou.subtitulo\" }]}");
                player.runCommand("tag @p [r=5, scores={subquest_20=0, pescaria=650..}] remove subquest1");
                player.runCommand("tag @p [r=5, scores={subquest_20=0, pescaria=650..}] remove subquest3");
                player.runCommand("tag @p [r=5, scores={subquest_20=0, pescaria=650..}] remove subquest4");
                player.runCommand("tag @p [r=5, scores={subquest_20=0, pescaria=650..}] remove subquest2");
                player.runCommand("tag @p [r=5, scores={subquest_20=0, pescaria=650..}] remove subquest6");
                player.runCommand("tag @p [r=5, scores={subquest_20=0, pescaria=650..}] remove subquest7");
                player.runCommand("tag @p [r=5, scores={subquest_20=0, pescaria=650..}] remove subquest8");
                player.runCommand("tag @p [r=5, scores={subquest_20=0, pescaria=650..}] remove subquest9");
                player.runCommand("tag @p [r=5, scores={subquest_20=0, pescaria=650..}] remove subquest10");
                player.runCommand("tag @p [r=5, scores={subquest_20=0, pescaria=650..}] remove subquest11");
                player.runCommand("tag @p [r=5, scores={subquest_20=0, pescaria=650..}] remove subquest21");
                player.runCommand("tag @p [r=5, scores={subquest_20=0, pescaria=650..}] remove subquest13");
                player.runCommand("tag @p [r=5, scores={subquest_20=0, pescaria=650..}] remove subquest14");
                player.runCommand("tag @p [r=5, scores={subquest_20=0, pescaria=650..}] remove subquest15");
                player.runCommand("tag @p [r=5, scores={subquest_20=0, pescaria=650..}] remove subquest16");
                player.runCommand("tag @p [r=5, scores={subquest_20=0, pescaria=650..}] remove subquest17");
                player.runCommand("tag @p [r=5, scores={subquest_20=0, pescaria=650..}] remove subquest18");
                player.runCommand("tag @p [r=5, scores={subquest_20=0, pescaria=650..}] remove subquest19");
                player.runCommand("tag @p [r=5, scores={subquest_20=0, pescaria=650..}] remove subquest12");
                player.runCommand("tag @p [r=5, scores={subquest_20=0, pescaria=650..}] remove subquest5");
                player.runCommand("tag @p [r=5, scores={subquest_20=0, pescaria=650..}] remove subquest22");
                player.runCommand("tag @p [r=5, scores={subquest_20=0, pescaria=650..}] remove subquest23");
                player.runCommand("tag @p [r=5, scores={subquest_20=0, pescaria=650..}] remove subquest24");
                player.runCommand("tag @p [r=5, scores={subquest_20=0, pescaria=650..}] remove subquest25");
                player.runCommand("tag @p [r=5, scores={subquest_20=0, pescaria=650..}] remove subquest26");
                player.runCommand("tag @p [r=5, scores={subquest_20=0, pescaria=650..}] remove subquest27");
                player.runCommand("tag @p [r=5, scores={subquest_20=0, pescaria=650..}] remove subquest28");
                player.runCommand("tag @p [r=5, scores={subquest_20=0, pescaria=650..}] remove subquest29");
                player.runCommand("tag @p [r=5, scores={subquest_20=0, pescaria=650..}] remove subquest30");
				
                break;
            
			case 1:
                player.runCommand("execute as @e [r=10, scores={subquest_20=0}] run give @p [r=5, scores={pararaios=1}] well:orbe_evolutiva 1 0 ");
                player.runCommand("execute as @e [r=10, scores={subquest_20=0}] run give @p [r=5, scores={pararaios=1}] well:container_coracao 1 0 ");
                player.runCommand("execute as @e [r=10, scores={subquest_20=0}] run tag @p [r=10, scores={pararaios=1}] remove subquest20");  
                player.runCommand("scoreboard players add @p [r=5, scores={subquest_20=0, pararaios=1..}] subquest_20 1");
                player.runCommand("scoreboard players set @p [r=5, scores={subquest_20=1, pararaios=1}] pararaios 2");
                player.runCommand("titleraw @p [r=5, scores={subquest_20=1}, c=1] title {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_20=1}, c=1] subtitle {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.subtitulo\" }]}");
                player.runCommand("execute as @p [r=5, scores={subquest_20=1}, c=1] run tellraw @a {\"rawtext\":[{\"selector\": \"@a[r=5,c=1]\"},{ \"translate\":\"subquest.concluida.mensagem.publica.20\" }]}");
                player.runCommand("playsound missioncomplete @p [r=5, scores={subquest_20=1}, c=1] ~ ~ ~");
                player.runCommand("scoreboard players set @p [r=5, scores={subquest_20=1}] subquest_20 2");
                player.runCommand("tag @p [r=5, scores={subquest_20=2}] add subquest0");
				
				player.runCommand("execute as @p [r=5, scores={subquest_20=2}, c=1] run setblock 1053 108 1061 air");
				
				break;
            
			case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DE REQUISITOS
	if (score0 === 0 && score1 < 650) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eSunny')
            .body({"rawtext": [{"translate": "dialogo.subquest20.requisitos"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DA MISSAO CUMPRIDA
	if (score0 >= 1) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eSunny')
            .body({"rawtext": [{"translate": "dialogo.subquest20.cumprida"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
});

///SUBQUESTS MAGOS

world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;

    if (!player || !player.runCommand) return;
    if (target.typeId !== "well:npc46") return;

    const obj0 = world.scoreboard.getObjective("subquest_25");
	const obj1 = world.scoreboard.getObjective("coleta_madeira"); //coleta_madeira=750
	
    

    const score0 = obj0?.getScore(player);
	const score1 = obj1?.getScore(player);
	
	//player.runCommand("playsound npc.homem.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.adulto @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.jovem @p [r=5]");
    player.runCommand("playsound npc.homem.dialogue.velho @p [r=5]");
    
    //player.runCommand("playsound npc.mulher.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.velha @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.adulta @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.jovem @p [r=5]");
    //player.runCommand("effect @e[type=!player,r=5] slowness 20 60 true");
  
    const chance = Math.random();
        if (chance < 0.25) {
          player.runCommand("playanimation @e[type=!player,r=5] animation.humanoid.custom.well.dialogo1");
        } else if (chance < 0.5) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo2");
        } else if (chance < 0.75) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo3");
        } else {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo4");
        }
    
	//DIALOGO DA MISSAO
    if (score0 === 0 && score1 >= 750) {
        const nina1 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eOrion')
            .body({"rawtext": [{"translate": "dialogo.25.subquest"}]})
            .button({"rawtext": [{"translate": "botao.subquest.aceitar"}]}, "textures/ui/permissions_visitor_hand.png")
            .button({"rawtext": [{"translate": "botao.subquest.sim"}]}, "textures/ui/pergaminhos/icones_submissoes/cajados.png")
			.button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina1.show(player).then(result => {
        if (result.canceled) return;
        switch (result.selection) {
            case 0:
                player.runCommand("tag @p [r=5, scores={subquest_25=0, coleta_madeira=750..}] remove subquest0");
                player.runCommand("tag @p [r=5, scores={subquest_25=0, coleta_madeira=750..}] add subquest25");
                player.runCommand("titleraw @p [r=5, scores={subquest_25=0, coleta_madeira=750..}] title {\"rawtext\":[{ \"translate\":\"subquest.aceitou.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_25=0, coleta_madeira=750..}] subtitle {\"rawtext\":[{ \"translate\":\"subquest.aceitou.subtitulo\" }]}");
                player.runCommand("tag @p [r=5, scores={subquest_25=0, coleta_madeira=750..}] remove subquest1");
                player.runCommand("tag @p [r=5, scores={subquest_25=0, coleta_madeira=750..}] remove subquest2");
                player.runCommand("tag @p [r=5, scores={subquest_25=0, coleta_madeira=750..}] remove subquest20");
                player.runCommand("tag @p [r=5, scores={subquest_25=0, coleta_madeira=750..}] remove subquest5");
                player.runCommand("tag @p [r=5, scores={subquest_25=0, coleta_madeira=750..}] remove subquest6");
                player.runCommand("tag @p [r=5, scores={subquest_25=0, coleta_madeira=750..}] remove subquest7");
                player.runCommand("tag @p [r=5, scores={subquest_25=0, coleta_madeira=750..}] remove subquest8");
                player.runCommand("tag @p [r=5, scores={subquest_25=0, coleta_madeira=750..}] remove subquest9");
                player.runCommand("tag @p [r=5, scores={subquest_25=0, coleta_madeira=750..}] remove subquest10");
                player.runCommand("tag @p [r=5, scores={subquest_25=0, coleta_madeira=750..}] remove subquest11");
                player.runCommand("tag @p [r=5, scores={subquest_25=0, coleta_madeira=750..}] remove subquest12");
                player.runCommand("tag @p [r=5, scores={subquest_25=0, coleta_madeira=750..}] remove subquest3");
                player.runCommand("tag @p [r=5, scores={subquest_25=0, coleta_madeira=750..}] remove subquest13");
                player.runCommand("tag @p [r=5, scores={subquest_25=0, coleta_madeira=750..}] remove subquest15");
                player.runCommand("tag @p [r=5, scores={subquest_25=0, coleta_madeira=750..}] remove subquest16");
                player.runCommand("tag @p [r=5, scores={subquest_25=0, coleta_madeira=750..}] remove subquest17");
                player.runCommand("tag @p [r=5, scores={subquest_25=0, coleta_madeira=750..}] remove subquest18");
                player.runCommand("tag @p [r=5, scores={subquest_25=0, coleta_madeira=750..}] remove subquest19");
                player.runCommand("tag @p [r=5, scores={subquest_25=0, coleta_madeira=750..}] remove subquest14");
                player.runCommand("tag @p [r=5, scores={subquest_25=0, coleta_madeira=750..}] remove subquest21");
                player.runCommand("tag @p [r=5, scores={subquest_25=0, coleta_madeira=750..}] remove subquest22");
                player.runCommand("tag @p [r=5, scores={subquest_25=0, coleta_madeira=750..}] remove subquest23");
                player.runCommand("tag @p [r=5, scores={subquest_25=0, coleta_madeira=750..}] remove subquest24");
                player.runCommand("tag @p [r=5, scores={subquest_25=0, coleta_madeira=750..}] remove subquest4");
                player.runCommand("tag @p [r=5, scores={subquest_25=0, coleta_madeira=750..}] remove subquest26");
                player.runCommand("tag @p [r=5, scores={subquest_25=0, coleta_madeira=750..}] remove subquest27");
                player.runCommand("tag @p [r=5, scores={subquest_25=0, coleta_madeira=750..}] remove subquest28");
                player.runCommand("tag @p [r=5, scores={subquest_25=0, coleta_madeira=750..}] remove subquest29");
                player.runCommand("tag @p [r=5, scores={subquest_25=0, coleta_madeira=750..}] remove subquest30");
				
                break;
            
			case 1:
                player.runCommand("give @p [r=5, scores={subquest_25=0}, hasitem={item=well:cajado_almas, item=well:cajado_sangue, item=well:cajado_gelo, item=well:cajado_venenoso, quantity=1..}] well:orbe_evolutiva 1 0 ");
                player.runCommand("give @p [r=5, scores={subquest_25=0}, hasitem={item=well:cajado_almas, item=well:cajado_sangue, item=well:cajado_gelo, item=well:cajado_venenoso, quantity=1..}] well:container_coracao 1 0 "); 
                player.runCommand("tag @p [r=5, scores={subquest_25=0}, hasitem={item=well:cajado_almas, item=well:cajado_sangue, item=well:cajado_gelo, item=well:cajado_venenoso, quantity=1..}] remove subquest25"); 
                player.runCommand("scoreboard players add @p [r=5, scores={subquest_25=0}, hasitem={item=well:cajado_almas, item=well:cajado_sangue, item=well:cajado_gelo, item=well:cajado_venenoso, quantity=1..}] subquest_25 1");
                player.runCommand("clear @p [r=5, scores={subquest_25=1..}, hasitem={item=well:cajado_almas, quantity=1..}] well:cajado_almas 0 10");
                player.runCommand("clear @p [r=5, scores={subquest_25=1..}, hasitem={item=well:cajado_sangue, quantity=1..}] well:cajado_sangue 0 10");
                player.runCommand("clear @p [r=5, scores={subquest_25=1..}, hasitem={item=well:cajado_gelo, quantity=1..}] well:cajado_gelo 0 10");
                player.runCommand("clear @p [r=5, scores={subquest_25=1..}, hasitem={item=well:cajado_venenoso, quantity=1..}] well:cajado_venenoso 0 10");
                player.runCommand("titleraw @p [r=5, scores={subquest_25=1}, c=1] title {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_25=1}, c=1] subtitle {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.subtitulo\" }]}");
                player.runCommand("execute as @p [r=5, scores={subquest_25=1}, c=1] run tellraw @a {\"rawtext\":[{\"selector\": \"@a[r=5,c=1]\"},{ \"translate\":\"subquest.concluida.mensagem.publica.25\" }]}");
                player.runCommand("playsound missioncomplete @p [r=5, scores={subquest_25=1}, c=1] ~ ~ ~");
                player.runCommand("scoreboard players set @p [r=5, scores={subquest_25=1}] subquest_25 2");
                player.runCommand("tag @p [r=5, scores={subquest_25=2}] add subquest0");
				
				break;
            
			case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DE REQUISITOS
	if (score0 === 0 && score1 < 750) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eOrion')
            .body({"rawtext": [{"translate": "dialogo.subquest25.requisitos"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DA MISSAO CUMPRIDA
	if (score0 >= 1) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eOrion')
            .body({"rawtext": [{"translate": "dialogo.subquest25.cumprida"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
});

world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;

    if (!player || !player.runCommand) return;
    if (target.typeId !== "well:npc47") return;

    const obj0 = world.scoreboard.getObjective("subquest_26");
	const obj1 = world.scoreboard.getObjective("agricultura"); //agricultura=750
	
    

    const score0 = obj0?.getScore(player);
	const score1 = obj1?.getScore(player);
	
	//player.runCommand("playsound npc.homem.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.adulto @p [r=5]");
    player.runCommand("playsound npc.homem.dialogue.jovem @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.velho @p [r=5]");
    
    //player.runCommand("playsound npc.mulher.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.velha @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.adulta @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.jovem @p [r=5]");
    //player.runCommand("effect @e[type=!player,r=5] slowness 20 60 true");
  
    const chance = Math.random();
        if (chance < 0.25) {
          player.runCommand("playanimation @e[type=!player,r=5] animation.humanoid.custom.well.dialogo1");
        } else if (chance < 0.5) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo2");
        } else if (chance < 0.75) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo3");
        } else {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo4");
        }
    
	//DIALOGO DA MISSAO
    if (score0 === 0 && score1 >= 750) {
        const nina1 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eLink')
            .body({"rawtext": [{"translate": "dialogo.26.subquest"}]})
            .button({"rawtext": [{"translate": "botao.subquest.aceitar"}]}, "textures/ui/permissions_visitor_hand.png")
            .button({"rawtext": [{"translate": "botao.subquest.sim"}]}, "textures/ui/pergaminhos/icones_submissoes/frasco_mana_cheio.png")
			.button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina1.show(player).then(result => {
        if (result.canceled) return;
        switch (result.selection) {
            case 0:
                player.runCommand("tag @p [r=5, scores={subquest_26=0, agricultura=750..}] remove subquest0");
                player.runCommand("tag @p [r=5, scores={subquest_26=0, agricultura=750..}] add subquest26");
                player.runCommand("titleraw @p [r=5, scores={subquest_26=0, agricultura=750..}] title {\"rawtext\":[{ \"translate\":\"subquest.aceitou.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_26=0, agricultura=750..}] subtitle {\"rawtext\":[{ \"translate\":\"subquest.aceitou.subtitulo\" }]}");
                player.runCommand("tag @p [r=5, scores={subquest_26=0, agricultura=750..}] remove subquest1");
                player.runCommand("tag @p [r=5, scores={subquest_26=0, agricultura=750..}] remove subquest2");
                player.runCommand("tag @p [r=5, scores={subquest_26=0, agricultura=750..}] remove subquest20");
                player.runCommand("tag @p [r=5, scores={subquest_26=0, agricultura=750..}] remove subquest5");
                player.runCommand("tag @p [r=5, scores={subquest_26=0, agricultura=750..}] remove subquest6");
                player.runCommand("tag @p [r=5, scores={subquest_26=0, agricultura=750..}] remove subquest7");
                player.runCommand("tag @p [r=5, scores={subquest_26=0, agricultura=750..}] remove subquest8");
                player.runCommand("tag @p [r=5, scores={subquest_26=0, agricultura=750..}] remove subquest9");
                player.runCommand("tag @p [r=5, scores={subquest_26=0, agricultura=750..}] remove subquest10");
                player.runCommand("tag @p [r=5, scores={subquest_26=0, agricultura=750..}] remove subquest11");
                player.runCommand("tag @p [r=5, scores={subquest_26=0, agricultura=750..}] remove subquest12");
                player.runCommand("tag @p [r=5, scores={subquest_26=0, agricultura=750..}] remove subquest3");
                player.runCommand("tag @p [r=5, scores={subquest_26=0, agricultura=750..}] remove subquest13");
                player.runCommand("tag @p [r=5, scores={subquest_26=0, agricultura=750..}] remove subquest15");
                player.runCommand("tag @p [r=5, scores={subquest_26=0, agricultura=750..}] remove subquest16");
                player.runCommand("tag @p [r=5, scores={subquest_26=0, agricultura=750..}] remove subquest17");
                player.runCommand("tag @p [r=5, scores={subquest_26=0, agricultura=750..}] remove subquest18");
                player.runCommand("tag @p [r=5, scores={subquest_26=0, agricultura=750..}] remove subquest19");
                player.runCommand("tag @p [r=5, scores={subquest_26=0, agricultura=750..}] remove subquest14");
                player.runCommand("tag @p [r=5, scores={subquest_26=0, agricultura=750..}] remove subquest21");
                player.runCommand("tag @p [r=5, scores={subquest_26=0, agricultura=750..}] remove subquest22");
                player.runCommand("tag @p [r=5, scores={subquest_26=0, agricultura=750..}] remove subquest23");
                player.runCommand("tag @p [r=5, scores={subquest_26=0, agricultura=750..}] remove subquest24");
                player.runCommand("tag @p [r=5, scores={subquest_26=0, agricultura=750..}] remove subquest4");
                player.runCommand("tag @p [r=5, scores={subquest_26=0, agricultura=750..}] remove subquest25");
                player.runCommand("tag @p [r=5, scores={subquest_26=0, agricultura=750..}] remove subquest27");
                player.runCommand("tag @p [r=5, scores={subquest_26=0, agricultura=750..}] remove subquest28");
                player.runCommand("tag @p [r=5, scores={subquest_26=0, agricultura=750..}] remove subquest29");
                player.runCommand("tag @p [r=5, scores={subquest_26=0, agricultura=750..}] remove subquest30");
				
                break;
            
			case 1:
                player.runCommand("give @p [r=5, scores={subquest_26=0}, hasitem={item=well:frasco_mana_cheio, quantity=1..}] well:orbe_evolutiva 1 0 ");
                player.runCommand("give @p [r=5, scores={subquest_26=0}, hasitem={item=well:frasco_mana_cheio, quantity=1..}] well:container_coracao 1 0 "); 
                player.runCommand("tag @p [r=5, scores={subquest_26=0}, hasitem={item=well:frasco_mana_cheio, quantity=1..}] remove subquest26"); 
                player.runCommand("scoreboard players add @p [r=5, scores={subquest_26=0}, hasitem={item=well:frasco_mana_cheio, quantity=1..}] subquest_26 1");
                player.runCommand("clear @p [r=5, scores={subquest_26=1..}, hasitem={item=well:frasco_mana_cheio, quantity=1..}] well:cajado_almas 0 1");
                player.runCommand("titleraw @p [r=5, scores={subquest_26=1}, c=1] title {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_26=1}, c=1] subtitle {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.subtitulo\" }]}");
                player.runCommand("execute as @p [r=5, scores={subquest_26=1}, c=1] run tellraw @a {\"rawtext\":[{\"selector\": \"@a[r=5,c=1]\"},{ \"translate\":\"subquest.concluida.mensagem.publica.26\" }]}");
                player.runCommand("playsound missioncomplete @p [r=5, scores={subquest_26=1}, c=1] ~ ~ ~");
                player.runCommand("scoreboard players set @p [r=5, scores={subquest_26=1}] subquest_26 2");
                player.runCommand("tag @p [r=5, scores={subquest_26=2}] add subquest0");
				
				break;
            
			case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DE REQUISITOS
	if (score0 === 0 && score1 < 750) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eLink')
            .body({"rawtext": [{"translate": "dialogo.subquest26.requisitos"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DA MISSAO CUMPRIDA
	if (score0 >= 1) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eLink')
            .body({"rawtext": [{"translate": "dialogo.subquest26.cumprida"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
});

world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;

    if (!player || !player.runCommand) return;
    if (target.typeId !== "well:npc50") return;

    const obj0 = world.scoreboard.getObjective("subquest_27");
	const obj1 = world.scoreboard.getObjective("pescaria"); //pescaria=800
	
    

    const score0 = obj0?.getScore(player);
	const score1 = obj1?.getScore(player);
	
	//player.runCommand("playsound npc.homem.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.adulto @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.jovem @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.velho @p [r=5]");
    
    //player.runCommand("playsound npc.mulher.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.velha @p [r=5]");
    player.runCommand("playsound npc.mulher.dialogue.adulta @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.jovem @p [r=5]");
    //player.runCommand("effect @e[type=!player,r=5] slowness 20 60 true");
  
    const chance = Math.random();
        if (chance < 0.25) {
          player.runCommand("playanimation @e[type=!player,r=5] animation.humanoid.custom.well.dialogo1");
        } else if (chance < 0.5) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo2");
        } else if (chance < 0.75) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo3");
        } else {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo4");
        }
    
	//DIALOGO DA MISSAO
    if (score0 === 0 && score1 >= 800) {
        const nina1 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eVivienne')
            .body({"rawtext": [{"translate": "dialogo.27.subquest"}]})
            .button({"rawtext": [{"translate": "botao.subquest.aceitar"}]}, "textures/ui/permissions_visitor_hand.png")
            .button({"rawtext": [{"translate": "botao.subquest.sim"}]}, "textures/ui/pergaminhos/icones_submissoes/velas.png")
			.button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina1.show(player).then(result => {
        if (result.canceled) return;
        switch (result.selection) {
            case 0:
                player.runCommand("tag @p [r=5, scores={subquest_27=0, pescaria=800..}] remove subquest0");
                player.runCommand("tag @p [r=5, scores={subquest_27=0, pescaria=800..}] add subquest27");
                player.runCommand("titleraw @p [r=5, scores={subquest_27=0, pescaria=800..}] title {\"rawtext\":[{ \"translate\":\"subquest.aceitou.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_27=0, pescaria=800..}] subtitle {\"rawtext\":[{ \"translate\":\"subquest.aceitou.subtitulo\" }]}");
                player.runCommand("tag @p [r=5, scores={subquest_27=0, pescaria=800..}] remove subquest1");
                player.runCommand("tag @p [r=5, scores={subquest_27=0, pescaria=800..}] remove subquest3");
                player.runCommand("tag @p [r=5, scores={subquest_27=0, pescaria=800..}] remove subquest4");
                player.runCommand("tag @p [r=5, scores={subquest_27=0, pescaria=800..}] remove subquest2");
                player.runCommand("tag @p [r=5, scores={subquest_27=0, pescaria=800..}] remove subquest6");
                player.runCommand("tag @p [r=5, scores={subquest_27=0, pescaria=800..}] remove subquest7");
                player.runCommand("tag @p [r=5, scores={subquest_27=0, pescaria=800..}] remove subquest8");
                player.runCommand("tag @p [r=5, scores={subquest_27=0, pescaria=800..}] remove subquest9");
                player.runCommand("tag @p [r=5, scores={subquest_27=0, pescaria=800..}] remove subquest10");
                player.runCommand("tag @p [r=5, scores={subquest_27=0, pescaria=800..}] remove subquest11");
                player.runCommand("tag @p [r=5, scores={subquest_27=0, pescaria=800..}] remove subquest21");
                player.runCommand("tag @p [r=5, scores={subquest_27=0, pescaria=800..}] remove subquest13");
                player.runCommand("tag @p [r=5, scores={subquest_27=0, pescaria=800..}] remove subquest14");
                player.runCommand("tag @p [r=5, scores={subquest_27=0, pescaria=800..}] remove subquest15");
                player.runCommand("tag @p [r=5, scores={subquest_27=0, pescaria=800..}] remove subquest16");
                player.runCommand("tag @p [r=5, scores={subquest_27=0, pescaria=800..}] remove subquest17");
                player.runCommand("tag @p [r=5, scores={subquest_27=0, pescaria=800..}] remove subquest18");
                player.runCommand("tag @p [r=5, scores={subquest_27=0, pescaria=800..}] remove subquest19");
                player.runCommand("tag @p [r=5, scores={subquest_27=0, pescaria=800..}] remove subquest12");
                player.runCommand("tag @p [r=5, scores={subquest_27=0, pescaria=800..}] remove subquest5");
                player.runCommand("tag @p [r=5, scores={subquest_27=0, pescaria=800..}] remove subquest22");
                player.runCommand("tag @p [r=5, scores={subquest_27=0, pescaria=800..}] remove subquest23");
                player.runCommand("tag @p [r=5, scores={subquest_27=0, pescaria=800..}] remove subquest24");
                player.runCommand("tag @p [r=5, scores={subquest_27=0, pescaria=800..}] remove subquest25");
                player.runCommand("tag @p [r=5, scores={subquest_27=0, pescaria=800..}] remove subquest26");
                player.runCommand("tag @p [r=5, scores={subquest_27=0, pescaria=800..}] remove subquest20");
                player.runCommand("tag @p [r=5, scores={subquest_27=0, pescaria=800..}] remove subquest28");
                player.runCommand("tag @p [r=5, scores={subquest_27=0, pescaria=800..}] remove subquest29");
                player.runCommand("tag @p [r=5, scores={subquest_27=0, pescaria=800..}] remove subquest30");
				
                break;
            
			case 1:
                player.runCommand("execute as @e [r=10, scores={subquest_27=0}] run give @p [r=5, scores={velas_acesas=1}] well:orbe_evolutiva 1 0 ");
                player.runCommand("execute as @e [r=10, scores={subquest_27=0}] run give @p [r=5, scores={velas_acesas=1}] well:container_coracao 1 0 ");
                player.runCommand("execute as @e [r=10, scores={subquest_27=0}] run tag @p [r=10, scores={velas_acesas=1}] remove subquest27");  
                player.runCommand("scoreboard players add @p [r=5, scores={subquest_27=0, velas_acesas=1..}] subquest_27 1");
                player.runCommand("scoreboard players set @p [r=5, scores={subquest_27=1, velas_acesas=1}] velas_acesas 2");
                player.runCommand("titleraw @p [r=5, scores={subquest_27=1}, c=1] title {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_27=1}, c=1] subtitle {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.subtitulo\" }]}");
                player.runCommand("execute as @p [r=5, scores={subquest_27=1}, c=1] run tellraw @a {\"rawtext\":[{\"selector\": \"@a[r=5,c=1]\"},{ \"translate\":\"subquest.concluida.mensagem.publica.27\" }]}");
                player.runCommand("playsound missioncomplete @p [r=5, scores={subquest_27=1}, c=1] ~ ~ ~");
                player.runCommand("scoreboard players set @p [r=5, scores={subquest_27=1}] subquest_27 2");
                player.runCommand("tag @p [r=5, scores={subquest_27=2}] add subquest0");
				
				break;
            
			case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DE REQUISITOS
	if (score0 === 0 && score1 < 800) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eVivienne')
            .body({"rawtext": [{"translate": "dialogo.subquest27.requisitos"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DA MISSAO CUMPRIDA
	if (score0 >= 1) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eVivienne')
            .body({"rawtext": [{"translate": "dialogo.subquest27.cumprida"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
});

world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;

    if (!player || !player.runCommand) return;
    if (target.typeId !== "well:npc49") return;

    const obj0 = world.scoreboard.getObjective("subquest_28");
	const obj1 = world.scoreboard.getObjective("mineiracao"); //mineiracao=800
	
    

    const score0 = obj0?.getScore(player);
	const score1 = obj1?.getScore(player);
	
	//player.runCommand("playsound npc.homem.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.adulto @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.jovem @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.velho @p [r=5]");
    
    //player.runCommand("playsound npc.mulher.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.velha @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.adulta @p [r=5]");
    player.runCommand("playsound npc.mulher.dialogue.jovem @p [r=5]");
    //player.runCommand("effect @e[type=!player,r=5] slowness 20 60 true");
  
    const chance = Math.random();
        if (chance < 0.25) {
          player.runCommand("playanimation @e[type=!player,r=5] animation.humanoid.custom.well.dialogo1");
        } else if (chance < 0.5) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo2");
        } else if (chance < 0.75) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo3");
        } else {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo4");
        }
    
	//DIALOGO DA MISSAO
    if (score0 === 0 && score1 >= 800) {
        const nina1 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eCelestia')
            .body({"rawtext": [{"translate": "dialogo.28.subquest"}]})
            .button({"rawtext": [{"translate": "botao.subquest.aceitar"}]}, "textures/ui/permissions_visitor_hand.png")
            .button({"rawtext": [{"translate": "botao.subquest.sim"}]}, "textures/ui/pergaminhos/icones_submissoes/porta.png")
			.button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina1.show(player).then(result => {
        if (result.canceled) return;
        switch (result.selection) {
            case 0:
                player.runCommand("tag @p [r=5, scores={subquest_28=0, mineiracao=800..}] remove subquest0");
                player.runCommand("tag @p [r=5, scores={subquest_28=0, mineiracao=800..}] add subquest28");
                player.runCommand("titleraw @p [r=5, scores={subquest_28=0, mineiracao=800..}] title {\"rawtext\":[{ \"translate\":\"subquest.aceitou.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_28=0, mineiracao=800..}] subtitle {\"rawtext\":[{ \"translate\":\"subquest.aceitou.subtitulo\" }]}");
                player.runCommand("tag @p [r=5, scores={subquest_28=0, mineiracao=800..}] remove subquest1");
                player.runCommand("tag @p [r=5, scores={subquest_28=0, mineiracao=800..}] remove subquest3");
                player.runCommand("tag @p [r=5, scores={subquest_28=0, mineiracao=800..}] remove subquest4");
                player.runCommand("tag @p [r=5, scores={subquest_28=0, mineiracao=800..}] remove subquest2");
                player.runCommand("tag @p [r=5, scores={subquest_28=0, mineiracao=800..}] remove subquest6");
                player.runCommand("tag @p [r=5, scores={subquest_28=0, mineiracao=800..}] remove subquest7");
                player.runCommand("tag @p [r=5, scores={subquest_28=0, mineiracao=800..}] remove subquest8");
                player.runCommand("tag @p [r=5, scores={subquest_28=0, mineiracao=800..}] remove subquest9");
                player.runCommand("tag @p [r=5, scores={subquest_28=0, mineiracao=800..}] remove subquest10");
                player.runCommand("tag @p [r=5, scores={subquest_28=0, mineiracao=800..}] remove subquest11");
                player.runCommand("tag @p [r=5, scores={subquest_28=0, mineiracao=800..}] remove subquest21");
                player.runCommand("tag @p [r=5, scores={subquest_28=0, mineiracao=800..}] remove subquest13");
                player.runCommand("tag @p [r=5, scores={subquest_28=0, mineiracao=800..}] remove subquest14");
                player.runCommand("tag @p [r=5, scores={subquest_28=0, mineiracao=800..}] remove subquest15");
                player.runCommand("tag @p [r=5, scores={subquest_28=0, mineiracao=800..}] remove subquest16");
                player.runCommand("tag @p [r=5, scores={subquest_28=0, mineiracao=800..}] remove subquest17");
                player.runCommand("tag @p [r=5, scores={subquest_28=0, mineiracao=800..}] remove subquest18");
                player.runCommand("tag @p [r=5, scores={subquest_28=0, mineiracao=800..}] remove subquest19");
                player.runCommand("tag @p [r=5, scores={subquest_28=0, mineiracao=800..}] remove subquest12");
                player.runCommand("tag @p [r=5, scores={subquest_28=0, mineiracao=800..}] remove subquest5");
                player.runCommand("tag @p [r=5, scores={subquest_28=0, mineiracao=800..}] remove subquest22");
                player.runCommand("tag @p [r=5, scores={subquest_28=0, mineiracao=800..}] remove subquest23");
                player.runCommand("tag @p [r=5, scores={subquest_28=0, mineiracao=800..}] remove subquest24");
                player.runCommand("tag @p [r=5, scores={subquest_28=0, mineiracao=800..}] remove subquest25");
                player.runCommand("tag @p [r=5, scores={subquest_28=0, mineiracao=800..}] remove subquest26");
                player.runCommand("tag @p [r=5, scores={subquest_28=0, mineiracao=800..}] remove subquest20");
                player.runCommand("tag @p [r=5, scores={subquest_28=0, mineiracao=800..}] remove subquest27");
                player.runCommand("tag @p [r=5, scores={subquest_28=0, mineiracao=800..}] remove subquest29");
                player.runCommand("tag @p [r=5, scores={subquest_28=0, mineiracao=800..}] remove subquest30");
				
                break;
            
			case 1:
                player.runCommand("execute as @e [r=10, scores={subquest_28=0}] run give @p [r=5, scores={porta_carmesin=1}] well:orbe_evolutiva 1 0 ");
                player.runCommand("execute as @e [r=10, scores={subquest_28=0}] run give @p [r=5, scores={porta_carmesin=1}] well:container_coracao 1 0 ");
                player.runCommand("execute as @e [r=10, scores={subquest_28=0}] run tag @p [r=10, scores={porta_carmesin=1}] remove subquest28");  
                player.runCommand("scoreboard players add @p [r=5, scores={subquest_28=0, porta_carmesin=1..}] subquest_28 1");
                player.runCommand("scoreboard players set @p [r=5, scores={subquest_28=1, porta_carmesin=1}] porta_carmesin 2");
                player.runCommand("titleraw @p [r=5, scores={subquest_28=1}, c=1] title {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_28=1}, c=1] subtitle {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.subtitulo\" }]}");
                player.runCommand("execute as @p [r=5, scores={subquest_28=1}, c=1] run tellraw @a {\"rawtext\":[{\"selector\": \"@a[r=5,c=1]\"},{ \"translate\":\"subquest.concluida.mensagem.publica.28\" }]}");
                player.runCommand("playsound missioncomplete @p [r=5, scores={subquest_28=1}, c=1] ~ ~ ~");
                player.runCommand("scoreboard players set @p [r=5, scores={subquest_28=1}] subquest_28 2");
                player.runCommand("tag @p [r=5, scores={subquest_28=2}] add subquest0");
				
				break;
            
			case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DE REQUISITOS
	if (score0 === 0 && score1 < 800) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eCelestia')
            .body({"rawtext": [{"translate": "dialogo.subquest28.requisitos"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DA MISSAO CUMPRIDA
	if (score0 >= 1) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eCelestia')
            .body({"rawtext": [{"translate": "dialogo.subquest28.cumprida"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
});

world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;

    if (!player || !player.runCommand) return;
    if (target.typeId !== "well:npc41") return;

    const obj0 = world.scoreboard.getObjective("subquest_16");
	const obj1 = world.scoreboard.getObjective("agricultura"); //agricultura=800
	
    

    const score0 = obj0?.getScore(player);
	const score1 = obj1?.getScore(player);
	
	//player.runCommand("playsound npc.homem.dialogue.crianca @p [r=5]");
    player.runCommand("playsound npc.homem.dialogue.adulto @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.jovem @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.velho @p [r=5]");
    
    //player.runCommand("playsound npc.mulher.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.velha @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.adulta @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.jovem @p [r=5]");
    //player.runCommand("effect @e[type=!player,r=5] slowness 20 60 true");
  
    const chance = Math.random();
        if (chance < 0.25) {
          player.runCommand("playanimation @e[type=!player,r=5] animation.humanoid.custom.well.dialogo1");
        } else if (chance < 0.5) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo2");
        } else if (chance < 0.75) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo3");
        } else {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo4");
        }
    
	//DIALOGO DA MISSAO
    if (score0 === 0 && score1 >= 800) {
        const nina1 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eAgeu')
            .body({"rawtext": [{"translate": "dialogo.16.subquest"}]})
            .button({"rawtext": [{"translate": "botao.subquest.aceitar"}]}, "textures/ui/permissions_visitor_hand.png")
            .button({"rawtext": [{"translate": "botao.subquest.mostrar"}]}, "textures/ui/pergaminhos/icones_submissoes/fantasma.png")
			.button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina1.show(player).then(result => {
        if (result.canceled) return;
        switch (result.selection) {
            case 0:
                player.runCommand("tag @p [r=5, scores={subquest_16=0, agricultura=800..}] remove subquest0");
                player.runCommand("tag @p [r=5, scores={subquest_16=0, agricultura=800..}] add subquest16");
                player.runCommand("titleraw @p [r=5, scores={subquest_16=0, agricultura=800..}] title {\"rawtext\":[{ \"translate\":\"subquest.aceitou.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_16=0, agricultura=800..}] subtitle {\"rawtext\":[{ \"translate\":\"subquest.aceitou.subtitulo\" }]}");
                player.runCommand("tag @p [r=5, scores={subquest_16=0, agricultura=800..}] remove subquest5");
                player.runCommand("tag @p [r=5, scores={subquest_16=0, agricultura=800..}] remove subquest2");
                player.runCommand("tag @p [r=5, scores={subquest_16=0, agricultura=800..}] remove subquest4");
                player.runCommand("tag @p [r=5, scores={subquest_16=0, agricultura=800..}] remove subquest13");
                player.runCommand("tag @p [r=5, scores={subquest_16=0, agricultura=800..}] remove subquest1");
                player.runCommand("tag @p [r=5, scores={subquest_16=0, agricultura=800..}] remove subquest7");
                player.runCommand("tag @p [r=5, scores={subquest_16=0, agricultura=800..}] remove subquest6");
                player.runCommand("tag @p [r=5, scores={subquest_16=0, agricultura=800..}] remove subquest8");
                player.runCommand("tag @p [r=5, scores={subquest_16=0, agricultura=800..}] remove subquest9");
                player.runCommand("tag @p [r=5, scores={subquest_16=0, agricultura=800..}] remove subquest11");
                player.runCommand("tag @p [r=5, scores={subquest_16=0, agricultura=800..}] remove subquest12");
                player.runCommand("tag @p [r=5, scores={subquest_16=0, agricultura=800..}] remove subquest3");
                player.runCommand("tag @p [r=5, scores={subquest_16=0, agricultura=800..}] remove subquest14");
                player.runCommand("tag @p [r=5, scores={subquest_16=0, agricultura=800..}] remove subquest15");
                player.runCommand("tag @p [r=5, scores={subquest_16=0, agricultura=800..}] remove subquest10");
                player.runCommand("tag @p [r=5, scores={subquest_16=0, agricultura=800..}] remove subquest17");
                player.runCommand("tag @p [r=5, scores={subquest_16=0, agricultura=800..}] remove subquest18");
                player.runCommand("tag @p [r=5, scores={subquest_16=0, agricultura=800..}] remove subquest19");
                player.runCommand("tag @p [r=5, scores={subquest_16=0, agricultura=800..}] remove subquest20");
                player.runCommand("tag @p [r=5, scores={subquest_16=0, agricultura=800..}] remove subquest21");
                player.runCommand("tag @p [r=5, scores={subquest_16=0, agricultura=800..}] remove subquest22");
                player.runCommand("tag @p [r=5, scores={subquest_16=0, agricultura=800..}] remove subquest23");
                player.runCommand("tag @p [r=5, scores={subquest_16=0, agricultura=800..}] remove subquest24");
                player.runCommand("tag @p [r=5, scores={subquest_16=0, agricultura=800..}] remove subquest25");
                player.runCommand("tag @p [r=5, scores={subquest_16=0, agricultura=800..}] remove subquest26");
                player.runCommand("tag @p [r=5, scores={subquest_16=0, agricultura=800..}] remove subquest27");
                player.runCommand("tag @p [r=5, scores={subquest_16=0, agricultura=800..}] remove subquest28");
                player.runCommand("tag @p [r=5, scores={subquest_16=0, agricultura=800..}] remove subquest29");
                player.runCommand("tag @p [r=5, scores={subquest_16=0, agricultura=800..}] remove subquest30");
				
                break;
            
			case 1:
                // recompensas
                player.runCommand("execute as @e[type=well:fantasma_fim,c=3,r=10] run give @p[r=5,scores={subquest_16=0}] well:orbe_evolutiva 1 0");
                player.runCommand("execute as @e[type=well:fantasma_fim,c=3,r=10] run give @p[r=5,scores={subquest_16=0}] well:container_coracao 1 0");
            
                // ❌ removida linha inválida com @p[type=entidade]
            
                // progresso da quest
                player.runCommand("execute as @e[type=well:fantasma_fim,c=3,r=10] run scoreboard players add @p[r=5,scores={subquest_16=0}] subquest_16 1");
            
                // mensagens
                player.runCommand("titleraw @p[r=5,scores={subquest_16=1},c=1] title {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.titulo\" }]}");
                player.runCommand("titleraw @p[r=5,scores={subquest_16=1},c=1] subtitle {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.subtitulo\" }]}");
                player.runCommand("execute as @p[r=5,scores={subquest_16=1},c=1] run tellraw @a {\"rawtext\":[{\"selector\":\"@a[r=5,c=1]\"},{\"translate\":\"subquest.concluida.mensagem.publica.16\"}]}");
                player.runCommand("playsound missioncomplete @p[r=5,scores={subquest_16=1},c=1] ~ ~ ~");
            
                // finalizar quest
                player.runCommand("tag @p[r=5,scores={subquest_16=1},c=1] remove subquest16");
                player.runCommand("scoreboard players set @p[r=5,scores={subquest_16=1}] subquest_16 2");
                player.runCommand("tag @p[r=5,scores={subquest_16=2}] add subquest0");
            
            break;

            
			case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DE REQUISITOS
	if (score0 === 0 && score1 < 800) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eAgeu')
            .body({"rawtext": [{"translate": "dialogo.subquest16.requisitos"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DA MISSAO CUMPRIDA
	if (score0 >= 1) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eAgeu')
            .body({"rawtext": [{"translate": "dialogo.subquest16.cumprida"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
});

world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;

    if (!player || !player.runCommand) return;
    if (target.typeId !== "well:npc42") return;

    const obj0 = world.scoreboard.getObjective("subquest_17");
	const obj1 = world.scoreboard.getObjective("pescaria"); //pescaria=900
	
    

    const score0 = obj0?.getScore(player);
	const score1 = obj1?.getScore(player);
	
	//player.runCommand("playsound npc.homem.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.adulto @p [r=5]");
    player.runCommand("playsound npc.homem.dialogue.jovem @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.velho @p [r=5]");
    
    //player.runCommand("playsound npc.mulher.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.velha @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.adulta @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.jovem @p [r=5]");
    //player.runCommand("effect @e[type=!player,r=5] slowness 20 60 true");
  
    const chance = Math.random();
        if (chance < 0.25) {
          player.runCommand("playanimation @e[type=!player,r=5] animation.humanoid.custom.well.dialogo1");
        } else if (chance < 0.5) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo2");
        } else if (chance < 0.75) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo3");
        } else {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo4");
        }
    
	//DIALOGO DA MISSAO
    if (score0 === 0 && score1 >= 900) {
        const nina1 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eEren')
            .body({"rawtext": [{"translate": "dialogo.17.subquest"}]})
            .button({"rawtext": [{"translate": "botao.subquest.aceitar"}]}, "textures/ui/permissions_visitor_hand.png")
            .button({"rawtext": [{"translate": "botao.subquest.mostrar"}]}, "textures/ui/bestiario/Descoberto/vagalume.png")
			.button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina1.show(player).then(result => {
        if (result.canceled) return;
        switch (result.selection) {
            case 0:
                player.runCommand("tag @p [r=5, scores={subquest_17=0, pescaria=900..}] remove subquest0");
                player.runCommand("tag @p [r=5, scores={subquest_17=0, pescaria=900..}] add subquest17");
                player.runCommand("titleraw @p [r=5, scores={subquest_17=0, pescaria=900..}] title {\"rawtext\":[{ \"translate\":\"subquest.aceitou.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_17=0, pescaria=900..}] subtitle {\"rawtext\":[{ \"translate\":\"subquest.aceitou.subtitulo\" }]}");
                player.runCommand("tag @p [r=5, scores={subquest_17=0, pescaria=900..}] remove subquest5");
                player.runCommand("tag @p [r=5, scores={subquest_17=0, pescaria=900..}] remove subquest2");
                player.runCommand("tag @p [r=5, scores={subquest_17=0, pescaria=900..}] remove subquest4");
                player.runCommand("tag @p [r=5, scores={subquest_17=0, pescaria=900..}] remove subquest13");
                player.runCommand("tag @p [r=5, scores={subquest_17=0, pescaria=900..}] remove subquest1");
                player.runCommand("tag @p [r=5, scores={subquest_17=0, pescaria=900..}] remove subquest7");
                player.runCommand("tag @p [r=5, scores={subquest_17=0, pescaria=900..}] remove subquest6");
                player.runCommand("tag @p [r=5, scores={subquest_17=0, pescaria=900..}] remove subquest8");
                player.runCommand("tag @p [r=5, scores={subquest_17=0, pescaria=900..}] remove subquest9");
                player.runCommand("tag @p [r=5, scores={subquest_17=0, pescaria=900..}] remove subquest11");
                player.runCommand("tag @p [r=5, scores={subquest_17=0, pescaria=900..}] remove subquest12");
                player.runCommand("tag @p [r=5, scores={subquest_17=0, pescaria=900..}] remove subquest3");
                player.runCommand("tag @p [r=5, scores={subquest_17=0, pescaria=900..}] remove subquest14");
                player.runCommand("tag @p [r=5, scores={subquest_17=0, pescaria=900..}] remove subquest15");
                player.runCommand("tag @p [r=5, scores={subquest_17=0, pescaria=900..}] remove subquest10");
                player.runCommand("tag @p [r=5, scores={subquest_17=0, pescaria=900..}] remove subquest16");
                player.runCommand("tag @p [r=5, scores={subquest_17=0, pescaria=900..}] remove subquest18");
                player.runCommand("tag @p [r=5, scores={subquest_17=0, pescaria=900..}] remove subquest19");
                player.runCommand("tag @p [r=5, scores={subquest_17=0, pescaria=900..}] remove subquest20");
                player.runCommand("tag @p [r=5, scores={subquest_17=0, pescaria=900..}] remove subquest21");
                player.runCommand("tag @p [r=5, scores={subquest_17=0, pescaria=900..}] remove subquest22");
                player.runCommand("tag @p [r=5, scores={subquest_17=0, pescaria=900..}] remove subquest23");
                player.runCommand("tag @p [r=5, scores={subquest_17=0, pescaria=900..}] remove subquest24");
                player.runCommand("tag @p [r=5, scores={subquest_17=0, pescaria=900..}] remove subquest25");
                player.runCommand("tag @p [r=5, scores={subquest_17=0, pescaria=900..}] remove subquest26");
                player.runCommand("tag @p [r=5, scores={subquest_17=0, pescaria=900..}] remove subquest27");
                player.runCommand("tag @p [r=5, scores={subquest_17=0, pescaria=900..}] remove subquest28");
                player.runCommand("tag @p [r=5, scores={subquest_17=0, pescaria=900..}] remove subquest29");
                player.runCommand("tag @p [r=5, scores={subquest_17=0, pescaria=900..}] remove subquest30");
				
                break;
            
			case 1:
                // recompensas
                player.runCommand("execute as @e[type=well:vagalume,c=3,r=10] run give @p[r=5,scores={subquest_17=0}] well:orbe_evolutiva 1 0");
                player.runCommand("execute as @e[type=well:vagalume,c=3,r=10] run give @p[r=5,scores={subquest_17=0}] well:container_coracao 1 0");
            
                // ❌ removida linha inválida com @p[type=entidade]
            
                // progresso da quest
                player.runCommand("execute as @e[type=well:vagalume,c=3,r=10] run scoreboard players add @p[r=5,scores={subquest_17=0}] subquest_17 1");
            
                // mensagens
                player.runCommand("titleraw @p[r=5,scores={subquest_17=1},c=1] title {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.titulo\" }]}");
                player.runCommand("titleraw @p[r=5,scores={subquest_17=1},c=1] subtitle {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.subtitulo\" }]}");
                player.runCommand("execute as @p[r=5,scores={subquest_17=1},c=1] run tellraw @a {\"rawtext\":[{\"selector\":\"@a[r=5,c=1]\"},{\"translate\":\"subquest.concluida.mensagem.publica.17\"}]}");
                player.runCommand("playsound missioncomplete @p[r=5,scores={subquest_17=1},c=1] ~ ~ ~");
            
                // finalizar quest
                player.runCommand("tag @p[r=5,scores={subquest_17=1},c=1] remove subquest17");
                player.runCommand("scoreboard players set @p[r=5,scores={subquest_17=1}] subquest_17 2");
                player.runCommand("tag @p[r=5,scores={subquest_17=2}] add subquest0");
            
            break;

            
			case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DE REQUISITOS
	if (score0 === 0 && score1 < 900) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eEren')
            .body({"rawtext": [{"translate": "dialogo.subquest17.requisitos"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DA MISSAO CUMPRIDA
	if (score0 >= 1) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eEren')
            .body({"rawtext": [{"translate": "dialogo.subquest17.cumprida"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
});

world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;

    if (!player || !player.runCommand) return;
    if (target.typeId !== "well:npc43") return;

    const obj0 = world.scoreboard.getObjective("subquest_22");
	const obj1 = world.scoreboard.getObjective("coleta_madeira"); //coleta_madeira=900
	
    

    const score0 = obj0?.getScore(player);
	const score1 = obj1?.getScore(player);
	
	//player.runCommand("playsound npc.homem.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.adulto @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.jovem @p [r=5]");
    player.runCommand("playsound npc.homem.dialogue.velho @p [r=5]");
    
    //player.runCommand("playsound npc.mulher.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.velha @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.adulta @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.jovem @p [r=5]");
    //player.runCommand("effect @e[type=!player,r=5] slowness 20 60 true");
  
    const chance = Math.random();
        if (chance < 0.25) {
          player.runCommand("playanimation @e[type=!player,r=5] animation.humanoid.custom.well.dialogo1");
        } else if (chance < 0.5) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo2");
        } else if (chance < 0.75) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo3");
        } else {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo4");
        }
    
	//DIALOGO DA MISSAO
    if (score0 === 0 && score1 >= 900) {
        const nina1 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eRoderick')
            .body({"rawtext": [{"translate": "dialogo.22.subquest"}]})
            .button({"rawtext": [{"translate": "botao.subquest.aceitar"}]}, "textures/ui/permissions_visitor_hand.png")
            .button({"rawtext": [{"translate": "botao.subquest.mostrar"}]}, "textures/ui/bestiario/Descoberto/vagalume/sereia.png")
			.button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina1.show(player).then(result => {
        if (result.canceled) return;
        switch (result.selection) {
            case 0:
                player.runCommand("tag @p [r=5, scores={subquest_22=0, coleta_madeira=900..}] remove subquest0");
                player.runCommand("tag @p [r=5, scores={subquest_22=0, coleta_madeira=900..}] add subquest22");
                player.runCommand("titleraw @p [r=5, scores={subquest_22=0, coleta_madeira=900..}] title {\"rawtext\":[{ \"translate\":\"subquest.aceitou.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_22=0, coleta_madeira=900..}] subtitle {\"rawtext\":[{ \"translate\":\"subquest.aceitou.subtitulo\" }]}");
                player.runCommand("tag @p [r=5, scores={subquest_22=0, coleta_madeira=900..}] remove subquest5");
                player.runCommand("tag @p [r=5, scores={subquest_22=0, coleta_madeira=900..}] remove subquest2");
                player.runCommand("tag @p [r=5, scores={subquest_22=0, coleta_madeira=900..}] remove subquest4");
                player.runCommand("tag @p [r=5, scores={subquest_22=0, coleta_madeira=900..}] remove subquest13");
                player.runCommand("tag @p [r=5, scores={subquest_22=0, coleta_madeira=900..}] remove subquest1");
                player.runCommand("tag @p [r=5, scores={subquest_22=0, coleta_madeira=900..}] remove subquest7");
                player.runCommand("tag @p [r=5, scores={subquest_22=0, coleta_madeira=900..}] remove subquest6");
                player.runCommand("tag @p [r=5, scores={subquest_22=0, coleta_madeira=900..}] remove subquest8");
                player.runCommand("tag @p [r=5, scores={subquest_22=0, coleta_madeira=900..}] remove subquest9");
                player.runCommand("tag @p [r=5, scores={subquest_22=0, coleta_madeira=900..}] remove subquest11");
                player.runCommand("tag @p [r=5, scores={subquest_22=0, coleta_madeira=900..}] remove subquest12");
                player.runCommand("tag @p [r=5, scores={subquest_22=0, coleta_madeira=900..}] remove subquest3");
                player.runCommand("tag @p [r=5, scores={subquest_22=0, coleta_madeira=900..}] remove subquest14");
                player.runCommand("tag @p [r=5, scores={subquest_22=0, coleta_madeira=900..}] remove subquest15");
                player.runCommand("tag @p [r=5, scores={subquest_22=0, coleta_madeira=900..}] remove subquest10");
                player.runCommand("tag @p [r=5, scores={subquest_22=0, coleta_madeira=900..}] remove subquest16");
                player.runCommand("tag @p [r=5, scores={subquest_22=0, coleta_madeira=900..}] remove subquest18");
                player.runCommand("tag @p [r=5, scores={subquest_22=0, coleta_madeira=900..}] remove subquest19");
                player.runCommand("tag @p [r=5, scores={subquest_22=0, coleta_madeira=900..}] remove subquest20");
                player.runCommand("tag @p [r=5, scores={subquest_22=0, coleta_madeira=900..}] remove subquest21");
                player.runCommand("tag @p [r=5, scores={subquest_22=0, coleta_madeira=900..}] remove subquest17");
                player.runCommand("tag @p [r=5, scores={subquest_22=0, coleta_madeira=900..}] remove subquest23");
                player.runCommand("tag @p [r=5, scores={subquest_22=0, coleta_madeira=900..}] remove subquest24");
                player.runCommand("tag @p [r=5, scores={subquest_22=0, coleta_madeira=900..}] remove subquest25");
                player.runCommand("tag @p [r=5, scores={subquest_22=0, coleta_madeira=900..}] remove subquest26");
                player.runCommand("tag @p [r=5, scores={subquest_22=0, coleta_madeira=900..}] remove subquest27");
                player.runCommand("tag @p [r=5, scores={subquest_22=0, coleta_madeira=900..}] remove subquest28");
                player.runCommand("tag @p [r=5, scores={subquest_22=0, coleta_madeira=900..}] remove subquest29");
                player.runCommand("tag @p [r=5, scores={subquest_22=0, coleta_madeira=900..}] remove subquest30");
				
                break;
            
			case 1:
                // recompensas
                player.runCommand("execute as @e[type=well:sereia,c=3,r=10] run give @p[r=5,scores={subquest_22=0}] well:orbe_evolutiva 1 0");
                player.runCommand("execute as @e[type=well:sereia,c=3,r=10] run give @p[r=5,scores={subquest_22=0}] well:container_coracao 1 0");
            
                // ❌ removida linha inválida com @p[type=entidade]
            
                // progresso da quest
                player.runCommand("execute as @e[type=well:sereia,c=3,r=10] run scoreboard players add @p[r=5,scores={subquest_22=0}] subquest_22 1");
            
                // mensagens
                player.runCommand("titleraw @p[r=5,scores={subquest_22=1},c=1] title {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.titulo\" }]}");
                player.runCommand("titleraw @p[r=5,scores={subquest_22=1},c=1] subtitle {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.subtitulo\" }]}");
                player.runCommand("execute as @p[r=5,scores={subquest_22=1},c=1] run tellraw @a {\"rawtext\":[{\"selector\":\"@a[r=5,c=1]\"},{\"translate\":\"subquest.concluida.mensagem.publica.22\"}]}");
                player.runCommand("playsound missioncomplete @p[r=5,scores={subquest_22=1},c=1] ~ ~ ~");
            
                // finalizar quest
                player.runCommand("tag @p[r=5,scores={subquest_22=1},c=1] remove subquest22");
                player.runCommand("scoreboard players set @p[r=5,scores={subquest_22=1}] subquest_22 2");
                player.runCommand("tag @p[r=5,scores={subquest_22=2}] add subquest0");
            
            break;

            
			case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DE REQUISITOS
	if (score0 === 0 && score1 < 900) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eRoderick')
            .body({"rawtext": [{"translate": "dialogo.subquest22.requisitos"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DA MISSAO CUMPRIDA
	if (score0 >= 1) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eRoderick')
            .body({"rawtext": [{"translate": "dialogo.subquest22.cumprida"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
});

world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;

    if (!player || !player.runCommand) return;
    if (target.typeId !== "well:npc44") return;

    const obj0 = world.scoreboard.getObjective("subquest_23");
	const obj1 = world.scoreboard.getObjective("agricultura"); //agricultura=900
	
    

    const score0 = obj0?.getScore(player);
	const score1 = obj1?.getScore(player);
	
	//player.runCommand("playsound npc.homem.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.adulto @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.jovem @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.velho @p [r=5]");
    
    //player.runCommand("playsound npc.mulher.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.velha @p [r=5]");
    player.runCommand("playsound npc.mulher.dialogue.adulta @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.jovem @p [r=5]");
    //player.runCommand("effect @e[type=!player,r=5] slowness 20 60 true");
  
    const chance = Math.random();
        if (chance < 0.25) {
          player.runCommand("playanimation @e[type=!player,r=5] animation.humanoid.custom.well.dialogo1");
        } else if (chance < 0.5) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo2");
        } else if (chance < 0.75) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo3");
        } else {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo4");
        }
    
	//DIALOGO DA MISSAO
    if (score0 === 0 && score1 >= 900) {
        const nina1 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eSapphire')
            .body({"rawtext": [{"translate": "dialogo.23.subquest"}]})
            .button({"rawtext": [{"translate": "botao.subquest.aceitar"}]}, "textures/ui/permissions_visitor_hand.png")
            .button({"rawtext": [{"translate": "botao.subquest.sim"}]}, "textures/ui/bestiario/Descoberto/coelho.png")
			.button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina1.show(player).then(result => {
        if (result.canceled) return;
        switch (result.selection) {
            case 0:
                player.runCommand("tag @p [r=5, scores={subquest_23=0, agricultura=900..}] remove subquest0");
                player.runCommand("tag @p [r=5, scores={subquest_23=0, agricultura=900..}] add subquest23");
                player.runCommand("titleraw @p [r=5, scores={subquest_23=0, agricultura=900..}] title {\"rawtext\":[{ \"translate\":\"subquest.aceitou.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_23=0, agricultura=900..}] subtitle {\"rawtext\":[{ \"translate\":\"subquest.aceitou.subtitulo\" }]}");
                player.runCommand("tag @p [r=5, scores={subquest_23=0, agricultura=900..}] remove subquest5");
                player.runCommand("tag @p [r=5, scores={subquest_23=0, agricultura=900..}] remove subquest2");
                player.runCommand("tag @p [r=5, scores={subquest_23=0, agricultura=900..}] remove subquest4");
                player.runCommand("tag @p [r=5, scores={subquest_23=0, agricultura=900..}] remove subquest13");
                player.runCommand("tag @p [r=5, scores={subquest_23=0, agricultura=900..}] remove subquest1");
                player.runCommand("tag @p [r=5, scores={subquest_23=0, agricultura=900..}] remove subquest7");
                player.runCommand("tag @p [r=5, scores={subquest_23=0, agricultura=900..}] remove subquest6");
                player.runCommand("tag @p [r=5, scores={subquest_23=0, agricultura=900..}] remove subquest8");
                player.runCommand("tag @p [r=5, scores={subquest_23=0, agricultura=900..}] remove subquest9");
                player.runCommand("tag @p [r=5, scores={subquest_23=0, agricultura=900..}] remove subquest11");
                player.runCommand("tag @p [r=5, scores={subquest_23=0, agricultura=900..}] remove subquest12");
                player.runCommand("tag @p [r=5, scores={subquest_23=0, agricultura=900..}] remove subquest3");
                player.runCommand("tag @p [r=5, scores={subquest_23=0, agricultura=900..}] remove subquest14");
                player.runCommand("tag @p [r=5, scores={subquest_23=0, agricultura=900..}] remove subquest15");
                player.runCommand("tag @p [r=5, scores={subquest_23=0, agricultura=900..}] remove subquest10");
                player.runCommand("tag @p [r=5, scores={subquest_23=0, agricultura=900..}] remove subquest16");
                player.runCommand("tag @p [r=5, scores={subquest_23=0, agricultura=900..}] remove subquest18");
                player.runCommand("tag @p [r=5, scores={subquest_23=0, agricultura=900..}] remove subquest19");
                player.runCommand("tag @p [r=5, scores={subquest_23=0, agricultura=900..}] remove subquest20");
                player.runCommand("tag @p [r=5, scores={subquest_23=0, agricultura=900..}] remove subquest21");
                player.runCommand("tag @p [r=5, scores={subquest_23=0, agricultura=900..}] remove subquest17");
                player.runCommand("tag @p [r=5, scores={subquest_23=0, agricultura=900..}] remove subquest22");
                player.runCommand("tag @p [r=5, scores={subquest_23=0, agricultura=900..}] remove subquest24");
                player.runCommand("tag @p [r=5, scores={subquest_23=0, agricultura=900..}] remove subquest25");
                player.runCommand("tag @p [r=5, scores={subquest_23=0, agricultura=900..}] remove subquest26");
                player.runCommand("tag @p [r=5, scores={subquest_23=0, agricultura=900..}] remove subquest27");
                player.runCommand("tag @p [r=5, scores={subquest_23=0, agricultura=900..}] remove subquest28");
                player.runCommand("tag @p [r=5, scores={subquest_23=0, agricultura=900..}] remove subquest29");
                player.runCommand("tag @p [r=5, scores={subquest_23=0, agricultura=900..}] remove subquest30");
				
                break;
            
			case 1:
                player.runCommand("execute as @e [r=10, scores={subquest_23=0}] run give @p [r=5, scores={coelhos_capturados=40}] well:orbe_evolutiva 1 0 ");
                player.runCommand("execute as @e [r=10, scores={subquest_23=0}] run give @p [r=5, scores={coelhos_capturados=40}] well:container_coracao 1 0 ");
                player.runCommand("execute as @e [r=10, scores={subquest_23=0}] run tag @p [r=10, scores={coelhos_capturados=40}] remove subquest23");  
                player.runCommand("scoreboard players add @p [r=5, scores={subquest_23=0, coelhos_capturados=40..}] subquest_23 1");
                player.runCommand("scoreboard players set @p [r=5, scores={subquest_23=1, coelhos_capturados=40}] coelhos_capturados 100");
                player.runCommand("titleraw @p [r=5, scores={subquest_23=1}, c=1] title {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_23=1}, c=1] subtitle {\"rawtext\":[{ \"translate\":\"subquest.atualizacao.subtitulo\" }]}");
                player.runCommand("execute as @p [r=5, scores={subquest_23=1}, c=1] run tellraw @a {\"rawtext\":[{\"selector\": \"@a[r=5,c=1]\"},{ \"translate\":\"subquest.concluida.mensagem.publica.23\" }]}");
                player.runCommand("playsound missioncomplete @p [r=5, scores={subquest_23=1}, c=1] ~ ~ ~");
                player.runCommand("scoreboard players set @p [r=5, scores={subquest_21=1}] subquest_23 2");
                player.runCommand("tag @p [r=5, scores={subquest_23=2}] add subquest0");
				
				break;
            
			case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DE REQUISITOS
	if (score0 === 0 && score1 < 900) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eSapphire')
            .body({"rawtext": [{"translate": "dialogo.subquest23.requisitos"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DA MISSAO CUMPRIDA
	if (score0 >= 1) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eSapphire')
            .body({"rawtext": [{"translate": "dialogo.subquest23.cumprida"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
});

world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;

    if (!player || !player.runCommand) return;
    if (target.typeId !== "well:npc45") return;

    const obj0 = world.scoreboard.getObjective("subquest_24");
	const obj1 = world.scoreboard.getObjective("coleta_madeira"); //coleta_madeira=1000
	
    

    const score0 = obj0?.getScore(player);
	const score1 = obj1?.getScore(player);
	
	//player.runCommand("playsound npc.homem.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.adulto @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.jovem @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.velho @p [r=5]");
    
    //player.runCommand("playsound npc.mulher.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.velha @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.adulta @p [r=5]");
    player.runCommand("playsound npc.mulher.dialogue.jovem @p [r=5]");
    //player.runCommand("effect @e[type=!player,r=5] slowness 20 60 true");
  
    const chance = Math.random();
        if (chance < 0.25) {
          player.runCommand("playanimation @e[type=!player,r=5] animation.humanoid.custom.well.dialogo1");
        } else if (chance < 0.5) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo2");
        } else if (chance < 0.75) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo3");
        } else {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo4");
        }
    
	//DIALOGO DA MISSAO
    if (score0 === 0 && score1 >= 1000) {
        const nina1 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eElisabeth')
            .body({"rawtext": [{"translate": "dialogo.24.subquest"}]})
            .button({"rawtext": [{"translate": "botao.subquest.aceitar"}]}, "textures/ui/permissions_visitor_hand.png")
            .button({"rawtext": [{"translate": "botao.subquest.sim"}]}, "textures/ui/pergaminhos/icones_submissoes/snow.png")
			.button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina1.show(player).then(result => {
        if (result.canceled) return;
        switch (result.selection) {
            case 0:
                player.runCommand("tag @p [r=5, scores={subquest_24=0, coleta_madeira=1000..}] remove subquest0");
                player.runCommand("tag @p [r=5, scores={subquest_24=0, coleta_madeira=1000..}] add subquest24");
                player.runCommand("titleraw @p [r=5, scores={subquest_24=0, coleta_madeira=1000..}] title {\"rawtext\":[{ \"translate\":\"subquest.aceitou.titulo\" }]}");
                player.runCommand("titleraw @p [r=5, scores={subquest_24=0, coleta_madeira=1000..}] subtitle {\"rawtext\":[{ \"translate\":\"subquest.aceitou.subtitulo\" }]}");
                player.runCommand("tag @p [r=5, scores={subquest_24=0, coleta_madeira=1000..}] remove subquest5");
                player.runCommand("tag @p [r=5, scores={subquest_24=0, coleta_madeira=1000..}] remove subquest2");
                player.runCommand("tag @p [r=5, scores={subquest_24=0, coleta_madeira=1000..}] remove subquest4");
                player.runCommand("tag @p [r=5, scores={subquest_24=0, coleta_madeira=1000..}] remove subquest13");
                player.runCommand("tag @p [r=5, scores={subquest_24=0, coleta_madeira=1000..}] remove subquest1");
                player.runCommand("tag @p [r=5, scores={subquest_24=0, coleta_madeira=1000..}] remove subquest7");
                player.runCommand("tag @p [r=5, scores={subquest_24=0, coleta_madeira=1000..}] remove subquest6");
                player.runCommand("tag @p [r=5, scores={subquest_24=0, coleta_madeira=1000..}] remove subquest8");
                player.runCommand("tag @p [r=5, scores={subquest_24=0, coleta_madeira=1000..}] remove subquest9");
                player.runCommand("tag @p [r=5, scores={subquest_24=0, coleta_madeira=1000..}] remove subquest11");
                player.runCommand("tag @p [r=5, scores={subquest_24=0, coleta_madeira=1000..}] remove subquest12");
                player.runCommand("tag @p [r=5, scores={subquest_24=0, coleta_madeira=1000..}] remove subquest3");
                player.runCommand("tag @p [r=5, scores={subquest_24=0, coleta_madeira=1000..}] remove subquest14");
                player.runCommand("tag @p [r=5, scores={subquest_24=0, coleta_madeira=1000..}] remove subquest15");
                player.runCommand("tag @p [r=5, scores={subquest_24=0, coleta_madeira=1000..}] remove subquest10");
                player.runCommand("tag @p [r=5, scores={subquest_24=0, coleta_madeira=1000..}] remove subquest16");
                player.runCommand("tag @p [r=5, scores={subquest_24=0, coleta_madeira=1000..}] remove subquest18");
                player.runCommand("tag @p [r=5, scores={subquest_24=0, coleta_madeira=1000..}] remove subquest19");
                player.runCommand("tag @p [r=5, scores={subquest_24=0, coleta_madeira=1000..}] remove subquest20");
                player.runCommand("tag @p [r=5, scores={subquest_24=0, coleta_madeira=1000..}] remove subquest21");
                player.runCommand("tag @p [r=5, scores={subquest_24=0, coleta_madeira=1000..}] remove subquest17");
                player.runCommand("tag @p [r=5, scores={subquest_24=0, coleta_madeira=1000..}] remove subquest22");
                player.runCommand("tag @p [r=5, scores={subquest_24=0, coleta_madeira=1000..}] remove subquest23");
                player.runCommand("tag @p [r=5, scores={subquest_24=0, coleta_madeira=1000..}] remove subquest25");
                player.runCommand("tag @p [r=5, scores={subquest_24=0, coleta_madeira=1000..}] remove subquest26");
                player.runCommand("tag @p [r=5, scores={subquest_24=0, coleta_madeira=1000..}] remove subquest27");
                player.runCommand("tag @p [r=5, scores={subquest_24=0, coleta_madeira=1000..}] remove subquest28");
                player.runCommand("tag @p [r=5, scores={subquest_24=0, coleta_madeira=1000..}] remove subquest29");
                player.runCommand("tag @p [r=5, scores={subquest_24=0, coleta_madeira=1000..}] remove subquest30");
				
                break;
            
			case 1:

            // Só players elegíveis e perto de snow golem
            player.runCommand(`execute as @a[scores={subquest_24=0}] at @s if entity @e[type=snow_golem,r=10] run give @s well:orbe_evolutiva 1 0`);
            player.runCommand(`execute as @a[scores={subquest_24=0}] at @s if entity @e[type=snow_golem,r=10] run give @s well:container_coracao 1 0`);
            
            // Atualiza score da missão
            player.runCommand(`execute as @a[scores={subquest_24=0}] at @s if entity @e[type=snow_golem,r=10] run scoreboard players add @s subquest_24 1`);
            
            // Título e som apenas pra quem acabou de completar
            player.runCommand(`titleraw @a[scores={subquest_24=1}] title {"rawtext":[{"translate":"subquest.atualizacao.titulo"}]}`);
            player.runCommand(`titleraw @a[scores={subquest_24=1}] subtitle {"rawtext":[{"translate":"subquest.atualizacao.subtitulo"}]}`);
            player.runCommand(`execute as @a[scores={subquest_24=1}] run tellraw @a {"rawtext":[{"selector":"@s"},{"translate":"subquest.concluida.mensagem.publica.24"}]}`);
            player.runCommand(`playsound missioncomplete @a[scores={subquest_24=1}] ~ ~ ~`);
            
            // Finaliza missão
            player.runCommand(`scoreboard players set @a[scores={subquest_24=1}] subquest_24 2`);
            player.runCommand(`tag @a[scores={subquest_24=2}] add subquest0`);
            
            break;

            
			case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DE REQUISITOS
	if (score0 === 0 && score1 < 1000) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eElisabeth')
            .body({"rawtext": [{"translate": "dialogo.subquest24.requisitos"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
	//DIALOGO DA MISSAO CUMPRIDA
	if (score0 >= 1) {
        const nina2 = new ActionFormData()
            .title('wellforced:renderentidade')//('§n§p§c§r§5§eElisabeth')
            .body({"rawtext": [{"translate": "dialogo.subquest24.cumprida"}]})
            .button({"rawtext": [{"translate": "opcoes.contratar"}]})
            .button({"rawtext": [{"translate": "opcoes.legal"}]})
	        .button(' ', "textures/ui/crossout.png")
			.button('', ev.hitEntity.id);

        nina2.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0: player.runCommand(""); break;
			case 1: player.runCommand(""); break;
            case 2: player.runCommand(""); break;
        }
     });

        return; // Para não continuar e abrir outro menu
    }
	
});

world.afterEvents.entityHitEntity.subscribe(ev => {
    const player = ev.damagingEntity;
    const target = ev.hitEntity;

    if (!player || !player.runCommand) return;
    if (target.typeId !== "well:npc48") return;
	
    
	//player.runCommand("playsound npc.homem.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.adulto @p [r=5]");
    //player.runCommand("playsound npc.homem.dialogue.jovem @p [r=5]");
    player.runCommand("playsound npc.homem.dialogue.velho @p [r=5]");
    
    //player.runCommand("playsound npc.mulher.dialogue.crianca @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.velha @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.adulta @p [r=5]");
    //player.runCommand("playsound npc.mulher.dialogue.jovem @p [r=5]");
    //player.runCommand("effect @e[type=!player,r=5] slowness 20 60 true");
  
    const chance = Math.random();
        if (chance < 0.25) {
          player.runCommand("playanimation @e[type=!player,r=5] animation.humanoid.custom.well.dialogo1");
        } else if (chance < 0.5) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo2");
        } else if (chance < 0.75) {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo3");
        } else {
          player.runCommand("playanimation @e[type=!player,r=5]  animation.humanoid.custom.well.dialogo4");
        }
	
	
	
	// DIALOGO DA MISSAO
    const nina1 = new ActionFormData()
        .title('wellforced:renderentidade')//('§n§p§c§r§5§eEldric')
        .body({ "rawtext": [{ "translate": "dialogo.mudar.classe" }] })
        .button({ "rawtext": [{ "translate": "botao.mudar.classe.humano" }] })
        .button({ "rawtext": [{ "translate": "botao.mudar.classe.mago" }] })
        .button(' ', "textures/ui/crossout.png")

    nina1.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0:
                player.runCommand("execute as @s[hasitem={item=echo_shard, quantity=5..}] run function classe/humano");
				player.runCommand("clear @s [hasitem={item=echo_shard, quantity=5..}] echo_shard 0 5");
                player.runCommand("execute as @s[hasitem={item=echo_shard, quantity=..4}] run tellraw @s {\"rawtext\":[{ \"translate\":\"dialogo.mudar.classe.negativo\" }]}");
				
				
				
				
                break;

            case 1:
                player.runCommand("execute as @s[hasitem={item=echo_shard, quantity=5..}] run function classe/mago");
				player.runCommand("clear @s [hasitem={item=echo_shard, quantity=5..}] echo_shard 0 5");
                player.runCommand("execute as @s[hasitem={item=echo_shard, quantity=..4}] run tellraw @s {\"rawtext\":[{ \"translate\":\"dialogo.mudar.classe.negativo\" }]}");
                break;

            case 2:
                player.runCommand(""); // Adicione o comando que quiser aqui
                break;
        }
    });
});

}
//export { Missoes_NPC };