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

#Trap
execute at @s[scores={milk_time=0}] as @e[tag=alarm,limit=1,sort=nearest] run tag @s[tag=active_trap] add triggered
execute at @s[scores={milk_time=1..}] if entity @e[tag=active_trap,distance=..15] run advancement grant @s only f:professional_robbery

#Sound
scoreboard players set @s[scores={shift=0}] stealing2 0
scoreboard players add @s[scores={shift=1..}] stealing2 1
execute at @s[scores={stealing2=1}] run playsound minecraft:block.note_block.harp master @a ~ ~ ~ 1 2
scoreboard players set @s[scores={stealing2=4..}] stealing2 0

#Xp display
xp set @s 16 levels
xp set @s 0 points

scoreboard players set @s[scores={shift=0}] stealing 0
scoreboard players add @s[scores={shift=1..}] stealing 1


execute if entity @s[scores={stealing=1}] run xp set @s 1 points
execute if entity @s[scores={stealing=2}] run xp set @s 2 points
execute if entity @s[scores={stealing=3}] run xp set @s 3 points
execute if entity @s[scores={stealing=4}] run xp set @s 4 points
execute if entity @s[scores={stealing=5}] run xp set @s 5 points
execute if entity @s[scores={stealing=6}] run xp set @s 6 points
execute if entity @s[scores={stealing=7}] run xp set @s 7 points
execute if entity @s[scores={stealing=8}] run xp set @s 8 points
execute if entity @s[scores={stealing=9}] run xp set @s 9 points
execute if entity @s[scores={stealing=10}] run xp set @s 10 points
execute if entity @s[scores={stealing=11}] run xp set @s 11 points
execute if entity @s[scores={stealing=12}] run xp set @s 12 points
execute if entity @s[scores={stealing=13}] run xp set @s 13 points
execute if entity @s[scores={stealing=14}] run xp set @s 14 points
execute if entity @s[scores={stealing=15}] run xp set @s 15 points
execute if entity @s[scores={stealing=16}] run xp set @s 16 points
execute if entity @s[scores={stealing=17}] run xp set @s 17 points
execute if entity @s[scores={stealing=18}] run xp set @s 18 points
execute if entity @s[scores={stealing=19}] run xp set @s 19 points
execute if entity @s[scores={stealing=20}] run xp set @s 20 points
execute if entity @s[scores={stealing=21}] run xp set @s 21 points
execute if entity @s[scores={stealing=22}] run xp set @s 22 points
execute if entity @s[scores={stealing=23}] run xp set @s 23 points
execute if entity @s[scores={stealing=24}] run xp set @s 24 points
execute if entity @s[scores={stealing=25}] run xp set @s 25 points
execute if entity @s[scores={stealing=26}] run xp set @s 26 points
execute if entity @s[scores={stealing=27}] run xp set @s 27 points
execute if entity @s[scores={stealing=28}] run xp set @s 28 points
execute if entity @s[scores={stealing=29}] run xp set @s 29 points
execute if entity @s[scores={stealing=30}] run xp set @s 30 points
execute if entity @s[scores={stealing=31}] run xp set @s 31 points
execute if entity @s[scores={stealing=32}] run xp set @s 32 points
execute if entity @s[scores={stealing=33}] run xp set @s 33 points
execute if entity @s[scores={stealing=34}] run xp set @s 34 points
execute if entity @s[scores={stealing=35}] run xp set @s 35 points
execute if entity @s[scores={stealing=36}] run xp set @s 36 points
execute if entity @s[scores={stealing=37}] run xp set @s 37 points
execute if entity @s[scores={stealing=38}] run xp set @s 38 points
execute if entity @s[scores={stealing=39}] run xp set @s 39 points
execute if entity @s[scores={stealing=40}] run xp set @s 40 points
xp set @s 0 levels

execute at @s[scores={stealing=1..}] run particle minecraft:dust 1 0 0 1 ~ ~0.5 ~ 0.4 0.2 0.4 1 10 force @a

#Give pumpkin
execute if score @s[tag=blue_base] stealing matches 40 run scoreboard players remove $team_blue pumpkin_count 1
execute if score @s[tag=red_base] stealing matches 40 run scoreboard players remove $team_red pumpkin_count 1
execute if score @s[tag=green_base] stealing matches 40 run scoreboard players remove $team_green pumpkin_count 1
execute if score @s[tag=yellow_base] stealing matches 40 run scoreboard players remove $team_yellow pumpkin_count 1

execute if score @s stealing matches 40 run function f:game/pumpkin/give
execute if score @s stealing matches 40 run advancement grant @s only f:thief
execute if score @s stealing matches 40 run scoreboard players add @s stolen 1
execute if score @s stealing matches 40 if score @s stolen matches 10.. run advancement grant @s only f:parasite

tag @s add no_sensor
execute if score @s stealing matches 40 if score @s milk_time matches 0 as @a[scores={activity_sensor=0,kill-timer=..0},tag=!no_sensor,tag=player] run function f:game/activity_sensor/info
execute if score @s stealing matches 40 if score @s milk_time matches 0 as @a[scores={activity_sensor=2,kill-timer=..0},tag=!no_sensor,tag=player] run function f:game/activity_sensor/info
execute if score @s stealing matches 40 if score @s milk_time matches 0 run title @a[scores={activity_sensor=0,kill-timer=..0},tag=!no_sensor,tag=player] actionbar ["",{"selector":"@s","bold":true},{"translate":"game.stole","color":"gray"}]
execute if score @s stealing matches 40 if score @s milk_time matches 0 run title @a[scores={activity_sensor=2,kill-timer=..0},tag=!no_sensor,tag=player] actionbar ["",{"selector":"@s","bold":true},{"translate":"game.stole","color":"gray"}]
tag @s remove no_sensor

execute at @s[scores={stealing=40}] run playsound minecraft:block.note_block.harp master @a ~ ~ ~ 1 0.5
execute if score @s stealing matches 40.. run scoreboard players set @s stealing 0
