import { world, ItemCooldownComponent, system } from '@minecraft/server';
import { useTypes, commandSubject } from '../Interfaces/on_Use_Interfaces';


world.afterEvents.itemCompleteUse.subscribe((data) => {
    console.warn(`Item completo usado: ${data.itemStack.typeId}`);

    // Verifica se o item consumido é uma poção específica
    if (data.itemStack.typeId === "well:sopa_apimentada") {
        // Executa comandos no jogador
        data.source.runCommand("scoreboard players set @s furia 100");
		data.source.runCommand("particle well:furia ~ ~1.5 ~");
		data.source.runCommand("particle minecraft:bleach ~ ~2 ~");
		data.source.runCommand("particle minecraft:misc_fire_vapor_particle ^^1.4^1");
		data.source.runCommand("particle minecraft:campfire_tall_smoke_particle ^^1.4^1");
		data.source.runCommand("particle minecraft:lava_particle ^^1^1");
		data.source.runCommand("particle minecraft:lava_particle ^^1^1");
		data.source.runCommand("particle minecraft:lava_particle ^^1^1");
		data.source.runCommand("particle minecraft:lava_particle ^^1^1");
		data.source.runCommand("particle minecraft:lava_particle ^^1^1");
		data.source.runCommand("playanimation @s animation.humanoid.sereia.tremer");
		data.source.runCommand("playsound mob.player.hurt_on_fire");
		data.source.runCommand("playsound random.burp");
		
		data.source.runCommand("camerashake add @s 0.5 0.5 positional");
		data.source.runCommand("event entity @s remove_animacao_combo");
		data.source.runCommand("execute as @s [scores={classe_humana=1, furia=100}] run title @s [scores={classe_humana=1, furia=100}] title furia_bar10");
        data.source.runCommand("execute as @s [scores={classe_humana=1, furia=90..99}] run title @s [scores={classe_humana=1, furia=90..99}] title mana_bar9");
        data.source.runCommand("execute as @s [scores={classe_humana=1, furia=80..89}] run title @s [scores={classe_humana=1, furia=80..89}] title mana_bar8");
        data.source.runCommand("execute as @s [scores={classe_humana=1, furia=70..79}] run title @s [scores={classe_humana=1, furia=70..79}] title mana_bar7");
        data.source.runCommand("execute as @s [scores={classe_humana=1, furia=60..69}] run title @s [scores={classe_humana=1, furia=60..69}] title mana_bar6");
        data.source.runCommand("execute as @s [scores={classe_humana=1, furia=50..59}] run title @s [scores={classe_humana=1, furia=50..59}] title mana_bar5");
        data.source.runCommand("execute as @s [scores={classe_humana=1, furia=40..49}] run title @s [scores={classe_humana=1, furia=40..49}] title mana_bar4");
        data.source.runCommand("execute as @s [scores={classe_humana=1, furia=30..39}] run title @s [scores={classe_humana=1, furia=30..39}] title mana_bar3");
        data.source.runCommand("execute as @s [scores={classe_humana=1, furia=20..29}] run title @s [scores={classe_humana=1, furia=20..29}] title mana_bar2");
        data.source.runCommand("execute as @s [scores={classe_humana=1, furia=10..19}] run title @s [scores={classe_humana=1, furia=10..19}] title mana_bar1");
        data.source.runCommand("execute as @s [scores={classe_humana=1, furia=0..9}] run title @s [scores={classe_humana=1, furia=0..9}] title mana_bar0");
		
        data.source.runCommand("titleraw @s actionbar {\"rawtext\":[{\"translate\":\"furia.aumentada.sopa\"}]}");
    }
});
world.afterEvents.itemCompleteUse.subscribe((data) => {
    console.warn(`Item completo usado: ${data.itemStack.typeId}`);

    // Verifica se o item consumido é uma poção específica
    if (data.itemStack.typeId === "well:pocao_gigante") {
        // Executa comandos no jogador
        data.source.runCommand("event entity @s gigante");
        data.source.runCommand("scoreboard players set @s camera_rpg 5");
    }
});
world.afterEvents.itemCompleteUse.subscribe((data) => {
    console.warn(`Item completo usado: ${data.itemStack.typeId}`);

    // Verifica se o item consumido é uma poção específica
    if (data.itemStack.typeId === "well:pocao_pequeno") {
        // Executa comandos no jogador
        data.source.runCommand("event entity @s pequeno");
        data.source.runCommand("scoreboard players set @s camera_rpg 4");
    }
});
world.afterEvents.itemCompleteUse.subscribe((data) => {
    console.warn(`Item completo usado: ${data.itemStack.typeId}`);

    // Verifica se o item consumido é uma poção específica
    if (data.itemStack.typeId === "well:pocao_desvanecimento") {
        // Executa comandos no jogador
        data.source.runCommand("event entity @s add_desvanecimento");
        data.source.runCommand("titleraw @s title {\"rawtext\":[{\"translate\":\"dialogue.desvanecimento\"}]}");
    }
});
world.afterEvents.itemCompleteUse.subscribe((data) => {
    console.warn(`Item completo usado: ${data.itemStack.typeId}`);

    // Verifica se o item consumido é uma poção específica
    if (data.itemStack.typeId === "minecraft:milk_bucket") {
        // Executa comandos no jogador
        data.source.runCommand("event entity @s tamanho_normal");
    }
});

world.afterEvents.itemCompleteUse.subscribe((data) => {
    console.warn(`Item completo usado: ${data.itemStack.typeId}`);

    // Verifica se o item consumido é uma poção específica
    if (data.itemStack.typeId === "well:frasco_mana_cheio") {
        // Executa comandos no jogador
        data.source.runCommand("scoreboard players add @s [scores={classe_mago=1, mana=..100}] mana 100");
		data.source.runCommand("particle well:orb_evolution");
		data.source.runCommand("fill ~ ~ ~ ~ ~ ~ well:luz_orbe [] replace air");
		data.source.runCommand("playanimation @s animation.humanoid.custom.classe.mago.cajado");
		data.source.runCommand("scoreboard players set @s [scores={classe_mago=1, mana=100..}] mana 100");
		data.source.runCommand("execute as @s [scores={classe_mago=1, mana=..100}] run playsound random.drink");
		data.source.runCommand("clear @s [scores={classe_mago=1, mana=..100}] well:frasco_mana_cheio 0 1");
		data.source.runCommand("function Missoes");
		data.source.runCommand("titleraw @s [scores={classe_mago=1, mana=100}] actionbar {\"rawtext\":[{\"selector\": \"@s[r=5,c=1]\"}, {\"translate\":\"dialogue.mana.cheia\"}]}");
		
		data.source.runCommand("execute as @s [scores={classe_mago=1, mana=100}] run title @s [scores={classe_mago=1, mana=100}] title mana_bar10");
        data.source.runCommand("execute as @s [scores={classe_mago=1, mana=90..99}] run title @s [scores={classe_mago=1, mana=90..99}] title mana_bar9");
        data.source.runCommand("execute as @s [scores={classe_mago=1, mana=80..89}] run title @s [scores={classe_mago=1, mana=80..89}] title mana_bar8");
        data.source.runCommand("execute as @s [scores={classe_mago=1, mana=70..79}] run title @s [scores={classe_mago=1, mana=70..79}] title mana_bar7");
        data.source.runCommand("execute as @s [scores={classe_mago=1, mana=60..69}] run title @s [scores={classe_mago=1, mana=60..69}] title mana_bar6");
        data.source.runCommand("execute as @s [scores={classe_mago=1, mana=50..59}] run title @s [scores={classe_mago=1, mana=50..59}] title mana_bar5");
        data.source.runCommand("execute as @s [scores={classe_mago=1, mana=40..49}] run title @s [scores={classe_mago=1, mana=40..49}] title mana_bar4");
        data.source.runCommand("execute as @s [scores={classe_mago=1, mana=30..39}] run title @s [scores={classe_mago=1, mana=30..39}] title mana_bar3");
        data.source.runCommand("execute as @s [scores={classe_mago=1, mana=20..29}] run title @s [scores={classe_mago=1, mana=20..29}] title mana_bar2");
        data.source.runCommand("execute as @s [scores={classe_mago=1, mana=10..19}] run title @s [scores={classe_mago=1, mana=10..19}] title mana_bar1");
        data.source.runCommand("execute as @s [scores={classe_mago=1, mana=0..9}] run title @s [scores={classe_mago=1, mana=0..9}] title mana_bar0");
		
		
    }
});
world.afterEvents.itemCompleteUse.subscribe((data) => {
    console.warn(`Item completo usado: ${data.itemStack.typeId}`);

    // Verifica se o item consumido é uma poção específica
    if (data.itemStack.typeId === "well:frasco_mana") {
        // Executa comandos no jogador
        data.source.runCommand("scoreboard players add @s [scores={classe_mago=1, mana=..100}] mana 10");
		data.source.runCommand("particle well:orb_evolution");
		data.source.runCommand("fill ~ ~ ~ ~ ~ ~ well:luz_orbe [] replace air");
		data.source.runCommand("playanimation @s animation.humanoid.custom.classe.mago.cajado");
		data.source.runCommand("scoreboard players set @s [scores={classe_mago=1, mana=100..}] mana 100");
		data.source.runCommand("execute as @s [scores={classe_mago=1, mana=..100}] run playsound random.drink");
		data.source.runCommand("clear @s [scores={classe_mago=1, mana=..99}] well:frasco_mana 0 1");
		data.source.runCommand("function Missoes");
		data.source.runCommand("titleraw @s [scores={classe_mago=1, mana=100}] actionbar {\"rawtext\":[{\"selector\": \"@s[r=5,c=1]\"}, {\"translate\":\"dialogue.mana.cheia\"}]}");
		
		
		data.source.runCommand("execute as @s [scores={classe_mago=1, mana=100}] run title @s [scores={classe_mago=1, mana=100}] title mana_bar10");
        data.source.runCommand("execute as @s [scores={classe_mago=1, mana=90..99}] run title @s [scores={classe_mago=1, mana=90..99}] title mana_bar9");
        data.source.runCommand("execute as @s [scores={classe_mago=1, mana=80..89}] run title @s [scores={classe_mago=1, mana=80..89}] title mana_bar8");
        data.source.runCommand("execute as @s [scores={classe_mago=1, mana=70..79}] run title @s [scores={classe_mago=1, mana=70..79}] title mana_bar7");
        data.source.runCommand("execute as @s [scores={classe_mago=1, mana=60..69}] run title @s [scores={classe_mago=1, mana=60..69}] title mana_bar6");
        data.source.runCommand("execute as @s [scores={classe_mago=1, mana=50..59}] run title @s [scores={classe_mago=1, mana=50..59}] title mana_bar5");
        data.source.runCommand("execute as @s [scores={classe_mago=1, mana=40..49}] run title @s [scores={classe_mago=1, mana=40..49}] title mana_bar4");
        data.source.runCommand("execute as @s [scores={classe_mago=1, mana=30..39}] run title @s [scores={classe_mago=1, mana=30..39}] title mana_bar3");
        data.source.runCommand("execute as @s [scores={classe_mago=1, mana=20..29}] run title @s [scores={classe_mago=1, mana=20..29}] title mana_bar2");
        data.source.runCommand("execute as @s [scores={classe_mago=1, mana=10..19}] run title @s [scores={classe_mago=1, mana=10..19}] title mana_bar1");
        data.source.runCommand("execute as @s [scores={classe_mago=1, mana=0..9}] run title @s [scores={classe_mago=1, mana=0..9}] title mana_bar0");
		
    }
});




