## Bossbar
execute store result storage vb dummy.id int 1 run scoreboard players get @s vb.id.bossbar
function vb:tick_entity/custom_mob/drowned_necromancer/bossbar_update with storage vb dummy

## Death
execute if score @s vb.entity.boss_health matches ..0 run function vb:tick_entity/custom_mob/drowned_necromancer/death with storage vb dummy

## Hurt
execute store result score @s vb.dummy1 run data get entity @s HurtTime
execute if score @s vb.dummy1 matches 1.. run function vb:tick_entity/custom_mob/drowned_necromancer/hurt

## Particles
particle dust{color:[0.0,0.51,0.9],scale:2} ~ ~-3.5 ~ 0.3 1.8 0.3 0 10
particle minecraft:snowflake ~ ~ ~ 1 1 1 0 3

## Orbs
execute store result score @s vb.dummy1 run random value 1..3
execute if score @s vb.dummy1 matches 1 if score @s vb.entity.boss_health matches 1..201 unless entity @e[tag=vb.custom_mob.oceanic_orb_trident,distance=..40] unless entity @e[tag=vb.custom_mob.oceanic_orb_core,distance=..40] run function vb:tick_entity/custom_mob/drowned_necromancer/orb {height:1.1}
execute if score @s vb.dummy1 matches 2 if score @s vb.entity.boss_health matches 1..201 unless entity @e[tag=vb.custom_mob.oceanic_orb_trident,distance=..40] unless entity @e[tag=vb.custom_mob.oceanic_orb_core,distance=..40] run function vb:tick_entity/custom_mob/drowned_necromancer/orb {height:1.3}
execute if score @s vb.dummy1 matches 3 if score @s vb.entity.boss_health matches 1..201 unless entity @e[tag=vb.custom_mob.oceanic_orb_trident,distance=..40] unless entity @e[tag=vb.custom_mob.oceanic_orb_core,distance=..40] run function vb:tick_entity/custom_mob/drowned_necromancer/orb {height:1.5}

## Simulate damage
execute store result score @s vb.dummy1 run data get entity @s HurtTime
execute if score @s vb.dummy1 matches 10 run scoreboard players remove @s vb.entity.boss_health 10
execute if score @s vb.dummy1 matches 10 if score @s vb.entity.boss_health matches ..200 run scoreboard players add @s vb.entity.drowned_necromancer_heal 10
execute if score @s vb.entity.drowned_necromancer_heal matches 1.. run particle minecraft:enchanted_hit ~ ~1 ~ 1 1 1 0 40
execute if score @s vb.entity.drowned_necromancer_heal matches 1.. run scoreboard players add @s vb.entity.boss_health 1
execute if score @s vb.entity.drowned_necromancer_heal matches 1.. run scoreboard players remove @s vb.entity.drowned_necromancer_heal 1
execute if score @s vb.entity.drowned_necromancer_heal matches 30.. run scoreboard players add @s vb.entity.boss_health 10
execute if score @s vb.entity.drowned_necromancer_heal matches 30.. run scoreboard players remove @s vb.entity.drowned_necromancer_heal 10

## Intro animation
# Increment time
scoreboard players add @s vb.entity.boss_time 1
# Rise from the water
execute if score @s vb.entity.boss_time matches ..7 run data modify entity @s Motion[1] set value 1
execute if score @s vb.entity.boss_time matches 8 run data merge entity @s {Motion:[0f,0f,0f],NoAI:1b,NoGravity:1b}
# Watch players
execute if score @s vb.entity.boss_time matches 8.. run tp @s ~ ~ ~ facing entity @p[distance=..40]

## Attacks
# Increment time
scoreboard players add @s vb.timer.boss_attack 1
execute if score @s vb.timer.boss_attack matches 301.. run scoreboard players set @s vb.timer.boss_attack 1
# Attacks
execute if score @s vb.timer.boss_attack matches 60 run function vb:tick_entity/custom_mob/drowned_necromancer/attack/tridents
execute if score @s vb.timer.boss_attack matches 120 run function vb:tick_entity/custom_mob/drowned_necromancer/attack/zap
execute if score @s vb.timer.boss_attack matches 180 run function vb:tick_entity/custom_mob/drowned_necromancer/attack/allies
execute if score @s vb.timer.boss_attack matches 240 run function vb:tick_entity/custom_mob/drowned_necromancer/attack/snipe
execute if score @s vb.timer.boss_attack matches 300 run function vb:tick_entity/custom_mob/drowned_necromancer/attack/slow
