# Functions

function slender:map_intro
function slender:map_end

    #Scenes
    function slender:scenes/intro1
    function slender:scenes/intro2
    function slender:scenes/office1
    function slender:scenes/power_off
    function slender:scenes/encounter1
    function slender:scenes/encounter2
    function slender:scenes/nose_bleeding
    function slender:scenes/chase
    
    
    #Scripts
    function slender:scripts/vending_machine
    function slender:scripts/vent_transition
    function slender:scripts/fuse_section
    function slender:scripts/corridor_mass
    function slender:scripts/vent_drop
    function slender:scripts/office1
    function slender:scripts/elevator/lobby
    function slender:scripts/elevator/elevator1
    function slender:scripts/interactions/interaction
    function slender:scripts/vent_breaking
    function slender:scripts/slenderman1
    function slender:scripts/slenderman2
    function slender:scripts/laura_office_visit
    function slender:scripts/electric_water_death
    function slender:scripts/elevator_shaft
    
    function slender:scripts/dialogy/shes_crazy
    function slender:scripts/dialogy/what_is_happening
    
    #Bossbars/Objectives
    function slender:bossbar/buy_snack
    function slender:bossbar/explore_floor
    function slender:bossbar/pick_snack
    function slender:bossbar/go_work
    function slender:bossbar/vent_break
    function slender:bossbar/back_to_office
    function slender:bossbar/run
    function slender:bossbar/call_the_elevator

    bossbar set objectives players @a
    bossbar set obj_detail players @a
    bossbar set fuse players @a
    
    execute if score ticks bossbar matches 1 run playsound minecraft:ui.toast.in master @a ~ ~ ~ 99999999999 1
    execute if score ticks bossbar matches 1..40 run scoreboard players add ticks bossbar 1
    
    #Ambient and Environment
    function slender:ambient/ambient
    function slender:ambient/thunder
    function slender:ambient/scripts



# Teleporting AJ models
tp @e[tag=aj.laura_enemy.root] @e[type=zombie,tag=laura,limit=1]
tp @e[tag=aj.laura.root] @e[tag=laura,limit=1]
tp @e[tag=aj.clean_guy_final.root] @e[tag=cleaning_guy,limit=1]

# Gamemode
execute if score gamemode map matches 0 run attribute @p minecraft:generic.movement_speed base set 0.1
execute if score gamemode map matches 1 run attribute @p minecraft:generic.movement_speed base set 0.045
execute if score gamemode map matches 2 run attribute @p minecraft:generic.movement_speed base set 0.060
execute if score gamemode map matches 3 run attribute @p minecraft:generic.movement_speed base set 0.115

execute if score gamemode map matches 0 run scoreboard players set camera_movement map 0
execute if score gamemode map matches 1..2 run scoreboard players set camera_movement map 1
execute if score gamemode map matches 3 run scoreboard players set camera_movement map 2

execute if score gamemode map matches 1..3 run gamemode adventure @a
execute if score gamemode map matches 1..3 run kill @e[type=item]

bossbar set fuse players @a
bossbar set obj_detail players @a
bossbar set objectives players @a

