# © Spark Universe, 2023
# authors: destruc7i0n
# description: main loop for p7
# called by: 

scoreboard players add @s[scores={tut_timer=..60}] tut_timer 1
scoreboard players add @s[scores={tut_timer=200..}] tut_timer 1

execute if score @s tut_timer matches 1 run tp @p[tag=instance_player] ~ ~ ~ 0 0
execute if score @s tut_timer matches 1 positioned ~ ~ ~3 run tp @e[tag=instance_pet] ~ ~ ~ facing @p[tag=instance_player]
# make the pet immobile for this part
execute if score @s tut_timer matches 1 run event entity @e[tag=instance_pet] spark:immobile

execute if score @s tut_timer matches 60 if entity @e[tag=instance_pet,family=dog] run give @p[tag=instance_player] spark:sweet 1 0 {"minecraft:item_lock": {"mode": "lock_in_slot"}, "minecraft:keep_on_death": {}}
execute if score @s tut_timer matches 60 if entity @e[tag=instance_pet,family=robot] run give @p[tag=instance_player] spark:robot_sweet 1 0 {"minecraft:item_lock": {"mode": "lock_in_slot"}, "minecraft:keep_on_death": {}}
execute if score @s tut_timer matches 60 run scoreboard players set @p[tag=instance_player] SS_ui_tutorial 8
# execute if score @s tut_timer matches 60 run playsound mob.villager.haggle @p[tag=instance_player]

# wait for trick to complete
execute if score @s tut_timer matches 61 if entity @e[tag=instance_pet,tag=trick] run scoreboard players set @s tut_timer 100
execute if score @s tut_timer matches 100 if entity @e[tag=instance_pet,tag=!trick] run scoreboard players set @s tut_timer 200

execute if score @s tut_timer matches 200 run scoreboard players set @p[tag=instance_player] SS_ui_tutorial 0
execute if score @s tut_timer matches 200 run playsound spark.zombies2.tutorial.end @p[tag=instance_player]
execute if score @s tut_timer matches 200 run music stop 4.0

execute if score @s tut_timer matches 260 run event entity @e[tag=instance_pet] spark:mobile
execute if score @s tut_timer matches 260 run function spark/tutorial/p7/next
