## Run from "controller.animation.dungeon_lever.powered_state"
## @s = ldz:dungeon_lever

scoreboard objectives add BeastBarrier dummy
scoreboard objectives add MysticBarrier dummy
scoreboard objectives add ScourgeBarrier dummy
scoreboard objectives add WraithBarrier dummy

playsound entity.dungeon_lever.activate @a ~ ~ ~

## PORTAL ROOM LEVER MOVING DOWN
execute as @s[family=portal_room_lever] run tellraw @a[tag=dev] { "rawtext": [ { "text": "§9Portal Room Lever Activated" } ] }
execute as @s[family=portal_room_lever] run event entity @e[type=ldz:magic_barrier,family=portal_room_barrier] set_barrier_to_disappear

execute as @s[family=portal_room_lever] at @e[family=portal_room_barrier] run fill ~-1 ~ ~ ~1 ~2 ~ ldz:lit_air
# execute as @s[family=portal_room_lever] if score .current TutorialStage matches 6 run event entity @e[type=ldz:bob_arrow,r=2,c=1] despawn
execute as @s[family=portal_room_lever] if score .current TutorialStage matches 7 as @p run function tutorial/complete



## BEAST HUB LEVER MOVING DOWN
execute as @s[family=beast_lever_hub] run tellraw @a[tag=dev] { "rawtext": [ { "text": "§9Beast Hub Lever Activated" } ] }
execute as @s[family=beast_lever_hub] run event entity @e[type=ldz:magic_barrier,family=beast_hub_barrier] set_barrier_to_disappear
execute as @s[family=beast_lever_hub] at @e[type=ldz:magic_barrier,family=beast_hub_barrier] run fill ~-1 ~ ~ ~1 ~2 ~ ldz:lit_air

## BEAST DUNGEON
execute as @s[family=beast_lever_dungeon] run tellraw @a[tag=dev] { "rawtext": [ { "text": "§9Beast Dungeon Lever Activated" } ] }
execute as @s[family=beast_lever_dungeon] run titleraw @a actionbar { "rawtext": [ { "text": "{txt:" }, { "translate": "text.hint.dungeon_barrier_lifted" }, { "text": ",bg:true,alpha_stay:5}" }] }
execute as @s[family=beast_lever_dungeon] run event entity @e[type=ldz:magic_barrier,family=beast_dungeon_barrier] set_barrier_to_disappear
execute as @s[family=beast_lever_dungeon] run event entity @e[type=ldz:help_bubble,family=beast_bubble] despawn
execute as @s[family=beast_lever_dungeon] at @e[type=ldz:magic_barrier,family=beast_dungeon_barrier] run fill ~-1 ~ ~ ~1 ~2 ~ air
execute as @s[family=beast_lever_dungeon] run scoreboard players set .var BeastBarrier -1
execute as @s[family=beast_lever_dungeon] run scoreboard objectives remove MagicBarrierDB
execute as @s[family=beast_lever_dungeon] run playsound entity.dungeon_lever.power_down_alt @a ~ ~ ~
execute as @s[family=beast_lever_dungeon] run setblock ~ ~-1 ~ ldz:ender_copper_2


## MYSTIC HUB LEVER MOVING DOWN
execute as @s[family=mystic_lever_hub] run tellraw @a[tag=dev] { "rawtext": [ { "text": "§9Mystic Hub Lever Activated" } ] }
execute as @s[family=mystic_lever_hub] run event entity @e[type=ldz:magic_barrier,family=mystic_hub_barrier] set_barrier_to_disappear
execute as @s[family=mystic_lever_hub] at @e[family=mystic_hub_barrier] run fill ~ ~ ~-1 ~ ~2 ~1 ldz:lit_air

## MYSTIC DUNGEON
execute as @s[family=mystic_lever_dungeon] run tellraw @a[tag=dev] { "rawtext": [ { "text": "§9Mystic Dungeon Lever Activated" } ] }
execute as @s[family=mystic_lever_dungeon] run titleraw @a actionbar { "rawtext": [ { "text": "{txt:" }, { "translate": "text.hint.dungeon_barrier_lifted" }, { "text": ",bg:true,alpha_stay:5}" }] }
execute as @s[family=mystic_lever_dungeon] run event entity @e[type=ldz:magic_barrier,family=mystic_dungeon_barrier] set_barrier_to_disappear
execute as @s[family=mystic_lever_dungeon] run event entity @e[type=ldz:help_bubble,family=mystic_bubble] despawn
execute as @s[family=mystic_lever_dungeon] at @e[type=ldz:magic_barrier,family=mystic_dungeon_barrier] run fill ~ ~ ~-1 ~ ~2 ~1 air
execute as @s[family=mystic_lever_dungeon] run scoreboard players set .var MysticBarrier -1
execute as @s[family=mystic_lever_dungeon] run scoreboard objectives remove MagicBarrierDM
execute as @s[family=mystic_lever_dungeon] run playsound entity.dungeon_lever.power_down_alt @a ~ ~ ~
execute as @s[family=mystic_lever_dungeon] run setblock ~ ~-1 ~ ldz:ender_copper_2


