scoreboard players set @s AttackTimer 0
scoreboard players set @s[scores={CadeyrnTimer=56..}] CadeyrnTimer 0
#check for half hp threshold 
scoreboard players set @s KyuDummy 10000
scoreboard players operation @s KyuDummy = @s CadeyrnBossBarHP
scoreboard players operation @s KyuDummy -= @s CadeyrnHalfHP
execute as @s[scores={KyuDummy=..-1}] run function zzzzdonotuse:cadeyrn/initiatephasetransition

bossbar set minecraft:cadeyrn players @a[tag=aaaaaaaaaaaa]
bossbar set minecraft:cadeyrn players @a[tag=CadeyrnFightTag]

execute at @e[type=armor_stand,name=CadeyrnFight] positioned ~32 126 ~32 run tp @e[dx=-64,dy=30,dz=-64,type=#suhc:pigtype,tag=!CadeyrnMinion] ~ -500 ~

#loot table for random attack
execute at @s[tag=!ChangePhaseCad] positioned ~ 255 ~ run loot spawn ~ ~ ~ loot minecraft:cadeyrn
#execute at @s positioned ~ 255 ~ run execute at @e[type=item,distance=..5,nbt={Item:{id:"minecraft:paper",Count:1b,tag:{display:{Lore:["\"Attack1\""]}}}}] run execute as @s run function zzzzdonotuse:cadeyrn/attacks/attack1
#execute at @s positioned ~ 255 ~ run execute at @e[type=item,distance=..5,nbt={Item:{id:"minecraft:paper",Count:1b,tag:{display:{Lore:["\"ChangeLocation\""]}}}}] run execute at @e[type=armor_stand,name=DayQ] run data merge block 999996 120 999969 {auto:1b}
#execute at @s positioned ~ 255 ~ run execute at @e[type=item,distance=..5,nbt={Item:{id:"minecraft:paper",Count:1b,tag:{display:{Lore:["\"AutoAttack\""]}}}}] run execute at @e[type=armor_stand,name=DayQ] run data merge block 999996 121 999969 {auto:1b}
execute at @s positioned ~ 255 ~ run execute at @e[type=item,distance=..5,nbt={Item:{id:"minecraft:paper",Count:1b,tag:{display:{Lore:["\"BasicFireball\""]}}}}] run execute at @e[type=armor_stand,name=DayQ] run data merge block 999996 122 999969 {auto:1b}
execute at @s[tag=!ThrewBigBone] positioned ~ 255 ~ run execute at @e[type=item,distance=..5,nbt={Item:{id:"minecraft:paper",Count:1b,tag:{display:{Lore:["\"BoneThrow\""]}}}}] run execute at @e[type=armor_stand,name=DayQ] run data merge block 999996 123 999969 {auto:1b}
execute at @s[tag=ThrewBigBone] positioned ~ 255 ~ run execute at @e[type=item,distance=..5,nbt={Item:{id:"minecraft:paper",Count:1b,tag:{display:{Lore:["\"BoneThrow\""]}}}}] run execute at @e[type=armor_stand,name=DayQ] run data merge block 999996 127 999969 {auto:1b}


execute at @s positioned ~ 255 ~ run execute at @e[type=item,distance=..5,nbt={Item:{id:"minecraft:paper",Count:1b,tag:{display:{Lore:["\"Brigade\""]}}}}] run execute at @e[type=armor_stand,name=DayQ] run data merge block 999996 124 999969 {auto:1b}
execute at @s positioned ~ 255 ~ run execute at @e[type=item,distance=..5,nbt={Item:{id:"minecraft:paper",Count:1b,tag:{display:{Lore:["\"ChargeSlash\""]}}}}] run execute at @e[type=armor_stand,name=DayQ] run data merge block 999996 125 999969 {auto:1b}
execute at @s positioned ~ 255 ~ run execute at @e[type=item,distance=..5,nbt={Item:{id:"minecraft:paper",Count:1b,tag:{display:{Lore:["\"FireSheet\""]}}}}] run execute at @e[type=armor_stand,name=DayQ] run data merge block 999996 126 999969 {auto:1b}
execute at @s positioned ~ 255 ~ run execute at @e[type=item,distance=..5,nbt={Item:{id:"minecraft:paper",Count:1b,tag:{display:{Lore:["\"SkeleFromBone\""]}}}}] run execute at @e[type=armor_stand,name=DayQ] run data merge block 999996 127 999969 {auto:1b}
execute at @s positioned ~ 255 ~ run execute at @e[type=item,distance=..5,nbt={Item:{id:"minecraft:paper",Count:1b,tag:{display:{Lore:["\"SoulSteal\""]}}}}] run execute at @e[type=armor_stand,name=DayQ] run data merge block 999996 128 999969 {auto:1b}
#execute at @s positioned ~ 255 ~ run execute at @e[type=item,distance=..5,nbt={Item:{id:"minecraft:paper",Count:1b,tag:{display:{Lore:["\"Attack1\""]}}}}] run execute at @e[type=armor_stand,name=DayQ] run data merge block 999996 120 999969 {auto:1b}

execute at @s positioned ~ 255 ~ run kill @e[type=item,distance=..10]