
# --> (@EVENT: clicked on a build-armor menu button - build chestplate, copper, confirmation button /// ID: 100,029)

# -> Message
execute if score #or.setting.output_messages OverlyRealistic.Settings.ArbitrarySetting matches 1 \
    if score #or.setting.overlay_messages OverlyRealistic.Settings.ArbitrarySetting matches 1 run \
        tellraw @s [\
        {\
            text:"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"\
        },\
        {\
            text:"[Lay Figure] \n",\
            color:"#929292",\
            bold:true\
        },\
        {\
            text:"→ Chestplate selections ",\
            color:"#929292"\
        },\
        {\
            text:"\n\n"\
        }\
    ]

# -> Sound
playsound ui.button.click block @s ~ ~ ~ 0.5 1
playsound entity.experience_orb.pickup block @s ~ ~ ~ 0.5 2

# -> Globalize button data
scoreboard players operation #or.lay_figure_data_button_0 OverlyRealistic.General.ArbitraryData = @s OverlyRealistic.World.LayFigure_ButtonProgress_0
scoreboard players operation #or.lay_figure_data_button_1 OverlyRealistic.General.ArbitraryData = @s OverlyRealistic.World.LayFigure_ButtonProgress_1
scoreboard players operation #or.lay_figure_data_button_2 OverlyRealistic.General.ArbitraryData = @s OverlyRealistic.World.LayFigure_ButtonProgress_2
scoreboard players operation #or.lay_figure_data_button_3 OverlyRealistic.General.ArbitraryData = @s OverlyRealistic.World.LayFigure_ButtonProgress_3
scoreboard players operation #or.lay_figure_data_button_4 OverlyRealistic.General.ArbitraryData = @s OverlyRealistic.World.LayFigure_ButtonProgress_4
scoreboard players operation #or.lay_figure_data_button_5 OverlyRealistic.General.ArbitraryData = @s OverlyRealistic.World.LayFigure_ButtonProgress_5

# -> If player has any empty sections then return and show a failure screen
execute if score #or.lay_figure_data_button_0 OverlyRealistic.General.ArbitraryData matches 0 \
    if score #or.lay_figure_data_button_1 OverlyRealistic.General.ArbitraryData matches 0 run \
        return run \
            dialog show @s overly_realistic:lay_figure/success_screens/confirm_armor_fail

# -> Reset costs
function overly_realistic:general/custom_blocks/lay_figure/menu_interactions/reset_resource_requirements_player

# -> Set base cost
scoreboard players set @s OverlyRealistic.World.LayFigure_ResourceRequirement_CopperPlate 6

# --> Set additional costs

# -> Pouldron
execute if score #or.lay_figure_data_button_0 OverlyRealistic.General.ArbitraryData matches 1 run \
    scoreboard players add @s OverlyRealistic.World.LayFigure_ResourceRequirement_IronPlate 2

# -> Pouldron and vambrance
execute if score #or.lay_figure_data_button_1 OverlyRealistic.General.ArbitraryData matches 1 run \
    scoreboard players add @s OverlyRealistic.World.LayFigure_ResourceRequirement_IronPlate 4


# --> Get player items

# -> Copper plate
execute store result score #or.player_resource_requirement_copper_plate OverlyRealistic.General.ArbitraryData run \
    clear @s *[custom_data~{or_armor_resource_type:"copper_plate"}] 0


# --> Check if player has the items necessary

# -> Copper plate (failure condition)
execute if score #or.player_resource_requirement_copper_plate OverlyRealistic.General.ArbitraryData < @s OverlyRealistic.World.LayFigure_ResourceRequirement_IronPlate run \
    return run \
        function overly_realistic:players/non_setting_triggers/events/event_100029/build_fail


# -> Success screen
function overly_realistic:players/non_setting_triggers/events/event_100029/build_succeed


# -> Globalize menu ID
#execute store result storage overly_realistic:lay_figure_menus lay_figure_menu_id int 1 run \
    scoreboard players set #or.lay_figure_data_menu_id OverlyRealistic.General.ArbitraryData 1001

# -> Globalize lay figure ID
#scoreboard players operation #or.lay_figure_data_lay_figure_id OverlyRealistic.General.ArbitraryData = @s OverlyRealistic.World.LayFigure_ID

# -> Operate on lay figure
#execute as @e[type=interaction,tag=OverlyRealistic.Block.LayFigure,distance=..8] at @s run \
    function overly_realistic:players/non_setting_triggers/events/event_100020/operate_on_lay_figure
