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 999991 137 999988 {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 999991 138 999988 {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 999991 139 999988 {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 999991 140 999988 {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 999991 144 999988 {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 999991 141 999988 {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 999991 142 999988 {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 999991 143 999988 {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 999991 144 999988 {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 999991 145 999988 {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 999991 137 999988 {auto:1b}

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