# Equipments
    # Phone + Right Arm
    execute if score equipment map matches 1 run item replace entity @e weapon.mainhand with charcoal{display:{Name:'{"text":""}'},CustomModelData:1}
    execute if score equipment map matches 1 run item replace entity @e weapon.offhand with charcoal{display:{Name:'{"text":""}'},CustomModelData:2}


    # Right Arm
    execute if score equipment map matches 2 run item replace entity @e weapon.mainhand with charcoal{display:{Name:'{"text":""}'},CustomModelData:1}
    execute if score equipment map matches 2 run item replace entity @e weapon.offhand with charcoal{display:{Name:'{"text":""}'},CustomModelData:10}

    # Right Arm Coffee
    execute if score equipment map matches 3 run item replace entity @e weapon.mainhand with charcoal{display:{Name:'{"text":""}'},CustomModelData:3}
    execute if score equipment map matches 3 run item replace entity @e weapon.offhand with charcoal{display:{Name:'{"text":""}'},CustomModelData:10}

    # Right Arm Blood
    execute if score equipment map matches 4 run item replace entity @e weapon.mainhand with charcoal{display:{Name:'{"text":""}'},CustomModelData:4}
    execute if score equipment map matches 4 run item replace entity @e weapon.offhand with charcoal{display:{Name:'{"text":""}'},CustomModelData:10}

    # Phone + Bloody Right Arm
    execute if score equipment map matches 5 run item replace entity @e weapon.mainhand with charcoal{display:{Name:'{"text":""}'},CustomModelData:4}
    execute if score equipment map matches 5 run item replace entity @e weapon.offhand with charcoal{display:{Name:'{"text":""}'},CustomModelData:2}


    # Phone + Crowbar

    # Nothing(empty)
    execute if score equipment map matches 10 run item replace entity @e weapon.mainhand with charcoal{display:{Name:'{"text":""}'},CustomModelData:10}
    execute if score equipment map matches 10 run item replace entity @e weapon.offhand with air


# Phone Light Source
    execute if score phone_light map matches 1 at @p run fill ~10 ~-10 ~-10 ~-10 ~10 ~10 air replace light[level=8]
    execute if score phone_light map matches 1 at @p run fill ~10 ~-10 ~-10 ~-10 ~10 ~10 air replace light[level=6]
    execute if score phone_light map matches 1 at @p run execute at @p[nbt={Inventory:[{id:"minecraft:charcoal"},{Slot:-106b}]}] run fill ~ ~ ~ ~ ~ ~ light[level=8] replace air

    # Flashing when going through the door/ladder
    execute if score phone_light map matches 1 at @p[nbt={Inventory:[{id:"minecraft:charcoal"},{Slot:-106b}]}] if block ~ ~ ~ spruce_door run fill ~1 ~-1 ~-1 ~-1 ~1 ~1 light[level=6] replace air
    execute if score phone_light map matches 1 at @p[nbt={Inventory:[{id:"minecraft:charcoal"},{Slot:-106b}]}] if block ~ ~ ~ warped_door run fill ~1 ~-1 ~-1 ~-1 ~1 ~1 light[level=6] replace air
    execute if score phone_light map matches 1 at @p[nbt={Inventory:[{id:"minecraft:charcoal"},{Slot:-106b}]}] if block ~ ~ ~ ladder run fill ~1 ~-1 ~-1 ~-1 ~1 ~1 light[level=6] replace air

    # Score to Off and On
    execute if score phone_light map matches 0 at @p run fill ~10 ~-10 ~-10 ~-10 ~10 ~10 air replace light[level=8]
    execute if score phone_light map matches 0 at @p run fill ~10 ~-10 ~-10 ~-10 ~10 ~10 air replace light[level=6]
    execute if score phone_light map matches 0 at @p run scoreboard players set phone_light map 10
# Darkness


execute if score darkness map matches 1 run summon item_display ~ ~ ~ {NoGravity:1b,Silent:1b,view_range:20f,billboard:"vertical",item_display:"head",Rotation:[90F,0F],Tags:["player"],CustomName:'{"text":"darkness"}',transformation:{left_rotation:[0f,0f,0f,1f],right_rotation:[0f,0f,0f,1f],translation:[0f,0f,0f],scale:[2f,3f,2f]},item:{id:"minecraft:coal",Count:1b,tag:{CustomModelData:2}}}
execute if score darkness map matches 1 run summon item_display ~ ~ ~ {NoGravity:1b,Silent:1b,view_range:20f,billboard:"vertical",item_display:"head",Rotation:[90F,0F],Tags:["player"],CustomName:'{"text":"darkness"}',transformation:{left_rotation:[0f,0f,0f,1f],right_rotation:[0f,0f,0f,1f],translation:[0f,0f,0f],scale:[2.2f,3f,2.2f]},item:{id:"minecraft:coal",Count:1b,tag:{CustomModelData:2}}}


