import {
	system,
	world, 
	EquipmentSlot, 
	ItemStack
} from "@minecraft/server";
import './ui.js';
import './pet.js';
import './entity_sounds.js';
import './guide_book.js';
const testing = false
{
const wp1Damage = [
	4,15,4,50
], wp2Damage = [
	15,40,20,80
], wp3Damage = [
	6,5,10,60
], wp4Damage = [
	5,10,4,55
], wp5Damage = [
	3,12,18,70
], wp6Damage = [
	10,6,8,80
], wp1CD = [
	4,5,6,15
], wp2CD = [
	6,8,10,15
], wp3CD = [
	2,4,6,15
], wp4CD = [
	8,4,8,15
], wp5CD = [
	8,6,10,15
], wp6CD = [
	6,8,10,15
]
const entitiesTypes = [
    {
        entities: new Set([
            "minecraft:cave_spider",
            "minecraft:drowned",
            "minecraft:endermite",
            "minecraft:husk",
            "minecraft:magma_cube",
            "minecraft:silverfish",
            "minecraft:skeleton",
            "minecraft:slime",
            "minecraft:spider",
            "minecraft:stray",
            "minecraft:zombie",
            "minecraft:zombie_pigman",
            "minecraft:zombie_villager",
            "minecraft:zombie_villager_v2"
        ]),
        xp: 1
    },
    {
        entities: new Set([
            "minecraft:blaze",
            "minecraft:creeper",
            "minecraft:enderman",
            "minecraft:ghast",
            "minecraft:hoglin",
            "minecraft:phantom",
            "minecraft:shulker",
            "minecraft:guardian",
            "minecraft:vex",
            "minecraft:zoglin"
        ]),
        xp: 3
    },
    {
        entities: new Set([
            "minecraft:evocation_illager",
            "minecraft:piglin",
            "minecraft:piglin_brute",
            "minecraft:pillager",
            "minecraft:ravager",
            "minecraft:vindicator",
            "minecraft:witch",
            "minecraft:wither_skeleton",
            "minecraft:elder_guardian",
			"tp_pw:feral_lynx_untamed",
			"tp_pw:flame_hawk_untamed",
			"tp_pw:storm_griffin_untamed",
			"tp_pw:nebula_dragon_untamed",
			"tp_pw:music_golem_untamed",
			"tp_pw:frost_fox_untamed",
        ]),
        xp: 4
    },
    { 
        entities: new Set([ 
        ]),
        xp: 50
    },
    { 
        entities: new Set([
            "minecraft:ender_dragon",
            "minecraft:wither",
            "minecraft:warden"
        ]),
        xp: 150
    }
]
const wpMinLVL = [
	1,2,3,5
]
let defaultEXP = 10;
function getTarget(entity) {
    let resolved = false;
    return new Promise((resolve) => {
        //entity.triggerEvent('tp_pw:identify_target');
        const ev = system.afterEvents.scriptEventReceive.subscribe((data) => {
            if (data.id === 'tp_pw:identify_target') {
                resolved = true;
                system.afterEvents.scriptEventReceive.unsubscribe(ev);
				console.warn('identified')
                resolve(data.sourceEntity); return;
            }
        });
        system.runTimeout(() => {
            system.afterEvents.scriptEventReceive.unsubscribe(ev);
			console.warn('done')
            if (!resolved) resolve(null);
        }, 20);
    });
}
system.afterEvents.scriptEventReceive.subscribe(data => {
	const id = data.id, entity = data.sourceEntity
	if (id === "tp_pw:level_max") {
		const exp = 0
		const lvl = 10
		const ult = 10
		weapons.forEach(weapon=>{
			entity.runCommand(`scoreboard players set @s tp_pw:${weapon}_EXP ${exp}`)
			entity.runCommand(`scoreboard players set @s tp_pw:${weapon}_LVL ${lvl}`)
			entity.runCommand(`scoreboard players set @s tp_pw:${weapon}_ULT ${ult}`)
		})
	}
	if (id === "tp_pw:pet_level_up") {
		world.getDimension("overworld").getEntities().forEach((entity)=>{
			aydiPet.forEach(id=>{
				if(entity.typeId===id) {
					entity.runCommand('scoreboard players add @s tp_pw:pet_LVL 10')
					entity.runCommand('scoreboard players set @s tp_pw:pet_EXP 0')
					entity.runCommand('scoreboard players set @s tp_pw:pet_HGR 600')
				}
			})
		})
	}
	// if (id === "tp_pw:identify_target") {
	// 	console.warn('My name is '+entity.name)
	// }
})
const aydiPet = [    `tp_pw:feral_lynx`,    `tp_pw:nebula_dragon`,    `tp_pw:flame_hawk`,    `tp_pw:frost_fox`,    `tp_pw:music_golem`,    `tp_pw:storm_griffin`]
const weapons = [	'blade_of_the_wild',	'celestial_gauntlets',	'ember_bow',	'glacier_staff',	'mystic_flute',	'thunder_mace'];const weaponSkills = {    'blade_of_the_wild': blade_of_the_wild_skill,    'celestial_gauntlets': celestial_gauntlets_skill,    'ember_bow': ember_bow_skill,    'glacier_staff': glacier_staff_skill,    'mystic_flute': mystic_flute_skill,    'thunder_mace': thunder_mace_skill};const pets = {    'blade_of_the_wild': `feral_lynx`,    'celestial_gauntlets': `nebula_dragon`,    'ember_bow': `flame_hawk`,    'glacier_staff': `frost_fox`,    'mystic_flute': `music_golem`,    'thunder_mace': `storm_griffin`};const petsId = [    `feral_lynx`,    `nebula_dragon`,    `flame_hawk`,    `frost_fox`,    `music_golem`,    `storm_griffin`];const multiMoveEntity = ['tp_pw:storm_griffin_untamed', 'tp_pw:nebula_dragon_untamed']
const bannedItems = [	'tp_pw:blade_of_the_wild_attack1',	'tp_pw:blade_of_the_wild_attack2',	'tp_pw:blade_of_the_wild_attack3',	'tp_pw:blade_of_the_wild_attack4',	'tp_pw:celestial_gauntlets_attack1',	'tp_pw:celestial_gauntlets_attack2',	'tp_pw:celestial_gauntlets_attack3',	'tp_pw:celestial_gauntlets_attack4',	'tp_pw:ember_bow_attack1',	'tp_pw:ember_bow_attack2',	'tp_pw:ember_bow_attack3',	'tp_pw:ember_bow_attack4',	'tp_pw:glacier_staff_attack1',	'tp_pw:glacier_staff_attack2',	'tp_pw:glacier_staff_attack3',	'tp_pw:glacier_staff_attack4',	'tp_pw:mystic_flute_attack1',	'tp_pw:mystic_flute_attack2',	'tp_pw:mystic_flute_attack3',	'tp_pw:mystic_flute_attack4',	'tp_pw:thunder_mace_attack1',	'tp_pw:thunder_mace_attack2',	'tp_pw:thunder_mace_attack3',	'tp_pw:thunder_mace_attack4']	
world.afterEvents.dataDrivenEntityTrigger.subscribe(event=>{
	const eventId = event.eventId
	const entity = event.entity
	try {
		petsId.forEach(petId=>{
			if(entity.typeId===`tp_pw:${petId}`){
				if(eventId==='eating'){
					entity.runCommand(`playsound tp_pw:entity.chomp @a ~~~`)
					const hunger = world.scoreboard.getObjective(`tp_pw:pet_HGR`)
					entity.setProperty('tp_pw:eating', true)
					entity.addEffect('slowness',5*20,{amplifier:255})
					hunger.setScore(entity, hunger.getScore(entity)+300)
					system.runTimeout(()=>{
						entity.setProperty('tp_pw:eating', false)
					},5*20)
				}
				if(eventId==='tamed') {
					entity.runCommandAsync('playsound tp_pw:entity.tamed @a ~~~')
					entity.runCommand(`event entity @e[type=tp_pw:text, c=1, tag=tp_pw:${entity.id}] text:despawn`)
				}
				if(eventId==='tf_walking' || eventId==='tf_flying') {
					world.getDimension('overworld').getEntities({tags:[`tp_pw:${entity.id}`]}).forEach(text=>{
						text.remove()
						entity.addTag('tp_pw:terjinakkan')
					})
					let dataEntitas = {
						health: entity.getComponent('minecraft:health').currentValue,
						hunger: world.scoreboard.getObjective('tp_pw:pet_HGR').getScore(entity),
						exp: world.scoreboard.getObjective('tp_pw:pet_EXP').getScore(entity),
						lvl: world.scoreboard.getObjective('tp_pw:pet_LVL').getScore(entity),
						ownerId: entity.getDynamicProperty('tp_pw:owner'),
						ownerName: entity.getDynamicProperty('tp_pw:ownerName'),
						mode: entity.getProperty('tp_pw:mode')
					}
					let lastLocation = entity.location
					const interval = system.runInterval(()=>{
						try {
							lastLocation = entity.location
						} catch (error) {
							
						}
						if(!entity.isValid()){
							world.getDimension('overworld').getEntities({type:entity.typeId, location:lastLocation}).forEach(newPet=>{
								setEntityData(dataEntitas, newPet)
								system.clearRun(interval)
							})
							try {
								system.clearRun(interval)
							} catch (error) {
								
							}
						}
					})
				}
				{
					if(eventId==='tp_pw:passive_mode') {
						entity.setProperty('tp_pw:mode', 'passive')
						entity.setDynamicProperty('tp_pw:mode', 'passive')
					}
					if(eventId==='tp_pw:neutral_mode') {
						entity.setProperty('tp_pw:mode', 'neutral')
						entity.setDynamicProperty('tp_pw:mode', 'neutral')
					}
					if(eventId==='tp_pw:aggressive_mode') {
						entity.setProperty('tp_pw:mode', 'aggressive')
						entity.setDynamicProperty('tp_pw:mode', 'aggressive')
					}
				}
			}
			if(entity.typeId===`tp_pw:${petId}_untamed`) {
				if(eventId==='tamed') {
					world.getDimension('overworld').getEntities({tags:[`tp_pw:${entity.id}`]}).forEach(text=>{
						text.remove()
						entity.addTag('tp_pw:terjinakkan')
					})
				}
				if(eventId==='tf_walking' || eventId==='tf_flying') {
					let dataEntitas = {
						health: entity.getComponent('minecraft:health').currentValue,
						has_target: entity.getProperty('tp_pw:has_target')
					}
					let lastLocation = entity.location
					const interval = system.runInterval(()=>{
						try {
							lastLocation = entity.location
						} catch (error) {
							
						}
						if(!entity.isValid()){
							system.clearRun(interval)
							world.getDimension('overworld').getEntities({type:entity.typeId, location:lastLocation, closest:1}).forEach(newPet=>{
								setEntityData(dataEntitas, newPet)
							})
							try {
								system.clearRun(interval)
							} catch (error) {
								
							}
						}
					})
				}
			}
		})
	} catch (error) {
		console.warn(error)
	}
	if(eventId==="tp_pw:hit") {
		console.warn('kena')
	}
})
function setEntityData(data, entity) {
	try {
		if(data.has_target===true && !entity.hasTag('tp_pw:initialized')) {
			entity.dimension.getPlayers({closest:1}).forEach(target=>{
				entity.applyDamage(1, {cause:'entityAttack', damagingEntity:target})
			})
		}
		entity.getComponent('minecraft:health').setCurrentValue(data.health)
		world.scoreboard.getObjective('tp_pw:pet_HGR').setScore(entity, data.hunger)
		world.scoreboard.getObjective('tp_pw:pet_EXP').setScore(entity, data.exp)
		world.scoreboard.getObjective('tp_pw:pet_LVL').setScore(entity, data.lvl)
		entity.setDynamicProperty('tp_pw:owner', data.ownerId)
		entity.setDynamicProperty('tp_pw:ownerName', data.ownerName)
		entity.addTag(`tp_pw:${data.ownerId}`)
		entity.addTag(`tp_pw:initialized`)
	} catch (error) {
	}
	system.runTimeout(()=>{
		try {
			entity.runCommand(`event entity @s tp_pw:${data.mode}_mode`)
		} catch (error) {
		}
	},1)
}
world.afterEvents.entitySpawn.subscribe((event)=>{
	const entity = event.entity
	aydiPet.forEach(nameId=>{
		if(entity.typeId===nameId+".tamer"){
			const pet = entity.typeId.replace('.tamer', '')
			entity.dimension.getPlayers({closest:1, location:entity.location}).forEach(player=>{
				entity.getComponent("minecraft:projectile").owner = player
				console.warn('owner terbentuk')
				const ownerName = player.name
				const ownerId = player.id
				let lastLocation = entity.location
				const interval = system.runInterval(()=>{
					try {
						lastLocation = entity.location
					} catch (error) {
					}
					if(!entity.isValid()){
						world.getDimension('overworld').getEntities({location:lastLocation, closest:1, type:pet}).forEach(newPet=>{
							newPet.addTag(`tp_pw:${ownerId}`)
							newPet.setDynamicProperty('tp_pw:owner', `${ownerId}`)
							newPet.setDynamicProperty(`tp_pw:ownerName`, ownerName)
							newPet.runCommand('scoreboard players set @s tp_pw:pet_LVL 1')
							newPet.runCommand('scoreboard players set @s tp_pw:pet_EXP 0')
							newPet.runCommand('scoreboard players set @s tp_pw:pet_HGR 600')
							newPet.runCommand('scoreboard players set @s tp_pw:petBooster 0')
							newPet.addTag(`tp_pw:initialized`)
							console.warn(newPet.typeId)
						})
						system.clearRun(interval)
					}
				})
			})
		}
	})
})
world.afterEvents.worldInitialize.subscribe(() => {
	weapons.forEach(weapon=>{
		world.getDimension('overworld').runCommand(`scoreboard objectives add tp_pw:${weapon}_EXP dummy`);
		world.getDimension('overworld').runCommand(`scoreboard objectives add tp_pw:${weapon}_LVL dummy`);
		world.getDimension('overworld').runCommand(`scoreboard objectives add tp_pw:${weapon}_ULT dummy`);
	})
	world.getDimension('overworld').runCommand('scoreboard objectives add tp_pw:pet_EXP dummy');
	world.getDimension('overworld').runCommand('scoreboard objectives add tp_pw:pet_LVL dummy');
	world.getDimension('overworld').runCommand('scoreboard objectives add tp_pw:pet_HGR dummy');
	world.getDimension('overworld').runCommand('scoreboard objectives add tp_pw:despawn_counter dummy');
	world.getDimension('overworld').runCommand('scoreboard objectives add tp_pw:entity_idle_delay dummy');
	world.getDynamicProperty("tp_pw:camera") !== undefined ? null: world.setDynamicProperty("tp_pw:camera", true)
	world.getDynamicProperty("tp_pw:sound") !== undefined ? null: world.setDynamicProperty("tp_pw:sound", true)
	world.getDynamicProperty("tp_pw:pvp") !== undefined ? null: world.setDynamicProperty("tp_pw:pvp", false)
	world.getDynamicProperty("tp_pw:settings_diff") !== undefined ? null: world.setDynamicProperty("tp_pw:settings_diff", 1) + world.getDimension('overworld').runCommand(`difficulty n`)

	system.runTimeout(()=>{
		world.getDimension('overworld').getEntities().forEach(entity=>{
			petsId.forEach(pet=>{
				if(entity.typeId!=`tp_pw:${pet}`)return
				entity.setProperty('tp_pw:eating', false)
				try {
				} catch (error) {
					
				}
			})
		})
	}, 5*20)
})
world.afterEvents.playerSpawn.subscribe((arg)=>{
	weapons.forEach(weapon=>{
		arg.player.runCommand(`scoreboard players set @s[tag=!tp_pw] tp_pw:${weapon}_CD 0`)
		arg.player.runCommand(`scoreboard players set @s[tag=!tp_pw] tp_pw:${weapon}_LVL 1`)
		arg.player.runCommand(`scoreboard players set @s[tag=!tp_pw] tp_pw:${weapon}_EXP 0`)
		arg.player.runCommand(`scoreboard players set @s[tag=!tp_pw] tp_pw:${weapon}_ULT 0`)
	})
	arg.player.runCommand(`give @s[tag=!tp_pw] tp_pw:guide_book`)
	arg.player.runCommand(`tag @s[tag=!tp_pw] add tp_pw`)
	arg.player.runCommand(`inputpermission set @s camera enabled`)
	arg.player.runCommand(`inputpermission set @s movement enabled`)
	arg.player.runCommand(`camera @s clear`)
	arg.player.runCommand(`hud @s reset`)
	arg.player.getDynamicProperty("tp_pw:petData") === undefined ? arg.player.setDynamicProperty("tp_pw:petData", true): null
})
world.getPlayers().forEach(player=>{
	player.runCommand(`inputpermission set @s camera enabled`)
	player.runCommand(`inputpermission set @s movement enabled`)
	player.runCommand(`camera @s clear`)
	player.runCommand(`hud @s reset`)
	player.removeTag('tp_pw:using_ability')
	const petAmount = player.dimension.getEntities({tags:[`tp_pw:`+player.id]})
	player.setDynamicProperty(`tp_pw:petAmount`, petAmount.length)
})
world.getDimension('overworld').getEntities().forEach(entity=>{
	petsId.forEach(pet=>{
		if(entity.typeId!=`tp_pw:${pet}`)return
		entity.setDynamicProperty('tp_pw:pet_ui', false)
		entity.triggerEvent('attack0')
		entity.setProperty('tp_pw:eating', false)
		try {
		} catch (error) {
			
		}
	})
})
world.afterEvents.itemUse.subscribe(event => {
	const player = event.source;
	const item = event.itemStack;

	weapons.forEach(weapon => {
		if (item.typeId === `tp_pw:${weapon}`) {
			let skill = null;
			let minLVL = 0
			switch (true) {
				case player.isOnGround && !player.isSneaking:
					skill = 0;
					minLVL = wpMinLVL[0];
					break;
				case player.isOnGround && player.isSneaking:
					skill = 1;
					minLVL = wpMinLVL[1];
					break;
				case !player.isOnGround && !player.isSneaking:
					skill = 2;
					minLVL = wpMinLVL[2];
					break;
				case !player.isOnGround && player.isSneaking:
					skill = 3;
					minLVL = wpMinLVL[3];
					break;
			}
			skill_filter(player, weapon, skill, minLVL);
		}
		if (item.typeId === `tp_pw:non_enchanted_${weapon}`) {
			player.runCommandAsync(`titleraw @p actionbar { \"rawtext\": [ { \"translate\" : \"actionbar.tp_pw:non_enchanted_click\" } ] }`)
		}
	});
	if (testing) {
		if(item.typeId==='minecraft:stick') {
			getTarget(player)
		}
		if(item.typeId==='minecraft:coal') {
			player.dimension.getEntities({type:'tp_pw:nebula_dragon', closest:1}).forEach(stormGriffin=>{
				console.warn(`Mode is ${stormGriffin.getProperty('tp_pw:mode')}`)
			})
		}
		
		if(item.typeId==='minecraft:blaze_rod') {
		}
		//Cinematic Camera Testing
		if(item.typeId==='minecraft:blaze_rod') {
			const magic = player.dimension.spawnEntity('tp_pw:gs_attack4', {
				x: player.location.x + player.getViewDirection().x * 4,
				y: player.location.y,
				z: player.location.z + player.getViewDirection().z * 4
			})
			for (let i = 0; i<30; i++) {
				magic.runCommand(`tp @s ~~-0.1~ ~~ true`)
			}
			magic.setRotation({
				x: 0,
				y: player.getRotation().y + 180
			});
			system.runTimeout(() => {
				magic.dimension.getEntities({maxDistance:10,location:magic.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
					{
						target.runCommand(`inputpermission set @s movement disabled`)
						target.runCommand(`inputpermission set @s camera disabled`)
						target.runCommand(`hud @s hide`)
						target.runCommand(`effect @s slowness 6 255`)
						target.runCommand(`camera @s fade time 0.5 0.5 0.2 color 255 255 255`)
					}
					system.runTimeout(()=>{
						player.runCommand('title @s clear')
						player.playAnimation(`animation.tp_pw.glacier_staff.tpp_blizzard_of_the_fox`, {
							nextState: `none`,
							blendOutTime: 1,
							stopExpression: `query.any_animation_finished`,
							controller: `controller_name1`
						});
						if (target.typeId==='minecraft:player') {
							target.addTag(`tp_pw:${magic.id}`)
							system.runTimeout(() => {
								magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^ ^1.5 ^ facing ${player.location.x} ${player.location.y+1} ${player.location.z}`)
								magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 2.5 linear pos ^ ^1.5 ^1 facing ${player.location.x} ${player.location.y+1} ${player.location.z}`)
							})
							system.runTimeout(() => {
								magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^ ^4 ^7 facing ~~~`)
								magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 2.5 linear pos ^ ^3 ^6 facing ~~~`)
							},2.5*20)
							system.runTimeout(() => {
								magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^-8 ^0.5 ^ facing ~~~`)
								magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 3.0 linear pos ^-7 ^0.5 ^ facing ~~~`)
							},5*20)
							system.runTimeout(() => {
								magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^5 ^1 ^ facing ${player.location.x} ${player.location.y} ${player.location.z}`)
								magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 2.5 linear pos ^6 ^2 ^ facing ${player.location.x} ${player.location.y} ${player.location.z}`)
							},8*20)
							system.runTimeout(() => {
								magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^3.3 ^1 ^8 facing ~~~`)
								magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 0.5 linear pos ^3.5 ^1 ^9 facing ~~~`)
							},10.5*20)
							system.runTimeout(() => {
								magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^3.5 ^1 ^9 facing ~~~`)
								magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 0.5 linear pos ^1 ^1 ^1 facing ^-2^^-2`)
							},11.0*20)
							system.runTimeout(() => {
								magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^-8 ^0.5 ^ facing ~~~`)
								magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 3.0 linear pos ^-9 ^0.5 ^ facing ~~1~`)
							},11.5*20)
						}
						//Entity Effects
						system.runTimeout(()=>{
							magic.runCommand('event entity @s active')
						},2.5*20)
						system.runTimeout(()=>{
							magic.runCommand('event entity @s active2')
						},8*20)
						//ATTACK ENDS
						system.runTimeout(()=>{
							const attackItem = getItemOnInventory(player, `tp_pw:${weapon}_attack${skill+1}`);
							if (attackItem) {
								const inventory = player.getComponent("minecraft:inventory");
								inventory.container.setItem(attackItem.slot, new ItemStack(`tp_pw:${weapon}`));
							}
							player.removeTag(`tp_pw:using_ability`)
							player.startItemCooldown(`tp_pw:${weapon}`, wp4CD[3]*20)
							player.runCommand(`scoreboard players set @s tp_pw:${weapon}_ULT 0`)
							{
								try {
									target.runCommand(`camera @s clear`)
									target.runCommand(`inputpermission set @s movement enabled`)
									target.runCommand(`inputpermission set @s camera enabled`)
									target.runCommand(`hud @s reset`)
								} catch (error) {
									
								}
							}
						},5.75*20)
					},1*20)
				})
			})
			player.runCommandAsync(`titleraw @p title { \"rawtext\": [ { \"translate\" : \"actionbar.tp_pw:${weapon}.4\" } ] }`)
		}
		if(item.typeId==='minecraft:paper') {
			const magic = player.dimension.spawnEntity('tp_pw:tm_attack4', {
				x: player.location.x + player.getViewDirection().x * 4,
				y: player.location.y,
				z: player.location.z + player.getViewDirection().z * 4
			})
			for (let i = 0; i<30; i++) {
				magic.runCommand(`tp @s ~~-0.1~ ~~ true`)
			}
			magic.setRotation({
				x: 0,
				y: player.getRotation().y + 180
			});
			system.runTimeout(() => {
				magic.dimension.getEntities({maxDistance:10,location:magic.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
					{
						target.runCommand(`inputpermission set @s movement disabled`)
						target.runCommand(`inputpermission set @s camera disabled`)
						target.runCommand(`hud @s hide`)
						target.runCommand(`effect @s slowness 6 255`)
						target.runCommand(`camera @s fade time 0.5 0.5 0.2 color 255 255 255`)
					}
					system.runTimeout(()=>{
						player.runCommand('title @s clear')
						player.playAnimation(`animation.tp_pw.thunder_mace.tpp_eye_of_the_storm`, {
							nextState: `none`,
							blendOutTime: 1,
							stopExpression: `query.any_animation_finished`,
							controller: `controller_name1`
						});
						if (target.typeId==='minecraft:player') {
							target.addTag(`tp_pw:${magic.id}`)
							system.runTimeout(() => {
								magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^ ^2 ^-4 facing ${player.location.x} ${player.location.y+1} ${player.location.z}`)
								magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 3.0 linear pos ^^2^-7 facing ${player.location.x} ${player.location.y+1} ${player.location.z}`)
							})
							system.runTimeout(() => {
								magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^-8 ^8 ^ facing ~~2~`)
								magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 2.0 linear pos ^-7^10^ facing ~~2~`)
							},3*20)
							system.runTimeout(() => {
								magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^ ^6 ^20 facing ~~2~`)
								magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 1.0 linear pos ^^6^10 facing ~~2~`)
							},5*20)
							system.runTimeout(() => {
								magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^-8 ^6 ^ facing ~~3~`)
								magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 4.5 linear pos ^-7^8^ facing ~~3~`)
							},6*20)
							system.runTimeout(() => {
								magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^ ^18 ^ facing ~~~`)
								magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 2.0 linear pos ^^20^ facing ~~~`)
							},10.5*20)
							system.runTimeout(() => {
								magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^-8 ^8 ^ facing ~~6~`)
								magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 0.5 linear pos ^-7^4^ facing ~~3~`)
							},12.5*20)
							system.runTimeout(() => {
								magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^-7^4^ facing ~~3~`)
								magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 0.5 linear pos ^-3^2^ facing ~~~`)
							},13*20)
						}
						//Entity Effects
						system.runTimeout(()=>{
							magic.runCommand('event entity @s active')
						},5*20)
						//ATTACK ENDS
						system.runTimeout(()=>{
							player.runCommand(`scoreboard players set @s tp_pw:${weapon}_ULT 0`)
							const attackItem = getItemOnInventory(player, `tp_pw:${weapon}_attack${skill+1}`);
							if (attackItem) {
								const inventory = player.getComponent("minecraft:inventory");
								inventory.container.setItem(attackItem.slot, new ItemStack(`tp_pw:${weapon}`));
							}
							player.removeTag(`tp_pw:using_ability`)
							player.startItemCooldown(`tp_pw:${weapon}`, wp1CD[3]*20)
							{
								try {
									target.runCommand(`camera @s clear`)
									target.runCommand(`inputpermission set @s movement enabled`)
									target.runCommand(`inputpermission set @s camera enabled`)
									target.runCommand(`hud @s reset`)
								} catch (error) {
									
								}
							}
						},20*20)
					},1*20)
				})
			})
			player.runCommandAsync(`titleraw @p title { \"rawtext\": [ { \"translate\" : \"actionbar.tp_pw:${weapon}.4\" } ] }`)
		}
		if(item.typeId==='minecraft:gunpowder') {
			const magic = player.dimension.spawnEntity('tp_pw:cg_attack3', {
				x: player.location.x + player.getViewDirection().x * 4,
				y: player.location.y,
				z: player.location.z + player.getViewDirection().z * 4
			})
			for (let i = 0; i<30; i++) {
				magic.runCommand(`tp @s ~~-0.1~ ~~ true`)
			}
			magic.setRotation({
				x: 0,
				y: player.getRotation().y + 180
			});
			system.runTimeout(() => {
				magic.dimension.getEntities({maxDistance:10,location:magic.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
					{
						target.runCommand(`inputpermission set @s movement disabled`)
						target.runCommand(`inputpermission set @s camera disabled`)
						target.runCommand(`hud @s hide`)
						target.runCommand(`effect @s slowness 6 255`)
						target.runCommand(`camera @s fade time 0.5 0.5 0.2 color 255 255 255`)
					}
					system.runTimeout(() => {
						player.runCommand('title @s clear')
						player.playAnimation(`animation.tp_pw.celestial_gauntlets.tpp_cosmic_convergence`, {
							nextState: `none`,
							blendOutTime: 1,
							stopExpression: `query.any_animation_finished`,
							controller: `controller_name1`
						});
						//player.runCommand('effect @s slowness 7 255')
						if (target.typeId==='minecraft:player'){
							target.addTag(`tp_pw:${magic.id}`)
							system.runTimeout(() => {
								magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^ ^2 ^-4 facing ${player.location.x} ${player.location.y+1} ${player.location.z}`)
								magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 2.0 linear pos ^^2^-7 facing ${player.location.x} ${player.location.y+1} ${player.location.z}`)
							})
							system.runTimeout(() => {
								magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^ ^6 ^20 facing ~~2~`)
								magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 2.0 linear pos ^^6^16 facing ~~2~`)
							},2*20)
							system.runTimeout(() => {
								magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^ ^8 ^-4 facing ${player.location.x} ${player.location.y+1} ${player.location.z}`)
								magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 3.0 linear pos ^^10^-7 facing ${player.location.x} ${player.location.y+1} ${player.location.z}`)
							},4*20)
							system.runTimeout(() => {
								magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^12 ^8 ^ facing ~~10~`)
								magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 1.0 linear pos ^10^6^ facing ~~10~`)
							},7*20)
							system.runTimeout(() => {
								magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^12 ^0.5 ^ facing ~~5~`)
								magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 2.0 linear pos ^15^0.5^ facing ~~6~`)
							},8*20)
							system.runTimeout(() => {
								magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^^18^ facing ~~2~`)
								magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 1.0 linear pos ^^25^ facing ~~~`)
							},10*20)
							system.runTimeout(() => {
								magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^-10 ^0.5 ^ facing ~~6~`)
								magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 0.5 linear pos ^-5^0.5^ facing ~~1~`)
							},11*20)
						}
						//Entity Effects
						system.runTimeout(()=>{
							magic.runCommand('event entity @s active')
						},2*20)
						//ATTACK ENDS
						system.runTimeout(()=>{
							const attackItem = getItemOnInventory(player, `tp_pw:${weapon}_attack${skill+1}`);
							if (attackItem) {
								const inventory = player.getComponent("minecraft:inventory");
								inventory.container.setItem(attackItem.slot, new ItemStack(`tp_pw:${weapon}`));
							}
							player.removeTag(`tp_pw:using_ability`)
							player.startItemCooldown(`tp_pw:${weapon}`, wp2CD[3]*20)
							player.runCommand(`scoreboard players set @s tp_pw:${weapon}_ULT 0`)
							{
								try {
									target.runCommand(`camera @s clear`)
									target.runCommand(`inputpermission set @s movement enabled`)
									target.runCommand(`inputpermission set @s camera enabled`)
									target.runCommand(`hud @s reset`)
								} catch (error) {
									
								}
							}
						},20*20)
					}, 1 * 20)
				})
			})
			player.runCommandAsync(`titleraw @p title { \"rawtext\": [ { \"translate\" : \"actionbar.tp_pw:${weapon}.4\" } ] }`)
		}
		if(item.typeId==='minecraft:charcoal') {
			const magic = player.dimension.spawnEntity('tp_pw:mf_attack4', {
				x: player.location.x + player.getViewDirection().x * 4,
				y: player.location.y,
				z: player.location.z + player.getViewDirection().z * 4
			})
			for (let i = 0; i<30; i++) {
				magic.runCommand(`tp @s ~~-0.1~ ~~ true`)
			}
			magic.setRotation({
				x: 0,
				y: player.getRotation().y + 180
			});
			system.runTimeout(() => {
				magic.dimension.getEntities({maxDistance:10,location:magic.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
					{
						target.runCommand(`inputpermission set @s movement disabled`)
						target.runCommand(`inputpermission set @s camera disabled`)
						target.runCommand(`hud @s hide`)
						target.runCommand(`camera @s fade time 0.5 0.5 0.2 color 255 255 255`)
						if(target!=player){target.runCommand(`effect @s slowness 5 255`)}
					}
					system.runTimeout(()=>{
						player.runCommand('title @s clear')
						player.playAnimation(`animation.tp_pw.mystic_flute.tpp_flute_symphony`, {
							nextState: `none`,
							blendOutTime: 1,
							stopExpression: `query.any_animation_finished`,
							controller: `controller_name1`
						});
						if (target.typeId==='minecraft:player') {
							target.addTag(`tp_pw:${magic.id}`)
							system.runTimeout(() => {
								magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^ ^2 ^1 facing ${player.location.x} ${player.location.y+1} ${player.location.z}`)
								magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 3.0 linear pos ^ ^3 ^-3 facing ${player.location.x} ${player.location.y+1} ${player.location.z}`)
							})
							system.runTimeout(() => {
								magic.runCommand('camera @p set minecraft:free pos ^ ^1 ^7 facing ~~1~')
								magic.runCommandAsync('camera @p set minecraft:free ease 2.0 linear pos ^^1^8 facing ~~1~')
							},3*20)
							system.runTimeout(() => {
								magic.runCommand('camera @p set minecraft:free pos ^ ^1 ^-1 facing ^-1^^3')
								magic.runCommandAsync('camera @p set minecraft:free ease 0.5 linear pos ^^0.5^-3 facing ~~6~')
							}, 5 * 20)
							system.runTimeout(() => {
								magic.runCommandAsync('camera @p set minecraft:free ease 0.5 linear pos ^^0.5^-6 facing ~~1~')
							}, 5.5 * 20)
						}
						//Entity Effects
						system.runTimeout(()=>{
							magic.runCommand('event entity @s active')
						},3*20)
						//ATTACK ENDS
						system.runTimeout(()=>{
							player.runCommand(`scoreboard players set @s tp_pw:${weapon}_ULT 0`)
							const attackItem = getItemOnInventory(player, `tp_pw:${weapon}_attack${skill+1}`);
							if (attackItem) {
								const inventory = player.getComponent("minecraft:inventory");
								inventory.container.setItem(attackItem.slot, new ItemStack(`tp_pw:${weapon}`));
							}
							player.removeTag(`tp_pw:using_ability`)
							player.startItemCooldown(`tp_pw:${weapon}`, wp5CD[3]*20)
							{
								try {
									target.runCommand(`camera @s clear`)
									target.runCommand(`inputpermission set @s movement enabled`)
									target.runCommand(`inputpermission set @s camera enabled`)
									target.runCommand(`hud @s reset`)
								} catch (error) {
									
								}
							}
						},6.5*20)
					},1*20)
				})
			})
			player.runCommandAsync(`titleraw @p title { \"rawtext\": [ { \"translate\" : \"actionbar.tp_pw:${weapon}.4\" } ] }`)
		}
		if(item.typeId==='minecraft:saddle') {
			player.dimension.getEntities({type:'tp_pw:storm_griffin_untamed', closest:1}).forEach(stormGriffin=>{
				console.warn(`The closest storm griffin delay is ${stormGriffin.getDynamicProperty('tp_pw:stage_change_delay')}`)
			})
		}
	}
})
world.afterEvents.entityDie.subscribe((arg) => {
	const killer = arg.damageSource.damagingEntity
	const victim = arg.deadEntity
	entitiesTypes.forEach(entityType => {
		try {
			if (entityType.entities.has(victim.typeId) && killer.typeId==='minecraft:player') {
				weapons.forEach(item => {
					if (checkItemInMainHand(killer, 'tp_pw:' + item)) {
						showItemStats(killer, item, entityType)
					} else {
						for (let i = 1; i <= 4; i++) {
							const attackItem = 'tp_pw:' + item + '_attack' + i;
							if (checkItemInMainHand(killer, attackItem)) {
								showItemStats(killer, item, entityType)
							break;
						}
						}
					}
				});				  
			}
		} catch (error) {
		}
	})
	const rmTag = [
		'tp_pw:target_scary_lantern1',
		'tp_pw:target_rusty_chains1',
		'tp_pw:target_digital_grave4',
		'tp_pw:target_scary_lantern4',
		"tp_pw:infected",
		"tp_pw:chainsaw_frenzy",
		"tp_pw:grind_through"
	];
	rmTag.forEach(tag => {
		try {
			if (victim.hasTag(tag)) {
				victim.removeTag(tag);
			}
		} catch (error) {
			
		}
	});
})
const anyWeapons = [
    'tp_pw:blade_of_the_wild',
    'tp_pw:ember_bow',
    'tp_pw:glacier_staff',
    'tp_pw:thunder_mace',
    'tp_pw:celestial_gauntlets',
    'tp_pw:mystic_flute',
    'tp_pw:blade_of_the_wild_attack1',
    'tp_pw:blade_of_the_wild_attack2',
    'tp_pw:blade_of_the_wild_attack3',
    'tp_pw:blade_of_the_wild_attack4',
    'tp_pw:ember_bow_attack1',
    'tp_pw:ember_bow_attack2',
    'tp_pw:ember_bow_attack3',
    'tp_pw:ember_bow_attack4',
    'tp_pw:glacier_staff_attack1',
    'tp_pw:glacier_staff_attack2',
    'tp_pw:glacier_staff_attack3',
    'tp_pw:glacier_staff_attack4',
    'tp_pw:thunder_mace_attack1',
    'tp_pw:thunder_mace_attack2',
    'tp_pw:thunder_mace_attack3',
    'tp_pw:thunder_mace_attack4',
    'tp_pw:celestial_gauntlets_attack1',
    'tp_pw:celestial_gauntlets_attack2',
    'tp_pw:celestial_gauntlets_attack3',
    'tp_pw:celestial_gauntlets_attack4',
    'tp_pw:mystic_flute_attack1',
    'tp_pw:mystic_flute_attack2',
    'tp_pw:mystic_flute_attack3',
    'tp_pw:mystic_flute_attack4'
];
world.afterEvents.entityHurt.subscribe((event) => {
	const attacker = event.damageSource.damagingEntity
	const entity = event.hurtEntity
    const damage = event.damage;
	petsId.forEach(pet=>{
		try {
			if(entity.typeId===`tp_pw:${pet}`){
				updateName(entity)
			}
			if(attacker.typeId===`tp_pw:${pet}`){
				const damageDisplay = entity.dimension.spawnEntity("tp_pw:damage", {
					x: entity.location.x + random(10, -10) / 10,
					y: entity.location.y + random(12, 20) / 10,
					z: entity.location.z + random(10, -10) / 10
				
				})
				damageDisplay.setProperty("tp_pw:value", Math.ceil(damage / 2))
				damageDisplay.setProperty("tp_pw:scale", random(1.3, 1.8))
				damageDisplay.triggerEvent("scale.1")
			}
		} catch (error) {
			
		}
	})
    anyWeapons.forEach(weapon=>{
        if(attacker==null) return
        if(attacker.typeId==="minecraft:player"&&checkItemInMainHand(attacker, weapon)){
            const damageDisplay = entity.dimension.spawnEntity("tp_pw:damage", {
                x: entity.location.x + random(10, -10) / 10,
                y: entity.location.y + random(12, 20) / 10,
                z: entity.location.z + random(10, -10) / 10
            
            })
            damageDisplay.setProperty("tp_pw:value", Math.ceil(damage / 2))
            damageDisplay.setProperty("tp_pw:scale", random(1.3, 1.8))
            damageDisplay.triggerEvent("scale.1")
        }
    })
})
function random(min, max) {
	return Math.random() * (max - min) + min;
}
function skill_filter(player, weapon, skill, minLVL) {
	const petEntity = player.dimension.getEntities({type:`tp_pw:${pets[weapon]}`,closest:1,location:player.location,tags:[`tp_pw:`+player.id]})
	if(petEntity.length===0){
		player.runCommandAsync(`titleraw @p actionbar { \"rawtext\": [ { \"translate\" : \"actionbar.tp_pw:please_tame_${pets[weapon]}\" } ] }`)
		player.runCommandAsync(`playsound note.bass @s`)
	} else {
		petEntity.forEach(pet=>{
			if(checkDistance(player,pet) <= 15) {
				if(!player.getItemCooldown(`tp_pw:`+weapon) && !player.hasTag('tp_pw:using_ability')) {
					//MINLEVEL FILTER
					const lvl = world.scoreboard.getObjective(`tp_pw:${weapon}_LVL`)
					const ult = world.scoreboard.getObjective(`tp_pw:${weapon}_ULT`)
					if(lvl.getScore(player)>=minLVL){
						const equippable = player.getComponent("minecraft:equippable");
						let mainhand = null
						let wp = null
						let delay = 0
						if(skill===3){delay=1}
						//FUNCTION EXECUTION
						if (skill===3) {
							if (ult.getScore(player)===10){
								const slot = player.selectedSlotIndex
								system.runTimeout(()=>{
									const inventory = player.getComponent("minecraft:inventory");
									inventory.container.setItem(slot, new ItemStack(`tp_pw:${weapon}_attack${skill+1}`));
								},delay * 20)
								const skillFunction = weaponSkills[weapon];
								if (skillFunction) {
									const petId = [
										player.getDynamicProperty(`tp_pw:feral_lynx`),
										player.getDynamicProperty(`tp_pw:nebula_dragon`),
										player.getDynamicProperty(`tp_pw:flame_hawk`),
										player.getDynamicProperty(`tp_pw:frost_fox`),
										player.getDynamicProperty(`tp_pw:music_golem`),
										player.getDynamicProperty(`tp_pw:storm_griffin`)
									]
									player.addTag('tp_pw:using_ability')
									skillFunction(player, weapon, skill, petId, minLVL);
								}
							} else {
								player.runCommandAsync(`titleraw @p actionbar { \"rawtext\": [ { \"translate\" : \"actionbar.tp_pw.weapon.ult_failed\" } ] }`)
								player.runCommandAsync(`playsound note.bass @s`)
							}
						} else {
							//Ember Bow Arrow Detection
							if(weapon==='ember_bow' && skill<3){
								if (getItemOnInventory(player, 'minecraft:arrow')) {
									system.runTimeout(()=>{
										player.runCommand('clear @s arrow 0 1')
										mainhand = equippable.getEquipmentSlot(EquipmentSlot.Mainhand);
										wp = new ItemStack(`tp_pw:${weapon}_attack${skill+1}`)
										wp.lockMode = "slot"
										mainhand.setItem(wp)
									},delay * 20)
									const skillFunction = weaponSkills[weapon];
									if (skillFunction) {
										const petId = [
											player.getDynamicProperty(`tp_pw:feral_lynx`),
											player.getDynamicProperty(`tp_pw:nebula_dragon`),
											player.getDynamicProperty(`tp_pw:flame_hawk`),
											player.getDynamicProperty(`tp_pw:frost_fox`),
											player.getDynamicProperty(`tp_pw:music_golem`),
											player.getDynamicProperty(`tp_pw:storm_griffin`)
										]
										player.addTag('tp_pw:using_ability')
										skillFunction(player, weapon, skill, petId, minLVL);
									}
								} else {
									player.runCommandAsync(`titleraw @p actionbar { \"rawtext\": [ { \"translate\" : \"actionbar.tp_pw:need_arrow\" } ] }`)
									player.runCommandAsync(`playsound note.bass @s`)
								}
							} else {
								system.runTimeout(()=>{
									mainhand = equippable.getEquipmentSlot(EquipmentSlot.Mainhand);
									wp = new ItemStack(`tp_pw:${weapon}_attack${skill+1}`)
									wp.lockMode = "slot"
									mainhand.setItem(wp)
								},delay * 20)
								const skillFunction = weaponSkills[weapon];
								if (skillFunction) {
									const petId = [
										player.getDynamicProperty(`tp_pw:feral_lynx`),
										player.getDynamicProperty(`tp_pw:nebula_dragon`),
										player.getDynamicProperty(`tp_pw:flame_hawk`),
										player.getDynamicProperty(`tp_pw:frost_fox`),
										player.getDynamicProperty(`tp_pw:music_golem`),
										player.getDynamicProperty(`tp_pw:storm_griffin`)
									]
									player.addTag('tp_pw:using_ability')
									skillFunction(player, weapon, skill, petId, minLVL);
								}
							}
						}
					} else {
						player.runCommandAsync(`titleraw @p actionbar { \"rawtext\": [ { \"translate\" : \"actionbar.tp_pw:you_need_level_${minLVL}\" } ] }`)
						player.runCommandAsync(`playsound note.bass @s`)
					}
				} else {
					player.runCommandAsync(`titleraw @p actionbar { \"rawtext\": [ { \"translate\" : \"actionbar.tp_pw:weapon_on_cooldown\" } ] }`)
					player.runCommandAsync(`playsound note.bass @s`)
				}
			} else {
				player.runCommandAsync(`titleraw @p actionbar { \"rawtext\": [ { \"translate\" : \"actionbar.tp_pw:stay_close_to_${pets[weapon]}\" } ] }`)
				player.runCommandAsync(`playsound note.bass @s`)
			}
		})
	}
}
function blade_of_the_wild_skill(player, weapon, skill, petId, minLVL) {
	const cameraSetting = world.getDynamicProperty('tp_pw:camera')
	const volumeSetting = world.getDynamicProperty('tp_pw:sound')
	const lvl = world.scoreboard.getObjective(`tp_pw:${weapon}_LVL`)
	switch (skill) {
		case 0:
			{
				const damage = wp1Damage[0]+(lvl.getScore(player)-minLVL)
				player.playAnimation(`animation.tp_pw.blade_of_the_wild.tpp_claw_of_the_lynx`, {
					nextState: `none`,
					blendOutTime: 1,
					stopExpression: `query.any_animation_finished`,
					controller: `controller_name1`
				});
		
				if (volumeSetting === true) {
					const soundEntity = player.dimension.spawnEntity(`tp_pw:sound_entity`, player.location)
					soundEntity.setProperty('tp_pw:weapon', 'botw')
					soundEntity.setProperty('tp_pw:attack', 1)
					system.runTimeout(()=>{
						system.runTimeout(() => {
							player.runCommand(`playsound tp_pw:n_ability.botw1 @a ~~~`)
						}, 0 * 20)
						system.runTimeout(() => {
							player.runCommand(`playsound tp_pw:n_ability.botw1 @a ~~~`)
						}, 0.5 * 20)
						system.runTimeout(() => {
							player.runCommand(`playsound tp_pw:n_ability.botw1 @a ~~~`)
						}, 1 * 20)
						system.runTimeout(() => {
							player.runCommand(`playsound tp_pw:n_ability.botw1 @a ~~~`)
						}, 1.5 * 20)
					},0.3*20)
				}
		
				
				system.runTimeout(() => {
					const dir = {
						x: player.getRotation().x,
						y: player.getRotation().y
					}
					const magic = player.dimension.spawnEntity('tp_pw:botw_attack1', {
						x: player.location.x + player.getViewDirection().x * 3,
						y: player.location.y + 1,
						z: player.location.z + player.getViewDirection().z * 3
					})
					// for (let i = 0; i<30; i++) {
					// 	magic.runCommand(`tp @s ~~-0.1~ ~~ true`)
					// }
					magic.setRotation({
						x: 0,
						y: player.getRotation().y
					});
					if (magic.isValid() == true) {
						const interval = system.runInterval(() => {
							if(!magic.isValid())return
							magic.dimension.getEntities({maxDistance:4,location:magic.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
								if(target===magic||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
								target.applyDamage(damage, {cause:'contact',damagingEntity:player})
							})
							magic.runCommand(`tp @s ^^^0.4 ${dir.y} ~`)
						})
						system.runTimeout(() => {
							system.clearRun(interval)
							magic.remove()
						}, 5 * 20)
					}
				}, 0 * 20)
				system.runTimeout(() => {
					const dir = {
						x: player.getRotation().x,
						y: player.getRotation().y
					}
					const magic = player.dimension.spawnEntity('tp_pw:botw_attack1', {
						x: player.location.x + player.getViewDirection().x * 3,
						y: player.location.y + 1,
						z: player.location.z + player.getViewDirection().z * 3
					})
					// for (let i = 0; i<30; i++) {
					// 	magic.runCommand(`tp @s ~~-0.1~ ~~ true`)
					// }
					magic.setRotation({
						x: 0,
						y: player.getRotation().y
					});
					if (magic.isValid() == true) {
						const interval = system.runInterval(() => {
							if(!magic.isValid())return
							magic.dimension.getEntities({maxDistance:4,location:magic.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
								if(target===magic||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
								target.applyDamage(damage, {cause:'contact',damagingEntity:player})
							})
							magic.runCommand(`tp @s ^^^0.4 ${dir.y} ~`)
						})
						system.runTimeout(() => {
							system.clearRun(interval)
							magic.remove()
						}, 5 * 20)
					}
				}, 0.5 * 20)
				system.runTimeout(() => {
					const dir = {
						x: player.getRotation().x,
						y: player.getRotation().y
					}
					const magic = player.dimension.spawnEntity('tp_pw:botw_attack1', {
						x: player.location.x + player.getViewDirection().x * 3,
						y: player.location.y + 1,
						z: player.location.z + player.getViewDirection().z * 3
					})
					// for (let i = 0; i<30; i++) {
					// 	magic.runCommand(`tp @s ~~-0.1~ ~~ true`)
					// }
					magic.setRotation({
						x: 0,
						y: player.getRotation().y
					});
					if (magic.isValid() == true) {
						const interval = system.runInterval(() => {
							if(!magic.isValid())return
							magic.dimension.getEntities({maxDistance:4,location:magic.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
								if(target===magic||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
								target.applyDamage(damage, {cause:'contact',damagingEntity:player})
							})
							magic.runCommand(`tp @s ^^^0.4 ${dir.y} ~`)
						})
						system.runTimeout(() => {
							system.clearRun(interval)
							magic.remove()
						}, 5 * 20)
					}
				}, 1 * 20)
				system.runTimeout(() => {
					const dir = {
						x: player.getRotation().x,
						y: player.getRotation().y
					}
					const magic = player.dimension.spawnEntity('tp_pw:botw_attack1', {
						x: player.location.x + player.getViewDirection().x * 3,
						y: player.location.y + 1,
						z: player.location.z + player.getViewDirection().z * 3
					})
					// for (let i = 0; i<30; i++) {
					// 	magic.runCommand(`tp @s ~~-0.1~ ~~ true`)
					// }
					magic.setRotation({
						x: 0,
						y: player.getRotation().y
					});
					if (magic.isValid() == true) {
						const interval = system.runInterval(() => {
							if(!magic.isValid())return
							magic.dimension.getEntities({maxDistance:4,location:magic.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
								if(target===magic||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
								target.applyDamage(damage, {cause:'contact',damagingEntity:player})
							})
							magic.runCommand(`tp @s ^^^0.4 ${dir.y} ~`)
						})
						system.runTimeout(() => {
							system.clearRun(interval)
							magic.remove()
						}, 5 * 20)
					}
				}, 1.5 * 20)
		
				//ATTACK ENDS
				system.runTimeout(()=>{
					const attackItem = getItemOnInventory(player, `tp_pw:${weapon}_attack${skill+1}`);
					if (attackItem) {
						const inventory = player.getComponent("minecraft:inventory");
						inventory.container.setItem(attackItem.slot, new ItemStack(`tp_pw:${weapon}`));
					}
					player.removeTag(`tp_pw:using_ability`)
					player.startItemCooldown(`tp_pw:${weapon}`, wp1CD[0]*20)
				},2.5*20)
				player.runCommandAsync(`titleraw @p actionbar { \"rawtext\": [ { \"translate\" : \"actionbar.tp_pw:${weapon}.1\" } ] }`)
			}
			break;
		case 1:
			{
				const damage = wp1Damage[1]+(lvl.getScore(player)-minLVL)
				player.playAnimation(`animation.tp_pw.blade_of_the_wild.tpp_ferocity`, {
					nextState: `none`,
					blendOutTime: 1,
					stopExpression: `query.any_animation_finished`,
					controller: `controller_name1`
				});
	
				if (volumeSetting === true) {
					const soundEntity = player.dimension.spawnEntity(`tp_pw:sound_entity`, player.location)
					soundEntity.setProperty('tp_pw:weapon', 'botw')
					soundEntity.setProperty('tp_pw:attack', 2)
					system.runTimeout(()=>{
						player.runCommand('playsound tp_pw:n_ability.botw2 @a ~~~')
						system.runTimeout(()=>{
							player.runCommand('playsound tp_pw:ability.fire_blast @a ~~~')
						},3.4*20)
					},0.58*20)
				}
	
				system.runTimeout(() => {
					const magic = player.dimension.spawnEntity('tp_pw:botw_attack2', {
						x: player.location.x + player.getViewDirection().x * 2,
						y: player.location.y + 1,
						z: player.location.z + player.getViewDirection().z * 2
					})
					// for (let i = 0; i<30; i++) {
					// 	magic.runCommand(`tp @s ~~-0.1~ ~~ true`)
					// }
					magic.setRotation({
						x: 0,
						y: player.getRotation().y
					});
					if (magic.isValid() == true) {
						{
							const sepong = system.runInterval(()=>{
								if(!magic.isValid())return
								magic.dimension.getEntities({maxDistance:4,location:magic.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
									if(target===magic||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
									target.teleport(moveTowards(target.location, magic.location, 0.3))
								})
							})
							system.runTimeout(()=>{
								const loc = {x:magic.location.x,y:magic.location.y+0.5,z:magic.location.z}
								magic.dimension.spawnParticle(`tp_pw:ferocity_1`, loc)
								magic.dimension.spawnParticle(`tp_pw:ferocity_2`, loc)
								magic.dimension.spawnParticle(`tp_pw:ferocity_3`, loc)
							})
							system.runTimeout(()=>{
								const loc = {x:magic.location.x,y:magic.location.y+0.5,z:magic.location.z}
								const loc2 = {x:magic.location.x,y:magic.location.y-0.9,z:magic.location.z}
								magic.dimension.spawnParticle(`tp_pw:ferocity_01`, loc)
								magic.dimension.spawnParticle(`tp_pw:ferocity_02`, loc)
								magic.dimension.spawnParticle(`tp_pw:ferocity_03`, loc)
								magic.dimension.spawnParticle(`tp_pw:ferocity_04`, loc)
								magic.dimension.spawnParticle(`tp_pw:ferocity_06`, loc)
								magic.dimension.spawnParticle(`tp_pw:ferocity_07`, loc)
								magic.dimension.spawnParticle(`tp_pw:ferocity_05`, loc2)
								magic.dimension.spawnParticle(`tp_pw:ferocity_05`, loc2)
								magic.dimension.spawnParticle(`tp_pw:ferocity_05`, loc2)
								system.clearRun(sepong)
							},3.25*20)
							system.runTimeout(()=>{
								const loc = {x:magic.location.x,y:magic.location.y-0.9,z:magic.location.z}
								magic.dimension.spawnParticle(`tp_pw:ferocity_5`, loc)
							},3.5*20)
						}
						magic.dimension.getEntities({maxDistance:4,location:magic.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
							if(target===magic||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
							target.addEffect('slowness',3*20,{amplifier:10})
							system.runTimeout(()=>{
								target.applyDamage(damage, {cause:'contact',damagingEntity:player})
								target.applyKnockback((target.location.x-player.location.x), (target.location.z-player.location.z), 1, 0.5)
							},3.46*20)
							if (volumeSetting === true) {
								system.runTimeout(()=>{
									magic.runCommand(`playsound tp_pw:cg.blackhole2 @a ~~~`)
								})
							}
						})
						system.runTimeout(() => {
							system.runTimeout(() => {
								magic.remove()
							}, 0.5 * 20)
						}, 3.46 * 20)
					}
				}, 0.58 * 20)
				
				//ATTACK ENDS
				system.runTimeout(()=>{
					const attackItem = getItemOnInventory(player, `tp_pw:${weapon}_attack${skill+1}`);
					if (attackItem) {
						const inventory = player.getComponent("minecraft:inventory");
						inventory.container.setItem(attackItem.slot, new ItemStack(`tp_pw:${weapon}`));
					}
					player.removeTag(`tp_pw:using_ability`)
					player.startItemCooldown(`tp_pw:${weapon}`, wp1CD[1]*20)
				},1.5*20)
				player.runCommandAsync(`titleraw @p actionbar { \"rawtext\": [ { \"translate\" : \"actionbar.tp_pw:${weapon}.2\" } ] }`)
			}
			break;
		case 2:
			{
				const damage = wp1Damage[2]+(lvl.getScore(player)-minLVL)
				player.playAnimation(`animation.tp_pw.blade_of_the_wild.tpp_spirit_of_the_hunt`, {
					nextState: `none`,
					blendOutTime: 1,
					stopExpression: `query.any_animation_finished`,
					controller: `controller_name1`
				});
				if (volumeSetting === true) {
					const soundEntity = player.dimension.spawnEntity(`tp_pw:sound_entity`, player.location)
					soundEntity.setProperty('tp_pw:weapon', 'botw')
					soundEntity.setProperty('tp_pw:attack', 3)
					player.runCommand('playsound tp_pw:n_ability.botw3 @a ~~~')
				}
				system.runTimeout(() => {
					const magic = player.dimension.spawnEntity('tp_pw:botw_attack3', {
						x: player.location.x + player.getViewDirection().x * 2,
						y: player.location.y,
						z: player.location.z + player.getViewDirection().z * 2
					})
					for (let i = 0; i<30; i++) {
						magic.runCommand(`tp @s ~~-0.1~ ~~ true`)
					}
					magic.setRotation({
						x: 0,
						y: player.getRotation().y
					});
					magic.runCommand('particle tp_pw:spirit_of_the_hunt_1')
					if (magic.isValid() == true) {
						const interval = system.runInterval(() => {
							magic.dimension.getEntities({maxDistance:8,location:magic.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
								if(target===magic||target==player||target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
								target.dimension.spawnEntity('tp_pw:spirit_lynx', target.location)
								system.runTimeout(()=>{
									target.runCommand('playsound tp_pw:n_ability.botw3_1 @a ~~~')
									target.applyDamage(damage, {cause:'contact',damagingEntity:player})
								},0.83*20)
							})
						}, 5)
						system.runTimeout(() => {
							system.clearRun(interval)
							magic.runCommand('tag @e[r=30] remove tp_pw:hunted')
							magic.remove()
						}, 10 * 20)
					}
				}, 0.58 * 20)
				//ATTACK ENDS
				system.runTimeout(()=>{
					const attackItem = getItemOnInventory(player, `tp_pw:${weapon}_attack${skill+1}`);
					if (attackItem) {
						const inventory = player.getComponent("minecraft:inventory");
						inventory.container.setItem(attackItem.slot, new ItemStack(`tp_pw:${weapon}`));
					}
					player.removeTag(`tp_pw:using_ability`)
					player.startItemCooldown(`tp_pw:${weapon}`, wp1CD[2]*20)
				},1.5*20)
				player.runCommandAsync(`titleraw @p actionbar { \"rawtext\": [ { \"translate\" : \"actionbar.tp_pw:${weapon}.3\" } ] }`)
			}
			break;
		case 3:
			{
				const damage = wp1Damage[3]+(lvl.getScore(player)-minLVL)
				const petEntity = player.dimension.getEntities({type: `tp_pw:feral_lynx`,maxDistance: 15, location: {x:player.location.x,y:player.location.y,z:player.location.z}, tags:[`tp_pw:`+player.id]})
				const magic = player.dimension.spawnEntity('tp_pw:ultimate_lynx', {
					x: player.location.x + player.getViewDirection().x * 4,
					y: player.location.y,
					z: player.location.z + player.getViewDirection().z * 4
				})
				for (let i = 0; i<30; i++) {
					magic.runCommand(`tp @s ~~-0.1~ ~~ true`)
				}
				magic.setRotation({
					x: 0,
					y: player.getRotation().y + 180
				});
				system.runTimeout(() => {
					petEntity.forEach(pet=>{
						magic.dimension.getEntities({maxDistance:10,location:magic.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
							{
								target.runCommand(`inputpermission set @s movement disabled`)
								target.runCommand(`hud @s hide`)
								target.runCommand(`camera @s fade time 0.5 0.5 0.2 color 255 255 255`)
								if(target.typeId!=='minecraft:player'){target.addEffect('slowness',11.6*20,{amplifier:255})}
							}
							system.runTimeout(()=>{
								if (cameraSetting === true && target.typeId==='minecraft:player') {
									target.addTag(`tp_pw:${magic.id}`)
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^2 ^1 ^3 facing @s`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 1.0 linear pos ^2 ^1 ^5 facing @s`)
									})
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^3 ^1 ^-3 facing @s`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 0.10 linear pos ^-3 ^1 ^-3 facing @s`)
									}, 1.63 * 20)
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^-5 ^1 ^-3 facing @s`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 0.10 linear pos ^5 ^0.3 ^-3 facing @s `)
									}, 2.1 * 20)
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^1 ^1 ^ facing ~~1~`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 2 linear pos ^2 ^2 ^ facing ~~2~`)
									}, 3 * 20)
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^-5 ^1 ^ facing ~~1~`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 2 linear pos ^-6 ^2 ^ facing ~~2~`)
									}, 5 * 20)
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^ ^1 ^-8 facing ~~1~`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 2 linear pos ^ ^2 ^-10 facing ~~1~`)
									}, 7 * 20)
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^ ^8 ^ facing ~~1~`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 2 linear pos ^ ^10 ^ facing ~~1~`)
									}, 9 * 20)
								}
								//CameraShake
								if (target.typeId==='minecraft:player') {
									cameraShake(1.03, target, 0.5, 0.3, 'positional')
									cameraShake(3+2.5, target, 0.5, 1, 'positional')
									cameraShake(3+7, target, 0.5, 3, 'positional')
								}
								//Camera Clear
								system.runTimeout(() => {
									target.runCommand(`camera @a fade time 0.3 1 1 color 255 255 255`)
								},10*20)
								system.runTimeout(() => {
									try {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] clear`)
										magic.dimension.getEntities({tags:[`tp_pw:`+magic.id]}).forEach(victim=>{victim.removeTag(`tp_pw:`+magic.id)})
									} catch (error) {
										
									}
								},10.3*20)
								//ATTACK ENDS
								system.runTimeout(()=>{
									const attackItem = getItemOnInventory(player, `tp_pw:${weapon}_attack${skill+1}`);
									if (attackItem) {
										const inventory = player.getComponent("minecraft:inventory");
										inventory.container.setItem(attackItem.slot, new ItemStack(`tp_pw:${weapon}`));
									}
									player.removeTag(`tp_pw:using_ability`)
									player.startItemCooldown(`tp_pw:${weapon}`, wp1CD[3]*20)
									player.runCommand(`scoreboard players set @s tp_pw:${weapon}_ULT 0`)
									{
										try {
											target.runCommand(`camera @s clear`)
											target.runCommand(`inputpermission set @s movement enabled`)
											target.runCommand(`inputpermission set @s camera enabled`)
											target.runCommand(`hud @s reset`)
										} catch (error) {
											
										}
									}
									if(target===magic||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
									target.applyDamage(damage, {cause:'contact',damagingEntity:player})
								},10.625*20)
								//Damaged illusion
								{
									if(target===magic||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
									damageIllusion(target, 1.75)
									damageIllusion(target, 2.46)
									damageIllusion(target, 7.88)
									damageIllusion(target, 8.71)

									damageIllusion(target, 4.79+3)
									damageIllusion(target, 7+3)
								}
							},1*20)
						})
						system.runTimeout(()=>{
							if (volumeSetting === true) {
								// const soundEntity = player.dimension.spawnEntity(`tp_pw:sound_entity`, player.location)
								// soundEntity.setProperty('tp_pw:weapon', 'botw')
								// soundEntity.setProperty('tp_pw:attack', 4)
								system.runTimeout(()=>{
									playSoundUltimate(magic, 'tp_pw:n_ability.ultimate_tension', 0.0)
									playSoundUltimate(magic, 'tp_pw:n_ability.botw_rune', 1.03)
									playSoundUltimate(magic, 'tp_pw:n_ability.botw1', 1.71)
									playSoundUltimate(magic, 'tp_pw:n_ability.botw1', 2.33)
									playSoundUltimate(magic, 'tp_pw:n_ability.botw1', 7.79)
									playSoundUltimate(magic, 'tp_pw:n_ability.botw1', 8.67)
									playSoundUltimate(magic, 'tp_pw:n_ability.botw_ultimate_ambient', 1.1)
									playSoundUltimate(magic, 'tp_pw:n_ability.botw_ultimate_lynx', 3)
									playSoundUltimate(magic, 'tp_pw:ability.blackhole_exploding', 3+7)
								})
							}
							pet.runCommand('effect @s invisibility 11 0 true')
							player.runCommand('title @s clear')
							system.runTimeout(()=>{magic.runCommand('event entity @s active')},3*20)
							player.playAnimation(`animation.tp_pw.blade_of_the_wild.tpp_spirit_bond`, {
								nextState: `none`,
								blendOutTime: 1,
								stopExpression: `query.any_animation_finished`,
								controller: `controller_name1`
							});
							//Particle Effects
							{
								system.runTimeout(() => {
									magic.runCommand('particle tp_pw:spirit_bond_1 ~~0.1~')
									magic.runCommand('particle tp_pw:spirit_bond_2 ~~0.1~')
									magic.runCommand('particle tp_pw:spirit_bond_3 ~~0.1~')
									magic.runCommand('particle tp_pw:spirit_bond_4 ~~0.1~')
									magic.runCommand('particle tp_pw:spirit_bond_7 ~~0.1~')
									magic.runCommand('particle tp_pw:spirit_bond_8 ~~0.1~')
								}, 1 * 20)
								system.runTimeout(() => {
									magic.runCommand('particle tp_pw:spirit_bond_2 ~~0.1~')
									magic.runCommand('particle tp_pw:spirit_bond_3 ~~0.1~')
									magic.runCommand('particle tp_pw:spirit_bond_4 ~~0.1~')
									magic.runCommand('particle tp_pw:spirit_bond_7 ~~0.1~')
									magic.runCommand('particle tp_pw:spirit_bond_8 ~~0.1~')
								}, 10 * 20)
							}
						},1*20)
					})
				})
				player.runCommandAsync(`titleraw @p title { \"rawtext\": [ { \"translate\" : \"actionbar.tp_pw:${weapon}.4\" } ] }`)
			}
			break;
	}
}
function celestial_gauntlets_skill(player, weapon, skill, petId, minLVL) {
	const cameraSetting = world.getDynamicProperty('tp_pw:camera')
	const volumeSetting = world.getDynamicProperty('tp_pw:sound')
	const lvl = world.scoreboard.getObjective(`tp_pw:${weapon}_LVL`)
	switch (skill) {
		case 0:
			{
				const damage = wp2Damage[0]+(lvl.getScore(player)-minLVL)
				player.playAnimation(`animation.tp_pw.celestial_gauntlets.tpp_starfall`, {
					nextState: `none`,
					blendOutTime: 1,
					stopExpression: `query.any_animation_finished`,
					controller: `controller_name1`
				});
				const magic = player.dimension.spawnEntity('tp_pw:cg_attack1', {
					x: player.location.x + player.getViewDirection().x * 5,
					y: player.location.y,
					z: player.location.z + player.getViewDirection().z * 5
				})
				for (let i = 0; i<30; i++) {
					magic.runCommand(`tp @s ~~-0.1~ ~~ true`)
				}
				if (volumeSetting === true) {
					const soundEntity = player.dimension.spawnEntity(`tp_pw:sound_entity`, player.location)
					soundEntity.setProperty('tp_pw:weapon', 'cg')
					soundEntity.setProperty('tp_pw:attack', 1)
					magic.runCommand('playsound tp_pw:n_ability.cg1 @a ~~~ ')
					system.runTimeout(()=>{
						magic.runCommand('playsound tp_pw:n_ability.starfall_ambient @a ~~~ ')
					},2*20)
				}
		
				system.runTimeout(() => {
					const interval = system.runInterval(() => {
						magic.dimension.getEntities({maxDistance:10,location:magic.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
							if(target===magic||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
							target.applyDamage(damage, {cause:'contact',damagingEntity:player})
						})
					})
					system.runTimeout(() => {
						system.clearRun(interval)
						magic.remove()
					}, 6 * 20)
				}, 1.13 * 20)
				//ATTACK ENDS
				system.runTimeout(()=>{
					const attackItem = getItemOnInventory(player, `tp_pw:${weapon}_attack${skill+1}`);
					if (attackItem) {
						const inventory = player.getComponent("minecraft:inventory");
						inventory.container.setItem(attackItem.slot, new ItemStack(`tp_pw:${weapon}`));
					}
					player.removeTag(`tp_pw:using_ability`)
					player.startItemCooldown(`tp_pw:${weapon}`, wp2CD[0]*20)
				},1.5*20)
				player.runCommandAsync(`titleraw @p actionbar { \"rawtext\": [ { \"translate\" : \"actionbar.tp_pw:${weapon}.1\" } ] }`)
			}
			break;
		case 1:
			{
				const damage = wp2Damage[1]+(lvl.getScore(player)-minLVL)
				player.playAnimation(`animation.tp_pw.celestial_gauntlets.tpp_blackhole`, {
					nextState: `none`,
					blendOutTime: 1,
					stopExpression: `query.any_animation_finished`,
					controller: `controller_name1`
				});
				if (volumeSetting === true) {
					const soundEntity = player.dimension.spawnEntity(`tp_pw:sound_entity`, player.location)
					soundEntity.setProperty('tp_pw:weapon', 'cg')
					soundEntity.setProperty('tp_pw:attack', 2)
				}
	
				system.runTimeout(() => {
					const magic = player.dimension.spawnEntity('tp_pw:cg_attack2', {
						x: player.location.x + player.getViewDirection().x * 2,
						y: player.location.y + 10,
						z: player.location.z + player.getViewDirection().z * 2
					})
					if (volumeSetting === true) {
						magic.runCommand(`playsound tp_pw:ability.blackhole_forming @a ~~~`)
					}
					magic.setRotation({
						x: 0,
						y: player.getRotation().y
					});
					magic.setRotation({
						x: 0,
						y: player.getRotation().y
					});
					magic.dimension.getEntities({maxDistance:16,location:magic.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
						let currentRadius = randomize(4, 8, false);
						let angle = randomize(0, 360, true);
						const angularSpeedIncrease = 0.01;
						let angularSpeed = 0.01;
						const interval = system.runInterval(() => {
							try {
								if(magic.isValid()) {
								if(target===magic||target==player || target.hasTag(`tp_pw:`+player.id))return
								let x = magic.location.x + currentRadius * Math.cos(angle);
								let y = magic.location.y + Math.sin(angle);
								let z = magic.location.z + currentRadius * Math.sin(angle);
								magic.dimension.getEntities({maxDistance:8,location:magic.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
									if(target===magic||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
									//target.applyDamage(damage, {cause:'contact',damagingEntity:player})
								})
								target.teleport({x:x,y:y,z:z})
								currentRadius = Math.max(0, currentRadius - 0.01);
								angle += angularSpeed;
								angularSpeed += angularSpeedIncrease;
								}else{system.clearRun(interval)}
							} catch (error) {
								
							}
						},1)
					})
					// let currentRadius = 5;
					// let angle = 180;
					// const angularSpeedIncrease = 0.01;
					// let angularSpeed = 0.01;
					// const interval = system.runInterval(() => {
					// 	let x = magic.location.x + currentRadius * Math.cos(angle);
					// 	let y = magic.location.y + Math.sin(angle);
					// 	let z = magic.location.z + currentRadius * Math.sin(angle);
					// 	magic.dimension.getEntities({maxDistance:8,location:magic.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
					// 		if(target===magic||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
					// 		target.applyDamage(damage, {cause:'contact',damagingEntity:player})
					// 	})
					// 	magic.dimension.getEntities({maxDistance:16,location:magic.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
					// 		if(target===magic||target==player || target.hasTag(`tp_pw:`+player.id))return
					// 		target.teleport({x:x,y:y,z:z})
					// 	})
					// 	currentRadius = Math.max(0, currentRadius - 0.01);
					// 	angle += angularSpeed;
					// 	angularSpeed += angularSpeedIncrease;
					// },1)
					system.runTimeout(() => {
						magic.dimension.getEntities({maxDistance:10,location:magic.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
							if(target===magic||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
							target.applyDamage(damage+10, {cause:'contact',damagingEntity:player})
						})
						if(volumeSetting === true) {
							magic.runCommand('playsound tp_pw:ability.blackhole_exploding @a ~~~')
						}
						magic.remove()
					}, 6 * 20)
				}, 0.5 * 20)
				//ATTACK ENDS
				system.runTimeout(()=>{
					const attackItem = getItemOnInventory(player, `tp_pw:${weapon}_attack${skill+1}`);
					if (attackItem) {
						const inventory = player.getComponent("minecraft:inventory");
						inventory.container.setItem(attackItem.slot, new ItemStack(`tp_pw:${weapon}`));
					}
					player.removeTag(`tp_pw:using_ability`)
					player.startItemCooldown(`tp_pw:${weapon}`, wp2CD[1]*20)
				},1.3333*20)
				player.runCommandAsync(`titleraw @p actionbar { \"rawtext\": [ { \"translate\" : \"actionbar.tp_pw:${weapon}.2\" } ] }`)
			}
			break;
		case 2:
			{
				const damage = wp2Damage[2]+(lvl.getScore(player)-minLVL)
				player.playAnimation(`animation.tp_pw.celestial_gauntlets.tpp_astral_shield`, {
					nextState: `none`,
					blendOutTime: 1,
					stopExpression: `query.any_animation_finished`,
					controller: `controller_name1`
				});
				if (volumeSetting === true) {
					const soundEntity = player.dimension.spawnEntity(`tp_pw:sound_entity`, player.location)
					soundEntity.setProperty('tp_pw:weapon', 'cg')
					soundEntity.setProperty('tp_pw:attack', 3)
					system.runTimeout(()=>{
						player.runCommand(`playsound tp_pw:ability.magic_blast @a ~~~`)
					},1*20)
				}
				system.runTimeout(() => {
					player.runCommand(`scoreboard players set @s tp_pw:astral_shield 30`)
					const magic = player.dimension.spawnEntity('tp_pw:cg_attack4', {
						x: player.location.x,
						y: player.location.y,
						z: player.location.z
					})
					for (let i = 0; i<30; i++) {
						magic.runCommand(`tp @s ~~-0.1~ ~~ true`)
					}
					magic.setRotation({
						x: 0,
						y: player.getRotation().y
					});
					const interval = system.runInterval(() => {
						if(!magic.isValid())return
						magic.runCommand(`tp @s ${player.location.x} ${player.location.y} ${player.location.z}`)
						magic.runCommand(`effect @p resistance 10 255 true`)
					})
					system.runTimeout(() => {
						system.clearRun(interval)
						magic.remove()
					}, 10 * 20)
				}, 1 * 20)
				//ATTACK ENDS
				system.runTimeout(()=>{
					const attackItem = getItemOnInventory(player, `tp_pw:${weapon}_attack${skill+1}`);
					if (attackItem) {
						const inventory = player.getComponent("minecraft:inventory");
						inventory.container.setItem(attackItem.slot, new ItemStack(`tp_pw:${weapon}`));
					}
					player.removeTag(`tp_pw:using_ability`)
					player.startItemCooldown(`tp_pw:${weapon}`, wp2CD[2]*20)
				},1.875*20)
				player.runCommandAsync(`titleraw @p actionbar { \"rawtext\": [ { \"translate\" : \"actionbar.tp_pw:${weapon}.3\" } ] }`)
			}
			break;
		case 3:
			{
				const damage = wp2Damage[3]+(lvl.getScore(player)-minLVL)
				const petEntity = player.dimension.getEntities({type: `tp_pw:nebula_dragon`,maxDistance: 15, location: {x:player.location.x,y:player.location.y,z:player.location.z}, tags:[`tp_pw:`+player.id]})
				const magic = player.dimension.spawnEntity('tp_pw:cg_attack3', {
					x: player.location.x + player.getViewDirection().x * 4,
					y: player.location.y,
					z: player.location.z + player.getViewDirection().z * 4
				})
				for (let i = 0; i<30; i++) {
					magic.runCommand(`tp @s ~~-0.1~ ~~ true`)
				}
				magic.setRotation({
					x: 0,
					y: player.getRotation().y + 180
				});
				system.runTimeout(() => {
					petEntity.forEach(pet=>{
						magic.dimension.getEntities({maxDistance:10,location:magic.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
							{
								target.runCommand(`inputpermission set @s movement disabled`)
								target.runCommand(`hud @s hide`)
								target.runCommand(`camera @s fade time 0.5 0.5 0.2 color 255 255 255`)
								if(target.typeId!=='minecraft:player'){target.addEffect('slowness',11.8*20,{amplifier:255})}
							}
							system.runTimeout(() => {
								//player.runCommand('effect @s slowness 7 255')
								if (cameraSetting === true && target.typeId==='minecraft:player'){
									target.addTag(`tp_pw:${magic.id}`)
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^ ^2 ^-4 facing ${player.location.x} ${player.location.y+1} ${player.location.z}`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 2.0 linear pos ^^2^-7 facing ${player.location.x} ${player.location.y+1} ${player.location.z}`)
									})
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^ ^3 ^4 facing ${player.location.x} ${player.location.y+1} ${player.location.z}`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 0.3 linear pos ^^5^7 facing ${player.location.x} ${player.location.y+1} ${player.location.z}`)
									},0.5*20)
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^ ^6 ^20 facing ~~2~`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 2.0 linear pos ^^6^16 facing ~~2~`)
									},2*20)
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^ ^8 ^-4 facing ${player.location.x} ${player.location.y+1} ${player.location.z}`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 3.0 linear pos ^^10^-7 facing ${player.location.x} ${player.location.y+1} ${player.location.z}`)
									},4*20)
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^8 ^8 ^ facing ${player.location.x} ${player.location.y+1} ${player.location.z}`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 0.5 linear pos ^10^10^ facing ${player.location.x} ${player.location.y+1} ${player.location.z}`)
									},5*20)
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^12 ^8 ^ facing ~~10~`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 1.0 linear pos ^10^6^ facing ~~10~`)
									},7*20)
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^12 ^0.5 ^ facing ~~5~`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 0.3 linear pos ^15^0.5^ facing ~~6~`)
									},8*20)
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^^18^ facing ~~2~`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 1.0 linear pos ^^25^ facing ~~~`)
									},10*20)
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^-10 ^0.5 ^ facing ~~6~`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 0.5 linear pos ^-5^0.5^ facing ~~1~`)
									},11*20)

								}
								//CameraShake
								if (target.typeId==='minecraft:player') {
									cameraShake(1.0, target, 0.5, 0.5, 'positional')
									cameraShake(2+3.6, target, 0.3, 7, 'positional')
									cameraShake(9+2, target, 0.5, 3, 'positional')
								}
								//Camera Clear
								system.runTimeout(() => {
									target.runCommand(`camera @s fade time 0.3 1 1 color 255 255 255`)
								},11.5*20)
								system.runTimeout(() => {
									magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] clear`)
									magic.dimension.getEntities({tags:[`tp_pw:`+magic.id]}).forEach(victim=>{victim.removeTag(`tp_pw:`+magic.id)})
								},11.8*20)
								//ATTACK ENDS
								system.runTimeout(()=>{
									const attackItem = getItemOnInventory(player, `tp_pw:${weapon}_attack${skill+1}`);
									if (attackItem) {
										const inventory = player.getComponent("minecraft:inventory");
										inventory.container.setItem(attackItem.slot, new ItemStack(`tp_pw:${weapon}`));
									}
									player.removeTag(`tp_pw:using_ability`)
									player.startItemCooldown(`tp_pw:${weapon}`, wp2CD[3]*20)
									player.runCommand(`scoreboard players set @s tp_pw:${weapon}_ULT 0`)
									{
										try {
											target.runCommand(`camera @s clear`)
											target.runCommand(`inputpermission set @s movement enabled`)
											target.runCommand(`inputpermission set @s camera enabled`)
											target.runCommand(`hud @s reset`)
										} catch (error) {
											
										}
									}
									if(target===magic||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
									target.applyDamage(damage, {cause:'contact',damagingEntity:player})
								},11.8*20)
								//Damaged illusion
								{
									if(target===magic||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
									damageIllusion(target, 0.96)
									damageIllusion(target, 5+2)
									damageIllusion(target, 9.33+2)
								}
							}, 1 * 20)
						})
						system.runTimeout(() => {
							pet.addEffect('invisibility', 11.8*20)
							player.runCommand('title @s clear')
							player.playAnimation(`animation.tp_pw.celestial_gauntlets.tpp_cosmic_convergence`, {
								nextState: `none`,
								blendOutTime: 1,
								stopExpression: `query.any_animation_finished`,
								controller: `controller_name1`
							});
							if (volumeSetting === true) {
								system.runTimeout(()=>{
									playSoundUltimate(magic, 'tp_pw:n_ability.ultimate_tension', 0.0)
									playSoundUltimate(magic, 'tp_pw:n_ability.botw_rune', 0.88)
									playSoundUltimate(magic, 'tp_pw:n_ability.botw_ultimate_ambient', 0.88)
									playSoundUltimate(magic, 'tp_pw:n_ability.cg_ultimate_player', 0.0)
									playSoundUltimate(magic, 'tp_pw:n_ability.cg1_ult', 6.3)
									playSoundUltimate(magic, 'tp_pw:n_ability.blackhole_forming', 5.8)
									playSoundUltimate(magic, 'tp_pw:dragon.wing', 0.5833);
									playSoundUltimate(magic, 'tp_pw:dragon.wing', 1.4583);
									playSoundUltimate(magic, 'tp_pw:dragon.wing', 2.4583);
									playSoundUltimate(magic, 'tp_pw:dragon.wing', 3.3333);
									playSoundUltimate(magic, 'tp_pw:dragon.wing', 4.7917);
									playSoundUltimate(magic, 'tp_pw:dragon.wing', 5.75);
									playSoundUltimate(magic, 'tp_pw:dragon.wing', 6.7917);
									playSoundUltimate(magic, 'tp_pw:n_ability.dragon_idle', 2.3);
									playSoundUltimate(magic, 'tp_pw:n_ability.dragon_death', 2.6+2);
									playSoundUltimate(magic, 'tp_pw:n_ability.blackhole_exploding', 9+2, 10, 1)
									
								})
							}
							//Particle Effects
							{
								system.runTimeout(()=>{
									const loc = {
										x:magic.location.x,
										y:magic.location.y+0.1,
										z:magic.location.z
									}
									magic.dimension.spawnParticle('tp_pw:cosmic_convergence_1', loc)
									magic.dimension.spawnParticle('tp_pw:cosmic_convergence_2', loc)
									magic.dimension.spawnParticle('tp_pw:cosmic_convergence_3', loc)
									magic.dimension.spawnParticle('tp_pw:cosmic_convergence_4', loc)
								},1*20)
								system.runTimeout(()=>{
									magic.triggerEvent('active2')
								},6*20)
							}
							//Entity Effects
							system.runTimeout(()=>{magic.runCommand('event entity @s active')},2*20)
							//ATTACK ENDS
							system.runTimeout(()=>{
								const attackItem = getItemOnInventory(player, `tp_pw:${weapon}_attack${skill+1}`);
								if (attackItem) {
									const inventory = player.getComponent("minecraft:inventory");
									inventory.container.setItem(attackItem.slot, new ItemStack(`tp_pw:${weapon}`));
								}
								player.removeTag(`tp_pw:using_ability`)
								player.startItemCooldown(`tp_pw:${weapon}`, wp2CD[3]*20)
								player.runCommand(`scoreboard players set @s tp_pw:${weapon}_ULT 0`)
								{
									try {
										target.runCommand(`camera @s clear`)
										target.runCommand(`inputpermission set @s movement enabled`)
										target.runCommand(`inputpermission set @s camera enabled`)
										target.runCommand(`hud @s reset`)
									} catch (error) {
										
									}
								}
							},11.8*20)
						}, 1 * 20)
					})
				})
				player.runCommandAsync(`titleraw @p title { \"rawtext\": [ { \"translate\" : \"actionbar.tp_pw:${weapon}.4\" } ] }`)
			}
			break;
	}
}
function ember_bow_skill(player, weapon, skill, petId, minLVL) {
	const cameraSetting = world.getDynamicProperty('tp_pw:camera')
	const volumeSetting = world.getDynamicProperty('tp_pw:sound')
	const lvl = world.scoreboard.getObjective(`tp_pw:${weapon}_LVL`)
	switch (skill) {
		case 0:
			{
				player.addEffect('slowness', 1*20, {amplifier:4})
				player.playAnimation(`animation.tp_pw.ember_bow.tpp_scorching_wall`, {
					nextState: `none`,
					blendOutTime: 1,
					stopExpression: `query.any_animation_finished`,
					controller: `controller_name1`
				});
				const damage = wp3Damage[0]+(lvl.getScore(player)-minLVL)
				const range = 1
				const loc = {
					x: player.location.x + player.getViewDirection().x * range,
					y: player.location.y + 1.5,
					z: player.location.z + player.getViewDirection().z * range
				}
				if (volumeSetting === true) {
					const soundEntity = player.dimension.spawnEntity(`tp_pw:sound_entity`, player.location)
					soundEntity.setProperty('tp_pw:weapon', 'eb')
					soundEntity.setProperty('tp_pw:attack', 1)
					player.runCommand(`playsound tp_pw:ability.fire_blazing @a ~~~`)
					system.runTimeout(()=>{
						player.runCommand(`playsound tp_pw:ability.fire_blast @a ~~~`)
					},0.8*20)
				}
				let rot = {x:player.getRotation().x,y:player.getRotation().y}
				const projectile = player.dimension.spawnEntity('tp_pw:ember_bow_projectile', loc)
				projectile.teleport(projectile.location, {rotation:rot})
				let maxDistance = 100;
				system.runTimeout(()=>{
					try {
						player.getEntitiesFromViewDirection().forEach(target=>{
							if(target !== player || target !== projectile)
							{
								maxDistance = target.distance
								console.warn(`distance: ${target.distance}`)
							}
						})
					} catch (error) {
					}
					let currentX = player.location.x + player.getViewDirection().x * maxDistance;
					let currentY = player.location.y + player.getViewDirection().y * maxDistance;
					let currentZ = player.location.z + player.getViewDirection().z * maxDistance;
					try {
						const seenBlock = player.getBlockFromViewDirection().block
						if(seenBlock!==null){
							currentX = seenBlock.location.x
							currentY = seenBlock.location.y
							currentZ = seenBlock.location.z
						}
					} catch (error) {
						
					}
					rot = {x:player.getRotation().x,y:player.getRotation().y}
					projectile.triggerEvent('tp_pw:scale1')
					projectile.teleport(projectile.location, {rotation:rot})
					const move = system.runInterval(()=>{
						if(!projectile.isValid()) return
						projectile.runCommand(`tp @s ^^^2 facing ${currentX} ${currentY} ${currentZ}`)
						try {
							if(!projectile.dimension.getBlock(projectile.location).isAir){
								console.warn(`hit block`)
								projectile.dimension.getEntities({maxDistance:5,location:projectile.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
									if(target===projectile||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
									target.applyDamage(damage, {cause:'contact',damagingEntity:player})
									target.applyKnockback((target.location.x-projectile.location.x), (target.location.z-projectile.location.z), 1, 1)
			
								})
								const parLoc = {
									x:projectile.location.x,
									y:projectile.location.y+1,
									z:projectile.location.z
								}
								projectile.dimension.spawnParticle('tp_pw:scorching_wall_1', parLoc)
								projectile.dimension.spawnParticle('tp_pw:scorching_wall_2', parLoc)
								projectile.dimension.spawnParticle('tp_pw:scorching_wall_3', parLoc)
								projectile.dimension.spawnParticle('tp_pw:scorching_wall_4', parLoc)
								projectile.remove()
								system.clearRun(move)
							}
							if(projectile.location.x===currentX && projectile.location.y===currentY && projectile.location.z===currentZ){
								const parLoc = {
									x:projectile.location.x,
									y:projectile.location.y+1,
									z:projectile.location.z
								}
								projectile.dimension.spawnParticle('tp_pw:scorching_wall_1', parLoc)
								projectile.dimension.spawnParticle('tp_pw:scorching_wall_2', parLoc)
								projectile.dimension.spawnParticle('tp_pw:scorching_wall_3', parLoc)
								projectile.dimension.spawnParticle('tp_pw:scorching_wall_4', parLoc)

								projectile.dimension.getEntities({maxDistance:5,location:projectile.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
									projectile.remove()
									system.clearRun(move)
		
									if(target===projectile||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
									target.applyDamage(damage, {cause:'contact',damagingEntity:player})
									target.applyKnockback((target.location.x-projectile.location.x), (target.location.z-projectile.location.z), 1, 1)
			
								})
								projectile.remove()
								system.clearRun(move)
							}
							projectile.dimension.getEntities({closest:1,maxDistance:2,location:projectile.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
								if(target===projectile||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
								//EFFECT
								target.applyDamage(damage, {cause:'contact',damagingEntity:player})
								target.applyKnockback((target.location.x-projectile.location.x), (target.location.z-projectile.location.z), 1, 1)
								if (volumeSetting === true) {
									target.runCommand(`playsound tp_pw:ability.fire_explosion @a ~~~ 10`)
								}
								//SPECIAL EFFECT
								const parLoc = {
									x:target.location.x,
									y:target.location.y+1,
									z:target.location.z
								}
								projectile.dimension.spawnParticle('tp_pw:scorching_wall_1', parLoc)
								projectile.dimension.spawnParticle('tp_pw:scorching_wall_2', parLoc)
								projectile.dimension.spawnParticle('tp_pw:scorching_wall_3', parLoc)
								projectile.dimension.spawnParticle('tp_pw:scorching_wall_4', parLoc)
								projectile.dimension.getEntities({maxDistance:5,location:projectile.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
									if(target===projectile||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
									target.applyDamage(damage, {cause:'contact',damagingEntity:player})
									target.applyKnockback((target.location.x-projectile.location.x), (target.location.z-projectile.location.z), 1, 1)
								})
								projectile.remove()
								system.clearRun(move)
							})
						} catch (error) {
							
						}
					})
				},1*20)
				//ATTACK ENDS
				system.runTimeout(()=>{
					const attackItem = getItemOnInventory(player, `tp_pw:${weapon}_attack${skill+1}`);
					if (attackItem) {
						const inventory = player.getComponent("minecraft:inventory");
						inventory.container.setItem(attackItem.slot, new ItemStack(`tp_pw:${weapon}`));
					}
					player.removeTag(`tp_pw:using_ability`)
					player.startItemCooldown(`tp_pw:${weapon}`, wp3CD[0]*20)
				},2.5*20)
				player.runCommandAsync(`titleraw @p actionbar { \"rawtext\": [ { \"translate\" : \"actionbar.tp_pw:${weapon}.1\" } ] }`)
			} 
			break;
		case 1:
			{
				player.addEffect('slowness', 1*20, {amplifier:4})
				player.playAnimation(`animation.tp_pw.ember_bow.tpp_phoenix_burst`, {
					nextState: `none`,
					blendOutTime: 1,
					stopExpression: `query.any_animation_finished`,
					controller: `controller_name1`
				});
				const damage = wp3Damage[1]+(lvl.getScore(player)-minLVL)
				const range = 1
				const loc = {
					x: player.location.x + player.getViewDirection().x * range,
					y: player.location.y + 1.5,
					z: player.location.z + player.getViewDirection().z * range
				}
				if (volumeSetting === true) {
					const soundEntity = player.dimension.spawnEntity(`tp_pw:sound_entity`, player.location)
					soundEntity.setProperty('tp_pw:weapon', 'eb')
					soundEntity.setProperty('tp_pw:attack', 1)
					player.runCommand(`playsound tp_pw:ability.fire_blazing @a ~~~`)
					system.runTimeout(()=>{
						player.runCommand(`playsound tp_pw:ability.fire_blast @a ~~~`)
					},0.8*20)
				}
				let rot = {x:player.getRotation().x,y:player.getRotation().y}
				const projectile = player.dimension.spawnEntity('tp_pw:ember_bow_projectile', loc)
				projectile.teleport(projectile.location, {rotation:rot})
				let maxDistance = 100;
				system.runTimeout(()=>{
					try {
						player.getEntitiesFromViewDirection().forEach(target=>{
							if(target !== player || target !== projectile)
							{
								maxDistance = target.distance
								console.warn(`distance: ${target.distance}`)
							}
						})
					} catch (error) {
					}
					let currentX = player.location.x + player.getViewDirection().x * maxDistance;
					let currentY = player.location.y + player.getViewDirection().y * maxDistance;
					let currentZ = player.location.z + player.getViewDirection().z * maxDistance;
					try {
						const seenBlock = player.getBlockFromViewDirection().block
						if(seenBlock!==null){
							currentX = seenBlock.location.x
							currentY = seenBlock.location.y
							currentZ = seenBlock.location.z
						}
					} catch (error) {
						
					}
					rot = {x:player.getRotation().x,y:player.getRotation().y}
					projectile.triggerEvent('tp_pw:scale1')
					projectile.teleport(projectile.location, {rotation:rot})
					const move = system.runInterval(()=>{
						if(!projectile.isValid()) return
						projectile.runCommand(`tp @s ^^^2 facing ${currentX} ${currentY} ${currentZ}`)
						try {
							if(!projectile.dimension.getBlock(projectile.location).isAir){
								console.warn(`hit block`)
								player.dimension.getEntities({closest:1,type:'tp_pw:flame_hawk',tags:[`tp_pw:`+player.id]}).forEach(flameHawk=>{
									flameHawk.addEffect('invisibility',3*20,{showParticles:false})
								})
								projectile.dimension.getEntities({maxDistance:5,location:projectile.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
									//SPECIAL EFFECT
									if(target===projectile||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
									system.runTimeout(()=>{
										if (volumeSetting === true) {
											target.runCommand(`playsound tp_pw:ability.fire_explosion @a ~~~ 10`)
										}
										const interval = system.runInterval(()=>{
											if(!target.isValid()) return
											target.applyDamage(damage, {cause:'fire',damagingEntity:player})
										})
										system.runTimeout(()=>{
											system.clearRun(interval)
										},2*20)
									},1*20)
								})
								const parLoc = {
									x:projectile.location.x,
									y:projectile.location.y+1,
									z:projectile.location.z
								}
								projectile.dimension.spawnParticle('tp_pw:scorching_wall_1', parLoc)
								projectile.dimension.spawnParticle('tp_pw:scorching_wall_2', parLoc)
								projectile.dimension.spawnParticle('tp_pw:scorching_wall_3', parLoc)
								projectile.dimension.spawnParticle('tp_pw:scorching_wall_4', parLoc)
								projectile.dimension.spawnEntity(`tp_pw:eb_attack2`, parLoc)
								projectile.remove()
								system.clearRun(move)
							}
							projectile.dimension.getEntities({closest:1,maxDistance:2,location:projectile.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item', 'tp_pw:ember_bow_projectile'],excludeFamilies:['tp_pw']}).forEach(target=>{
								if(target===projectile||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
								//EFFECT
								const loc = {
									x:target.location.x,
									y:target.location.y+1,
									z:target.location.z
								}
								if (volumeSetting === true) {
									target.runCommand(`playsound tp_pw:ability.fire_explosion @a ~~~ 10`)
								}
								target.dimension.spawnEntity(`tp_pw:eb_attack2`, loc)
								player.dimension.getEntities({closest:1,type:'tp_pw:flame_hawk',tags:[`tp_pw:`+player.id]}).forEach(flameHawk=>{
									flameHawk.addEffect('invisibility',3*20,{showParticles:false})
								})
								if (volumeSetting === true) {
									projectile.runCommand(`playsound tp_pw:ability.fire_explosion @a ~~~ 10 1`)
								}
								//SPECIAL EFFECT
								const parLoc = {
									x:target.location.x,
									y:target.location.y+1,
									z:target.location.z
								}
								projectile.dimension.spawnParticle('tp_pw:scorching_wall_1', parLoc)
								projectile.dimension.spawnParticle('tp_pw:scorching_wall_2', parLoc)
								projectile.dimension.spawnParticle('tp_pw:scorching_wall_3', parLoc)
								projectile.dimension.spawnParticle('tp_pw:scorching_wall_4', parLoc)
								projectile.dimension.getEntities({maxDistance:5,location:projectile.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item', 'tp_pw:ember_bow_projectile'],excludeFamilies:['tp_pw']}).forEach(target=>{
									if(target===projectile||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
									system.runTimeout(()=>{
										if (volumeSetting === true) {
											target.runCommand(`playsound tp_pw:ability.fire_explosion @a ~~~ 10`)
										}
										const interval = system.runInterval(()=>{
											if(!target.isValid()) return
											target.applyDamage(damage, {cause:'fire',damagingEntity:player})
										})
										system.runTimeout(()=>{
											system.clearRun(interval)
										},2*20)
									},1*20)
								})
								projectile.remove()
								system.clearRun(move)
							})
						} catch (error) {
							
						}
					})
				},1*20)
				//ATTACK ENDS
				system.runTimeout(()=>{
					const attackItem = getItemOnInventory(player, `tp_pw:${weapon}_attack${skill+1}`);
					if (attackItem) {
						const inventory = player.getComponent("minecraft:inventory");
						inventory.container.setItem(attackItem.slot, new ItemStack(`tp_pw:${weapon}`));
					}
					player.removeTag(`tp_pw:using_ability`)
					player.startItemCooldown(`tp_pw:${weapon}`, wp3CD[0]*20)
				},2.5*20)
				player.runCommandAsync(`titleraw @p actionbar { \"rawtext\": [ { \"translate\" : \"actionbar.tp_pw:${weapon}.2\" } ] }`)
			}
			break;
		case 2:
			{
				player.addEffect('slowness', 1*20, {amplifier:4})
				player.playAnimation(`animation.tp_pw.ember_bow.tpp_winged_blaze`, {
					nextState: `none`,
					blendOutTime: 1,
					stopExpression: `query.any_animation_finished`,
					controller: `controller_name1`
				});
				const damage = wp3Damage[2]+(lvl.getScore(player)-minLVL)
				const range = 1
				const loc = {
					x: player.location.x + player.getViewDirection().x * range,
					y: player.location.y + 1.5,
					z: player.location.z + player.getViewDirection().z * range
				}
				if (volumeSetting === true) {
					const soundEntity = player.dimension.spawnEntity(`tp_pw:sound_entity`, player.location)
					soundEntity.setProperty('tp_pw:weapon', 'eb')
					soundEntity.setProperty('tp_pw:attack', 1)
					player.runCommand(`playsound tp_pw:ability.fire_blazing @a ~~~`)
					system.runTimeout(()=>{
						player.runCommand(`playsound tp_pw:ability.fire_blast @a ~~~`)
					},0.8*20)
				}
				let rot = {x:player.getRotation().x,y:player.getRotation().y}
				const projectile = player.dimension.spawnEntity('tp_pw:ember_bow_projectile', loc)
				projectile.teleport(projectile.location, {rotation:rot})
				let maxDistance = 100;
				system.runTimeout(()=>{
					try {
						player.getEntitiesFromViewDirection().forEach(target=>{
							if(target !== player || target !== projectile)
							{
								maxDistance = target.distance
								console.warn(`distance: ${target.distance}`)
							}
						})
					} catch (error) {
					}
					let currentX = player.location.x + player.getViewDirection().x * maxDistance;
					let currentY = player.location.y + player.getViewDirection().y * maxDistance;
					let currentZ = player.location.z + player.getViewDirection().z * maxDistance;
					try {
						const seenBlock = player.getBlockFromViewDirection().block
						if(seenBlock!==null){
							currentX = seenBlock.location.x
							currentY = seenBlock.location.y
							currentZ = seenBlock.location.z
						}
					} catch (error) {
						
					}
					rot = {x:player.getRotation().x,y:player.getRotation().y}
					projectile.triggerEvent('tp_pw:scale1')
					projectile.teleport(projectile.location, {rotation:rot})
					const move = system.runInterval(()=>{
						if(!projectile.isValid()) return
						projectile.runCommand(`tp @s ^^^2 facing ${currentX} ${currentY} ${currentZ}`)
						try {
							if(!projectile.dimension.getBlock(projectile.location).isAir){
								const parLoc = {
									x:projectile.location.x,
									y:projectile.location.y,
									z:projectile.location.z
								}
								system.runTimeout(()=>{
									world.getDimension("overworld").spawnParticle('tp_pw:scorching_wall_5', parLoc)
									world.getDimension("overworld").spawnParticle('tp_pw:scorching_wall_6', parLoc)
									world.getDimension("overworld").spawnParticle('tp_pw:scorching_wall_7', parLoc)
									
									system.runTimeout(()=>{
										world.getDimension("overworld").spawnParticle('tp_pw:winged_blaze_1', parLoc)
										world.getDimension("overworld").spawnParticle('tp_pw:winged_blaze_2', parLoc)
									},1*20)
									system.runTimeout(()=>{
										world.getDimension("overworld").spawnParticle('tp_pw:winged_blaze_1_1', parLoc)
									},1.04*20)
									system.runTimeout(()=>{
										world.getDimension("overworld").spawnParticle('tp_pw:scorching_wall_2', parLoc)
										world.getDimension("overworld").spawnParticle('tp_pw:scorching_wall_3', parLoc)
										world.getDimension("overworld").spawnParticle('tp_pw:scorching_wall_4', parLoc)
									},1.58*20)
									system.runTimeout(()=>{
										world.getDimension("overworld").spawnParticle('tp_pw:winged_blaze_3', parLoc)
										world.getDimension("overworld").spawnParticle('tp_pw:winged_blaze_3', parLoc)
									},1.63*20)
									system.runTimeout(()=>{
										world.getDimension("overworld").spawnParticle('tp_pw:winged_blaze_4', parLoc)
										world.getDimension("overworld").spawnParticle('tp_pw:winged_blaze_5', parLoc)
										world.getDimension("overworld").spawnParticle('tp_pw:winged_blaze_6', parLoc)
										world.getDimension("overworld").spawnParticle('tp_pw:winged_blaze_7', parLoc)
										world.getDimension("overworld").spawnParticle('tp_pw:winged_blaze_8', parLoc)
										world.getDimension("overworld").spawnParticle('tp_pw:winged_blaze_9', parLoc)
									},2.17*20)
								})
								const lastProjectileLocation = {
									x: projectile.location.x,
									y: projectile.location.y,
									z: projectile.location.z
								}
								projectile.dimension.spawnEntity(`tp_pw:eb_attack3`, lastProjectileLocation)
								projectile.dimension.getEntities({maxDistance:5,location:projectile.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
									if(target===projectile||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
									console.warn('found target')
									target.applyDamage(damage, {cause:'contact',damagingEntity:player})
									system.runTimeout(()=>{
										system.runTimeout(()=>{
											target.applyKnockback((target.location.x-lastProjectileLocation.x), (target.location.z-lastProjectileLocation.z), 2, 2)
										},0.75*20)
									})
								})
								projectile.remove()
								system.clearRun(move)
								projectile.runCommand(`playsound tp_pw:ability.fire_explosion @a ~~~`)
							}
							projectile.dimension.getEntities({maxDistance:2,location:projectile.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
								if(target===projectile||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
								//EFFECT
		
								const lastProjectileLocation = {
									x: projectile.location.x,
									y: projectile.location.y,
									z: projectile.location.z
								}
								//SPECIAL EFFECT
								const parLoc = {
									x:target.location.x,
									y:target.location.y,
									z:target.location.z
								}
								projectile.dimension.spawnEntity(`tp_pw:eb_attack3`, target.location)
								projectile.dimension.getEntities({maxDistance:5,location:projectile.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
									if(target===projectile||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
									target.applyDamage(damage, {cause:'contact',damagingEntity:player})
									system.runTimeout(()=>{
										system.runTimeout(()=>{
											target.applyKnockback((target.location.x-lastProjectileLocation.x), (target.location.z-lastProjectileLocation.z), 2, 2)
										},0.75*20)
									})
								})
								system.runTimeout(()=>{
									target.runCommand(`playsound tp_pw:ability.fire_explosion @a ~~~ 10 1`)
									target.dimension.spawnParticle('tp_pw:scorching_wall_5', parLoc)
									target.dimension.spawnParticle('tp_pw:scorching_wall_6', parLoc)
									target.dimension.spawnParticle('tp_pw:scorching_wall_7', parLoc)
									system.runTimeout(()=>{
										console.warn(`YESS`)
										target.runCommand(`playsound tp_pw:ability.fire_explosion @a ~~~ 10 1`)
										target.applyKnockback((target.location.x-lastProjectileLocation.x), (target.location.z-lastProjectileLocation.z), 2, 2)
									},0.75*20)
									system.clearRun(move)
								})
								projectile.remove()
							})
						} catch (error) {
							
						}
					}, 0.01)
				},1*20)
				//ATTACK ENDS
				system.runTimeout(()=>{
					const attackItem = getItemOnInventory(player, `tp_pw:${weapon}_attack${skill+1}`);
					if (attackItem) {
						const inventory = player.getComponent("minecraft:inventory");
						inventory.container.setItem(attackItem.slot, new ItemStack(`tp_pw:${weapon}`));
					}
					player.removeTag(`tp_pw:using_ability`)
					player.startItemCooldown(`tp_pw:${weapon}`, wp3CD[0]*20)
				},2.5*20)
				player.runCommandAsync(`titleraw @p actionbar { \"rawtext\": [ { \"translate\" : \"actionbar.tp_pw:${weapon}.3\" } ] }`)
			}
			break;
		case 3:
			{
				const damage = wp3Damage[3]+(lvl.getScore(player)-minLVL)
				const petEntity = player.dimension.getEntities({type: `tp_pw:flame_hawk`,maxDistance: 15, location: {x:player.location.x,y:player.location.y,z:player.location.z}, tags:[`tp_pw:`+player.id]})
				const magic = player.dimension.spawnEntity('tp_pw:eb_attack4', {
					x: player.location.x + player.getViewDirection().x * 4,
					y: player.location.y,
					z: player.location.z + player.getViewDirection().z * 4
				})
				for (let i = 0; i<30; i++) {
					magic.runCommand(`tp @s ~~-0.1~ ~~ true`)
				}
				magic.setRotation({
					x: 0,
					y: player.getRotation().y + 180
				});
				system.runTimeout(() => {
					petEntity.forEach(pet=>{
						magic.dimension.getEntities({maxDistance:10,location:magic.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
							{
								target.runCommand(`inputpermission set @s movement disabled`)
								target.runCommand(`hud @s hide`)
								target.runCommand(`camera @s fade time 0.5 0.5 0.2 color 255 255 255`)
								if(target.typeId!=='minecraft:player'){target.addEffect('slowness',12.3*20,{amplifier:255})}
							}
							system.runTimeout(()=>{
								//Camera Movement
								if (cameraSetting === true && target.typeId==='minecraft:player') {
									target.addTag(`tp_pw:${magic.id}`)
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^ ^2 ^1 facing ${player.location.x} ${player.location.y+1} ${player.location.z}`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 3.0 linear pos ^ ^3 ^-3 facing ${player.location.x} ${player.location.y+1} ${player.location.z}`)
									})
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^-5 ^4 ^4 facing ^^1^1`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 2.0 linear pos ^-3 ^3 ^3 facing ^^1^1`)
									},3*20)
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^-8 ^4 ^-4 facing ~~1~`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 2.0 linear pos ^-5 ^3 ^-3 facing ~~1~`)
									},5*20)
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^ ^3 ^8 facing ~~1~`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 2.0 linear pos ^ ^3 ^6 facing ~~1~`)
									},7*20)
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^ ^3 ^-8 facing ~~1~`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 2.0 linear pos ^ ^3 ^-6 facing ~~1~`)
									},9*20)
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^ ^10 ^ facing ~~1~`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 1.0 linear pos ^ ^11 ^ facing ~~1~`)
									},10.42*20)
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^-8 ^2 ^ facing ~~~`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 0.58 linear pos ^-3 ^1 ^ facing ~~~`)
									},11.42*20)

								}
								//CameraShake
								if (target.typeId==='minecraft:player') {
									cameraShake(2.0, target, 0.5, 2, 'positional')
									cameraShake(7.75, target, 0.5, 1, 'positional')
									cameraShake(11.8, target, 0.5, 3, 'positional')
								}
								//Camera Clear
								system.runTimeout(() => {
									target.runCommand(`camera @s fade time 0.3 1 1 color 255 255 255`)
								},12.0*20)
								system.runTimeout(() => {
									magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] clear`)
									magic.dimension.getEntities({tags:[`tp_pw:`+magic.id]}).forEach(victim=>{victim.removeTag(`tp_pw:`+magic.id)})
								},12.3*20)
								//ATTACK ENDS
								system.runTimeout(()=>{
									const attackItem = getItemOnInventory(player, `tp_pw:${weapon}_attack${skill+1}`);
									if (attackItem) {
										const inventory = player.getComponent("minecraft:inventory");
										inventory.container.setItem(attackItem.slot, new ItemStack(`tp_pw:${weapon}`));
									}
									player.removeTag(`tp_pw:using_ability`)
									player.runCommand(`camera @s clear`)
									player.startItemCooldown(`tp_pw:${weapon}`, wp1CD[3]*20)
									player.runCommand(`scoreboard players set @s tp_pw:${weapon}_ULT 0`)
									{
										try {
											target.runCommand(`camera @s clear`)
											target.runCommand(`inputpermission set @s movement enabled`)
											target.runCommand(`inputpermission set @s camera enabled`)
											target.runCommand(`hud @s reset`)
										} catch (error) {
											
										}
									}
									if(target===magic||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
									target.applyDamage(damage, {cause:'contact',damagingEntity:player})
								},12.3*20)
								//Damaged illusion
								{
									if(target===magic||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
									damageIllusion(target, 1.92)
									damageIllusion(target, 7.75+3)
									damageIllusion(target, 8.71+3)
								}
							},1*20)
						})
						system.runTimeout(()=>{
							pet.runCommand('effect @s invisibility 12 0 true')
							player.runCommand('title @s clear')
							player.playAnimation(`animation.tp_pw.ember_bow.tpp_hawk_rebirth`, {
								nextState: `none`,
								blendOutTime: 1,
								stopExpression: `query.any_animation_finished`,
								controller: `controller_name1`
							});
							if (volumeSetting === true) {
								const soundEntity = player.dimension.spawnEntity(`tp_pw:sound_entity`, player.location)
								soundEntity.setProperty('tp_pw:weapon', 'eb')
								soundEntity.setProperty('tp_pw:attack', 4)
								system.runTimeout(()=>{
									magic.runCommand(`playsound tp_pw:ability.magic_ambient @a ~~~`)
								},2*20)
								system.runTimeout(()=>{
									magic.runCommand(`playsound tp_pw:ult.hawk_scream @a ~~~ 10 0.8`)
								},3*20)
								system.runTimeout(()=>{
									magic.runCommand(`playsound tp_pw:ult.hawk_scream @a ~~~`)
								},10*20)
								system.runTimeout(()=>{
									magic.runCommand(`playsound tp_pw:ability.fire_explosion @a ~~~`)
								},11.8*20)
								system.runTimeout(()=>{
									playSoundUltimate(magic, 'tp_pw:n_ability.ultimate_tension', 0.0)
									playSoundUltimate(magic, 'tp_pw:n_ability.botw_rune', 1.5)
									playSoundUltimate(magic, 'tp_pw:n_ability.botw_ultimate_ambient', 1.5)
								})
							}
							//Particle Effects
							system.runTimeout(() => {
								system.runTimeout(()=>{
									const loc = {
										x:magic.location.x,
										y:magic.location.y+0.1,
										z:magic.location.z,
									}
									magic.dimension.spawnParticle(`tp_pw:hawk_rebirth_1`, loc)
									magic.dimension.spawnParticle(`tp_pw:hawk_rebirth_2`, loc)
									magic.dimension.spawnParticle(`tp_pw:hawk_rebirth_3`, loc)
								},1.5*20)
								system.runTimeout(()=>{
									const loc = {
										x:magic.location.x,
										y:magic.location.y+0.1,
										z:magic.location.z,
									}
									magic.dimension.spawnParticle(`tp_pw:hawk_rebirth_4`, loc)
								},2*20)
							})
							//Entity Effects
							system.runTimeout(() => {magic.runCommand('event entity @s active')},3*20)
							system.runTimeout(() => {
								magic.runCommand('event entity @s form')
								if (volumeSetting === true) {
									magic.runCommand(`playsound tp_pw:ability.fire_blast @a ~~~`)
								}
							}, 7.75 * 20)
							system.runTimeout(() => {
								player.camera.fade({
									fadeTime: {
										fadeInTime: 0.2,
										holdTime: 0.0,
										fadeOutTime: 0.3
									},
									fadeColor: {
										red: 1,
										green: 1,
										blue: 1
									}
								})
							}, 7.75 * 20)
							//ATTACK ENDS
							system.runTimeout(()=>{
								const attackItem = getItemOnInventory(player, `tp_pw:${weapon}_attack${skill+1}`);
								if (attackItem) {
									const inventory = player.getComponent("minecraft:inventory");
									inventory.container.setItem(attackItem.slot, new ItemStack(`tp_pw:${weapon}`));
								}
								player.removeTag(`tp_pw:using_ability`)
								player.runCommand(`camera @s clear`)
								player.startItemCooldown(`tp_pw:${weapon}`, wp1CD[3]*20)
								player.runCommand(`scoreboard players set @s tp_pw:${weapon}_ULT 0`)
								{
									try {
										target.runCommand(`camera @s clear`)
										target.runCommand(`inputpermission set @s movement enabled`)
										target.runCommand(`inputpermission set @s camera enabled`)
										target.runCommand(`hud @s reset`)
									} catch (error) {
										
									}
								}
							},12.3*20)
						},1*20)
					})
				})
				player.runCommandAsync(`titleraw @p title { \"rawtext\": [ { \"translate\" : \"actionbar.tp_pw:${weapon}.4\" } ] }`)
			}
			break;
	}
}
function glacier_staff_skill(player, weapon, skill, petId, minLVL) {
	const cameraSetting = world.getDynamicProperty('tp_pw:camera')
	const volumeSetting = world.getDynamicProperty('tp_pw:sound')
	const lvl = world.scoreboard.getObjective(`tp_pw:${weapon}_LVL`)
	switch (skill) {
		case 0:
			{
				const damage = wp4Damage[0]+(lvl.getScore(player)-minLVL)
				player.playAnimation(`animation.tp_pw.glacier_staff.tpp_frozen_bolt`, {
					nextState: `none`,
					blendOutTime: 1,
					stopExpression: `query.any_animation_finished`,
					controller: `controller_name1`
				});
				if (volumeSetting === true) {
					const soundEntity = player.dimension.spawnEntity(`tp_pw:sound_entity`, player.location)
					soundEntity.setProperty('tp_pw:weapon', 'gs')
					soundEntity.setProperty('tp_pw:attack', 1)
					system.runTimeout(()=>{
						player.runCommand(`playsound tp_pw:n_ability.gs1 @a ~~~`)
					},1*20)
				}
				system.runTimeout(() => {
					const magic = player.dimension.spawnEntity('tp_pw:gs_attack1', {
						x: player.location.x + player.getViewDirection().x * 3,
						y: player.location.y,
						z: player.location.z + player.getViewDirection().z * 3
					})
					const damager = player.dimension.spawnEntity('tp_pw:gs_attack_damage', {
						x: player.location.x + player.getViewDirection().x * 3,
						y: player.location.y,
						z: player.location.z + player.getViewDirection().z * 3
					})
					for (let i = 0; i<30; i++) {
						magic.runCommand(`tp @s ~~-0.1~ ~~ true`)
					}
					magic.setRotation({
						x: 0,
						y: player.getRotation().y
					});
					const interval = system.runInterval(() => {
						const frontPlayer = {
							x: player.location.x + player.getViewDirection().x * 3,
							y: player.location.y,
							z: player.location.z + player.getViewDirection().z * 3
						}
						magic.runCommandAsync(`tp @s ${frontPlayer.x} ${frontPlayer.y} ${frontPlayer.z} ${player.getRotation().y} ${player.getRotation().x}`)
						damager.runCommandAsync(`tp @s ${player.location.x} ${player.location.y} ${player.location.z} ${player.getRotation().y} ${player.getRotation().x}`)
						for(let i=0;i<7;i++){
							damager.dimension.getEntities({maxDistance:4,location:damager.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
								if(target===damager||target===magic||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
								target.applyDamage(damage, {cause:'contact',damagingEntity:player})
								target.addEffect('slowness', 3*20, {amplifier:2})
							})
							damager.runCommandAsync(`tp @s ^^^1`)
						}
					})
					system.runTimeout(() => {
						system.clearRun(interval)
						magic.runCommand('event entity @s despawn')
					}, 6 * 20)
				}, 0.75 * 20)
				//ATTACK ENDS
				system.runTimeout(()=>{
					const attackItem = getItemOnInventory(player, `tp_pw:${weapon}_attack${skill+1}`);
					if (attackItem) {
						const inventory = player.getComponent("minecraft:inventory");
						inventory.container.setItem(attackItem.slot, new ItemStack(`tp_pw:${weapon}`));
					}
					player.removeTag(`tp_pw:using_ability`)
					player.startItemCooldown(`tp_pw:${weapon}`, wp4CD[0]*20)
				},1.75*20)
				player.runCommandAsync(`titleraw @p actionbar { \"rawtext\": [ { \"translate\" : \"actionbar.tp_pw:${weapon}.1\" } ] }`)
			}
			break;
		case 1:
			{
				const damage = wp4Damage[1]+(lvl.getScore(player)-minLVL)
				player.playAnimation(`animation.tp_pw.glacier_staff.tpp_chillwave`, {
					nextState: `none`,
					blendOutTime: 1,
					stopExpression: `query.any_animation_finished`,
					controller: `controller_name1`
				});
				const magic = player.dimension.spawnEntity('tp_pw:gs_attack2', {
					x: player.location.x + player.getViewDirection().x * 1,
					y: player.location.y,
					z: player.location.z + player.getViewDirection().z * 1
				})
				if (volumeSetting === true) {
					const soundEntity = player.dimension.spawnEntity(`tp_pw:sound_entity`, player.location)
					soundEntity.setProperty('tp_pw:weapon', 'gs')
					soundEntity.setProperty('tp_pw:attack', 2)
					player.runCommand('playsound tp_pw:n_ability.gs2 @a ~~~')
				}
				magic.setRotation({
					x: 0,
					y: player.getRotation().y
				});
				let maxDistance = 100;
				system.runTimeout(() => {
					try {
						player.getEntitiesFromViewDirection().forEach(target=>{
							if(target !== player || target !== projectile)
							{
								maxDistance = target.distance
								console.warn(`distance: ${target.distance}`)
							}
						})
					} catch (error) {
					}
					let currentX = player.location.x + player.getViewDirection().x * maxDistance;
					let currentY = player.location.y + player.getViewDirection().y * maxDistance;
					let currentZ = player.location.z + player.getViewDirection().z * maxDistance;
					try {
						const seenBlock = player.getBlockFromViewDirection().block
						if(seenBlock!==null){
							currentX = seenBlock.location.x
							currentY = seenBlock.location.y
							currentZ = seenBlock.location.z
						}
					} catch (error) {
						
					}
					let rot = {x:player.getRotation().x,y:player.getRotation().y}
					magic.setProperty('tp_pw:launched', true)
					const rotY = player.getRotation().y
					const rotX = player.getRotation().x
					magic.runCommandAsync(`tp @s ${player.location.x} ${player.location.y+1.5} ${player.location.z} ${player.getRotation().y} ${player.getRotation().x}`)
					// system.runInterval(()=>{
					// 	if(!magic.isValid()) return
					// 	try {
					// 		if(!magic.dimension.getBlock(magic.location).isAir){
					// 			const parLoc = {
					// 				x: magic.location.x,
					// 				y: magic.location.y+0.1,
					// 				z: magic.location.z
					// 			}
					// 			magic.runCommand('playsound tp_pw:n_ability.gs2_1 @a ~~~')
					// 			magic.dimension.spawnParticle('tp_pw:gs_explosion_1', parLoc)
					// 			magic.dimension.spawnParticle('tp_pw:gs_explosion_2', parLoc)
					// 			magic.dimension.spawnParticle('tp_pw:gs_explosion_3', parLoc)
					// 			magic.dimension.spawnParticle('tp_pw:gs_explosion_4', parLoc)
					// 			magic.dimension.spawnParticle('tp_pw:gs_explosion_5', parLoc)
					// 			magic.dimension.spawnParticle('tp_pw:gs_explosion_6', parLoc)
					// 			magic.dimension.spawnParticle('tp_pw:gs_explosion_7', parLoc)
					// 			magic.dimension.spawnParticle('tp_pw:gs_explosion_8', parLoc)
					// 			magic.dimension.spawnParticle('tp_pw:gs_explosion_9', parLoc)
					// 			magic.dimension.spawnParticle('tp_pw:gs_explosion_10', parLoc)
					// 			magic.remove()
					// 		}
					// 	} catch (error) {
							
					// 	}
					// 	magic.dimension.getEntities({maxDistance:3,location:magic.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
					// 		if(target===magic||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
					// 		console.warn('TARGET FOUND')
					// 		target.runCommand('playsound tp_pw:n_ability.gs2_1 @a ~~~')
					// 		target.applyDamage(damage, {cause:'contact',damagingEntity:player})
					// 		const parLoc = {
					// 			x: target.location.x,
					// 			y: target.location.y+0.1,
					// 			z: target.location.z
					// 		}
					// 		magic.dimension.spawnParticle('tp_pw:gs_explosion_1', parLoc)
					// 		magic.dimension.spawnParticle('tp_pw:gs_explosion_2', parLoc)
					// 		magic.dimension.spawnParticle('tp_pw:gs_explosion_3', parLoc)
					// 		magic.dimension.spawnParticle('tp_pw:gs_explosion_4', parLoc)
					// 		magic.dimension.spawnParticle('tp_pw:gs_explosion_5', parLoc)
					// 		magic.dimension.spawnParticle('tp_pw:gs_explosion_6', parLoc)
					// 		magic.dimension.spawnParticle('tp_pw:gs_explosion_7', parLoc)
					// 		magic.dimension.spawnParticle('tp_pw:gs_explosion_8', parLoc)
					// 		magic.dimension.spawnParticle('tp_pw:gs_explosion_9', parLoc)
					// 		magic.dimension.spawnParticle('tp_pw:gs_explosion_10', parLoc)
					// 		magic.remove()
					// 	})
					// 	//PERHATIAN
					// 	try {
					// 		magic.dimension.getEntities({maxDistance:3,location:magic.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
					// 			if(target===magic||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
					// 			console.warn('TARGET FOUND')
					// 			target.applyDamage(damage, {cause:'contact',damagingEntity:player})
					// 			const parLoc = {
					// 				x: target.location.x,
					// 				y: target.location.y+0.1,
					// 				z: target.location.z
					// 			}
					// 			magic.dimension.spawnParticle('tp_pw:gs_explosion_1', parLoc)
					// 			magic.dimension.spawnParticle('tp_pw:gs_explosion_2', parLoc)
					// 			magic.dimension.spawnParticle('tp_pw:gs_explosion_3', parLoc)
					// 			magic.dimension.spawnParticle('tp_pw:gs_explosion_4', parLoc)
					// 			magic.dimension.spawnParticle('tp_pw:gs_explosion_5', parLoc)
					// 			magic.dimension.spawnParticle('tp_pw:gs_explosion_6', parLoc)
					// 			magic.dimension.spawnParticle('tp_pw:gs_explosion_7', parLoc)
					// 			magic.dimension.spawnParticle('tp_pw:gs_explosion_8', parLoc)
					// 			magic.dimension.spawnParticle('tp_pw:gs_explosion_9', parLoc)
					// 			magic.dimension.spawnParticle('tp_pw:gs_explosion_10', parLoc)
					// 			magic.remove()
					// 		})
					// 	} catch (error) {
							
					// 	}
					// 	if(!magic.isValid()) return
					// 	magic.runCommandAsync(`tp @s ^^^1 ${rotY} ${rotX}`)
					// })
					const move = system.runInterval(()=>{
						const projectile = magic
						if(!projectile.isValid()) return
						projectile.runCommand(`tp @s ^^^1 facing ${currentX} ${currentY} ${currentZ}`)
						try {
							if(!projectile.dimension.getBlock(projectile.location).isAir){
								console.warn(`hit block`)
								projectile.dimension.getEntities({maxDistance:5,location:projectile.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
									if(target===projectile||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
									console.warn('TARGET FOUND')
									target.runCommand('playsound tp_pw:n_ability.gs2_1 @a ~~~')
									target.applyDamage(damage, {cause:'contact',damagingEntity:player})
								})
								const parLoc = {
									x: projectile.location.x,
									y: projectile.location.y+0.1,
									z: projectile.location.z
								}
								projectile.runCommand('playsound tp_pw:n_ability.gs2_1 @a ~~~')
								projectile.dimension.spawnParticle('tp_pw:gs_explosion_1', parLoc)
								projectile.dimension.spawnParticle('tp_pw:gs_explosion_2', parLoc)
								projectile.dimension.spawnParticle('tp_pw:gs_explosion_3', parLoc)
								projectile.dimension.spawnParticle('tp_pw:gs_explosion_4', parLoc)
								projectile.dimension.spawnParticle('tp_pw:gs_explosion_5', parLoc)
								projectile.dimension.spawnParticle('tp_pw:gs_explosion_6', parLoc)
								projectile.dimension.spawnParticle('tp_pw:gs_explosion_7', parLoc)
								projectile.dimension.spawnParticle('tp_pw:gs_explosion_8', parLoc)
								projectile.dimension.spawnParticle('tp_pw:gs_explosion_9', parLoc)
								projectile.dimension.spawnParticle('tp_pw:gs_explosion_10', parLoc)
								projectile.remove()
								system.clearRun(move)
							}
							if(projectile.location.x===currentX && projectile.location.y===currentY && projectile.location.z===currentZ){
								const parLoc = {
									x: projectile.location.x,
									y: projectile.location.y+0.1,
									z: projectile.location.z
								}
								projectile.runCommand('playsound tp_pw:n_ability.gs2_1 @a ~~~')
								projectile.dimension.spawnParticle('tp_pw:gs_explosion_1', parLoc)
								projectile.dimension.spawnParticle('tp_pw:gs_explosion_2', parLoc)
								projectile.dimension.spawnParticle('tp_pw:gs_explosion_3', parLoc)
								projectile.dimension.spawnParticle('tp_pw:gs_explosion_4', parLoc)
								projectile.dimension.spawnParticle('tp_pw:gs_explosion_5', parLoc)
								projectile.dimension.spawnParticle('tp_pw:gs_explosion_6', parLoc)
								projectile.dimension.spawnParticle('tp_pw:gs_explosion_7', parLoc)
								projectile.dimension.spawnParticle('tp_pw:gs_explosion_8', parLoc)
								projectile.dimension.spawnParticle('tp_pw:gs_explosion_9', parLoc)
								projectile.dimension.spawnParticle('tp_pw:gs_explosion_10', parLoc)
								projectile.dimension.getEntities({maxDistance:5,location:projectile.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
									if(target===projectile||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
									target.applyDamage(damage, {cause:'contact',damagingEntity:player})
									target.applyKnockback((target.location.x-projectile.location.x), (target.location.z-projectile.location.z), 1, 1)
			
								})
								projectile.remove()
								system.clearRun(move)
							}
							projectile.dimension.getEntities({maxDistance:3,location:projectile.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
								if(target===projectile||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
								//EFFECT
								target.applyDamage(damage, {cause:'contact',damagingEntity:player})
								target.applyKnockback((target.location.x-projectile.location.x), (target.location.z-projectile.location.z), 1, 1)
								if (volumeSetting === true) {
									projectile.runCommand('playsound tp_pw:n_ability.gs2_1 @a ~~~')
								}
								const parLoc = {
									x: projectile.location.x,
									y: projectile.location.y+0.1,
									z: projectile.location.z
								}
								projectile.dimension.spawnParticle('tp_pw:gs_explosion_1', parLoc)
								projectile.dimension.spawnParticle('tp_pw:gs_explosion_2', parLoc)
								projectile.dimension.spawnParticle('tp_pw:gs_explosion_3', parLoc)
								projectile.dimension.spawnParticle('tp_pw:gs_explosion_4', parLoc)
								projectile.dimension.spawnParticle('tp_pw:gs_explosion_5', parLoc)
								projectile.dimension.spawnParticle('tp_pw:gs_explosion_6', parLoc)
								projectile.dimension.spawnParticle('tp_pw:gs_explosion_7', parLoc)
								projectile.dimension.spawnParticle('tp_pw:gs_explosion_8', parLoc)
								projectile.dimension.spawnParticle('tp_pw:gs_explosion_9', parLoc)
								projectile.dimension.spawnParticle('tp_pw:gs_explosion_10', parLoc)
								projectile.dimension.getEntities({maxDistance:5,location:projectile.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
									if(target===projectile||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
									target.applyDamage(damage, {cause:'contact',damagingEntity:player})
									target.applyKnockback((target.location.x-projectile.location.x), (target.location.z-projectile.location.z), 1, 1)
								})
								projectile.remove()
								system.clearRun(move)
							})
						} catch (error) {
							
						}
					}, 0.01)
				}, 1.38 * 20)
				//ATTACK ENDS
				system.runTimeout(()=>{
					const attackItem = getItemOnInventory(player, `tp_pw:${weapon}_attack${skill+1}`);
					if (attackItem) {
						const inventory = player.getComponent("minecraft:inventory");
						inventory.container.setItem(attackItem.slot, new ItemStack(`tp_pw:${weapon}`));
					}
					player.removeTag(`tp_pw:using_ability`)
					player.startItemCooldown(`tp_pw:${weapon}`, wp4CD[1]*20)
				},2.5*20)
				player.runCommandAsync(`titleraw @p actionbar { \"rawtext\": [ { \"translate\" : \"actionbar.tp_pw:${weapon}.2\" } ] }`)
			}
			break;
		case 2:
			{
				const damage = wp4Damage[2]+(lvl.getScore(player)-minLVL)
				player.playAnimation(`animation.tp_pw.glacier_staff.tpp_winter_spikes`, {
					nextState: `none`,
					blendOutTime: 1,
					stopExpression: `query.any_animation_finished`,
					controller: `controller_name1`
				});
				const magic = player.dimension.spawnEntity('tp_pw:gs_attack3', {
					x: player.location.x + player.getViewDirection().x * 3,
					y: player.location.y,
					z: player.location.z + player.getViewDirection().z * 3
				})
				for (let i = 0; i<30; i++) {
					magic.runCommand(`tp @s ~~-0.1~ ~~ true`)
				}
				if (volumeSetting === true) {
					const soundEntity = player.dimension.spawnEntity(`tp_pw:sound_entity`, player.location)
					soundEntity.setProperty('tp_pw:weapon', 'gs')
					soundEntity.setProperty('tp_pw:attack', 3)
					system.runTimeout(()=>{
						magic.runCommand(`playsound tp_pw:n_ability.gs3 @a ~~~`)
					}, 0.8*20)
				}
				magic.setRotation({
					x: 0,
					y: player.getRotation().y
				});
				system.runTimeout(() => {
					{
						const loc = {
							x:magic.location.x,
							y:magic.location.y+0.1,
							z:magic.location.z
						}
						const loc2 = {
							x:magic.location.x,
							y:magic.location.y+2,
							z:magic.location.z
						}
						magic.dimension.spawnParticle(`tp_pw:icey_effect_1`, loc)
						magic.dimension.spawnParticle(`tp_pw:icey_effect_2`, loc2)
						magic.dimension.spawnParticle(`tp_pw:icey_effect_3`, loc)
						magic.dimension.spawnParticle(`tp_pw:icey_effect_4`, loc)
						magic.dimension.spawnParticle(`tp_pw:icey_effect_5`, loc)
						system.runTimeout(()=>{
							if (volumeSetting === true) {
								magic.runCommand(`playsound tp_pw:n_ability.gs3_1 @a ~~~`)
							}
							magic.dimension.spawnParticle('tp_pw:gs_explosion_1', loc)
							magic.dimension.spawnParticle('tp_pw:gs_explosion_2', loc)
							//magic.dimension.spawnParticle('tp_pw:gs_explosion_3', loc)
							magic.dimension.spawnParticle('tp_pw:gs_explosion_4', loc)
							magic.dimension.spawnParticle('tp_pw:gs_explosion_5', loc)
							magic.dimension.spawnParticle('tp_pw:gs_explosion_6', loc)
							magic.dimension.spawnParticle('tp_pw:gs_explosion_7', loc)
							magic.dimension.spawnParticle('tp_pw:gs_explosion_8', loc)
							magic.dimension.spawnParticle('tp_pw:gs_explosion_9', loc)
							magic.dimension.spawnParticle('tp_pw:gs_explosion_10', loc)
						}, 7.0*20)
					}
					const interval = system.runInterval(() => {
						if (magic.isValid() === true) {
							magic.dimension.getEntities({maxDistance:8,location:magic.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
								if(target===magic||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
								target.applyDamage(damage, {cause:'contact',damagingEntity:player})
								target.addEffect('slowness', 1*20, {amplifier:10})
							})
						} else {
							system.clearRun(interval)
						}
					})
					system.runTimeout(() => {
						system.clearRun(interval)
						magic.remove()
					}, 8 * 20)
				}, 0.7 * 20)
				//ATTACK ENDS
				system.runTimeout(()=>{
					//player.runCommand(`scoreboard players set @s tp_pw:${weapon}_ULT 0`)
					const attackItem = getItemOnInventory(player, `tp_pw:${weapon}_attack${skill+1}`);
					if (attackItem) {
						const inventory = player.getComponent("minecraft:inventory");
						inventory.container.setItem(attackItem.slot, new ItemStack(`tp_pw:${weapon}`));
					}
					player.removeTag(`tp_pw:using_ability`)
					player.startItemCooldown(`tp_pw:${weapon}`, wp4CD[2]*20)
				},1.25*20)
				player.runCommandAsync(`titleraw @p actionbar { \"rawtext\": [ { \"translate\" : \"actionbar.tp_pw:${weapon}.3\" } ] }`)
			}
			break;
		case 3:
			{
				const damage = wp4Damage[3]+(lvl.getScore(player)-minLVL)
				const petEntity = player.dimension.getEntities({type: `tp_pw:frost_fox`,maxDistance: 15, location: {x:player.location.x,y:player.location.y,z:player.location.z}, tags:[`tp_pw:`+player.id]})
				const magic = player.dimension.spawnEntity('tp_pw:gs_attack4', {
					x: player.location.x + player.getViewDirection().x * 4,
					y: player.location.y,
					z: player.location.z + player.getViewDirection().z * 4
				})
				for (let i = 0; i<30; i++) {
					magic.runCommand(`tp @s ~~-0.1~ ~~ true`)
				}
				magic.setRotation({
					x: 0,
					y: player.getRotation().y + 180
				});
				system.runTimeout(() => {
					petEntity.forEach(pet=>{
						magic.dimension.getEntities({maxDistance:10,location:magic.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
							{
								target.runCommand(`inputpermission set @s camera disabled`)
								target.runCommand(`inputpermission set @s movement disabled`)
								target.runCommand(`hud @s hide`)
								if(target.typeId!=='minecraft:player'){target.addEffect('slowness',14.8*20,{amplifier:255})}
								target.runCommand(`camera @s fade time 0.5 0.5 0.2 color 255 255 255`)
							}
							system.runTimeout(()=>{
								if (cameraSetting === true && target.typeId==='minecraft:player') {
									target.addTag(`tp_pw:${magic.id}`)
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^ ^1.5 ^ facing ${player.location.x} ${player.location.y+1} ${player.location.z}`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 2.5 linear pos ^ ^1.5 ^1 facing ${player.location.x} ${player.location.y+1} ${player.location.z}`)
									})
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^ ^4 ^7 facing ~~~`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 0.5 linear pos ^ ^3 ^6 facing ~~~`)
									},2.5*20)
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^-8 ^0.5 ^ facing ~~~`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 1.0 linear pos ^-7 ^0.5 ^ facing ~~~`)
									},5*20)
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^5 ^1 ^ facing ${player.location.x} ${player.location.y} ${player.location.z}`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 0.5 linear pos ^6 ^2 ^ facing ${player.location.x} ${player.location.y} ${player.location.z}`)
									},8*20)
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^3.3 ^1 ^8 facing ~~~`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 0.3 linear pos ^3.5 ^1 ^9 facing ~~~`)
									},10.5*20)
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^3.5 ^1 ^9 facing ~~~`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 0.3 linear pos ^1 ^1 ^1 facing ^-2^^-2`)
									},11.5*20)
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^-8 ^0.5 ^ facing ~~~`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 1.0 linear pos ^-9 ^0.5 ^ facing ~~1~`)
									},12.5*20)

								}
								//CameraShake
								if (target.typeId==='minecraft:player') {
									cameraShake(2.5, target, 0.5, 0.5, 'positional')
									cameraShake(6, target, 0.5, 1, 'positional')
									cameraShake(1.25+8, target, 0.3, 2, 'positional')
									cameraShake(12, target, 0.5, 3, 'positional')
								}
								//Camera Clear
								system.runTimeout(() => {
									target.runCommand(`camera @s fade time 0.3 1 1 color 255 255 255`)
								},14.5*20)
								system.runTimeout(() => {
									magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] clear`)
									magic.dimension.getEntities({tags:[`tp_pw:`+magic.id]}).forEach(victim=>{victim.removeTag(`tp_pw:`+magic.id)})
								},14.8*20)
								//ATTACK ENDS
								system.runTimeout(()=>{
									const attackItem = getItemOnInventory(player, `tp_pw:${weapon}_attack${skill+1}`);
									if (attackItem) {
										const inventory = player.getComponent("minecraft:inventory");
										inventory.container.setItem(attackItem.slot, new ItemStack(`tp_pw:${weapon}`));
									}
									player.removeTag(`tp_pw:using_ability`)
									player.startItemCooldown(`tp_pw:${weapon}`, wp4CD[3]*20)
									player.runCommand(`scoreboard players set @s tp_pw:${weapon}_ULT 0`)
									{
										try {
											target.runCommand(`camera @s clear`)
											target.runCommand(`inputpermission set @s movement enabled`)
											target.runCommand(`inputpermission set @s camera enabled`)
											target.runCommand(`hud @s reset`)
										} catch (error) {
											
										}
									}
									if(target===magic||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
									target.applyDamage(damage, {cause:'contact',damagingEntity:player})
								},14.8*20)
								//Damaged illusion
								{
									if(target===magic||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
									damageIllusion(target, 2.54)
									damageIllusion(target, 6.2)
									damageIllusion(target, 4.25+8)
								}
							},1*20)
						})
						system.runTimeout(()=>{
							pet.addEffect('invisibility', 14.8*20)
							player.runCommand('title @s clear')
							player.playAnimation(`animation.tp_pw.glacier_staff.tpp_blizzard_of_the_fox`, {
								nextState: `none`,
								blendOutTime: 1,
								stopExpression: `query.any_animation_finished`,
								controller: `controller_name1`
							});
							if (volumeSetting === true) {
								system.runTimeout(()=>{
									playSoundUltimate(magic, 'tp_pw:n_ability.gs_ultimate_player', 0.0)
									playSoundUltimate(magic, 'tp_pw:n_ability.ultimate_tension', 0.0)
									playSoundUltimate(magic, 'tp_pw:n_ability.botw_rune', 2.5)
									playSoundUltimate(magic, 'tp_pw:n_ability.botw_ultimate_ambient', 2.6)
									playSoundUltimate(magic, 'tp_pw:n_ability.gs3_ult', 6.0)
									playSoundUltimate(magic, 'tp_pw:n_ability.gs1_ult', 2.5)
									playSoundUltimate(magic, 'tp_pw:n_ability.gs3_1_ult', 12.0)
									playSoundUltimate(magic, 'tp_pw:n_ability.gs_ultimate_fox', 8.2)
								})
							}
							//Entity Effects
							system.runTimeout(()=>{magic.runCommand('event entity @s active')},2.5*20)
							system.runTimeout(()=>{
								magic.runCommand('event entity @s active2')
							},8*20)
							//Particle Effects
							{
								system.runTimeout(()=>{
									const loc = {
										x:magic.location.x,
										y:magic.location.y+0.1,
										z:magic.location.z,
									}
									magic.dimension.spawnParticle('tp_pw:runic_binding_circle_cute_1', loc)
									magic.dimension.spawnParticle('tp_pw:runic_binding_circle_cute_2', loc)
								},2.5*20)
								system.runTimeout(()=>{
									const loc = {
										x:magic.location.x,
										y:magic.location.y+0.1,
										z:magic.location.z,
									}
									magic.dimension.spawnParticle('tp_pw:runic_binding_circle_cute_4', loc)
									magic.dimension.spawnParticle('tp_pw:runic_binding_circle_cute_5', loc)
									magic.dimension.spawnParticle('tp_pw:runic_binding_circle_cute_6', loc)
								},3*20)
								system.runTimeout(()=>{
									const loc = {
										x:magic.location.x,
										y:magic.location.y+0.1,
										z:magic.location.z,
									}
									magic.dimension.spawnParticle('tp_pw:runic_binding_circle_cute_7', loc)
								},5*20)
								system.runTimeout(()=>{
									const loc = {
										x:magic.location.x,
										y:magic.location.y+0.1,
										z:magic.location.z,
									}
									magic.dimension.spawnParticle('tp_pw:icey_effect_1_ultimate', loc)
									magic.dimension.spawnParticle('tp_pw:icey_effect_2', loc)
									magic.dimension.spawnParticle('tp_pw:icey_effect_4', loc)
									magic.dimension.spawnParticle('tp_pw:runic_binding_circle_cute_10', loc)
									magic.dimension.spawnParticle('tp_pw:runic_binding_circle_cute_15', loc)
								},6*20)
								system.runTimeout(()=>{
									const loc = {
										x:magic.location.x,
										y:magic.location.y+0.1,
										z:magic.location.z,
									}
									magic.dimension.spawnParticle('tp_pw:icey_effect_4', loc)
								},12*20)
							}
						},1*20)
					})
				})
				player.runCommandAsync(`titleraw @p title { \"rawtext\": [ { \"translate\" : \"actionbar.tp_pw:${weapon}.4\" } ] }`)
			}
			break;
	}
}
function mystic_flute_skill(player, weapon, skill, petId, minLVL) {
	const cameraSetting = world.getDynamicProperty('tp_pw:camera')
	const volumeSetting = world.getDynamicProperty('tp_pw:sound')
	const lvl = world.scoreboard.getObjective(`tp_pw:${weapon}_LVL`)
	switch (skill) {
		case 0:
			{
				const damage = wp5Damage[0]+(lvl.getScore(player)-minLVL)
				player.playAnimation(`animation.tp_pw.mystic_flute.tpp_harmony_strike`, {
					nextState: `none`,
					blendOutTime: 1,
					stopExpression: `query.any_animation_finished`,
					controller: `controller_name1`
				});
				const magic = player.dimension.spawnEntity('tp_pw:mf_attack1', {
					x: player.location.x + player.getViewDirection().x * 2,
					y: player.location.y,
					z: player.location.z + player.getViewDirection().z * 2
				})
				const damager = player.dimension.spawnEntity('tp_pw:mf_attack1_damage', {
					x: player.location.x + player.getViewDirection().x * 2,
					y: player.location.y,
					z: player.location.z + player.getViewDirection().z * 2
				})
				for (let i = 0; i<30; i++) {
					magic.runCommand(`tp @s ~~-0.1~ ~~ true`)
				}
				magic.setRotation({
					x: 0,
					y: player.getRotation().y
				});
				if (volumeSetting === true) {
					// const soundEntity = player.dimension.spawnEntity(`tp_pw:sound_entity`, player.location)
					// soundEntity.setProperty('tp_pw:weapon', 'mf')
					// soundEntity.setProperty('tp_pw:attack', 1)
					system.runTimeout(()=>{
						player.runCommand(`playsound tp_pw:n_ability.mf1 @a ~~~`)
						player.runCommand(`playsound tp_pw:n_ability.flute_melody @a ~~~`)
						player.runCommand(`playsound tp_pw:n_ability.earthquake @a ~~~`)
					})
				}
				const interval = system.runInterval(() => {
					magic.runCommandAsync(`tp @s ${player.location.x} ${player.location.y+1} ${player.location.z} ${player.getRotation().y} ${player.getRotation().x}`)
					damager.runCommandAsync(`tp @s ${player.location.x} ${player.location.y+1} ${player.location.z} ${player.getRotation().y} ${player.getRotation().x}`)
					for(let i=0;i<10;i++){
						damager.dimension.getEntities({maxDistance:i*2,location:damager.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
							if(target===magic||target===damager||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
							target.applyDamage(damage, {cause:'contact',damagingEntity:player})
						})
						damager.runCommandAsync(`tp @s ^^^2`)
					}
				})
				system.runTimeout(() => {
					system.clearRun(interval)
					magic.remove()
				}, 6 * 20)
				//ATTACK ENDS
				system.runTimeout(()=>{
					const attackItem = getItemOnInventory(player, `tp_pw:${weapon}_attack${skill+1}`);
					if (attackItem) {
						const inventory = player.getComponent("minecraft:inventory");
						inventory.container.setItem(attackItem.slot, new ItemStack(`tp_pw:${weapon}`));
					}
					player.removeTag(`tp_pw:using_ability`)
					player.startItemCooldown(`tp_pw:${weapon}`, wp5CD[0]*20)
				},1.4167*20)
				player.runCommandAsync(`titleraw @p actionbar { \"rawtext\": [ { \"translate\" : \"actionbar.tp_pw:${weapon}.1\" } ] }`)
			}
			break;
		case 1:
			{
				const damage = wp5Damage[2]+(lvl.getScore(player)-minLVL)
				player.playAnimation(`animation.tp_pw.mystic_flute.tpp_wind_dance`, {
					nextState: `none`,
					blendOutTime: 1,
					stopExpression: `query.any_animation_finished`,
					controller: `controller_name1`
				});
				if (volumeSetting === true) {
					// const soundEntity = player.dimension.spawnEntity(`tp_pw:sound_entity`, player.location)
					// soundEntity.setProperty('tp_pw:weapon', 'mf')
					// soundEntity.setProperty('tp_pw:attack', 3)
					player.runCommand(`playsound tp_pw:n_ability.flute_melody_1 @a ~~~`)
				}
				system.runTimeout(() => {
					const magic = player.dimension.spawnEntity('tp_pw:mf_attack3', {
						x: player.location.x,
						y: player.location.y,
						z: player.location.z
					})
					const damager = player.dimension.spawnEntity('tp_pw:mf_attack1_damage', {
						x: player.location.x + player.getViewDirection().x * 2,
						y: player.location.y,
						z: player.location.z + player.getViewDirection().z * 2
					})
					for (let i = 0; i<30; i++) {
						magic.runCommand(`tp @s ~~-0.1~ ~~ true`)
					}
					magic.setRotation({
						x: 0,
						y: player.getRotation().y
					});
					const teleport = system.runInterval(()=>{
						magic.runCommandAsync(`tp @s ${player.location.x} ${player.location.y+1} ${player.location.z} ${player.getRotation().y} ${player.getRotation().x}`)
					})
					system.runTimeout(() => {
						if (volumeSetting === true) {
							player.runCommand(`playsound tp_pw:ability.bass_ambient @a ~~~`)
							player.runCommand(`playsound tp_pw:ability.blackhole_exploding @a ~~~`)
						}
						system.clearRun(teleport)
						for(let i=0;i<15;i++){
							damager.dimension.getEntities({maxDistance:i*2,location:damager.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
								if(target===damager||target===magic||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
								target.applyDamage(damage, {cause:'contact',damagingEntity:player})
							})
							damager.runCommandAsync(`tp @s ^^^2`)
						}
					}, 3.0 * 20)
					system.runTimeout(() => {
						magic.runCommand(`event entity @s despawn`)
					}, 5.0 * 20)
				}, 0.25 * 20)
				//ATTACK ENDS
				system.runTimeout(()=>{
					const attackItem = getItemOnInventory(player, `tp_pw:${weapon}_attack${skill+1}`);
					if (attackItem) {
						const inventory = player.getComponent("minecraft:inventory");
						inventory.container.setItem(attackItem.slot, new ItemStack(`tp_pw:${weapon}`));
					}
					player.removeTag(`tp_pw:using_ability`)
					player.startItemCooldown(`tp_pw:${weapon}`, wp5CD[2]*20)
				},1.875*20)
				player.runCommandAsync(`titleraw @p actionbar { \"rawtext\": [ { \"translate\" : \"actionbar.tp_pw:${weapon}.2\" } ] }`)
			}
			break;
		case 2:
			{
				const damage = wp5Damage[1]+(lvl.getScore(player)-minLVL)
				player.addEffect('resistance', 5.52*20, {amplifier:10, showParticles:false})
				player.playAnimation(`animation.tp_pw.mystic_flute.tpp_sonic_boom`, {
					nextState: `none`,
					blendOutTime: 1,
					stopExpression: `query.any_animation_finished`,
					controller: `controller_name1`
				});
				if (volumeSetting === true) {
					// const soundEntity = player.dimension.spawnEntity(`tp_pw:sound_entity`, player.location)
					// soundEntity.setProperty('tp_pw:weapon', 'mf')
					// soundEntity.setProperty('tp_pw:attack', 2)
					player.runCommand(`playsound tp_pw:n_ability.flute_melody_2 @a ~~~`)
				}
				system.runTimeout(() => {
					const magic = player.dimension.spawnEntity('tp_pw:mf_attack2', {
						x: player.location.x,
						y: player.location.y,
						z: player.location.z
					})
					for (let i = 0; i<30; i++) {
						magic.runCommand(`tp @s ~~-0.1~ ~~ true`)
					}
					magic.setRotation({
						x: 0,
						y: player.getRotation().y
					});
					const interval = system.runInterval(() => {
						if(!magic.isValid())return
						magic.runCommand(`tp @s ${player.location.x} ${player.location.y} ${player.location.z}`)
					})
					system.runTimeout(() => {
						if (volumeSetting === true) {
							player.runCommand(`playsound tp_pw:ability.bass_ambient @a ~~~`)
							player.runCommand(`playsound tp_pw:ability.blackhole_exploding @a ~~~`)
						}
						magic.dimension.getEntities({maxDistance:8,location:magic.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
							if(target===magic||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
							target.applyDamage(damage, {cause:'contact',damagingEntity:player})
							target.applyKnockback((target.location.x-player.location.x),(target.location.z-player.location.z),1,1)
						})
						system.clearRun(interval)
						magic.runCommand(`event entity @s despawn`)
					}, 5.52 * 20)
				}, 0.25 * 20)
				//ATTACK ENDS
				system.runTimeout(()=>{
					const attackItem = getItemOnInventory(player, `tp_pw:${weapon}_attack${skill+1}`);
					if (attackItem) {
						const inventory = player.getComponent("minecraft:inventory");
						inventory.container.setItem(attackItem.slot, new ItemStack(`tp_pw:${weapon}`));
					}
					player.removeTag(`tp_pw:using_ability`)
					player.startItemCooldown(`tp_pw:${weapon}`, wp5CD[1]*20)
				},1.4167*20)
				player.runCommandAsync(`titleraw @p actionbar { \"rawtext\": [ { \"translate\" : \"actionbar.tp_pw:${weapon}.3\" } ] }`)
			}
			break;
		case 3:
			{
				const damage = wp5Damage[3]+(lvl.getScore(player)-minLVL)
				const petEntity = player.dimension.getEntities({type: `tp_pw:music_golem`,maxDistance: 15, location: {x:player.location.x,y:player.location.y,z:player.location.z}, tags:[`tp_pw:`+player.id]})
				const magic = player.dimension.spawnEntity('tp_pw:mf_attack4', {
					x: player.location.x + player.getViewDirection().x * 4,
					y: player.location.y,
					z: player.location.z + player.getViewDirection().z * 4
				})
				for (let i = 0; i<30; i++) {
					magic.runCommand(`tp @s ~~-0.1~ ~~ true`)
				}
				magic.setRotation({
					x: 0,
					y: player.getRotation().y + 180
				});
				system.runTimeout(() => {
					petEntity.forEach(pet=>{
						//Target Select Section (Camera, Damage)
						magic.dimension.getEntities({maxDistance:10,location:magic.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
							{
								target.runCommand(`inputpermission set @s movement disabled`)
								target.runCommand(`hud @s hide`)
								target.runCommand(`camera @s fade time 0.5 0.5 0.2 color 255 255 255`)
								if(target.typeId!=='minecraft:player'){target.addEffect('slowness',6.3*20,{amplifier:255})}
							}
							system.runTimeout(()=>{
								if (cameraSetting === true && target.typeId==='minecraft:player') {
									target.addTag(`tp_pw:${magic.id}`)
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^ ^2 ^1 facing ${player.location.x} ${player.location.y+1} ${player.location.z}`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 3.0 linear pos ^ ^3 ^-3 facing ${player.location.x} ${player.location.y+1} ${player.location.z}`)
									})
									system.runTimeout(() => {
										magic.runCommand('camera @p set minecraft:free pos ^ ^1 ^7 facing ~~1~')
										magic.runCommandAsync('camera @p set minecraft:free ease 0.10 linear pos ^^1^8 facing ~~1~')
									},3*20)
									system.runTimeout(() => {
										magic.runCommand('camera @p set minecraft:free pos ^6 ^1 ^8 facing ^^^3')
										magic.runCommandAsync('camera @p set minecraft:free ease 2.0 linear pos ^8^1^8 facing ^^^3')
									},4.0*20)
									system.runTimeout(() => {
										magic.runCommand('camera @p set minecraft:free pos ^ ^3 ^-6 facing ^^^0')
										magic.runCommandAsync('camera @p set minecraft:free ease 0.3 linear pos ^^3^-7 facing ~~2~')
									}, 6 * 20)
									system.runTimeout(() => {
										magic.runCommand('camera @p set minecraft:free pos ^10 ^3 ^ facing ^^^0')
										magic.runCommandAsync('camera @p set minecraft:free ease 0.5 linear pos ^14^3^ facing ~~2~')
									}, 6.8 * 20)
								}
								//CameraShake
								if (target.typeId==='minecraft:player') {
									cameraShake(2, target, 0.5, 1, 'positional')
									cameraShake(6, target, 0.5, 1, 'positional')
									cameraShake(6.8, target, 1, 3, 'positional')
								}
								//Camera Clear
								system.runTimeout(() => {
									target.runCommand(`camera @s fade time 0.3 1 1 color 255 255 255`)
								},8.0*20)
								system.runTimeout(() => {
									magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] clear`)
									magic.dimension.getEntities({tags:[`tp_pw:`+magic.id]}).forEach(victim=>{victim.removeTag(`tp_pw:`+magic.id)})
								},8.3*20)
								//ATTACK ENDS
								system.runTimeout(()=>{
									player.runCommand(`scoreboard players set @s tp_pw:${weapon}_ULT 0`)
									const attackItem = getItemOnInventory(player, `tp_pw:${weapon}_attack${skill+1}`);
									if (attackItem) {
										const inventory = player.getComponent("minecraft:inventory");
										inventory.container.setItem(attackItem.slot, new ItemStack(`tp_pw:${weapon}`));
									}
									player.removeTag(`tp_pw:using_ability`)
									player.startItemCooldown(`tp_pw:${weapon}`, wp5CD[3]*20)
									{
										try {
											target.runCommand(`camera @s clear`)
											target.runCommand(`inputpermission set @s movement enabled`)
											target.runCommand(`inputpermission set @s camera enabled`)
											target.runCommand(`hud @s reset`)
										} catch (error) {
											
										}
									}
									if(target===magic||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
									target.applyDamage(damage, {cause:'contact',damagingEntity:player})
								},8.5*20)
								//Damaged illusion
								{
									if(target===magic||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
									damageIllusion(target, 1.21)
									damageIllusion(target, 2.75+3)
									damageIllusion(target, 3.8+3)
								}
							},1*20)
						})
						//Technical Section (Animations, Particles, Effects)
						system.runTimeout(()=>{
							pet.runCommand('effect @s invisibility 9 0 true')
							player.runCommand('title @s clear')
							player.playAnimation(`animation.tp_pw.mystic_flute.tpp_flute_symphony`, {
								nextState: `none`,
								blendOutTime: 1,
								stopExpression: `query.any_animation_finished`,
								controller: `controller_name1`
							});
							if (volumeSetting === true) {
								system.runTimeout(()=>{
									playSoundUltimate(magic, 'tp_pw:n_ability.ultimate_tension', 0.0)
									playSoundUltimate(magic, 'tp_pw:n_ability.botw_rune', 2.03)
									playSoundUltimate(magic, 'tp_pw:n_ability.botw_ultimate_ambient', 2.05)
									playSoundUltimate(magic, 'tp_pw:n_ability.flute_melody_2_ult', 1.25)
									playSoundUltimate(magic, 'tp_pw:n_ability.flute_melody_1_ult', 3.13)
									playSoundUltimate(magic, 'tp_pw:n_ability.flute_melody_ult', 5.17)
									playSoundUltimate(magic, 'tp_pw:n_ability.mf_ultimate_pet', 3.0)
								})
							}
							//Particle Effects
							{
								system.runTimeout(()=>{
									const loc = {
										x:magic.location.x,
										y:magic.location.y+0.1,
										z:magic.location.z
									}
									const loc2 = {
										x:magic.location.x,
										y:magic.location.y+1,
										z:magic.location.z
									}
									magic.dimension.spawnParticle('tp_pw:dancing_circle_1', loc)
									magic.dimension.spawnParticle('tp_pw:dancing_circle_2', loc2)
								},2*20)
								system.runTimeout(()=>{
									const loc = {
										x:magic.location.x,
										y:magic.location.y+2,
										z:magic.location.z
									}
									const loc2 = {
										x:magic.location.x,
										y:magic.location.y+1,
										z:magic.location.z
									}
									magic.dimension.spawnParticle('tp_pw:dancing_circle_4', loc)
								},6.5*20)
								system.runTimeout(()=>{
									const loc = {
										x:magic.location.x,
										y:magic.location.y,
										z:magic.location.z
									}
									magic.dimension.spawnParticle('tp_pw:spirit_bond_2', loc)
									magic.dimension.spawnParticle('tp_pw:spirit_bond_3', loc)
									magic.dimension.spawnParticle('tp_pw:spirit_bond_4', loc)
									magic.dimension.spawnParticle('tp_pw:spirit_bond_5', loc)
									magic.dimension.spawnParticle('tp_pw:spirit_bond_6', loc)
								},6.8*20)
							}
							//Entity Effects
							system.runTimeout(()=>{magic.runCommand('event entity @s active')},3*20)
						},1*20)
					})
				})
				player.runCommandAsync(`titleraw @p title { \"rawtext\": [ { \"translate\" : \"actionbar.tp_pw:${weapon}.4\" } ] }`)
			}
			break;
	}
}
function thunder_mace_skill(player, weapon, skill, petId, minLVL) {
	const cameraSetting = world.getDynamicProperty('tp_pw:camera')
	const volumeSetting = world.getDynamicProperty('tp_pw:sound')
	const lvl = world.scoreboard.getObjective(`tp_pw:${weapon}_LVL`)
	switch (skill) {
		case 0:
			{
				const damage = wp6Damage[0]+(lvl.getScore(player)-minLVL)
				player.playAnimation(`animation.tp_pw.thunder_mace.tpp_thunder_strike`, {
					nextState: `none`,
					blendOutTime: 1,
					stopExpression: `query.any_animation_finished`,
					controller: `controller_name1`
				});
				const magic = player.dimension.spawnEntity('tp_pw:tm_attack1', {
					x: player.location.x + player.getViewDirection().x * 2,
					y: player.location.y,
					z: player.location.z + player.getViewDirection().z * 2
				})
				for (let i = 0; i<30; i++) {
					magic.runCommand(`tp @s ~~-0.1~ ~~ true`)
				}
				if (volumeSetting === true) {
					const soundEntity = player.dimension.spawnEntity(`tp_pw:sound_entity`, player.location)
					soundEntity.setProperty('tp_pw:weapon', 'tm')
					soundEntity.setProperty('tp_pw:attack', 1)
					system.runTimeout(()=>{
						player.runCommand(`playsound tp_pw:ability.thunder_strike @a ~~~`)
					},0.5*20)
				}
				magic.setRotation({
					x: 0,
					y: player.getRotation().y
				});
				system.runTimeout(() => {
					magic.dimension.getEntities({maxDistance:8,location:magic.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
						if(target===magic||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
						target.applyDamage(damage, {cause:'contact',damagingEntity:player})
					})
					system.runTimeout(() => {
						magic.runCommand(`event entity @s despawn`)
					}, 0.5 * 20)
				}, 0.5 * 20)
				//ATTACK ENDS
				system.runTimeout(()=>{
					const attackItem = getItemOnInventory(player, `tp_pw:${weapon}_attack${skill+1}`);
					if (attackItem) {
						const inventory = player.getComponent("minecraft:inventory");
						inventory.container.setItem(attackItem.slot, new ItemStack(`tp_pw:${weapon}`));
					}
					player.removeTag(`tp_pw:using_ability`)
					player.startItemCooldown(`tp_pw:${weapon}`, wp6CD[0]*20)
				},1.25*20)
				player.runCommandAsync(`titleraw @p actionbar { \"rawtext\": [ { \"translate\" : \"actionbar.tp_pw:${weapon}.1\" } ] }`)
			}
			break;
		case 1:
			{
				const damage = wp6Damage[1]+(lvl.getScore(player)-minLVL)
				player.playAnimation(`animation.tp_pw.thunder_mace.tpp_storm_call`, {
					nextState: `none`,
					blendOutTime: 1,
					stopExpression: `query.any_animation_finished`,
					controller: `controller_name1`
				});
				if (volumeSetting === true) {
					const soundEntity = player.dimension.spawnEntity(`tp_pw:sound_entity`, player.location)
					soundEntity.setProperty('tp_pw:weapon', 'tm')
					soundEntity.setProperty('tp_pw:attack', 2)
					player.runCommand(`playsound tp_pw:ability.thunder_storm @a ~~~`)
				}
				system.runTimeout(() => {
					const magic = player.dimension.spawnEntity('tp_pw:tm_attack2', {
						x: player.location.x,
						y: player.location.y,
						z: player.location.z
					})
					for (let i = 0; i<30; i++) {
						magic.runCommand(`tp @s ~~-0.1~ ~~ true`)
					}
					{
						const loc = {
							x:magic.location.x,
							y:magic.location.y+6,
							z:magic.location.z
						}
						magic.dimension.spawnParticle(`tp_pw:clouds_forming_1`, loc)
						magic.dimension.spawnParticle(`tp_pw:clouds_forming_2`, loc)
					}
					magic.setRotation({
						x: 0,
						y: player.getRotation().y
					});
					let maxTarget = 0
					magic.dimension.getEntities({maxDistance:8,location:magic.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
						if(target===magic||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)) || maxTarget > 5)return
						maxTarget += 1
						let delay = Math.random()*(20-5)+5
						const interval = system.runInterval(() => {
							if (magic.isValid() === true) {
								try {
									target.runCommand(`playsound tp_pw:ability.thunder_strike @a ~~~`)
									target.applyDamage(damage, {cause:'contact',damagingEntity:player})
									target.dimension.spawnParticle('tp_pw:clouds_forming_3', target.location)
									target.dimension.spawnParticle('tp_pw:clouds_forming_4', target.location)
									target.dimension.spawnParticle('tp_pw:clouds_forming_5', target.location)
									target.dimension.spawnParticle('tp_pw:clouds_forming_6', target.location)
									target.dimension.spawnParticle('tp_pw:clouds_forming_7', target.location)
									delay = Math.random()*(20-5)+5
								} catch (error) {
								}
							} else {
								system.clearRun(interval)
							}
						}, delay)
						system.runTimeout(() => {
							system.clearRun(interval)
						}, 5 * 20)
					})
	
				}, 0.25 * 20)
				//ATTACK ENDS
				system.runTimeout(()=>{
					const attackItem = getItemOnInventory(player, `tp_pw:${weapon}_attack${skill+1}`);
					if (attackItem) {
						const inventory = player.getComponent("minecraft:inventory");
						inventory.container.setItem(attackItem.slot, new ItemStack(`tp_pw:${weapon}`));
					}
					player.removeTag(`tp_pw:using_ability`)
					player.startItemCooldown(`tp_pw:${weapon}`, wp6CD[1]*20)
				},1.625*20)
				player.runCommandAsync(`titleraw @p actionbar { \"rawtext\": [ { \"translate\" : \"actionbar.tp_pw:${weapon}.2\" } ] }`)
			}
			break;
		case 2:
			{
				const damage = wp6Damage[2]+(lvl.getScore(player)-minLVL)
				player.playAnimation(`animation.tp_pw.thunder_mace.tpp_charged_beam`, {
					nextState: `none`,
					blendOutTime: 1,
					stopExpression: `query.any_animation_finished`,
					controller: `controller_name1`
				});
				const magic = player.dimension.spawnEntity('tp_pw:tm_attack3', {
					x: player.location.x + player.getViewDirection().x * 2,
					y: player.location.y,
					z: player.location.z + player.getViewDirection().z * 2
				})
				for (let i = 0; i<30; i++) {
					magic.runCommand(`tp @s ~~-0.1~ ~~ true`)
				}
				magic.setRotation({
					x: 0,
					y: player.getRotation().y
				});
				if (volumeSetting === true) {
					const soundEntity = player.dimension.spawnEntity(`tp_pw:sound_entity`, player.location)
					soundEntity.setProperty('tp_pw:weapon', 'tm')
					soundEntity.setProperty('tp_pw:attack', 3)
					player.runCommand(`playsound tp_pw:ability.thunder_storm @a ~~~`)
					system.runTimeout(()=>{
						player.runCommand(`playsound tp_pw:ability.charged_beam @a ~~~`)
					},3.5*20)
				}
				const waw = system.runInterval(() => {
					if (magic.isValid() === true) {
						magic.runCommandAsync(`tp @s ${player.location.x} ${player.location.y} ${player.location.z} ${player.getRotation().y} ${player.getRotation().x}`)
					} else {
						system.clearRun(waw)
					}
				})
				system.runTimeout(() => {
					system.clearRun(waw)
					const interval = system.runInterval(() => {
						magic.runCommandAsync(`tp @s ${player.location.x} ${player.location.y} ${player.location.z} ${player.getRotation().y} ${player.getRotation().x}`)
						player.getEntitiesFromViewDirection().forEach(ray=>{
							const dis = ray.distance;
							const target = ray.entity
							if(target===magic||target==player || target.hasTag(`tp_pw:`+player.id)||dis > 10 || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
							target.applyDamage(damage, {cause:'contact',damagingEntity:player})
							target.applyKnockback((target.location.x-player.location.x),(target.location.z-player.location.z),0.5,0.2)
						})
					})
					system.runTimeout(() => {
						system.clearRun(interval)
						magic.runCommand('event entity @s despawn')
					}, 6 * 20)
				}, 3.5 * 20)
				//ATTACK ENDS
				system.runTimeout(()=>{
					const attackItem = getItemOnInventory(player, `tp_pw:${weapon}_attack${skill+1}`);
					if (attackItem) {
						const inventory = player.getComponent("minecraft:inventory");
						inventory.container.setItem(attackItem.slot, new ItemStack(`tp_pw:${weapon}`));
					}
					player.removeTag(`tp_pw:using_ability`)
					player.startItemCooldown(`tp_pw:${weapon}`, wp6CD[2]*20)
				},10.25*20)
				player.runCommandAsync(`titleraw @p actionbar { \"rawtext\": [ { \"translate\" : \"actionbar.tp_pw:${weapon}.3\" } ] }`)
			}
			break;
		case 3:
			{
				const damage = wp6Damage[3]+(lvl.getScore(player)-minLVL)
				const petEntity = player.dimension.getEntities({closest:1,type: `tp_pw:storm_griffin`,maxDistance: 15, location: {x:player.location.x,y:player.location.y,z:player.location.z}, tags:[`tp_pw:`+player.id]})
				const magic = player.dimension.spawnEntity('tp_pw:tm_attack4', {
					x: player.location.x + player.getViewDirection().x * 4,
					y: player.location.y,
					z: player.location.z + player.getViewDirection().z * 4
				})
				for (let i = 0; i<30; i++) {
					magic.runCommand(`tp @s ~~-0.1~ ~~ true`)
				}
				magic.setRotation({
					x: 0,
					y: player.getRotation().y + 180
				});
				system.runTimeout(() => {
					petEntity.forEach(pet=>{
						magic.dimension.getEntities({maxDistance:10,location:magic.location,excludeTypes:['minecraft:xp_orb', 'minecraft:item'],excludeFamilies:['tp_pw']}).forEach(target=>{
							{
								target.runCommand(`inputpermission set @s movement disabled`)
								target.runCommand(`hud @s hide`)
								if(target.typeId!=='minecraft:player'){target.addEffect('slowness',13.8*20,{amplifier:255})}
								target.runCommand(`camera @s fade time 0.5 0.5 0.2 color 255 255 255`)
							}
							system.runTimeout(()=>{
								if (cameraSetting === true && target.typeId==='minecraft:player') {
									target.addTag(`tp_pw:${magic.id}`)
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^ ^2 ^ facing ${player.location.x} ${player.location.y+1} ${player.location.z}`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 1.0 linear pos ^^2^-2 facing ${player.location.x} ${player.location.y+1} ${player.location.z}`)
									})
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^ ^2 ^6 facing ${player.location.x} ${player.location.y+1} ${player.location.z}`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 1.0 linear pos ^^2^10 facing ${player.location.x} ${player.location.y+1} ${player.location.z}`)
									},1*20)
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^4 ^2 ^ facing ~~~`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 0.30 linear pos ^8^2^ facing ~~~`)
									},2*20)
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^-8 ^8 ^ facing ~~2~`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 2.0 linear pos ^-7^10^ facing ~~2~`)
									},3*20)
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^ ^6 ^20 facing ~~2~`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 1.0 linear pos ^^6^10 facing ~~2~`)
									},5*20)
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^-8 ^6 ^ facing ~~3~`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 4.5 linear pos ^-10^8^ facing ~~3~`)
									},6*20)
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^ ^18 ^ facing ~~~`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 2.0 linear pos ^^20^ facing ~~~`)
									},10.5*20)
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^-8 ^8 ^ facing ~~6~`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 0.5 linear pos ^-7^4^ facing ~~3~`)
									},12.5*20)
									system.runTimeout(() => {
										magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free pos ^-7^4^ facing ~~3~`)
										magic.runCommandAsync(`camera @a[tag=tp_pw:${magic.id}] set minecraft:free ease 0.5 linear pos ^-3^2^ facing ~~~`)
									},13*20)

								}
								//CameraShake
								if (target.typeId==='minecraft:player') {
									cameraShake(2, target, 0.5, 1, 'positional')
									cameraShake(5, target, 0.3, 3, 'positional')
									cameraShake(13.3, target, 1, 3, 'positional')
								}
								//Camera Clear
								system.runTimeout(() => {
									target.runCommand(`camera @s fade time 0.3 1 1 color 255 255 255`)
								},13.5*20)
								system.runTimeout(() => {
									magic.runCommand(`camera @a[tag=tp_pw:${magic.id}] clear`)
									magic.dimension.getEntities({tags:[`tp_pw:`+magic.id]}).forEach(victim=>{victim.removeTag(`tp_pw:`+magic.id)})
								},13.8*20)
								//ATTACK ENDS
								system.runTimeout(()=>{
									player.runCommand(`scoreboard players set @s tp_pw:${weapon}_ULT 0`)
									const attackItem = getItemOnInventory(player, `tp_pw:${weapon}_attack${skill+1}`);
									if (attackItem) {
										const inventory = player.getComponent("minecraft:inventory");
										inventory.container.setItem(attackItem.slot, new ItemStack(`tp_pw:${weapon}`));
									}
									player.removeTag(`tp_pw:using_ability`)
									player.startItemCooldown(`tp_pw:${weapon}`, wp1CD[3]*20)
									{
										try {
											target.runCommand(`camera @s clear`)
											target.runCommand(`inputpermission set @s movement enabled`)
											target.runCommand(`inputpermission set @s camera enabled`)
											target.runCommand(`hud @s reset`)
										} catch (error) {
											
										}
									}
									if(target===magic||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
									target.applyDamage(damage, {cause:'contact',damagingEntity:player})
								},13.8*20)
								//Damaged illusion
								{
									if(target===magic||target==player || target.hasTag(`tp_pw:`+player.id) || (getPVPmode()?null:aydiPet.includes(target.typeId)))return
									damageIllusion(target, 2.0)
									damageIllusion(target, 13.3)
								}
							},1*20)
						})
						//Technical Section
						system.runTimeout(()=>{
							pet.addEffect('invisibility', 14.3*20)
							player.runCommand('title @s clear')
							player.playAnimation(`animation.tp_pw.thunder_mace.tpp_eye_of_the_storm`, {
								nextState: `none`,
								blendOutTime: 1,
								stopExpression: `query.any_animation_finished`,
								controller: `controller_name1`
							});
							if (volumeSetting === true) {
								const soundEntity = player.dimension.spawnEntity(`tp_pw:sound_entity`, player.location)
								soundEntity.setProperty('tp_pw:weapon', 'tm')
								soundEntity.setProperty('tp_pw:attack', 4)
								system.runTimeout(()=>{
									magic.runCommand(`playsound tp_pw:ability.thunder_strike @a ~~~`)
								},2*20)
								system.runTimeout(()=>{
									magic.runCommand(`playsound tp_pw:ability.thunder_storm @a ~~~`)
									system.runTimeout(()=>{
										magic.runCommand(`playsound tp_pw:ability.thunder_storm @a ~~~`)
										system.runTimeout(()=>{
											magic.runCommand(`playsound tp_pw:ability.thunder_storm @a ~~~`)
											system.runTimeout(()=>{
												magic.runCommand(`playsound tp_pw:ability.thunder_storm @a ~~~`)
												system.runTimeout(()=>{
													magic.runCommand(`playsound tp_pw:ability.thunder_storm @a ~~~`)
													system.runTimeout(()=>{
														magic.runCommand(`playsound tp_pw:ability.thunder_storm @a ~~~`)
													},1.5*20)
												},1.5*20)
											},1.5*20)
										},1.5*20)
									},1.5*20)
								},1.5*20)
								system.runTimeout(()=>{
									magic.runCommand(`playsound tp_pw:ability.thunder_strike @a`)
								},12.3*20)
								system.runTimeout(()=>{
									magic.runCommand(`playsound tp_pw:ability.thunder_strike @a ~~~`)
									magic.runCommand(`playsound tp_pw:ability.fire_explosion @a ~~~`)
								},13.3*20)
								system.runTimeout(()=>{
									magic.runCommand(`playsound tp_pw:ult.griffin_scream @a ~~~ 10 0.8`)
								},5*20)
								system.runTimeout(()=>{
									magic.runCommand(`playsound tp_pw:ult.griffin_scream @a ~~~`)
								},10*20)

								system.runTimeout(()=>{
									playSoundUltimate(magic, 'tp_pw:n_ability.ultimate_tension', 0.0)
									playSoundUltimate(magic, 'tp_pw:n_ability.botw_rune', 1.03)
									playSoundUltimate(magic, 'tp_pw:n_ability.botw_ultimate_ambient', 1.1)
								})
							}
							//Particle Effects
							{
								system.runTimeout(()=>{
									const loc = {
										x:magic.location.x,
										y:magic.location.y+0.1,
										z:magic.location.z
									}
									magic.dimension.spawnParticle('tp_pw:eye_of_the_storm_1', loc)
									magic.dimension.spawnParticle('tp_pw:eye_of_the_storm_2', loc)
									magic.dimension.spawnParticle('tp_pw:eye_of_the_storm_3', loc)
								},1.0*20)
								system.runTimeout(()=>{
									const loc = {
										x:magic.location.x,
										y:magic.location.y,
										z:magic.location.z
									}
									magic.dimension.spawnParticle('tp_pw:electricity_pulsing_shockwaves_1', loc)
									magic.dimension.spawnParticle('tp_pw:electricity_pulsing_shockwaves_2', loc)
									magic.dimension.spawnParticle('tp_pw:electricity_pulsing_shockwaves_3', loc)
									magic.dimension.spawnParticle('tp_pw:electricity_pulsing_shockwaves_4', loc)
									magic.dimension.spawnParticle('tp_pw:electricity_pulsing_shockwaves_5', loc)
									magic.dimension.spawnParticle('tp_pw:electricity_pulsing_shockwaves_6', loc)
									magic.dimension.spawnParticle('tp_pw:electricity_pulsing_shockwaves_7', loc)
								},2.0*20)
								system.runTimeout(()=>{
									const loc = {
										x:magic.location.x,
										y:magic.location.y+6,
										z:magic.location.z
									}
									magic.dimension.spawnParticle('tp_pw:clouds_forming_1', loc)
									magic.dimension.spawnParticle('tp_pw:clouds_forming_2', loc)
									magic.dimension.spawnParticle('tp_pw:clouds_forming_5', loc)
									magic.dimension.spawnParticle('tp_pw:clouds_forming_7', loc)
								},1.5*20)
								system.runTimeout(()=>{
									const loc = {
										x:magic.location.x,
										y:magic.location.y+6,
										z:magic.location.z
									}
									magic.dimension.spawnParticle('tp_pw:clouds_forming_1', loc)
									magic.dimension.spawnParticle('tp_pw:clouds_forming_2', loc)
									magic.dimension.spawnParticle('tp_pw:clouds_forming_5', loc)
									magic.dimension.spawnParticle('tp_pw:clouds_forming_7', loc)
								},3.5*20)
								system.runTimeout(()=>{
									const loc = {
										x:magic.location.x,
										y:magic.location.y+6,
										z:magic.location.z
									}
									magic.dimension.spawnParticle('tp_pw:clouds_forming_1', loc)
									magic.dimension.spawnParticle('tp_pw:clouds_forming_2', loc)
									magic.dimension.spawnParticle('tp_pw:clouds_forming_5', loc)
									magic.dimension.spawnParticle('tp_pw:clouds_forming_7', loc)
								},5.5*20)
								system.runTimeout(()=>{
									const loc = {
										x:magic.location.x,
										y:magic.location.y+6,
										z:magic.location.z
									}
									magic.dimension.spawnParticle('tp_pw:clouds_forming_1', loc)
									magic.dimension.spawnParticle('tp_pw:clouds_forming_2', loc)
									magic.dimension.spawnParticle('tp_pw:clouds_forming_5', loc)
									magic.dimension.spawnParticle('tp_pw:clouds_forming_7', loc)
								},7.5*20)
								system.runTimeout(()=>{
									const loc = {
										x:magic.location.x,
										y:magic.location.y+6,
										z:magic.location.z
									}
									magic.dimension.spawnParticle('tp_pw:clouds_forming_1', loc)
									magic.dimension.spawnParticle('tp_pw:clouds_forming_2', loc)
									magic.dimension.spawnParticle('tp_pw:clouds_forming_5', loc)
									magic.dimension.spawnParticle('tp_pw:clouds_forming_7', loc)
								},7.5*20)
								system.runTimeout(()=>{
									system.runTimeout(()=>{
										const loc = {
											x:magic.location.x,
											y:magic.location.y,
											z:magic.location.z
										}
										magic.dimension.spawnParticle('tp_pw:clouds_forming_4', loc)
										magic.dimension.spawnParticle('tp_pw:clouds_forming_6', loc)
									},6*20)
									system.runTimeout(()=>{
										const loc = {
											x:magic.location.x,
											y:magic.location.y,
											z:magic.location.z
										}
										magic.dimension.spawnParticle('tp_pw:electricity_pulsing_shockwaves_1', loc)
										magic.dimension.spawnParticle('tp_pw:electricity_pulsing_shockwaves_2', loc)
										magic.dimension.spawnParticle('tp_pw:electricity_pulsing_shockwaves_3', loc)
										magic.dimension.spawnParticle('tp_pw:electricity_pulsing_shockwaves_4', loc)
										magic.dimension.spawnParticle('tp_pw:electricity_pulsing_shockwaves_5', loc)
										magic.dimension.spawnParticle('tp_pw:electricity_pulsing_shockwaves_6', loc)
										magic.dimension.spawnParticle('tp_pw:electricity_pulsing_shockwaves_7', loc)
									},6.3*20)
								},5*20)
								system.runTimeout(()=>{
									const loc = {
										x:magic.location.x,
										y:magic.location.y,
										z:magic.location.z
									}
									magic.dimension.spawnParticle('tp_pw:electricity_pulsing_shockwaves_1', loc)
									magic.dimension.spawnParticle('tp_pw:electricity_pulsing_shockwaves_2', loc)
									magic.dimension.spawnParticle('tp_pw:electricity_pulsing_shockwaves_3', loc)
									magic.dimension.spawnParticle('tp_pw:electricity_pulsing_shockwaves_4', loc)
									magic.dimension.spawnParticle('tp_pw:electricity_pulsing_shockwaves_5', loc)
									magic.dimension.spawnParticle('tp_pw:electricity_pulsing_shockwaves_6', loc)
									magic.dimension.spawnParticle('tp_pw:electricity_pulsing_shockwaves_7', loc)
								},13.3*20)
							}
							//Entity Effects
							system.runTimeout(()=>{magic.runCommand('event entity @s active')},5*20)
						},1*20)
					})
				})
				player.runCommandAsync(`titleraw @p title { \"rawtext\": [ { \"translate\" : \"actionbar.tp_pw:${weapon}.4\" } ] }`)
			}
			break;
	}
}
function checkDistance(subject, target) {
	const deltaX = target.location.x - subject.location.x;
	const deltaY = target.location.y - subject.location.y;
	const deltaZ = target.location.z - subject.location.z;
	const distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ);
	return distance;
}
function getItemOnInventory(player, item) {
	/** @type { mc.EntityInventoryComponent } */
	const inventory = player.getComponent("minecraft:inventory");
	for (let i = 0; i < inventory.container?.size; i++) {
		const itemI = inventory.container.getItem(i);
		if (itemI && itemI.typeId === item) {
			return { slot: i }; // Return only the slot index
		}
	}
	return null; // Return null if not found
}
function checkItemInMainHand(player, itemId) {
    if (player.getComponent("equippable")?.getEquipment("Mainhand")?.typeId === itemId) {
        return true
    } else {
        return false
    }
}
function dataTextHeight(pet){
	let height = null
	switch (pet.typeId) {
		case 'tp_pw:feral_lynx':
			height = 2
			break;
		case 'tp_pw:flame_hawk':
			height = 2.5
			break;
		case 'tp_pw:frost_fox':
			height = 2
			break;
		case 'tp_pw:music_golem':
			height = 3.3
			break;
		case 'tp_pw:nebula_dragon':
			height = 2.8
			break;
		case 'tp_pw:storm_griffin':
			height = 2.8
			break;
	}
	return height;
}
function showItemStats(player,item, entityType){
	const lvl = world.scoreboard.getObjective(`tp_pw:${item}_LVL`)
	const ult = world.scoreboard.getObjective(`tp_pw:${item}_ULT`)
	//DEBUG 1 console.warn('MEGANG GERGAJI')
	if(lvl.getScore(player) <10 ){
	world.getDynamicProperty("tp_pw:boost_time") > 0
	? player.runCommandAsync(`scoreboard players add @s tp_pw:${item}_EXP ${entityType.xp * 2}`)
	: player.runCommandAsync(`scoreboard players add @s tp_pw:${item}_EXP ${entityType.xp}`)}
	if (lvl.getScore(player) >= 5 && ult.getScore(player) < 10) {
		player.runCommandAsync(`scoreboard players add @s tp_pw:${item}_ULT 1`)
	} 
	system.runTimeout(()=>{
		const lvl = world.scoreboard.getObjective(`tp_pw:${item}_LVL`)
		const exp = world.scoreboard.getObjective(`tp_pw:${item}_EXP`)
		const ult = world.scoreboard.getObjective(`tp_pw:${item}_ULT`)
		const xpl = defaultEXP * (lvl.getScore(player)) * 0.8
		if (exp.getScore(player) >= xpl) 
			{levelUp(player,lvl,exp)}
		const ultBar = `§6${'/'.repeat(ult.getScore(player))}§j${'/'.repeat(10 - ult.getScore(player))}`
		const actionBarText = `{
			"rawtext": [
				{ "translate": "actionbar.tp_pw.weapon.lvl" },
				{ "text": "§b(§r${lvl.getScore(player)}§b)§r " }
				`+
				(lvl.getScore(player)<10
				? `, { "translate": "actionbar.tp_pw.weapon.exp" },
				{ "text": "§b(§r${exp.getScore(player)}§6/§f${xpl}§b)§r" }`
				: '')
				+
				(lvl.getScore(player) >= 5 && ult.getScore(player) < 10
				? `, { "text": "\n" },
				{ "translate": "actionbar.tp_pw.weapon.ult" },
				{ "text": "§b(§r§l${ultBar}§r§b)§r" }`
				: lvl.getScore(player) >= 5 && ult.getScore(player) >= 10
				? `, { "text": "\n" },
				{ "translate": "actionbar.tp_pw.weapon.ult" },
				{ "translate": "actionbar.tp_pw.weapon.ult_full" }`
				: '')+
				`
			]
		}`
		player.runCommand(`titleraw @s actionbar ${actionBarText}`)
	}, 0.5 * 20)
}
function levelUp(player,lvl,exp){
	lvl.addScore(player,1)
	exp.setScore(player,0)
}
function healthDisplayer(entity) {
	const health = entity.getComponent("minecraft:health")
	const totalBars = 10;
	const healthPercent = health.currentValue / health.defaultValue;
	const healthBars = Math.round(healthPercent * totalBars);
	
	const greenBar = '+'.repeat(healthBars);
	const redBar = '+'.repeat(totalBars - healthBars);
	return `§c§l${greenBar}§j${redBar}`;
}
function hungerDisplayer(entity) {
	const hgr = world.scoreboard.getObjective('tp_pw:pet_HGR')
	const totalBars = 10;
	const healthPercent = hgr.getScore(entity) / 600;
	const healthBars = Math.round(healthPercent * totalBars);
	
	const greenBar = '#'.repeat(healthBars);
	const redBar = '#'.repeat(totalBars - healthBars);
	return `§r§g${greenBar}§j${redBar}`;
}
function modeDisplayer(mode) {
	switch (mode) {
		case 'passive': 
			return `§l§dPassive`;
		case 'neutral':
			return `§l§2Neutral`;
		case 'aggressive':
			return `§l§4Aggressive`;
		default:
			return 'Unknown mode';  // Menambahkan nilai default jika mode tidak cocok
	}
}
function moveTowards(current, target, maxDistanceDelta) {
	// Menghitung arah dari current ke target
	const direction = {
		x: target.x - current.x,
		y: target.y - current.y,
		z: target.z - current.z
	};

	// Menghitung jarak antara current dan target
	const distance = Math.sqrt(direction.x * direction.x + direction.y * direction.y + direction.z * direction.z);

	// Jika jarak sudah lebih kecil dari maxDistanceDelta, kita langsung pindah ke target
	if (distance <= maxDistanceDelta || distance === 0) {
		return target;
	}

	// Menormalisasi arah dan mengalikan dengan maxDistanceDelta untuk pergerakan
	const normalizedDirection = {
		x: direction.x / distance,
		y: direction.y / distance,
		z: direction.z / distance
	};

	// Menggerakkan current menuju target
	return {
		x: current.x + normalizedDirection.x * maxDistanceDelta,
		y: current.y + normalizedDirection.y * maxDistanceDelta,
		z: current.z + normalizedDirection.z * maxDistanceDelta
	};
}
function damageIllusion(target, duration) {
	system.runTimeout(()=>{
		target.applyKnockback(target.location.x, target.location.z, 0, 0.5)
		target.runCommandAsync(`playsound game.player.hurt @a ~~~`)
		try {
			target.runCommandAsync(`playsound mob.${target.typeId.replace(`minecraft:`, '')}.hurt @a ~~~`)
		} catch (error) {
			
		}
	},duration*20)
}
function randomize(min, max, round) {
	return round ? Math.round(Math.random() * (max-min)+min) : Math.random() * (max-min)+min
}
function playSoundUltimate(entity, sound, duration, volume, pitch) {
	system.runTimeout(()=>{
		entity.runCommand(`playsound ${sound} @a[r=20] ~~~ ${volume != undefined ? volume : ``} ${pitch != undefined ? pitch : ``}`)
	},duration*20)
}
function cameraShake(timer, entity, intensity, duration, mode) {
	system.runTimeout(()=>{
		entity.runCommand(`camerashake add @s ${intensity} ${duration} ${mode}`)
	},timer*20)
}
system.runInterval(() => {
	world.getPlayers().forEach(player => {
		if (!player.hasTag('tp_pw:using_ability')) {
			bannedItems.forEach(item => {
				try {
					const bannedItem = getItemOnInventory(player, item);
					if (bannedItem) {
						const inventory = player.getComponent("minecraft:inventory");
						inventory.container.setItem(bannedItem.slot, new ItemStack(item.replace(/_attack.*$/, '').trim()));
					}
				} catch (error) {
					
				}
			});
		}
		const petAmount = player.dimension.getEntities({tags:[`tp_pw:`+player.id]})
		try {
			if(player.getDynamicProperty(`tp_pw:petAmount`)!=petAmount.length){
				player.setDynamicProperty(`tp_pw:petAmount`, petAmount.length)
			}
		} catch (error) {
			
		}
		weapons.forEach(weapon=>{
			if ((checkItemInMainHand(player, `tp_pw:${weapon}`))) {
				const lvl = world.scoreboard.getObjective(`tp_pw:${weapon}_LVL`)
				const exp = world.scoreboard.getObjective(`tp_pw:${weapon}_EXP`)
				const ult = world.scoreboard.getObjective(`tp_pw:${weapon}_ULT`)
				const xpl = defaultEXP * (lvl.getScore(player)) * 0.8
				if (ult.getScore(player) > 10) {ult.setScore(player, 10)}
				const ultBar = `§6${'/'.repeat(ult.getScore(player))}§j${'/'.repeat(10 - ult.getScore(player))}`
	const actionBarText = `{
		"rawtext": [
			{ "translate": "actionbar.tp_pw.weapon.lvl" },
			{ "text": "§b(§r${lvl.getScore(player)}§b)§r " }
			`+
			(lvl.getScore(player)<10
			? `, { "translate": "actionbar.tp_pw.weapon.exp" },
			{ "text": "§b(§r${exp.getScore(player)}§6/§f${xpl}§b)§r" }`
			: '')
			+
			(lvl.getScore(player) >= 5 && ult.getScore(player) < 10
			? `, { "text": "\n" },
			{ "translate": "actionbar.tp_pw.weapon.ult" },
			{ "text": "§b(§r§l${ultBar}§r§b)§r" }`
			: lvl.getScore(player) >= 5 && ult.getScore(player) >= 10
			? `, { "text": "\n" },
			{ "translate": "actionbar.tp_pw.weapon.ult" },
			{ "translate": "actionbar.tp_pw.weapon.ult_full" }`
			: '')+
			`
		]
	}`
				player.runCommand(`titleraw @s[tag=!tp_pw:${weapon}_data] actionbar ${actionBarText}`)
				player.addTag(`tp_pw:${weapon}_data`)
			} else {player.removeTag(`tp_pw:${weapon}_data`)}
		})
	});
	world.getDimension('overworld').getEntities().forEach(entity=>{
		multiMoveEntity.forEach(id=>{
			if(entity.typeId===id){
				const randomDelay = Math.round(Math.random() * (30-10)+10)
				if(entity.getDynamicProperty('tp_pw:stage_change_delay')===undefined){entity.setDynamicProperty('tp_pw:stage_change_delay', randomDelay)}
				if(entity.getDynamicProperty('tp_pw:stage_change_delay')===0){
					if(entity.getProperty('tp_pw:move_stage')==='walk'){
						entity.triggerEvent('tf_flying')
						entity.setDynamicProperty('tp_pw:stage_change_delay', randomDelay)
					} else if(entity.getProperty('tp_pw:move_stage')==='fly'){
						entity.triggerEvent('tf_walking')
						entity.setDynamicProperty('tp_pw:stage_change_delay', randomDelay)
					}
				}
				//if(entity.getProperty('tp_pw:move_stage')==='walk'){entity.runCommand(`tp @s ~~-0.1~ ~~ true`)}
				if(entity.getProperty('tp_pw:move_stage')==='walk'&&entity.getProperty('tp_pw:has_target')===true){
					//entity.triggerEvent('fly_stage')
				}
			}
		})
		if(entity.typeId==="tp_pw:text") {
			//const owner = entity.getTags().find(tag => tag.startsWith("tp_pw:"))
			let owner = null
			entity.getTags().forEach(tag=>{
				if(tag.startsWith('tp_pw:')) {
					owner = tag.replace('tp_pw:', '')
				}
			})
			const pemilikanying = entity.dimension.getEntities({id:`${owner}`})
			if (pemilikanying.length > 0) {
				//console.warn('ADA WEHHHHH')
			}
			if (pemilikanying.length === 0) {
				entity.remove()
			}
		}
	})
});
system.runInterval(() => {
	world.getPlayers().forEach(player=>{
		if(player.getDynamicProperty('tp_pw:petData')===true){player.getEntitiesFromViewDirection().forEach(target=>{
			const entity = target.entity
			petsId.forEach(pet=>{
				if(!entity.isValid()) return
				if (target.distance <= 8 && entity.typeId === 'tp_pw:'+pet) {
					const sb = entity.getDynamicProperty('tp_pw:pet_ui')
					if(sb==false||sb==undefined){entity.setDynamicProperty('tp_pw:pet_ui', true)}
				}
				if (target.distance <= 6 && entity.typeId === 'tp_pw:'+pet+'_untamed' && entity.getComponent('minecraft:mark_variant').value===4 && !entity.hasTag('tp_pw:terjinakkan')) {
					if(!entity.isValid()) return
					const textEntity = entity.dimension.getEntities({tags:[`tp_pw:${entity.id}`]})
					textEntity.forEach(name=>{
						name.remove()
					})
					const counter = world.scoreboard.getObjective('tp_pw:despawn_counter')
					let nameTag = ``
					try {
						nameTag = `Tame the pet by feeding it it's food!\nDespawn Counter: ${counter.getScore(entity)}`
					} catch (error) {	
					}
					entity.runCommand(`summon tp_pw:text "${nameTag}" ~~1~`)
					entity.runCommand(`tag @e[type=tp_pw:text,c=1] add tp_pw:${entity.id}`)
					system.runInterval(()=>{
						if(entity.isValid()) {
							entity.runCommand(`tp @e[type=tp_pw:text,c=1,r=3,tag=tp_pw:${entity.id}] ~~1~`)
						}
					})
				}
			})
		})}
	})
	world.getDimension('overworld').getEntities().forEach(entity=>{
		petsId.forEach(id=>{
			if(entity.typeId===`tp_pw:`+id){
				if (!entity.isValid()) return
				const hunger = world.scoreboard.getObjective(`tp_pw:pet_HGR`)
				const delay = entity.getDynamicProperty('tp_pw:healingDelay')
				const health = entity.getComponent('minecraft:health')
				const isSitting = entity.getProperty('tp_pw:is_sitting')
				try {
					if(hunger.getScore(entity)>600){hunger.setScore(entity, 600)}
					if(hunger.getScore(entity)<600&&health.currentValue===health.defaultValue&&isSitting){
						//console.warn('pet hungry on')
						entity.triggerEvent('hungry')
					} else if(hunger.getScore(entity)>=600 || isSitting===false || health.currentValue<health.defaultValue){
						entity.triggerEvent('hungry_off')
						//console.warn('pet hungry off')
					}
					if(delay==undefined){
						entity.setDynamicProperty('tp_pw:healingDelay', 2)
					}
					if(delay>0){
						entity.setDynamicProperty('tp_pw:healingDelay', delay-1)
					}
					if(health.currentValue < health.defaultValue && delay === 0){
						healing(entity, hunger, health)
					}
				} catch (error) {
					
				}
				try {
					if(hunger.getScore(entity)<=50&&entity.getProperty(`tp_pw:hungry`)===false){
						entity.setProperty(`tp_pw:hungry`, true)
					} else if(hunger.getScore(entity)>50&&entity.getProperty(`tp_pw:hungry`)===true){
						entity.setProperty(`tp_pw:hungry`, false)
					}
				} catch (error) {
					
				}


				if (entity.getDynamicProperty('tp_pw:pet_ui')==true) {
					updateName(entity)
					try {
						const dp = entity.getDynamicProperty('tp_pw:pet_ui_timer')
						if(dp==false||dp==undefined){
							entity.setDynamicProperty('tp_pw:pet_ui_timer',true)
							system.runTimeout(()=>{
								entity.setDynamicProperty('tp_pw:pet_ui', false)
								entity.setDynamicProperty('tp_pw:pet_ui_timer', false)
							},6*20)
						}
					} catch (error) {
					}
				}
			}
		})
		//Despawn Counter
		const countDown = world.scoreboard.getObjective('tp_pw:despawn_counter')
		try {
			if(countDown.getScore(entity) > 0){
				countDown.setScore(entity, countDown.getScore(entity)-1)
			}
		} catch (error) {
		}
		const stageDelay = entity.getDynamicProperty('tp_pw:stage_change_delay')
		if(stageDelay>0){
			entity.setDynamicProperty('tp_pw:stage_change_delay', stageDelay-1)
		}
	})
},1*20)
function healing(entity, hunger, health){
	entity.setDynamicProperty('tp_pw:healingDelay', 1)
	//console.warn('hiling cuy')
	if(hunger.getScore(entity)>0&&health.currentValue<health.defaultValue){
		health.setCurrentValue(health.currentValue+1)
		hunger.setScore(entity,hunger.getScore(entity)-2)
	}
}
function updateName(entity) {
	if(!entity.isValid()) return
	entity.runCommand(`event entity @e[type=tp_pw:text,tag=tp_pw:${entity.id}] text:despawn`)
	const ownerId = entity.getDynamicProperty('tp_pw:owner')
	const lvl = world.scoreboard.getObjective('tp_pw:pet_LVL')
	const exp = world.scoreboard.getObjective('tp_pw:pet_EXP')
	const hgr = world.scoreboard.getObjective('tp_pw:pet_HGR')
	const health = entity.getComponent('minecraft:health')
	const mode = entity.getProperty('tp_pw:mode')
	let ownerName = entity.getDynamicProperty(`tp_pw:ownerName`)
	entity.dimension.getPlayers().forEach(player=>{
		if(player.id===ownerId){
			entity.setDynamicProperty(`tp_pw:ownerName`, player.name)
		}
	})
	let nameTag = ``
	let isHungry = ``
	try {
		if(entity.getProperty('tp_pw:hungry')){
			isHungry = `\n§4(PET IS HUNGRY)`
		}
		nameTag = `§e${ownerName}\'s pet§r\n§l§6HEALTH\n§e${healthDisplayer(entity)}§r\n§l§6HUNGER\n§e${hungerDisplayer(entity)}§r\n§l§6LVL: §e${lvl.getScore(entity)}§r\n§l§6EXP: §e${exp.getScore(entity)}§r/§e${(defaultEXP * (lvl.getScore(entity)))*0.8}§r\n\n§l§6MODE: §e${modeDisplayer(mode)}§r${isHungry}`
	} catch (error) {	
	}
	system.runTimeout(()=>{
		if(!entity.isValid()) return
		entity.runCommand(`summon tp_pw:text "${nameTag}" ~~${dataTextHeight(entity)}~`)
		entity.runCommand(`tag @e[type=tp_pw:text,c=1] add tp_pw:${entity.id}`)
		system.runInterval(()=>{
			if(!entity.isValid()) return
			entity.runCommand(`tp @e[type=tp_pw:text,c=1,tag=tp_pw:${entity.id}] ~~${dataTextHeight(entity)}~`)
			const textEntity = entity.dimension.getEntities({tags:[`tp_pw:${entity.id}`]})
		})
	},0.05*20)
}
function getPVPmode() {
	return world.getDynamicProperty("tp_pw:pvp")
}
}