const on_Use = [
    
	{
        use_type: useTypes.Item_Use,
        itemID: "well:teleporterapido",
        code_type: {
            command: {
                commands: [
                    "tag @p add contagem_remove_npc",
					"playanimation @s animation.humanoid.custom.classe.mago.cajado"
                ],
                subject: commandSubject.Player
            },
            code: (data)=>{
                ////world.sendMessage(data.source.name);
            }
        }
    },
	
	{
        use_type: useTypes.Item_Use,
        itemID: "well:nectar_frasco",
        code_type: {
            command: {
                commands: [
                    "scoreboard players remove @s [scores={iluminacao_descarga=80..364}] iluminacao_descarga 80",
					"clear @s [scores={iluminacao_descarga=80..}] well:nectar_frasco 0 1",
					"titleraw @s [scores={iluminacao_descarga=..80}] actionbar {\"rawtext\":[{\"selector\": \"@s[r=5,c=1]\"}, {\"translate\":\"dialogue.bateria.cheia\"}]}",
					"tellraw @a [scores={iluminacao_descarga=80..}] {\"rawtext\":[{\"selector\": \"@s[r=5,c=1]\"}, {\"translate\":\"dialogue.bateria.recarregou\"}]}",
					"give @s [scores={iluminacao_descarga=80..}] glass_bottle"
                ],
                subject: commandSubject.Player
            },
            code: (data)=>{
                ////world.sendMessage(data.source.name);
            }
        }
    },
	
	{
        use_type: useTypes.Item_Use,
        itemID: "well:fada_no_frasco",
        code_type: {
            command: {
                commands: [
                    "effect @s regeneration 10 5 true",
					"replaceitem entity @s slot.weapon.mainhand 0 minecraft:glass_bottle 1",
					"playsound cura @s",
					"particle well:orb_evolution",
					"setblock ~ ~ ~ well:luz_orbe",
					"execute as @p [r=5] run particle minecraft:totem_particle ~ ~2 ~",
					"tellraw @a {\"rawtext\":[{\"selector\": \"@s[r=5,c=1]\"}, {\"translate\":\"dialogue.fada_item.msg1\"}]}"
                ],
                subject: commandSubject.Player
            },
            code: (data)=>{
                ////world.sendMessage(data.source.name);
            }
        }
    },
	
	{
        use_type: useTypes.Item_Use,
        itemID: "well:flauta_do_deserto",
        code_type: {
            command: {
                commands: [
                    "summon well:musica ~ ~ ~",
					"playsound Flauta @p ~ ~ ~"//,
					//"dialogue open @e [type=npc:hilda, r=8, c=1] @p [c=1, tag=hero1, r=8] hilda2"
                ],
                subject: commandSubject.Player
            },
            code: (data)=>{
                //world.sendMessage(data.source.name);
            }
        }
    },
	
	{
        use_type: useTypes.Item_Use,
        itemID: "well:mochila_item",
    
        code_type: {
            command: {
                commands: [
                    "clear @s well:mochila_item"
                ],
                subject: commandSubject.Player
            },
    
            code: (data) => {
    
                const player = data.source;
                const dim = player.dimension;
                const loc = player.location;
    
                // Spawn da mochila
                const mochila = dim.spawnEntity("well:mochila", loc);
    
                // DOMAR imediatamente funciona
                const tameable = mochila.getComponent("minecraft:tameable");
                if (tameable) tameable.tame(player);
    
                // ⏳ esperar 1 tick pra entidade "carregar"
                system.run(() => {
    
                    const nameable = mochila.getComponent("minecraft:nameable");
    
                    if (nameable) {
                        nameable.setName(`§6Mochila do ${player.name}`);
                    }
    
                });
    
            }
        }
    },



	
	{
        use_type: useTypes.Item_Use,
        itemID: "well:container_coracao",
        code_type: {
            command: {
                commands: [
                    "scoreboard players add @s container_coracao 1",
					"particle well:orb_evolution",
					"setblock ~ ~ ~ well:luz_orbe",
					"playanimation @s animation.humanoid.custom.classe.mago.cajado",
					"scoreboard players add @s timer_ui 2",
					"function container",
					"playsound SuperItem @p [scores={container_coracao=..39}] ~ ~ ~ 0.3",
					"scoreboard players set @s [scores={container_coracao=40..}] container_coracao 40",
					"clear @s [scores={container_coracao=2..39}] well:container_coracao 0 1",
					"titleraw @s [scores={container_coracao=2..39}] actionbar {\"rawtext\":[{\"selector\": \"@s[r=5,c=1]\"}, {\"translate\":\"dialogue.acrescentou.container\"}]}"
                ],
                subject: commandSubject.Player
            },
            code: (data)=>{
                //world.sendMessage(data.source.name);
            }
        }
    },
	
	{
        use_type: useTypes.Item_Use,
        itemID: "well:enxada_ruby",
        code_type: {
            command: {
                commands: [
                    "fill ~2 ~-1 ~ ~-1 ~ ~2 farmland [] replace grass",
					"playanimation @s animation.humanoid.custom.classe.mago.cajado",
					"fill ~-2 ~-1 ~ ~-1 ~ ~-2 farmland [] replace grass",
					"fill ~-2 ~-1 ~ ~-1 ~ ~2 farmland [] replace grass",
					"fill ~2 ~-1 ~ ~-1 ~ ~-2 farmland [] replace grass",
					"fill ~2 ~-1 ~ ~-1 ~ ~2 farmland [] replace dirt",
					"fill ~-2 ~-1 ~ ~-1 ~ ~-2 farmland [] replace dirt",
					"fill ~-2 ~-1 ~ ~-1 ~ ~2 farmland [] replace dirt",
					"fill ~2 ~-1 ~ ~-1 ~ ~-2 farmland [] replace dirt"
                ],
                subject: commandSubject.Player
            },
            code: (data)=>{
                //world.sendMessage(data.source.name);
            }
        }
    },
	
	{
        use_type: useTypes.Item_Use,
        itemID: "well:orbe_evolutiva",
        code_type: {
            command: {
                commands: [
				    "playanimation @s animation.humanoid.custom.classe.mago.cajado",
					"particle well:orb_evolution",
					
					"execute as @s [scores={skill_mago_orbe=..30}] run fill ~ ~ ~ ~ ~ ~ well:luz_orbe [] replace air",
					"execute as @s [scores={skill_elfo_orbe=..30}] run fill ~ ~ ~ ~ ~ ~ well:luz_orbe [] replace air",
					"execute as @s [scores={skill_humana_orbe=..30}] run fill ~ ~ ~ ~ ~ ~ well:luz_orbe [] replace air",
					"execute as @s [scores={skill_mago_orbe=..30}] run playsound Item @s ~ ~ ~ 0.08",
					"execute as @s [scores={skill_elfo_orbe=..30}] run playsound Item @s ~ ~ ~ 0.08",
					"execute as @s [scores={skill_humana_orbe=..30}] run playsound Item @s ~ ~ ~ 0.08",
                    
					"scoreboard players add @s [scores={classe_humana=1}] skill_humana_orbe 1",
					"scoreboard players add @s [scores={classe_elfo=1}] skill_elfo_orbe 1",
					"scoreboard players add @s [scores={classe_mago=1}] skill_mago_orbe 1",
					
					"scoreboard players set @s [scores={skill_mago_orbe=30}] skill_humana_orbe 31",
					"scoreboard players set @s [scores={skill_elfo_orbe=30}] skill_elfo_orbe 31",
					"scoreboard players set @s [scores={skill_humana_orbe=30}] skill_mago_orbe 31",
					"clear @s [scores={skill_mago_orbe=..30}] well:orbe_evolutiva 0 1",
					"clear @s [scores={skill_elfo_orbe=..30}] well:orbe_evolutiva 0 1",
					"clear @s [scores={skill_humana_orbe=..30}] well:orbe_evolutiva 0 1",
					
					"replaceitem entity @s [scores={skill_mago_orbe=5}] slot.hotbar 0 well:cajado_mago2 1 0 {\"item_lock\": {\"mode\": \"lock_in_slot\"}, \"keep_on_death\": {}}",
					"replaceitem entity @s [scores={skill_mago_orbe=10}] slot.hotbar 0 well:cajado_mago3 1 0 {\"item_lock\": {\"mode\": \"lock_in_slot\"}, \"keep_on_death\": {}}",
					"replaceitem entity @s [scores={skill_mago_orbe=20}] slot.hotbar 0 well:cajado_mago4 1 0 {\"item_lock\": {\"mode\": \"lock_in_slot\"}, \"keep_on_death\": {}}",
					"replaceitem entity @s [scores={skill_mago_orbe=30}] slot.hotbar 0 well:cajado_mago5 1 0 {\"item_lock\": {\"mode\": \"lock_in_slot\"}, \"keep_on_death\": {}}",
					
					"replaceitem entity @s [scores={skill_humana_orbe=5}] slot.hotbar 0 well:espada_humano2 1 0 {\"item_lock\": {\"mode\": \"lock_in_slot\"}, \"keep_on_death\": {}}",
					"replaceitem entity @s [scores={skill_humana_orbe=10}] slot.hotbar 0 well:espada_humano3 1 0 {\"item_lock\": {\"mode\": \"lock_in_slot\"}, \"keep_on_death\": {}}",
					"replaceitem entity @s [scores={skill_humana_orbe=20}] slot.hotbar 0 well:espada_humano4 1 0 {\"item_lock\": {\"mode\": \"lock_in_slot\"}, \"keep_on_death\": {}}",
					"replaceitem entity @s [scores={skill_humana_orbe=30}] slot.hotbar 0 well:espada_humano5 1 0 {\"item_lock\": {\"mode\": \"lock_in_slot\"}, \"keep_on_death\": {}}",
					
					//MSG TITLE EVOLUTIONS LVS
					"titleraw @s [scores={skill_humana_orbe=5}] title {\"rawtext\":[ {\"translate\":\"dialogue.subiulv.evolucao.2\"}]}",
					"titleraw @s [scores={skill_humana_orbe=10}] title {\"rawtext\":[ {\"translate\":\"dialogue.subiulv.evolucao.3\"}]}",
					"titleraw @s [scores={skill_humana_orbe=20}] title {\"rawtext\":[ {\"translate\":\"dialogue.subiulv.evolucao.4\"}]}",
					"titleraw @s [scores={skill_humana_orbe=30}] title {\"rawtext\":[ {\"translate\":\"dialogue.subiulv.evolucao.5\"}]}",
					"titleraw @s [scores={skill_humana_orbe=5}] subtitle {\"rawtext\":[ {\"translate\":\"dialogue.subiulvsubtitle.evolucao.2\"}]}",
					"titleraw @s [scores={skill_humana_orbe=10}] subtitle {\"rawtext\":[ {\"translate\":\"dialogue.subiulvsubtitle.evolucao.3\"}]}",
					"titleraw @s [scores={skill_humana_orbe=20}] subtitle {\"rawtext\":[ {\"translate\":\"dialogue.subiulvsubtitle.evolucao.4\"}]}",
					"titleraw @s [scores={skill_humana_orbe=30}] subtitle {\"rawtext\":[ {\"translate\":\"dialogue.subiulvsubtitle.evolucao.5\"}]}",
					
					"titleraw @s [scores={skill_elfo_orbe=5}] title {\"rawtext\":[ {\"translate\":\"dialogue.subiulv.evolucao.2\"}]}",
					"titleraw @s [scores={skill_elfo_orbe=10}] title {\"rawtext\":[ {\"translate\":\"dialogue.subiulv.evolucao.3\"}]}",
					"titleraw @s [scores={skill_elfo_orbe=20}] title {\"rawtext\":[ {\"translate\":\"dialogue.subiulv.evolucao.4\"}]}",
					"titleraw @s [scores={skill_elfo_orbe=30}] title {\"rawtext\":[ {\"translate\":\"dialogue.subiulv.evolucao.5\"}]}",
					"titleraw @s [scores={skill_elfo_orbe=5}] subtitle {\"rawtext\":[ {\"translate\":\"dialogue.subiulvsubtitle.evolucao.2\"}]}",
					"titleraw @s [scores={skill_elfo_orbe=10}] subtitle {\"rawtext\":[ {\"translate\":\"dialogue.subiulvsubtitle.evolucao.3\"}]}",
					"titleraw @s [scores={skill_elfo_orbe=20}] subtitle {\"rawtext\":[ {\"translate\":\"dialogue.subiulvsubtitle.evolucao.4\"}]}",
					"titleraw @s [scores={skill_elfo_orbe=30}] subtitle {\"rawtext\":[ {\"translate\":\"dialogue.subiulvsubtitle.evolucao.5\"}]}",
					
					"titleraw @s [scores={skill_mago_orbe=5}] title {\"rawtext\":[ {\"translate\":\"dialogue.subiulv.evolucao.2\"}]}",
					"titleraw @s [scores={skill_mago_orbe=10}] title {\"rawtext\":[ {\"translate\":\"dialogue.subiulv.evolucao.3\"}]}",
					"titleraw @s [scores={skill_mago_orbe=20}] title {\"rawtext\":[ {\"translate\":\"dialogue.subiulv.evolucao.4\"}]}",
					"titleraw @s [scores={skill_mago_orbe=30}] title {\"rawtext\":[ {\"translate\":\"dialogue.subiulv.evolucao.5\"}]}",
					"titleraw @s [scores={skill_mago_orbe=5}] subtitle {\"rawtext\":[ {\"translate\":\"dialogue.subiulvsubtitle.evolucao.2\"}]}",
					"titleraw @s [scores={skill_mago_orbe=10}] subtitle {\"rawtext\":[ {\"translate\":\"dialogue.subiulvsubtitle.evolucao.3\"}]}",
					"titleraw @s [scores={skill_mago_orbe=20}] subtitle {\"rawtext\":[ {\"translate\":\"dialogue.subiulvsubtitle.evolucao.4\"}]}",
					"titleraw @s [scores={skill_mago_orbe=30}] subtitle {\"rawtext\":[ {\"translate\":\"dialogue.subiulvsubtitle.evolucao.5\"}]}",
					
					//LEVEL UP ELFO
					"execute as @s [scores={skill_elfo_orbe=5}] run particle well:lv_up ~ ~ ~",
					"execute as @s [scores={skill_elfo_orbe=10}] run particle well:lv_up ~ ~ ~",
					"execute as @s [scores={skill_elfo_orbe=20}] run particle well:lv_up ~ ~ ~",
					"execute as @s [scores={skill_elfo_orbe=30}] run particle well:lv_up ~ ~ ~",
					"execute as @s [scores={skill_elfo_orbe=5}] run playsound missioncomplete @s",
					"execute as @s [scores={skill_elfo_orbe=10}] run playsound missioncomplete @s",
					"execute as @s [scores={skill_elfo_orbe=20}] run playsound missioncomplete @s",
					"execute as @s [scores={skill_elfo_orbe=30}] run playsound missioncomplete @s",
					
					//LEVEL UP HUMANO
					"execute as @s [scores={skill_humana_orbe=5}] run particle well:lv_up ~ ~ ~",
					"execute as @s [scores={skill_humana_orbe=10}] run particle well:lv_up ~ ~ ~",
					"execute as @s [scores={skill_humana_orbe=20}] run particle well:lv_up ~ ~ ~",
					"execute as @s [scores={skill_humana_orbe=30}] run particle well:lv_up ~ ~ ~",
					"execute as @s [scores={skill_humana_orbe=5}] run playsound missioncomplete @s",
					"execute as @s [scores={skill_humana_orbe=10}] run playsound missioncomplete @s",
					"execute as @s [scores={skill_humana_orbe=20}] run playsound missioncomplete @s",
					"execute as @s [scores={skill_humana_orbe=30}] run playsound missioncomplete @s",
					
					//LEVEL UP MAGO
					"execute as @s [scores={skill_mago_orbe=5}] run particle well:lv_up ~ ~ ~",
					"execute as @s [scores={skill_mago_orbe=10}] run particle well:lv_up ~ ~ ~",
					"execute as @s [scores={skill_mago_orbe=20}] run particle well:lv_up ~ ~ ~",
					"execute as @s [scores={skill_mago_orbe=30}] run particle well:lv_up ~ ~ ~",
					"execute as @s [scores={skill_mago_orbe=5}] run playsound missioncomplete @s",
					"execute as @s [scores={skill_mago_orbe=10}] run playsound missioncomplete @s",
					"execute as @s [scores={skill_mago_orbe=20}] run playsound missioncomplete @s",
					"execute as @s [scores={skill_mago_orbe=30}] run playsound missioncomplete @s",
					
					//MSG ACTIONBAR ORBES NECESSÁRIAS
					"titleraw @s [scores={skill_mago_orbe=0..5}] actionbar {\"rawtext\":[ {\"score\":{\"name\": \"@s\", \"objective\": \"skill_mago_orbe\"}}, {\"translate\":\"dialogue.mago.evolucao.2\"}]}",
					"titleraw @s [scores={skill_mago_orbe=6..10}] actionbar {\"rawtext\":[ {\"score\":{\"name\": \"@s\", \"objective\": \"skill_mago_orbe\"}}, {\"translate\":\"dialogue.mago.evolucao.3\"}]}",
					"titleraw @s [scores={skill_mago_orbe=11..20}] actionbar {\"rawtext\":[ {\"score\":{\"name\": \"@s\", \"objective\": \"skill_mago_orbe\"}}, {\"translate\":\"dialogue.mago.evolucao.4\"}]}",
					"titleraw @s [scores={skill_mago_orbe=21..30}] actionbar {\"rawtext\":[ {\"score\":{\"name\": \"@s\", \"objective\": \"skill_mago_orbe\"}}, {\"translate\":\"dialogue.mago.evolucao.5\"}]}",
					
					"titleraw @s [scores={skill_humana_orbe=0..5}] actionbar {\"rawtext\":[ {\"score\":{\"name\": \"@s\", \"objective\": \"skill_humana_orbe\"}}, {\"translate\":\"dialogue.mago.evolucao.2\"}]}",
					"titleraw @s [scores={skill_humana_orbe=6..10}] actionbar {\"rawtext\":[ {\"score\":{\"name\": \"@s\", \"objective\": \"skill_humana_orbe\"}}, {\"translate\":\"dialogue.mago.evolucao.3\"}]}",
					"titleraw @s [scores={skill_humana_orbe=11..20}] actionbar {\"rawtext\":[ {\"score\":{\"name\": \"@s\", \"objective\": \"skill_humana_orbe\"}}, {\"translate\":\"dialogue.mago.evolucao.4\"}]}",
					"titleraw @s [scores={skill_humana_orbe=21..30}] actionbar {\"rawtext\":[ {\"score\":{\"name\": \"@s\", \"objective\": \"skill_humana_orbe\"}}, {\"translate\":\"dialogue.mago.evolucao.5\"}]}",
                
					"titleraw @s [scores={skill_elfo_orbe=0..5}] actionbar {\"rawtext\":[ {\"score\":{\"name\": \"@s\", \"objective\": \"skill_elfo_orbe\"}}, {\"translate\":\"dialogue.mago.evolucao.2\"}]}",
					"titleraw @s [scores={skill_elfo_orbe=6..10}] actionbar {\"rawtext\":[ {\"score\":{\"name\": \"@s\", \"objective\": \"skill_elfo_orbe\"}}, {\"translate\":\"dialogue.mago.evolucao.3\"}]}",
					"titleraw @s [scores={skill_elfo_orbe=11..20}] actionbar {\"rawtext\":[ {\"score\":{\"name\": \"@s\", \"objective\": \"skill_elfo_orbe\"}}, {\"translate\":\"dialogue.mago.evolucao.4\"}]}",
					"titleraw @s [scores={skill_elfo_orbe=21..30}] actionbar {\"rawtext\":[ {\"score\":{\"name\": \"@s\", \"objective\": \"skill_elfo_orbe\"}}, {\"translate\":\"dialogue.mago.evolucao.5\"}]}"
                ],
                subject: commandSubject.Player
            },
            code: (data)=>{
                //world.sendMessage(data.source.name);
            }
        }
    },
	
	{
        use_type: useTypes.Item_Use,
        itemID: "well:espada_ruby",
        code_type: {
            command: {
                commands: [
                    "summon well:dano_em_area ^^^4",
					"particle well:dano_area ^^1^4",
					"playsound golpe.area @a [r=5] ~ ~ ~ 0.7",
					"playanimation @s animation.humanoid.ataque.simples.braco"
                ],
                subject: commandSubject.Player
            },
            code: (data)=>{
                //world.sendMessage(data.source.name);
            }
        }
    },
	
	////////////////////////////////////////////////////////
	
	//HUMANOS
    {
        use_type: useTypes.Item_Use,
        itemID: "well:espada_humano",
        code_type: {
            command: {
                commands: [
                    "scoreboard players remove @s furia 10",
                    "scoreboard players set @s stamina_player 0",
                    "scoreboard players set @s animacao_esquiva 0",
                    "titleraw @s [scores={classe_humana=1, furia=1..100}] actionbar {\"rawtext\": [{\"translate\": \"furia.10\"}]}",
                    "titleraw @s [scores={classe_humana=1, furia=..0}] actionbar {\"rawtext\": [{\"translate\": \"dialogue.furia.vazia\"}]}",
                    
                    "execute as @s [scores={classe_humana=1, furia=100}] run title @s title furia_bar10",
                    "execute as @s [scores={classe_humana=1, furia=90..99}] run title @s title furia_bar9",
                    "execute as @s [scores={classe_humana=1, furia=80..89}] run title @s title furia_bar8",
                    "execute as @s [scores={classe_humana=1, furia=70..79}] run title @s title furia_bar7",
                    "execute as @s [scores={classe_humana=1, furia=60..69}] run title @s title furia_bar6",
                    "execute as @s [scores={classe_humana=1, furia=50..59}] run title @s title furia_bar5",
                    "execute as @s [scores={classe_humana=1, furia=40..49}] run title @s title furia_bar4",
                    "execute as @s [scores={classe_humana=1, furia=30..39}] run title @s title furia_bar3",
                    "execute as @s [scores={classe_humana=1, furia=20..29}] run title @s title furia_bar2",
                    "execute as @s [scores={classe_humana=1, furia=10..19}] run title @s title furia_bar1",
                    "execute as @s [scores={classe_humana=1, furia=0..9}] run title @s title furia_bar0"
                ],
                subject: commandSubject.Player
            },
            code: (data) => {
                const player = data.source;
                if (!player) return;
    
                const get = (obj) => {
                    try { return world.scoreboard.getObjective(obj)?.getScore(player) ?? 0; } catch { return 0; }
                };
    
                const classe = get("classe_humana");
                const skillAtaque = get("skill_ataque");
                const furia = get("furia");
    
                // ---------- REQUISITOS ----------
                if (classe !== 1) return;
                if (furia <= 0) return;
    
                // Limpa knockback anterior (evita acumular de usos seguidos)
                try { player.runCommand("event entity @s remove_knockback"); } catch {}
    
                // Aplica o knockback (resistência ou efeito customizado) no início
                try { player.runCommand("event entity @s add_knockback"); } catch {}
    
                // ---------- FUNÇÃO PARA SUMMON DOMADO ----------
                function summonDomado(tipo, evento) {
                    const ent = player.dimension.spawnEntity(tipo, player.location);
                    if (!ent) return;
    
                    const tameable = ent.getComponent("minecraft:tameable");
                    if (tameable) tameable.tame(player);
    
                    const sittable = ent.getComponent("minecraft:sittable");
                    if (sittable) sittable.setSitting(false);
    
                    system.runTimeout(() => { ent.triggerEvent(evento); }, 1);
                    return ent;
                }
    
                // ---------- ATAQUE NORMAL (skill_ataque = 0) ----------
                if (skillAtaque === 0) {
                    world.scoreboard.getObjective("furia")?.addScore(player, -10);
    
                    const timeline = [
                        () => {
                            player.runCommand(`camera @s set well:camera_rpg`);
                            player.runCommand(`playanimation @s animation.humano_guerreiro.combo1`);
                            player.runCommand(`scriptevent script:swing`);
                            player.runCommand(`camerashake add @s 0.3 0.5 positional`);
                            player.addEffect("resistance", 20, { amplifier: 5, showParticles: false });
                            player.addEffect("speed", 2, { amplifier: 5, showParticles: false });
    
                            summonDomado("well:dano_area_varios_niveis", "dano5");
                            player.runCommand(`effect @s weakness 6 50 true`);
                            player.runCommand(`scoreboard players set @s combos_animacoes 0`);
                            player.runCommand(`hud @s hide status_effects`);
                        },
                        () => {
                            player.runCommand(`playanimation @s animation.humano_guerreiro.combo2`);
                            player.runCommand(`scriptevent script:swing3`);
                            player.runCommand(`camerashake add @s 0.3 0.5 positional`);
                            player.runCommand(`playsound item.shield.block @p ~ ~ ~`);
                            summonDomado("well:dano_area_varios_niveis", "dano6");
                        },
                        () => {
                            player.runCommand(`playanimation @s animation.humano_guerreiro.combo3`);
                            player.runCommand(`scriptevent script:swing3`);
                            player.runCommand(`playsound mob.boss2.espadas @p ~ ~ ~`);
                            summonDomado("well:dano_area_varios_niveis", "dano6");
                        },
                        () => {
                            player.runCommand(`playanimation @s animation.humano_guerreiro.combo4`);
                            player.runCommand(`scriptevent script:pulo_frente_guerreiro`);
                            player.runCommand(`camerashake add @s 0.4 0.5 positional`);
                            summonDomado("well:dano_area_varios_niveis", "dano8");
                        },
                        () => {
                            player.runCommand(`playanimation @s animation.humano_guerreiro.combo5`);
                            player.runCommand(`camerashake add @s 0.4 0.5 positional`);
                            summonDomado("well:dano_area_varios_niveis", "dano8");
                        },
                        () => {
                            player.runCommand(`playanimation @s animation.humano_guerreiro.combo6`);
                            player.runCommand(`scriptevent script:pulo_frente_guerreiro`);
                            player.runCommand(`inputpermission set @s camera disabled`);
                            player.runCommand(`inputpermission set @s movement disabled`);
                            summonDomado("well:dano_area_varios_niveis", "dano10");
                        },
                        () => {
                            player.runCommand(`inputpermission set @s camera enabled`);
                            player.runCommand(`inputpermission set @s movement enabled`);
                        },
                        () => {
                            // === FINAL DA SKILL NORMAL: remove knockback e limpa tudo ===
                            player.runCommand(`inputpermission set @s camera enabled`);
                            player.runCommand(`effect @s weakness 0`);
                            player.runCommand(`scoreboard players set @s combos_animacoes 1`);
                            player.runCommand(`inputpermission set @s movement enabled`);
                            player.runCommand(`camera @s clear`);
    
                            try { player.runCommand("event entity @s remove_knockback"); } catch {}
                        }
                    ];
    
                    const stepDelay = [0, 10, 20, 30, 40, 50, 70, 80];
                    stepDelay.forEach((delay, i) => system.runTimeout(() => timeline[i]?.(), delay));
                }
    
                // ---------- ATAQUE ESPECIAL (skill_ataque = 1) ----------
                if (skillAtaque === 1 && furia >= 1 && furia <= 100) {
                    const ent = player.dimension.spawnEntity("well:aurea_power", player.location);
                    if (!ent) {
                        // Se falhar o spawn, remove knockback imediatamente
                        try { player.runCommand("event entity @s remove_knockback"); } catch {}
                        return;
                    }
    
                    const tameable = ent.getComponent("minecraft:tameable");
                    if (tameable) tameable.tame(player);
    
                    const sittable = ent.getComponent("minecraft:sittable");
                    if (sittable) sittable.setSitting(false);
    
                    player.runCommand(`inputpermission set @s movement disabled`);
                    player.runCommand(`inputpermission set @s lateral_movement disabled`);
                    player.runCommand(`camera @s set well:camera_rpg`);
                    player.runCommand(`hud @s hide status_effects`);
    
                    system.runTimeout(() => {
                        player.runCommand(`ride @e[type=well:aurea_power,c=1,r=3] start_riding @s teleport_ride`);
                    }, 2);
    
                    player.runCommand(`playanimation @s animation.humano_guerreiro.ataque_escudo`);
                    player.runCommand(`effect @s strength 30 1 false`);
                    player.runCommand(`effect @s weakness 20 50 true`);
                    player.runCommand(`effect @s resistance 5 40`);
                    player.runCommand(`camerashake add @s 0.7 1 positional`);
                    player.runCommand(`scriptevent script:escudo_ladino`);
                    player.runCommand(`playsound ladino_ataque_escudo @a[r=10]`);
                    player.runCommand(`playsound apply_effect.raid_omen`);
                    player.runCommand(`playsound item.trident.riptide_2`);
                    player.runCommand(`playsound item.trident.thunder @a[r=15] ~ ~ ~ 0.3 1 2`);
    
                    function roarKnockback(player, ent, range = 6, horizontal = 15, vertical = 10) {
                        const dimension = player.dimension;
                        const entities = dimension.getEntities({ location: player.location, maxDistance: range });
    
                        entities.forEach(e => {
                            if (e === player || e === ent) return;
                            const family = e.getComponent("minecraft:family");
                            if (family && family.value === "sistema") return;
    
                            const dx = e.location.x - player.location.x;
                            const dz = e.location.z - player.location.z;
                            const length = Math.sqrt(dx*dx + dz*dz) || 0.01;
    
                            const vx = (dx / length) * horizontal * (0.8 + Math.random() * 0.4);
                            const vz = (dz / length) * horizontal * (0.8 + Math.random() * 0.4);
                            const vy = vertical * (0.8 + Math.random() * 0.4) + 0.5;
    
                            if (e.hasComponent("minecraft:physics")) {
                                e.getComponent("minecraft:physics").applyImpulse({ x: vx, y: vy, z: vz });
                            } else if (e.hasComponent("minecraft:movement")) {
                                e.applyKnockback(vx, vz, horizontal, vy); // método alternativo se existir
                            }
                        });
                    }
    
                    system.runTimeout(() => {
                        roarKnockback(player, ent, 6, 15, 10);
                    }, 5);
    
                    // === FINAL DA SKILL ESPECIAL: remove knockback e limpa ===
                    system.runTimeout(() => {
                        player.runCommand(`ride @s stop_riding`);
                        ent.triggerEvent("remove");
                        player.runCommand(`inputpermission set @s movement enabled`);
                        player.runCommand(`inputpermission set @s lateral_movement enabled`);
                        player.runCommand(`camera @s clear`);
    
                        try { player.runCommand("event entity @s remove_knockback"); } catch {}
                    }, 240);
                }
            }
        }
    },

	{
        use_type: useTypes.Item_Use,
        itemID: "well:espada_humano2",
        code_type: {
            command: {
                commands: [
				    
                    "execute as @s [scores={classe_humana=1, skill_ataque=0, furia=20..100}] run summon well:orbe_sombria ^-0.3^3.2^ ~ ~",
					
					"execute as @s [scores={classe_humana=1, skill_ataque=1, furia=20..100}] run event entity @s shinigami_sombrio",
					"execute as @s [scores={classe_humana=1, skill_ataque=1, furia=20..100}] run event entity @s add_tamed_dummy_armor_invisible",
					"execute as @s [scores={classe_humana=1, skill_ataque=1, furia=20..100}] run playanimation @s animation.item_maos_combo_sombrio",
					
					"/scoreboard players set @s stamina_player 0",
					"/scoreboard players set @s animacao_esquiva 0",
					
					"execute as @s [scores={classe_humana=1, skill_ataque=1, furia=20..100}] run scoreboard players remove @s furia 30",
					
					"titleraw @s [scores={classe_humana=1, furia=..0}] actionbar {\"rawtext\": [{\"translate\": \"dialogue.furia.vazia\"}]}",
					
					"execute as @s [scores={classe_humana=1, furia=100}] run title @s [scores={classe_humana=1, furia=100}] title furia_bar10",
                    "execute as @s [scores={classe_humana=1, furia=90..99}] run title @s [scores={classe_humana=1, furia=90..99}] title furia_bar9",
                    "execute as @s [scores={classe_humana=1, furia=80..89}] run title @s [scores={classe_humana=1, furia=80..89}] title furia_bar8",
                    "execute as @s [scores={classe_humana=1, furia=70..79}] run title @s [scores={classe_humana=1, furia=70..79}] title furia_bar7",
                    "execute as @s [scores={classe_humana=1, furia=60..69}] run title @s [scores={classe_humana=1, furia=60..69}] title furia_bar6",
                    "execute as @s [scores={classe_humana=1, furia=50..59}] run title @s [scores={classe_humana=1, furia=50..59}] title furia_bar5",
                    "execute as @s [scores={classe_humana=1, furia=40..49}] run title @s [scores={classe_humana=1, furia=40..49}] title furia_bar4",
                    "execute as @s [scores={classe_humana=1, furia=30..39}] run title @s [scores={classe_humana=1, furia=30..39}] title furia_bar3",
                    "execute as @s [scores={classe_humana=1, furia=20..29}] run title @s [scores={classe_humana=1, furia=20..29}] title furia_bar2",
                    "execute as @s [scores={classe_humana=1, furia=10..19}] run title @s [scores={classe_humana=1, furia=10..19}] title furia_bar1",
                    "execute as @s [scores={classe_humana=1, furia=0..9}] run title @s [scores={classe_humana=1, furia=0..9}] title furia_bar0"
					
					
                ],
                subject: commandSubject.Player
            },
            code: (data)=>{
                //world.sendMessage(data.source.name);
            }
        }
    },
	
	{
        use_type: useTypes.Item_Use,
        itemID: "well:espada_humano3",
        code_type: {
            command: {
                commands: [
				    "playanimation @s animation.humanoid.custom.classe.mago.cajado",
					//Skill 1
					"execute as @s [r=5, scores={classe_humana=1, skill_ataque=0, furia=1..100}] run summon well:entidade_substituicao",
					"execute as @s [r=5, scores={classe_humana=1, skill_ataque=0, furia=1..100}] run playsound substituicao.ninja @a [r=20]",
                    "execute as @s [r=5, scores={classe_humana=1, skill_ataque=0, furia=1..100}] run particle well:explosao_ninja ~ ~1 ~",
                    //"execute as @s [r=5, scores={classe_humana=1, skill_ataque=0, furia=1..100}] run spreadplayers ~ ~ 12 15 @s ~10",
					
					
					"execute as @s [tag=!arena, tag=!boss1, tag=!boss2, tag=!boss3, tag=!boss4, scores={classe_humana=1, skill_ataque=0, furia=1..100}] run spreadplayers ~ ~ 12 15 @s ~10",
					
					
					"execute as @s [tag=arena, scores={classe_humana=1, skill_ataque=0, furia=1..100}] run effect @s levitation 1 8 true",
					"execute as @s [tag=boss1, scores={classe_humana=1, skill_ataque=0, furia=1..100}] run effect @s levitation 1 8 true",
					"execute as @s [tag=boss2, scores={classe_humana=1, skill_ataque=0, furia=1..100}] run effect @s levitation 1 8 true",
					"execute as @s [tag=boss3, scores={classe_humana=1, skill_ataque=0, furia=1..100}] run effect @s levitation 1 8 true",
					"execute as @s [tag=boss4, scores={classe_humana=1, skill_ataque=0, furia=1..100}] run effect @s levitation 1 8 true",
					
					"execute as @s [tag=arena, scores={classe_humana=1, skill_ataque=0, furia=1..100}] run effect @s speed 2 5 true",
					"execute as @s [tag=boss1, scores={classe_humana=1, skill_ataque=0, furia=1..100}] run effect @s speed 2 5 true",
					"execute as @s [tag=boss2, scores={classe_humana=1, skill_ataque=0, furia=1..100}] run effect @s speed 2 5 true",
					"execute as @s [tag=boss3, scores={classe_humana=1, skill_ataque=0, furia=1..100}] run effect @s speed 2 5 true",
					"execute as @s [tag=boss4, scores={classe_humana=1, skill_ataque=0, furia=1..100}] run effect @s speed 2 5 true",
					
					
					"execute as @s [tag=arena, scores={classe_humana=1, skill_ataque=0, furia=1..100}] run effect @s resistance 5 40 true",
					
					
					
					
					"execute as @s [tag=arena, scores={classe_humana=1, skill_ataque=0, furia=1..100}] run playanimation @s animation.humanoid.esquiva.frente",
					"execute as @s [tag=boss1, scores={classe_humana=1, skill_ataque=0, furia=1..100}] run playanimation @s animation.humanoid.esquiva.frente",
					"execute as @s [tag=boss2, scores={classe_humana=1, skill_ataque=0, furia=1..100}] run playanimation @s animation.humanoid.esquiva.frente",
					"execute as @s [tag=boss3, scores={classe_humana=1, skill_ataque=0, furia=1..100}] run playanimation @s animation.humanoid.esquiva.frente",
					"execute as @s [tag=boss4, scores={classe_humana=1, skill_ataque=0, furia=1..100}] run playanimation @s animation.humanoid.esquiva.frente",
					
					
					
					
					
					
					"execute as @s [r=5, scores={classe_humana=1, skill_ataque=0, furia=1..100}] run effect @s resistance 10 10 true",
                    "execute as @s [r=5, scores={classe_humana=1, skill_ataque=0, furia=1..100}] run effect @s invisibility 5 2 true",
                    "execute as @s [r=5, scores={classe_humana=1, skill_ataque=0, furia=1..100}] run event entity @s add_substituicao",
					//"execute as @s [r=5, scores={classe_humana=1, skill_ataque=0, furia=1..100}] run event entity @s add_bombas_ninja",
					
					"/scoreboard players set @s stamina_player 0",
					"/scoreboard players set @s animacao_esquiva 0",
					
                    //Skill 2
					"execute as @s [r=5, scores={classe_humana=1, skill_ataque=1, furia=1..100}] run event entity @s add_especial_ninja_corte",
					
					"scoreboard players remove @s furia 20",
					
					"execute as @s [scores={classe_humana=1, furia=100}] run title @s [scores={classe_humana=1, furia=100}] title furia_bar10",
                    "execute as @s [scores={classe_humana=1, furia=90..99}] run title @s [scores={classe_humana=1, furia=90..99}] title furia_bar9",
                    "execute as @s [scores={classe_humana=1, furia=80..89}] run title @s [scores={classe_humana=1, furia=80..89}] title furia_bar8",
                    "execute as @s [scores={classe_humana=1, furia=70..79}] run title @s [scores={classe_humana=1, furia=70..79}] title furia_bar7",
                    "execute as @s [scores={classe_humana=1, furia=60..69}] run title @s [scores={classe_humana=1, furia=60..69}] title furia_bar6",
                    "execute as @s [scores={classe_humana=1, furia=50..59}] run title @s [scores={classe_humana=1, furia=50..59}] title furia_bar5",
                    "execute as @s [scores={classe_humana=1, furia=40..49}] run title @s [scores={classe_humana=1, furia=40..49}] title furia_bar4",
                    "execute as @s [scores={classe_humana=1, furia=30..39}] run title @s [scores={classe_humana=1, furia=30..39}] title furia_bar3",
                    "execute as @s [scores={classe_humana=1, furia=20..29}] run title @s [scores={classe_humana=1, furia=20..29}] title furia_bar2",
                    "execute as @s [scores={classe_humana=1, furia=10..19}] run title @s [scores={classe_humana=1, furia=10..19}] title furia_bar1",
                    "execute as @s [scores={classe_humana=1, furia=0..9}] run title @s [scores={classe_humana=1, furia=0..9}] title furia_bar0"
					
					
                ],
                subject: commandSubject.Player
            },
            code: (data)=>{
                //world.sendMessage(data.source.name);
            }
        }
    },

	{
        use_type: useTypes.Item_Use,
        itemID: "well:espada_humano4",
        code_type: {
            command: {
                commands: [
				    "playanimation @s animation.humanoid.custom.classe.mago.cajado",
					//Skill 1
					"execute as @s [r=5, scores={classe_humana=1, skill_ataque=0, furia=1..100}] run event entity @s add_especial_machado_skill1",
					
					//Skill 2
					"execute as @s [r=5, scores={classe_humana=1, skill_ataque=1, furia=1..100}] run event entity @s machado_giratorio_ataque",
					
					"/scoreboard players set @s stamina_player 0",
					"/scoreboard players set @s animacao_esquiva 0",
					
					"scoreboard players remove @s furia 20",
					
					"titleraw @s [scores={classe_humana=1, furia=1..100}] actionbar {\"rawtext\": [{\"translate\": \"furia.20\"}]}",
					"titleraw @s [scores={classe_humana=1, furia=..0}] actionbar {\"rawtext\": [{\"translate\": \"dialogue.furia.vazia\"}]}",
					
					
					"execute as @s [scores={classe_humana=1, furia=100}] run title @s [scores={classe_humana=1, furia=100}] title furia_bar10",
                    "execute as @s [scores={classe_humana=1, furia=90..99}] run title @s [scores={classe_humana=1, furia=90..99}] title furia_bar9",
                    "execute as @s [scores={classe_humana=1, furia=80..89}] run title @s [scores={classe_humana=1, furia=80..89}] title furia_bar8",
                    "execute as @s [scores={classe_humana=1, furia=70..79}] run title @s [scores={classe_humana=1, furia=70..79}] title furia_bar7",
                    "execute as @s [scores={classe_humana=1, furia=60..69}] run title @s [scores={classe_humana=1, furia=60..69}] title furia_bar6",
                    "execute as @s [scores={classe_humana=1, furia=50..59}] run title @s [scores={classe_humana=1, furia=50..59}] title furia_bar5",
                    "execute as @s [scores={classe_humana=1, furia=40..49}] run title @s [scores={classe_humana=1, furia=40..49}] title furia_bar4",
                    "execute as @s [scores={classe_humana=1, furia=30..39}] run title @s [scores={classe_humana=1, furia=30..39}] title furia_bar3",
                    "execute as @s [scores={classe_humana=1, furia=20..29}] run title @s [scores={classe_humana=1, furia=20..29}] title furia_bar2",
                    "execute as @s [scores={classe_humana=1, furia=10..19}] run title @s [scores={classe_humana=1, furia=10..19}] title furia_bar1",
                    "execute as @s [scores={classe_humana=1, furia=0..9}] run title @s [scores={classe_humana=1, furia=0..9}] title furia_bar0"
					
                ],
                subject: commandSubject.Player
            },
            code: (data)=>{
                //world.sendMessage(data.source.name);
            }
        }
    },
	
	{
        use_type: useTypes.Item_Use,
        itemID: "well:espada_humano5",
        code_type: {
            command: {
                commands: [
				    "playanimation @s animation.humanoid.custom.classe.mago.cajado",
					//Skill 1
					"scoreboard players remove @s furia 30",
					"execute as @s [r=5, scores={classe_humana=1, skill_ataque=0, furia=1..100}] run event entity @s add_especial_marretao_skill1",
					
					"execute as @s [r=5, scores={classe_humana=1, skill_ataque=1, furia=1..100}] run event entity @s martelo_quebra_solo",
					
					"/scoreboard players set @s stamina_player 0",
					"/scoreboard players set @s animacao_esquiva 0",
					
					"execute as @s [scores={furia=100}] run title @s [scores={classe_humana=1, furia=100}] title furia_bar10",
                    "execute as @s [scores={furia=90..99}] run title @s [scores={classe_humana=1, furia=90..99}] title furia_bar9",
                    "execute as @s [scores={furia=80..89}] run title @s [scores={classe_humana=1, furia=80..89}] title furia_bar8",
                    "execute as @s [scores={furia=70..79}] run title @s [scores={classe_humana=1, furia=70..79}] title furia_bar7",
                    "execute as @s [scores={furia=60..69}] run title @s [scores={classe_humana=1, furia=60..69}] title furia_bar6",
                    "execute as @s [scores={furia=50..59}] run title @s [scores={classe_humana=1, furia=50..59}] title furia_bar5",
                    "execute as @s [scores={furia=40..49}] run title @s [scores={classe_humana=1, furia=40..49}] title furia_bar4",
                    "execute as @s [scores={furia=30..39}] run title @s [scores={classe_humana=1, furia=30..39}] title furia_bar3",
                    "execute as @s [scores={furia=20..29}] run title @s [scores={classe_humana=1, furia=20..29}] title furia_bar2",
                    "execute as @s [scores={furia=10..19}] run title @s [scores={classe_humana=1, furia=10..19}] title furia_bar1",
                    "execute as @s [scores={furia=0..9}] run title @s [scores={classe_humana=1, furia=0..9}] title furia_bar0"
					
                ],
                subject: commandSubject.Player
            },
            code: (data)=>{
                //world.sendMessage(data.source.name);
            }
        }
    },
	
	
	//MAGOS
	{
        use_type: useTypes.Item_Use,
        itemID: "well:cajado_mago",
        code_type: {
            command: {
                commands: [
				    "playanimation @s animation.humanoid.custom.classe.mago.cajado",
					//Skill 1
                    "effect @s [r=5, scores={classe_mago=1, skill_ataque=0, mana=1..100}] night_vision 60 5 true",
					"scoreboard players remove @s mana 10",
					"execute as @s [scores={classe_mago=1, skill_ataque=0, mana=1..100}] run summon well:circulo_cura ~ ~-0.3 ~ ~ ~ invisibilidade",
					"execute as @s [scores={classe_mago=1, skill_ataque=0, mana=1..100}] run tp @e [type=well:circulo_cura, r=10] @s",
					"titleraw @s [scores={classe_mago=1, skill_ataque=0, mana=1..100}] actionbar {\"rawtext\": [{\"translate\": \"mana.10\"}]}",
					"titleraw @s [scores={classe_mago=1, skill_ataque=0, mana=..0}] actionbar {\"rawtext\": [{\"translate\": \"dialogue.mana.vazia\"}]}",
					
					"execute as @s [scores={classe_mago=1, mana=100}] run title @s [scores={classe_mago=1, mana=100}] title mana_bar10",
                    "execute as @s [scores={classe_mago=1, mana=90..99}] run title @s [scores={classe_mago=1, mana=90..99}] title mana_bar9",
                    "execute as @s [scores={classe_mago=1, mana=80..89}] run title @s [scores={classe_mago=1, mana=80..89}] title mana_bar8",
                    "execute as @s [scores={classe_mago=1, mana=70..79}] run title @s [scores={classe_mago=1, mana=70..79}] title mana_bar7",
                    "execute as @s [scores={classe_mago=1, mana=60..69}] run title @s [scores={classe_mago=1, mana=60..69}] title mana_bar6",
                    "execute as @s [scores={classe_mago=1, mana=50..59}] run title @s [scores={classe_mago=1, mana=50..59}] title mana_bar5",
                    "execute as @s [scores={classe_mago=1, mana=40..49}] run title @s [scores={classe_mago=1, mana=40..49}] title mana_bar4",
                    "execute as @s [scores={classe_mago=1, mana=30..39}] run title @s [scores={classe_mago=1, mana=30..39}] title mana_bar3",
                    "execute as @s [scores={classe_mago=1, mana=20..29}] run title @s [scores={classe_mago=1, mana=20..29}] title mana_bar2",
                    "execute as @s [scores={classe_mago=1, mana=10..19}] run title @s [scores={classe_mago=1, mana=10..19}] title mana_bar1",
                    "execute as @s [scores={classe_mago=1, mana=0..9}] run title @s [scores={classe_mago=1, mana=0..9}] title mana_bar0",
					
					"/scoreboard players set @s stamina_player 0",
					"/scoreboard players set @s animacao_esquiva 0"
					
                ],
                subject: commandSubject.Player
            },
            code: (data)=>{
                //world.sendMessage(data.source.name);
            }
        }
    },
	{
        use_type: useTypes.Item_Use,
        itemID: "well:cajado_mago2",
        code_type: {
            command: {
                commands: [
				    "playanimation @s animation.humanoid.custom.classe.mago.cajado",
					//Skill 1
                    "tag @s [r=5, scores={classe_mago=1, skill_ataque=0}] add mago_executor",
					"tag @e [scores={classe_mago=1, skill_ataque=0}, tag=!mago_executor, type=!well:player_congelado, r=8] add congelado_mob",
					"effect @s [r=5, scores={classe_mago=1, skill_ataque=0, mana=1..100}] fire_resistance 60 5 true",
					"execute as @s [r=5, scores={classe_mago=1, skill_ataque=0, mana=1..100}] run particle well:explosao_gelada",
					"execute as @s [r=5, scores={classe_mago=1, skill_ataque=0, mana=1..100}] run particle minecraft:cauldron_explosion_emitter ~ ~1 ~",
					"execute as @s [r=5, scores={classe_mago=1, skill_ataque=0, mana=1..100}] run playsound magia.gelo @a [r=10]",
					"scoreboard players remove @s [r=5, scores={classe_mago=1, skill_ataque=0}] mana 20",
					"execute as @s [r=5, scores={classe_mago=1, skill_ataque=0, mana=1..100}] at @e [r=5, tag=!mago_executor] run summon well:player_congelado",
					"execute as @s [r=5, scores={classe_mago=1, skill_ataque=0, mana=1..100}] at @e [r=5, tag=!mago_executor] run particle well:explosao_gelo",
					"titleraw @s [scores={classe_mago=1, skill_ataque=0, mana=1..100}] actionbar {\"rawtext\": [{\"translate\": \"mana.20\"}]}",
					"titleraw @s [scores={classe_mago=1, skill_ataque=0, mana=..0}] actionbar {\"rawtext\": [{\"translate\": \"dialogue.mana.vazia\"}]}",
					
					//Skill 2
					"tag @s [r=5, scores={classe_mago=1, skill_ataque=1}] add mago_executor",
					"tag @e [tag=!mago_executor, type=!well:player_congelado, type=!well:espeto_gelo, r=20] add congelado_mob",
					"execute as @s [r=5, scores={classe_mago=1, skill_ataque=1, mana=1..100}] run playsound magia.gelo @a [r=10]",
					"execute as @s [r=5, scores={classe_mago=1, skill_ataque=1, mana=1..100}] run particle well:explosao_gelada",
					"scoreboard players remove @s [r=5, scores={classe_mago=1, skill_ataque=1}] mana 10",
					"execute as @s [r=5, scores={classe_mago=1, skill_ataque=1, mana=1..100}] at @e [family=!pet, tag=congelado_mob, r=20] run summon well:espeto_gelo",
					"titleraw @s [scores={classe_mago=1, skill_ataque=1, mana=1..100}] actionbar {\"rawtext\": [{\"translate\": \"mana.10\"}]}",
					"titleraw @s [scores={classe_mago=1, skill_ataque=1, mana=..0}] actionbar {\"rawtext\": [{\"translate\": \"dialogue.mana.vazia\"}]}",
					
					"execute as @s [scores={mana=100}] run title @s [scores={classe_mago=1, mana=100}] title mana_bar10",
                    "execute as @s [scores={mana=90..99}] run title @s [scores={classe_mago=1, mana=90..99}] title mana_bar9",
                    "execute as @s [scores={mana=80..89}] run title @s [scores={classe_mago=1, mana=80..89}] title mana_bar8",
                    "execute as @s [scores={mana=70..79}] run title @s [scores={classe_mago=1, mana=70..79}] title mana_bar7",
                    "execute as @s [scores={mana=60..69}] run title @s [scores={classe_mago=1, mana=60..69}] title mana_bar6",
                    "execute as @s [scores={mana=50..59}] run title @s [scores={classe_mago=1, mana=50..59}] title mana_bar5",
                    "execute as @s [scores={mana=40..49}] run title @s [scores={classe_mago=1, mana=40..49}] title mana_bar4",
                    "execute as @s [scores={mana=30..39}] run title @s [scores={classe_mago=1, mana=30..39}] title mana_bar3",
                    "execute as @s [scores={mana=20..29}] run title @s [scores={classe_mago=1, mana=20..29}] title mana_bar2",
                    "execute as @s [scores={mana=10..19}] run title @s [scores={classe_mago=1, mana=10..19}] title mana_bar1",
                    "execute as @s [scores={mana=0..9}] run title @s [scores={classe_mago=1, mana=0..9}] title mana_bar0",
					
					"/scoreboard players set @s stamina_player 0",
					"/scoreboard players set @s animacao_esquiva 0"
                ],
                subject: commandSubject.Player
            },
            code: (data)=>{
                //world.sendMessage(data.source.name);
            }
        }
    },
    {
        use_type: useTypes.Item_Use,
        itemID: "well:cajado_mago3",
        code_type: {
            code: (data) => {
    
                const player = data.source;
                if (!player) return;
    
                // ======= PEGAR SCOREBOARD FORMA CORRETA =======
                const get = (obj) => {
                    try {
                        return world.scoreboard.getObjective(obj)?.getScore(player) ?? 0;
                    } catch {
                        return 0;
                    }
                };
    
                // Requisitos
                if (get("classe_mago") !== 1) return;
                if (get("skill_ataque") !== 1) return;
                if (get("mana") <= 0) return;
    
                // Custa 30 de mana
                world.scoreboard.getObjective("mana")?.addScore(player, -30);
    
                // Duração total
                const DURATION = 200; // 10 segundos
                let ticks = 0;
    
                const loop = system.runInterval(() => {
    
                    // CANCELA se parar o ataque ou ficar sem mana
                    if (get("skill_ataque") !== 1 || get("mana") <= 0) {
                        system.clearRun(loop);
                        return;
                    }
    
                    // PARTICULAS
                    if (ticks % 15 === 0) {
                        player.dimension.runCommand(
                            `particle well:arco_voltaico ${player.location.x} ${player.location.y} ${player.location.z}`
                        );
                    }
    
                    // PLAYSOUND a cada 40 ticks (~2s)
                    if (ticks % 40 === 0) {
                        player.runCommand(
                            `playsound arco.voltaico @a ~ ~ ~ 0.6`
                        );
                    }
    
                    // SUMONAR ENTIDADE a cada 4 ticks
                    if (ticks % 4 === 0) {
                        const ent = player.dimension.spawnEntity(
                            "well:dano_area_varios_niveis",
                            player.location
                        );
    
                        if (ent) {
                            // Aplica evento depois de carregar
                            system.runTimeout(() => {
                                ent.triggerEvent("dano4");
                            }, 1);
    
                            // === DOMAR PRA NÃO DAR DANO NO DONO ===
                            const tameable = ent.getComponent("minecraft:tameable");
                            if (tameable) tameable.tame(player);
    
                            const sit = ent.getComponent("minecraft:sittable");
                            if (sit) sit.setSitting(false);
                        }
                    }
    
                    ticks++;
                    if (ticks >= DURATION) system.clearRun(loop);
    
                }, 1);
            }
        }
    },
	{
        use_type: useTypes.Item_Use,
        itemID: "well:cajado_mago4",
        code_type: {
            command: {
                commands: [
				    "playanimation @s animation.humanoid.custom.classe.mago.cajado",
					"titleraw @s [scores={classe_mago=1, mana=..0}] actionbar {\"rawtext\": [{\"translate\": \"dialogue.mana.vazia\"}]}",
                    //Skill 1
					"event entity @s [r=10, scores={classe_mago=1, skill_ataque=0, mana=1..100}] use_item_mago4",
					
					//Skill  2
					"tag @s [r=5, scores={classe_mago=1, skill_ataque=1}] add mago_executor",
					"tag @e [tag=!mago_executor, type=!well:mao_mago, r=20] add congelado_mob",
					"scoreboard players remove @s [r=5, scores={classe_mago=1, skill_ataque=1}] mana 20",
					"execute as @s [r=5, scores={classe_mago=1, skill_ataque=1, mana=1..100}] at @e [family=!pet, tag=!mago_executor, tag=congelado_mob, r=20] run summon well:mao_mago ~~~ ~-90",
					"titleraw @s [scores={classe_mago=1, skill_ataque=1, mana=1..100}] actionbar {\"rawtext\": [{\"translate\": \"mana.30\"}]}",
					"titleraw @s [scores={classe_mago=1, carregar=3, mana=..0}] actionbar {\"rawtext\": [{\"translate\": \"dialogue.mana.vazia\"}]}",
					
					"execute as @s [scores={classe_mago=1, mana=100}] run title @s [scores={classe_mago=1, mana=100}] title mana_bar10",
                    "execute as @s [scores={classe_mago=1, mana=90..99}] run title @s [scores={classe_mago=1, mana=90..99}] title mana_bar9",
                    "execute as @s [scores={classe_mago=1, mana=80..89}] run title @s [scores={classe_mago=1, mana=80..89}] title mana_bar8",
                    "execute as @s [scores={classe_mago=1, mana=70..79}] run title @s [scores={classe_mago=1, mana=70..79}] title mana_bar7",
                    "execute as @s [scores={classe_mago=1, mana=60..69}] run title @s [scores={classe_mago=1, mana=60..69}] title mana_bar6",
                    "execute as @s [scores={classe_mago=1, mana=50..59}] run title @s [scores={classe_mago=1, mana=50..59}] title mana_bar5",
                    "execute as @s [scores={classe_mago=1, mana=40..49}] run title @s [scores={classe_mago=1, mana=40..49}] title mana_bar4",
                    "execute as @s [scores={classe_mago=1, mana=30..39}] run title @s [scores={classe_mago=1, mana=30..39}] title mana_bar3",
                    "execute as @s [scores={classe_mago=1, mana=20..29}] run title @s [scores={classe_mago=1, mana=20..29}] title mana_bar2",
                    "execute as @s [scores={classe_mago=1, mana=10..19}] run title @s [scores={classe_mago=1, mana=10..19}] title mana_bar1",
                    "execute as @s [scores={classe_mago=1, mana=0..9}] run title @s [scores={classe_mago=1, mana=0..9}] title mana_bar0",
					
					"/scoreboard players set @s stamina_player 0",
					"/scoreboard players set @s animacao_esquiva 0"
					
					
					
					
					
                ],
                subject: commandSubject.Player
            },
            code: (data)=>{
                //world.sendMessage(data.source.name);
            }
        }
    },
	{
        use_type: useTypes.Item_Use,
        itemID: "well:cajado_mago5",
        code_type: {
            command: {
                commands: [
					//Skill  2
					"playanimation @s animation.humanoid.custom.classe.mago.cajado",
					"tag @s [r=5, scores={classe_mago=1, skill_ataque=1}] add mago_executor",
					"tag @e [tag=!mago_executor, type=!well:mao_mago, r=20] add congelado_mob",
					"scoreboard players remove @s [r=5, scores={classe_mago=1, skill_ataque=1}] mana 30",
					"execute as @s [r=30, scores={classe_mago=1, skill_ataque=1, mana=1..100}] run camerashake add @a [r=30] 0.1 3 rotational",
					"execute as @s [r=30, scores={classe_mago=1, skill_ataque=1, mana=1..100}] run effect @a [r=20] darkness 2 1 true",
					"execute as @s [r=5, scores={classe_mago=1, skill_ataque=1, mana=1..100}] at @e [family=!pet, tag=!mago_executor, tag=congelado_mob, r=30] run summon well:bola_fogo ~ ~20 ~ ~ ~ meteoro_mago",
					"titleraw @s [scores={classe_mago=1, skill_ataque=1, mana=1..100}] actionbar {\"rawtext\": [{\"translate\": \"mana.30\"}]}",
					"titleraw @s [scores={classe_mago=1, skill_ataque=1, mana=..0}] actionbar {\"rawtext\": [{\"translate\": \"dialogue.mana.vazia\"}]}",
					
					"execute as @s [scores={mana=100}] run title @s [scores={classe_mago=1, mana=100}] title mana_bar10",
                    "execute as @s [scores={mana=90..99}] run title @s [scores={classe_mago=1, mana=90..99}] title mana_bar9",
                    "execute as @s [scores={mana=80..89}] run title @s [scores={classe_mago=1, mana=80..89}] title mana_bar8",
                    "execute as @s [scores={mana=70..79}] run title @s [scores={classe_mago=1, mana=70..79}] title mana_bar7",
                    "execute as @s [scores={mana=60..69}] run title @s [scores={classe_mago=1, mana=60..69}] title mana_bar6",
                    "execute as @s [scores={mana=50..59}] run title @s [scores={classe_mago=1, mana=50..59}] title mana_bar5",
                    "execute as @s [scores={mana=40..49}] run title @s [scores={classe_mago=1, mana=40..49}] title mana_bar4",
                    "execute as @s [scores={mana=30..39}] run title @s [scores={classe_mago=1, mana=30..39}] title mana_bar3",
                    "execute as @s [scores={mana=20..29}] run title @s [scores={classe_mago=1, mana=20..29}] title mana_bar2",
                    "execute as @s [scores={mana=10..19}] run title @s [scores={classe_mago=1, mana=10..19}] title mana_bar1",
                    "execute as @s [scores={mana=0..9}] run title @s [scores={classe_mago=1, mana=0..9}] title mana_bar0",
					
					"/scoreboard players set @s stamina_player 0",
					"/scoreboard players set @s animacao_esquiva 0"
					
                ],
                subject: commandSubject.Player
            },
            code: (data)=>{
                //world.sendMessage(data.source.name);
            }
        }
    },
	
	
	
	///////////////////////////////////
	
	{
        use_type: useTypes.Item_Use,
        itemID: "well:cajado_sangue",
        code_type: {
            command: {
                commands: [
				    "playanimation @s animation.humanoid.custom.classe.mago.cajado",
                    "event entity @e [type=well:dragao_sangue, r=3] projectil_dragao",
					"execute at @e [type=well:dragao_sangue, r=3] run playsound mob.enderdragon.growl",
					"execute at @e [type=well:dragao_sangue, r=3] run playanimation @e [type=well:dragao_sangue, r=3] animation.european_dragon.breath",
					"execute at @e [type=well:dragao_sangue, r=3] run effect @e [type=well:dragao_sangue, r=3] slowness 1 20 true",
					"scoreboard players add @e [type=well:dragao_sangue, c=1, r=5] voo_dragao 50"
                ],
                subject: commandSubject.Player
            },
            code: (data)=>{
                //world.sendMessage(data.source.name);
            }
        }
    },
	{
        use_type: useTypes.Item_Use,
        itemID: "well:cajado_almas",
        code_type: {
            command: {
                commands: [
				    "playanimation @s animation.humanoid.custom.classe.mago.cajado",
                    "event entity @e [type=well:dragao_almas, r=5] projectil_dragao",
					"execute at @e [type=well:dragao_almas, r=7] run playsound mob.enderdragon.growl",
					"execute at @e [type=well:dragao_almas, r=5] run playanimation @e [type=well:dragao_almas, r=5] animation.european_dragon.breath",
					"execute at @e [type=well:dragao_almas, r=5] run effect @e [type=well:dragao_almas, r=5] slowness 1 20 true",
					"scoreboard players add @e [type=well:dragao_almas, c=1, r=5] voo_dragao 50"
                ],
                subject: commandSubject.Player
            },
            code: (data)=>{
                //world.sendMessage(data.source.name);
            }
        }
    },
	{
        use_type: useTypes.Item_Use,
        itemID: "well:cajado_gelo",
        code_type: {
            command: {
                commands: [
				    "playanimation @s animation.humanoid.custom.classe.mago.cajado",
                    "event entity @e [type=well:dragao_gelo, r=3] projectil_dragao",
					"execute at @e [type=well:dragao_gelo, r=3] run playsound mob.enderdragon.growl",
					"execute at @e [type=well:dragao_gelo, r=3] run playanimation @e [type=well:dragao_gelo, r=3] animation.european_dragon.breath",
					"execute at @e [type=well:dragao_gelo, r=3] run effect @e [type=well:dragao_gelo, r=3] slowness 1 20 true",
					"scoreboard players add @e [type=well:dragao_gelo, c=1, r=5] voo_dragao 50"
                ],
                subject: commandSubject.Player
            },
            code: (data)=>{
                //world.sendMessage(data.source.name);
            }
        }
    },
	{
        use_type: useTypes.Item_Use,
        itemID: "well:cajado_venenoso",
        code_type: {
            command: {
                commands: [
				    "playanimation @s animation.humanoid.custom.classe.mago.cajado",
                    "event entity @e [type=well:dragao_venenoso, r=3] projectil_dragao",
					"execute at @e [type=well:dragao_venenoso, r=3] run playsound mob.enderdragon.growl",
					"execute at @e [type=well:dragao_venenoso, r=3] run playanimation @e [type=well:dragao_venenoso, r=3] animation.european_dragon.breath",
					"execute at @e [type=well:dragao_venenoso, r=3] run effect @e [type=well:dragao_venenoso, r=3] slowness 1 20 true",
					"scoreboard players add @e [type=well:dragao_venenoso, c=1, r=5] voo_dragao 50"
                ],
                subject: commandSubject.Player
            },
            code: (data)=>{
                //world.sendMessage(data.source.name);
            }
        }
    },
	
	{
        use_type: useTypes.Item_Use,
        itemID: "well:cajado_sombrio",
        code_type: {
            command: {
                commands: [
				    "playanimation @s animation.humanoid.custom.classe.mago.cajado",
                    "event entity @e [type=well:dragao_almas_sombras, r=5] projectil_dragao",
					"execute at @e [type=well:dragao_almas_sombras, r=7] run playsound mob.enderdragon.growl",
					"execute at @e [type=well:dragao_almas_sombras, r=5] run playanimation @e [type=well:dragao_almas_sombras, r=5] animation.european_dragon.breath",
					"execute at @e [type=well:dragao_almas_sombras, r=5] run effect @e [type=well:dragao_almas_sombras, r=5] slowness 1 20 true",
					"scoreboard players add @e [type=well:dragao_almas_sombras, c=1, r=5] voo_dragao 50"
                ],
                subject: commandSubject.Player
            },
            code: (data)=>{
                //world.sendMessage(data.source.name);
            }
        }
    },
	
	{
    use_type: useTypes.Item_Use,
        itemID: "well:folha_bestiario",
        code_type: {
            command: {
                commands: [
                    "event entity @s use_item"
                ],
                subject: commandSubject.Player
            },
            code: (data) => {
                const player = data.source;
    
                // 🛑 Se já executou, bloqueia
                if (player.hasTag("bestiario_lock")) return;
    
                // 🔒 Trava execução
                player.addTag("bestiario_lock");
    
                // 🎲 Sorteia entre 1 e 79
                const pagina = Math.floor(Math.random() * 79) + 1;
    
                player.runCommand(`scoreboard players set @s pagina${pagina} 1`);
                player.sendMessage(`§a📖 Página descoberta: §ePagina ${pagina}`);
    
                // ⏱️ Remove a trava depois (5 ticks ≈ 0.25s)
                system.runTimeout(() => {
                    if (player.isValid()) {
                        player.removeTag("bestiario_lock");
                    }
                }, 5);
            }
        }
    }

	
	
];
const itemUses = [
    world.afterEvents.itemUse,
    world.afterEvents.itemUseOn,
    world.afterEvents.itemCompleteUse,
    world.afterEvents.itemReleaseUse,
    world.afterEvents.itemStartUse,
    world.afterEvents.itemStartUseOn,
    world.afterEvents.itemStopUse,
    world.afterEvents.itemStopUseOn
];
const itemUsesTypes = [
    useTypes.Item_Use,
    useTypes.Item_Use_On,
    useTypes.Item_Complete_Use,
    useTypes.Item_Release_Use,
    useTypes.Item_Start_Use,
    useTypes.Item_Start_Use_On,
    useTypes.Item_Stop_Use,
    useTypes.Item_Stop_Use_On
];

world.afterEvents.worldLoad.subscribe(() => {
    for (let i = 0; i < itemUses.length; i++) {
        const itemUse = itemUses[i];
        itemUse.subscribe((data) => {
            const Data = data;
            const code = on_Use.find((f) => f.use_type == itemUsesTypes[i] && f.itemID == Data.itemStack.typeId);
            if (code == undefined) return;

            // Verifique se o jogador está agachado e interrompa a execução se estiver
            if (Data.source.isSneaking) {
                return; // Não execute nada se o jogador estiver agachado
            }

            const component = Data.itemStack.getComponent(ItemCooldownComponent.componentId);
            if (component?.getCooldownTicksRemaining(Data.source) >= 1 && component?.getCooldownTicksRemaining(Data.source) <= component?.cooldownTicks - 2) return;
            if (component) component.startCooldown(Data.source);

            const command = code.code_type.command;
            const func = code.code_type.code;

            if (func != undefined) {
                func(Data); // Executa a função associada ao código
            }

            if (command != undefined) {
                let subject = Data.source;
                if (command.subject == commandSubject.Dimension) subject = Data.source.dimension;
                for (const cmd of command.commands) {
                    subject.runCommand(cmd); // Executa os comandos
                }
            }
        });
    }
});