execute if score darkness map matches 1..10 as @p at @s rotated ~ 0 run tp @e[name=darkness] ^ ^ ^
execute if score darkness map matches 1..2 run scoreboard players add darkness map 1

# WALKING CAMERA

execute if score camera_movement map matches 1 if score @p camera_movement matches 1..40 as @p at @s run tp @s ~ ~ ~ ~ ~0.10
 execute if score camera_movement map matches 1 if score @p camera_movement matches 40..80 as @p at @s run tp @s ~ ~ ~ ~ ~-0.10
 execute if score camera_movement map matches 1 if score @p walking matches 1.. if score @p camera_movement matches 1..10 as @p at @s run tp @s ~ ~ ~ ~0.125 ~0.25
 execute if score camera_movement map matches 1 if score @p walking matches 1.. if score @p camera_movement matches 10..20 as @p at @s run tp @s ~ ~ ~ ~-0.125 ~-0.25
 execute if score camera_movement map matches 1 if score @p walking matches 1.. if score @p camera_movement matches 20..30 as @p at @s run tp @s ~ ~ ~ ~0.125 ~0.25
 execute if score camera_movement map matches 1 if score @p walking matches 1.. if score @p camera_movement matches 30..40 as @p at @s run tp @s ~ ~ ~ ~-0.125 ~-0.25
 execute if score camera_movement map matches 1 if score @p walking matches 1.. if score @p camera_movement matches 40..50 as @p at @s run tp @s ~ ~ ~ ~0.125 ~0.25
 execute if score camera_movement map matches 1 if score @p walking matches 1.. if score @p camera_movement matches 50..60 as @p at @s run tp @s ~ ~ ~ ~-0.125 ~-0.25
 execute if score camera_movement map matches 1 if score @p walking matches 1.. if score @p camera_movement matches 60..70 as @p at @s run tp @s ~ ~ ~ ~0.125 ~0.25
 execute if score camera_movement map matches 1 if score @p walking matches 1.. if score @p camera_movement matches 70..80 as @p at @s run tp @s ~ ~ ~ ~-0.125 ~-0.25
 execute if score camera_movement map matches 1 if score @p camera_movement matches 1..40 as @e[tag=camera] at @s run tp @e[tag=camera] ~ ~ ~ ~ ~0.10
 execute if score camera_movement map matches 1 if score @p camera_movement matches 40..80 as @e[tag=camera] at @s run tp @e[tag=camera] ~ ~ ~ ~ ~-0.10
 execute if score camera_movement map matches 1 as @p at @s run scoreboard players add @s camera_movement 1
 execute if score camera_movement map matches 1 if score @p camera_movement matches 80.. as @p at @s run scoreboard players set @p camera_movement 1


# RUNNING CAMERA

 execute if score camera_movement map matches 2 if score @p walking matches 1.. if score @p camera_movement matches 1..5 as @p at @s run tp @s ~ ~ ~ ~0.35 ~0.5
 execute if score camera_movement map matches 2 if score @p walking matches 1.. if score @p camera_movement matches 5..10 as @p at @s run tp @s ~ ~ ~ ~-0.35 ~-0.5
 execute if score camera_movement map matches 2 as @a[nbt={OnGround:0b}] if score @p camera_movement matches 1..5 as @p at @s run tp @s ~ ~ ~ ~0.35 ~0.5
 execute if score camera_movement map matches 2 as @a[nbt={OnGround:0b}] if score @p camera_movement matches 5..10 as @p at @s run tp @s ~ ~ ~ ~-0.35 ~-0.5
 execute if score camera_movement map matches 2 as @p at @s run scoreboard players add @s camera_movement 1
 execute if score camera_movement map matches 2 if score @p camera_movement matches 10.. as @p at @s run scoreboard players set @p camera_movement 1

execute as @p[nbt={Motion:[0.0,0.0,0.0]}] if score @p walking matches 1.. run scoreboard players set @p walking 0

