execute if entity @a[advancements={main:progression/other/reroll=false}] run return fail
execute if entity @s[tag=essence_interaction] run return fail
execute if entity @s[tag=relic_interaction] run return fail

#sfx
$execute as @a[tag=$(character)] if score @s transformator < .reroll_load transformator at @s run return run playsound block.chain.place master @s ~ ~ ~ 3 1 1

#consume
$execute at @s positioned ~-0.5 ~-0.5 ~-0.5 as @n[tag=artifact,dx=0,dz=0,dy=0] as @a[tag=$(character)] if score @s transformator >= .reroll_load transformator at @s run scoreboard players operation @s transformator -= .reroll_load transformator
# $execute at @s positioned ~-0.5 ~-0.5 ~-0.5 as @n[tag=blue_artifact,dx=0,dz=0,dy=0] as @a[tag=$(character),scores={transformator=1..}] at @s run scoreboard players remove @s transformator 1
# $execute at @s positioned ~-0.5 ~-0.5 ~-0.5 as @n[tag=purple_artifact,dx=0,dz=0,dy=0] as @a[tag=$(character),scores={transformator=1..}] at @s run scoreboard players remove @s transformator 1
# $execute at @s positioned ~-0.5 ~-0.5 ~-0.5 as @n[tag=orange_artifact,dx=0,dz=0,dy=0] as @a[tag=$(character),scores={transformator=1..}] at @s run scoreboard players remove @s transformator 1

scoreboard players add .reroll_load transformator 1

$execute as @a[tag=$(character)] run tag @s remove $(character)

playsound block.redstone_torch.burnout master @a ~ ~ ~ 10 2
playsound block.wooden_trapdoor.close master @a ~ ~ ~ 2 0
playsound block.anvil.use master @a ~ ~ ~ 2 1

particle enchanted_hit ~ ~1 ~ 0.25 0.25 0.25 0.1 20 force

execute at @s positioned ~-0.5 ~-0.5 ~-0.5 as @n[type=item,tag=green_artifact] at @s[tag=green_artifact,dx=0,dz=0,dy=0] run return run function main:mechanics/artifacts/reroll/give {"quality":green}

execute at @s positioned ~-0.5 ~-0.5 ~-0.5 as @n[type=item,tag=blue_artifact] at @s[tag=blue_artifact,dx=0,dz=0,dy=0] run return run function main:mechanics/artifacts/reroll/give {"quality":blue}

execute at @s positioned ~-0.5 ~-0.5 ~-0.5 as @n[type=item,tag=purple_artifact,dx=0,dz=0,dy=0] at @s[tag=purple_artifact] run return run function main:mechanics/artifacts/reroll/give {"quality":purple}

execute at @s positioned ~-0.5 ~-0.5 ~-0.5 as @n[type=item,tag=orange_artifact,dx=0,dz=0,dy=0] at @s[tag=orange_artifact] run return run function main:mechanics/artifacts/reroll/give {"quality":orange}

execute at @s positioned ~-0.5 ~-0.5 ~-0.5 as @n[type=item,tag=handicraft,dx=0,dz=0,dy=0] at @s[tag=handicraft] run return run function main:mechanics/artifacts/reroll/give {"quality":purple}

execute at @s positioned ~-0.5 ~-0.5 ~-0.5 as @n[type=item,tag=set_reward,dx=0,dz=0,dy=0] at @s[tag=set_reward] run return run function main:mechanics/artifacts/reroll/give {"quality":orange}

execute at @s positioned ~-0.5 ~-0.5 ~-0.5 as @n[type=item,tag=tutorial_item,dx=0,dz=0,dy=0] at @s[tag=tutorial_item] run return run function main:mechanics/artifacts/id/green/tutorial_item