#tick up the scoreboard used in this function once every 10 ticks, and reset the timer used to count the 10 ticks
scoreboard players set @s Cadeyrn10Tick 0
scoreboard players add @s[tag=!MidAttack] CadeyrnTimer 1

#random checks at ticks 3/7/11 to do an auto attack
#each one has a 1/8 chance to succeed, and only one of them may succeed
execute as @s[tag=!DoingAuto,scores={CadeyrnTimer=3}] run execute if predicate suhc:25percent run execute if predicate suhc:50percent run execute at @e[type=armor_stand,name=DayQ] run data merge block 999991 138 999988 {auto:1b}
execute as @s[tag=!DoingAuto,scores={CadeyrnTimer=7}] run execute if predicate suhc:25percent run execute if predicate suhc:50percent run execute at @e[type=armor_stand,name=DayQ] run data merge block 999991 138 999988 {auto:1b}
execute as @s[tag=!DoingAuto,scores={CadeyrnTimer=11}] run execute if predicate suhc:25percent run execute if predicate suhc:50percent run execute at @e[type=armor_stand,name=DayQ] run data merge block 999991 138 999988 {auto:1b}
execute as @s[tag=!DoingAuto,scores={CadeyrnTimer=11}] run scoreboard players set @s CadeyrnTimer 35

#always do an auto attack at tick 35
execute as @s[tag=!DoingAuto,scores={CadeyrnTimer=35}] run execute at @e[type=armor_stand,name=DayQ] run data merge block 999991 138 999988 {auto:1b}


#at tick 60, check if players are present and if the arena needs to reset
#the function below also contains the DoAttack function, which is done if players are present. If none are, the arena is instead reset.
execute as @s[scores={CadeyrnTimer=56..}] run function zzzzdonotuse:cadeyrn/checkreset

#function which updates the bossbar health...based on 2 entities with constantly regenerating health ;-;
execute as @s run function zzzzdonotuse:cadeyrn/updatebosshp




#execute as @s run scoreboard players set @s CadeyrnHealth 0
#execute as @e[tag=CadeyrnTP] run execute store result score @s CadeyrnHealth run data get entity @s Health
#execute as @s run scoreboard players operation @s CadeyrnHealth += @e[tag=CadeyrnTP,type=minecraft:skeleton_horse] CadeyrnHealth
#execute store result bossbar minecraft:cadeyrn value run scoreboard players get @s CadeyrnHealth

#changelocation
#execute as @s run execute at @e[type=armor_stand,name=DayQ] run data merge block 999996 120 999969 {auto:1b}

#autoattack
#execute as @s run execute at @e[type=armor_stand,name=DayQ] run data merge block 999996 121 999969 {auto:1b}

#I use this a lot so it's just here for easy copy/paste
#execute if predicate suhc:25percent run