#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
#
#    This function has been created by Skilendarz Group.
#             https://skilendarz.com
#
#      GIVE MAP MAKERS THE CREDIT THEY DESERVE!
#             COPYING IS PROHIBITED!
#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#

#Trigger
scoreboard players add missile time 0
execute if block 189 148 -398 minecraft:stone_button[powered=true] if score missile time matches 0 run scoreboard players set missile time 1
execute if score missile time matches 1.. run scoreboard players add missile time 1

#Timer
execute if score missile time matches 2 run summon minecraft:armor_stand 173 135 -395 {ArmorItems:[{},{},{},{id:"lime_dye",Count:1b,tag:{CustomModelData:45}}],Invisible:1,NoGravity:1,Tags:["missile"]}
execute if score missile time matches 2 as @a[distance=..60,x=202,y=146,z=-406] at @s run playsound minecraft:sound.rocket master @s ~ ~ ~ 0.5

execute if score missile time matches 2..15 as @e[tag=missile] at @s run tp @s ~ ~0.2 ~
execute if score missile time matches 16..30 as @e[tag=missile] at @s run tp @s ~ ~0.5 ~
execute if score missile time matches 31..40 as @e[tag=missile] at @s run tp @s ~0.1 ~0.7 ~
execute if score missile time matches 41..50 as @e[tag=missile] at @s run tp @s ~0.3 ~1 ~
execute if score missile time matches 51..200 as @e[tag=missile] at @s run tp @s ~0.6 ~1.5 ~

execute if score missile time matches 28..35 run scoreboard players add @e[tag=missile] time 1
execute if score missile time matches 38..45 run scoreboard players add @e[tag=missile] time 2
execute if score missile time matches 48..55 run scoreboard players add @e[tag=missile] time 3

execute if score missile time matches 200 run kill @e[tag=missile]
execute if score missile time matches 250 as @a[distance=..60,x=202,y=146,z=-406] at @s run playsound minecraft:sound.explosion master @s ~ ~ ~
execute if score missile time matches 240 run time set 41000
execute if score missile time matches 250 as @a[distance=..60,x=202,y=146,z=-406] at @s run particle minecraft:explosion ~1 ~5 ~ 0 0 0 0 2 force @s

#Visual
execute as @e[tag=missile] run data merge entity @s {Pose:{Head:[0.0f,0.0f,0.01f]}}
execute as @e[tag=missile] store result entity @s Pose.Head[2] float 0.5 run scoreboard players get @s time

execute at @e[tag=missile] run particle minecraft:poof ~-1 ~-2 ~ 0 -1 0 1 0 force @a
execute at @e[tag=missile] run particle minecraft:cloud ~-1 ~-2 ~ 0 -1 0 1 0 force @a
execute at @e[tag=missile] run particle minecraft:cloud ~-1 ~-2 ~ 0 -1 -0.1 1 0 force @a
execute at @e[tag=missile] run particle minecraft:cloud ~-1 ~-2 ~ 0 -1 0.1 1 0 force @a
execute at @e[tag=missile] run particle minecraft:cloud ~-1 ~-2 ~ -0.1 -1 0 1 0 force @a
execute at @e[tag=missile] run particle minecraft:cloud ~-1 ~-2 ~ 0.1 -1 0 1 0 force @a
execute at @e[tag=missile] run particle minecraft:flame ~-1 ~-2 ~ 0 -1 -0.1 0.5 0 force @a
execute at @e[tag=missile] run particle minecraft:flame ~-1 ~-2 ~ 0 -1 0.1 0.5 0 force @a
execute at @e[tag=missile] run particle minecraft:flame ~-1 ~-1.2 ~ 0.1 -1 0 0.5 0 force @a
execute at @e[tag=missile] run particle minecraft:flame ~-1 ~-2 ~ -0.1 -1 0 0.5 0 force @a