## SCOURGE HUB LEVER MOVING DOWN
execute as @s[family=scourge_lever_hub] run tellraw @a[tag=dev] { "rawtext": [ { "text": "§9Scourge Hub Lever Activated" } ] }
execute as @s[family=scourge_lever_hub] run event entity @e[type=ldz:magic_barrier,family=scourge_hub_barrier] set_barrier_to_disappear
execute as @s[family=scourge_lever_hub] at @e[type=ldz:magic_barrier,family=scourge_hub_barrier] run fill ~-1 ~ ~ ~1 ~2 ~ ldz:lit_air

## SCOURGE DUNGEON
execute as @s[family=scourge_lever_dungeon] run tellraw @a[tag=dev] { "rawtext": [ { "text": "§9Scourge Dungeon Lever Activated" } ] }
execute as @s[family=scourge_lever_dungeon] run titleraw @a actionbar { "rawtext": [ { "text": "{txt:" }, { "translate": "text.hint.dungeon_barrier_lifted" }, { "text": ",bg:true,alpha_stay:5}" }] }
execute as @s[family=scourge_lever_dungeon] run event entity @e[type=ldz:magic_barrier,family=scourge_dungeon_barrier] set_barrier_to_disappear
execute as @s[family=scourge_lever_dungeon] run event entity @e[type=ldz:help_bubble,family=scourge_bubble] despawn
execute as @s[family=scourge_lever_dungeon] at @e[type=ldz:magic_barrier,family=scourge_dungeon_barrier] run fill ~ ~ ~-1 ~ ~2 ~1 air
execute as @s[family=scourge_lever_dungeon] run scoreboard players set .var ScourgeBarrier -1
execute as @s[family=scourge_lever_dungeon] run scoreboard objectives remove MagicBarrierDS
execute as @s[family=scourge_lever_dungeon] run playsound entity.dungeon_lever.power_down_alt @a ~ ~ ~
execute as @s[family=scourge_lever_dungeon] run setblock ~ ~-1 ~ ldz:ender_copper_2


## WRAITH HUB LEVER MOVING DOWN
execute as @s[family=wraith_lever_hub] run tellraw @a[tag=dev] { "rawtext": [ { "text": "§9Wraith Hub Lever Activated" } ] }
execute as @s[family=wraith_lever_hub] run event entity @e[type=ldz:magic_barrier,family=wraith_hub_barrier] set_barrier_to_disappear
execute as @s[family=wraith_lever_hub] at @e[type=ldz:magic_barrier,family=wraith_hub_barrier] run fill ~ ~ ~-1 ~ ~2 ~1 ldz:lit_air

## WRAITH DUNGEON
execute as @s[family=wraith_lever_dungeon] run tellraw @a[tag=dev] { "rawtext": [ { "text": "§9Wraith Dungeon Lever Activated" } ] }
execute as @s[family=wraith_lever_dungeon] run titleraw @a actionbar { "rawtext": [ { "text": "{txt:" }, { "translate": "text.hint.dungeon_barrier_lifted" }, { "text": ",bg:true,alpha_stay:5}" }] }
execute as @s[family=wraith_lever_dungeon] run event entity @e[type=ldz:magic_barrier,family=wraith_dungeon_barrier] set_barrier_to_disappear
execute as @s[family=wraith_lever_dungeon] run event entity @e[type=ldz:help_bubble,family=wraith_bubble] despawn
execute as @s[family=wraith_lever_dungeon] at @e[type=ldz:magic_barrier,family=wraith_dungeon_barrier] run fill ~ ~ ~-1 ~ ~2 ~1 air
execute as @s[family=wraith_lever_dungeon] run scoreboard players set .var WraithBarrier -1
execute as @s[family=wraith_lever_dungeon] run scoreboard objectives remove MagicBarrierDW
execute as @s[family=wraith_lever_dungeon] run playsound entity.dungeon_lever.power_down_alt @a ~ ~ ~
execute as @s[family=wraith_lever_dungeon] run setblock ~ ~-1 ~ ldz:ender_copper_2
execute as @s[family=wraith_lever_dungeon] run setblock 595 170 52 basalt
execute as @s[family=wraith_lever_dungeon] run setblock 595 169 52 lantern
execute as @s[family=wraith_lever_dungeon] run setblock 595 169 48 lantern

## Despawn any old bob arrows
event entity @e[type=ldz:bob_arrow] despawn

## Summon a new bob arrow
execute as @s[family=beast_lever_dungeon] as @e[type=ldz:magic_barrier,family=beast_dungeon_barrier] at @s if entity @e[type=ldz:ender_chef,r=5] run summon ldz:bob_arrow 82 156 -479 180 0 set_diagonal_to_true
execute as @s[family=mystic_lever_dungeon] as @e[type=ldz:magic_barrier,family=mystic_dungeon_barrier] at @s if entity @e[type=ldz:ender_charger,r=5] run summon ldz:bob_arrow -528 170 -159 90 0 set_diagonal_to_true
execute as @s[family=scourge_lever_dungeon] as @e[type=ldz:magic_barrier,family=scourge_dungeon_barrier] at @s if entity @e[type=ldz:ender_gardener,r=5] run summon ldz:bob_arrow 27 168 446 -90 0 set_diagonal_to_true
execute as @s[family=wraith_lever_dungeon] as @e[type=ldz:magic_barrier,family=wraith_dungeon_barrier] at @s if entity @e[type=ldz:ender_hydro,r=5] run summon ldz:bob_arrow 588 168.7 50 -90 0 set_diagonal_to_true