# © Spark Universe, 2023
# authors: destruc7i0n
# description: loop for p6
# 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..60 positioned ~ ~ ~3 run tp @e[tag=instance_pet] ~ ~ ~ 0 0

execute if score @s tut_timer matches 60 run function spark/tutorial/p6/spawn_attack_zombie

# check when the pet is incapacitated
execute if score @s tut_timer matches 61 if entity @e[tag=instance_pet,tag=incapacitated] run function spark/tutorial/p6/on_incapacitated_pet

# wait for player to use healing pack
execute if score @s tut_timer matches 100 run give @p[tag=instance_player,hasitem={item=spark:special_healing_pack,quantity=0}] spark:special_healing_pack 1 0 {"minecraft:item_lock": {"mode": "lock_in_slot"}, "minecraft:keep_on_death": {}}
execute if score @s tut_timer matches 100 if entity @e[tag=instance_pet,tag=!incapacitated] run scoreboard players set @s tut_timer 200
execute if score @s tut_timer matches 200 run clear @p[tag=instance_player] spark:special_healing_pack
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.success_minor @p[tag=instance_player]

execute if score @s tut_timer matches 260 run event entity @e[tag=instance_pet] spark:mobile
# after a bit move to last step
execute if score @s tut_timer matches 260 run function spark/tutorial/p6/next