# Objectives
    #Fuse
    execute if score obj_fuse map matches 0 run bossbar set minecraft:fuse name ["",{"text":"Collect Fuse Tubes"},{"text":" 0/3","bold":true,"color":"white"}]

    execute if score obj_fuse map matches 1 run bossbar set minecraft:fuse name ["",{"text":"Collect Fuse Tubes"},{"text":" 1/3","bold":true,"color":"white"}]

    execute if score obj_fuse map matches 2 run bossbar set minecraft:fuse name ["",{"text":"Collect Fuse Tubes"},{"text":" 2/3","bold":true,"color":"white"}]

    execute if score obj_fuse map matches 3 run bossbar set minecraft:fuse name ["",{"text":"Collect Fuse Tubes"},{"text":" 3/3","bold":true,"color":"green"}]



# Hunger(disable sprint)

execute if score gamemode map matches 1..3 if entity @p[nbt={foodLevel:0}] run effect give @p saturation 2 1 true
execute if score gamemode map matches 1..3 if entity @p[nbt={foodLevel:1}] run effect give @p saturation 1 1 true
execute if score gamemode map matches 1..3 if entity @p[nbt={foodLevel:2}] run effect give @p hunger 1 150 true
execute if score gamemode map matches 1..3 if entity @p[nbt={foodLevel:20}] run effect give @p hunger 1 255 true
execute if score gamemode map matches 1..3 if entity @p[nbt={foodLevel:19}] run effect give @p hunger 1 255 true
execute if score gamemode map matches 1..3 if entity @p[nbt={foodLevel:18}] run effect give @p hunger 1 255 true
execute if score gamemode map matches 1..3 if entity @p[nbt={foodLevel:17}] run effect give @p hunger 1 255 true
execute if score gamemode map matches 1..3 if entity @p[nbt={foodLevel:16}] run effect give @p hunger 1 255 true
execute if score gamemode map matches 1..3 if entity @p[nbt={foodLevel:15}] run effect give @p hunger 1 255 true
execute if score gamemode map matches 1..3 if entity @p[nbt={foodLevel:14}] run effect give @p hunger 1 255 true
execute if score gamemode map matches 1..3 if entity @p[nbt={foodLevel:13}] run effect give @p hunger 1 255 true
execute if score gamemode map matches 1..3 if entity @p[nbt={foodLevel:12}] run effect give @p hunger 1 255 true
execute if score gamemode map matches 1..3 if entity @p[nbt={foodLevel:11}] run effect give @p hunger 1 255 true
execute if score gamemode map matches 1..3 if entity @p[nbt={foodLevel:10}] run effect give @p hunger 1 255 true
execute if score gamemode map matches 1..3 if entity @p[nbt={foodLevel:9}] run effect give @p hunger 1 255 true
execute if score gamemode map matches 1..3 if entity @p[nbt={foodLevel:8}] run effect give @p hunger 1 255 true
execute if score gamemode map matches 1..3 if entity @p[nbt={foodLevel:7}] run effect give @p hunger 1 255 true
execute if score gamemode map matches 1..3 if entity @p[nbt={foodLevel:6}] run effect give @p hunger 1 255 true
execute if score gamemode map matches 1..3 if entity @p[nbt={foodLevel:5}] run effect give @p hunger 1 255 true
execute if score gamemode map matches 1..3 if entity @p[nbt={foodLevel:4}] run effect give @p hunger 1 255 true
execute if score gamemode map matches 1..3 if entity @p[nbt={foodLevel:3}] run effect give @p hunger 1 255 true
execute if score gamemode map matches 0 if entity @p[nbt={foodLevel:0}] run effect give @p saturation 5 255 true
execute if score gamemode map matches 0 if entity @p[nbt={foodLevel:1}] run effect give @p saturation 5 255 true
execute if score gamemode map matches 0 if entity @p[nbt={foodLevel:2}] run effect give @p saturation 5 255 true
