execute if score #startSEQ V matches 1 run function npc:dialogue/start

execute as @e[tag=d_0] on target run tag @e[tag=d_0] add lvl1
execute as @e[tag=lvl1] unless entity @s[tag=lvl1b] run function npc:dialogue/lvl1

execute if entity @a[scores={checkpoint=1}] unless entity @a[scores={checkpoint=..0},tag=player] if block 80 -1 -10 barrier run data merge entity ac67ec9f-b328-419b-b9b9-f8d18e4176a4 {block_state:{Name:"minecraft:glass"}}
execute if entity @a[scores={checkpoint=1}] unless entity @a[scores={checkpoint=..0},tag=player] if block 80 -1 -10 barrier run playsound minecraft:block.end_portal_frame.fill master @a 80 -1 -10 2 1.7
execute if entity @a[scores={checkpoint=1}] unless entity @a[scores={checkpoint=..0},tag=player] if block 80 -1 -10 barrier run fill 80 -1 -9 80 -1 -11 air

execute if entity @a[scores={checkpoint=2}] unless entity @a[scores={checkpoint=..1},tag=player] unless entity @e[tag=d_1] run tag @e[tag=d_1_] add d_1

execute as @e[tag=d_1] on target run tag @e[tag=d_1] add lvl3
execute as @e[tag=lvl3] unless entity @s[tag=lvl3b] run function npc:dialogue/lvl3

execute if score #npc_m1 V matches 1 run function npc:move/1

execute if entity @a[scores={checkpoint=3}] unless entity @a[scores={checkpoint=..2},tag=player] unless entity @e[tag=pre_lvl4] unless entity @e[tag=lvl4] run function npc:dialogue/prep_lvl4
execute as @e[tag=pre_lvl4] unless entity @s[tag=lvl4] run function npc:move/2

execute as @e[tag=lvl4] on target run tag @e[tag=lvl4] add lvl4a
execute as @e[tag=lvl4a] unless entity @s[tag=lvl4b] run function npc:dialogue/lvl4

execute if entity @a[scores={checkpoint=4}] unless entity @a[scores={checkpoint=..3},tag=player] if entity @e[tag=npc_2] run function npc:dialogue/prep_lvl5

execute as @e[tag=lvl5] on target run tag @e[tag=lvl5] add lvl5a
execute as @e[tag=lvl5a] unless entity @s[tag=lvl5b] run function npc:dialogue/lvl5

execute if entity @a[scores={checkpoint=5}] unless entity @a[scores={checkpoint=..4},tag=player] unless entity @e[tag=npc_4] run function npc:dialogue/prep_lvl6

execute as @e[tag=lvl6] on target run tag @e[tag=lvl6] add lvl6a
execute as @e[tag=lvl6a] unless entity @s[tag=lvl6b] run function npc:dialogue/lvl6

execute if entity @a[scores={checkpoint=6}] unless entity @a[scores={checkpoint=..5},tag=player] unless score #lvl7d time matches -1 run function npc:dialogue/lvl7
execute if entity @a[scores={checkpoint=6}] run execute as @e[tag=npc_troll] at @s if entity @p[distance=..7,gamemode=spectator] run tp @s ~ ~ ~ facing entity @p

execute if entity @a[scores={checkpoint=7}] unless entity @a[scores={checkpoint=..6},tag=player] if block 34 37 -23 air run function system:event/final
execute if score #final time matches 1..600 run function npc:dialogue/final
#blink
scoreboard players add #npc.blink time 1
execute if score #npc.blink time matches 1 run execute store result score #npc.blink V run random value 40..200
execute if score #npc.blink time matches 3 run item replace entity @e[tag=npc,tag=!npc_troll] armor.head with player_head{SkullOwner:{Id:[I;-1270540108,-998941926,-1858353752,-1399270529],Properties:{textures:[{Value:"e3RleHR1cmVzOntTS0lOOnt1cmw6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMWZhMjlmMmZlNjBkMzhjMjRjNGQ3ODZlMDZmMjI5OWQxZjYzYmQzN2FjZmU0YTk1ZGRkZDM4MTdjZjRkYzVkYSJ9fX0="}]}}}
execute if score #npc.blink time >= #npc.blink V run item replace entity @e[tag=npc,tag=!npc_troll] armor.head with player_head{SkullOwner:{Id:[I;1636478810,-991209298,-1700698047,-827300248],Properties:{textures:[{Value:"e3RleHR1cmVzOntTS0lOOnt1cmw6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZWZiNjE5NzZlYzI2NTQxZDQ1YzdhOTYwZTM3MDE3MTZkNmFhN2VmNmU5YzNkZjYyMDE2MTAyNTI4ZDQ4YjA5NCJ9fX0="}]}}}
execute if score #npc.blink time >= #npc.blink V run scoreboard players reset #npc.blink time