execute as @e[tag=ngboss] run function survivalplus:finale/boss/clear
execute as @e[tag=ng+portal] at @s positioned ~ ~8 ~ unless entity @e[tag=bosshealer] run setblock ~ ~ ~ air destroy

execute as @e[tag=ngboss] run loot spawn ~ ~ ~ loot survivalplus:rng/cyclephase
execute if entity @e[type=item,nbt={Item:{components:{"minecraft:custom_data":{clonephase:tag}}}}] as @e[tag=ngboss] run function survivalplus:finale/boss/abilities/clone
execute if entity @e[type=item,nbt={Item:{components:{"minecraft:custom_data":{fastphase:tag}}}}] as @e[tag=ngboss] run function survivalplus:finale/boss/abilities/fast
execute if entity @e[type=item,nbt={Item:{components:{"minecraft:custom_data":{healphase:tag}}}}] as @e[tag=ngboss] run function survivalplus:finale/boss/abilities/heal
execute if entity @e[type=item,nbt={Item:{components:{"minecraft:custom_data":{heavyphase:tag}}}}] as @e[tag=ngboss] run function survivalplus:finale/boss/abilities/heavy
execute if entity @e[type=item,nbt={Item:{components:{"minecraft:custom_data":{neutralphase:tag}}}}] as @e[tag=ngboss] run function survivalplus:finale/boss/abilities/neutral
execute if entity @e[type=item,nbt={Item:{components:{"minecraft:custom_data":{rangephase:tag}}}}] as @e[tag=ngboss] run function survivalplus:finale/boss/abilities/range
execute if entity @e[type=item,nbt={Item:{components:{"minecraft:custom_data":{slowphase:tag}}}}] as @e[tag=ngboss] run function survivalplus:finale/boss/abilities/slow
execute if entity @e[type=item,nbt={Item:{components:{"minecraft:custom_data":{tpphase:tag}}}}] as @e[tag=ngboss] run function survivalplus:finale/boss/abilities/tp
execute if entity @e[type=item,nbt={Item:{components:{"minecraft:custom_data":{weakphase:tag}}}}] as @e[tag=ngboss] run function survivalplus:finale/boss/abilities/weak
execute if entity @e[type=item,nbt={Item:{components:{"minecraft:custom_data":{yoinkphase:tag}}}}] as @e[tag=ngboss] run function survivalplus:finale/boss/abilities/yoink

kill @e[type=item,nbt={Item:{components:{"minecraft:custom_data":{del:tag}}}}]
schedule function survivalplus:finale/boss/cycle 13s replace
execute if entity @e[tag=ngboss,tag=lowhp] run schedule function survivalplus:finale/boss/cycle 3.5s replace