# Instructions
tellraw @a[tag=!samsung_portal_recipe_unlocked] [{text:"[My Samsung Empire]",color:dark_blue},{text:": Craft a ",color:white},{text:"Samsung Portal",color:"light_purple",bold:true,hover_event:{action:"show_item",id:"leather",components:{"minecraft:custom_name":{text:"Samsung Portal",color:"light_purple",italic:false,bold:true},custom_data:{samsung_portal:1},lore:[{text:"Press ",extra:[{keybind:"key.use"},{text:" To Teleport To The Samsung Dimension!"}],color:"gray",italic:false}],"minecraft:item_model":"ender_eye","minecraft:enchantment_glint_override":true}}},{text:" to begin your Samsung empire!",color:white}]
recipe give @a[tag=!samsung_portal_recipe_unlocked] samsung:samsung_portal
tag @a[tag=!samsung_portal_recipe_unlocked] add samsung_portal_recipe_unlocked
execute if score #store_quality value matches 122.. run scoreboard players set #store_quality value 121

# Scoreboard
function samsung:tick/scoreboard

# Samsung Portal


# Trigger
execute in samsung:samsung_store as @a[distance=1..] run scoreboard players enable @s add_functions
execute as @a[scores={add_functions=1..}] if items entity @s container.* *[custom_data={function:true}] run scoreboard players add #samsung_functions value 1
execute as @a[scores={add_functions=1..}] if items entity @s container.* *[custom_data={function:true}] run clear @s *[custom_data={function:true}] 1
execute as @a[scores={add_functions=1..}] if items entity @s container.* *[custom_data={function:true}] run scoreboard players remove @s add_functions 1
execute as @a[scores={add_functions=1..}] unless items entity @s container.* *[custom_data={function:true}] run tellraw @s {"text":"Error! You do not have any functions!",color:red}
execute as @a[scores={add_functions=1..}] unless items entity @s container.* *[custom_data={function:true}] run scoreboard players set @s add_functions 0

# Ad Drone
execute as @e[type=bat,tag=samsung_ad_drone] at @s run function samsung:forceload_circle
execute as @e[type=bat,tag=samsung_ad_drone] at @s as @e[type=villager,distance=..15,tag=!ad_recived,tag=!samsung_customer] at @s run function samsung:get_samsung_ad

# Functions
execute if score #samsung_functions value >= #functions_needed value run function samsung:launch_new_one_ui
execute if score #samsung_phones_for_sale value matches 1.. if score #customer_cooldown value matches ..0 in samsung:samsung_store run function samsung:new_customer {money:5,void_command:'tellraw @s "Void TP is not working..."'}
execute if score #samsung_phones_for_sale value matches ..0 if score #customer_cooldown value matches ..0 in samsung:samsung_store run function samsung:new_customer
execute if score #one_ui_version value matches 1.. run advancement grant @a only samsung:launch_one_ui

# Place objects


# Store
scoreboard players enable @a buy_samsung_item
execute as @a[scores={buy_samsung_item=1}] if score #samsung_money value matches 5.. run give @s emerald
execute as @a[scores={buy_samsung_item=1}] if score #samsung_money value matches 5.. run scoreboard players remove #samsung_money value 5
execute as @a[scores={buy_samsung_item=1}] if score #samsung_money value matches ..4 run tellraw @s [{text:"Error! You do not have enough money! ",color:red},{text:"[Try again]",color:green,"click_event":{action:"show_dialog",dialog:"samsung:store"}}]
execute as @a[scores={buy_samsung_item=1}] run scoreboard players set @s buy_samsung_item 0
# Shelf I
execute as @a[scores={buy_samsung_item=2}] if score #samsung_money value matches 45.. run give @s leather[item_model="oak_shelf",custom_name={text:"Shelf I",color:gray,italic:false,bold:true},lore=[[{text:"Press ",color:gray,italic:false},{keybind:"key.use"}," to spawn Shelf I!"],{text:"+3 Max Devices",color:green,italic:false}],max_stack_size=1,custom_data={shelf_1:true},consumable={consume_seconds:999999999}]
execute as @a[scores={buy_samsung_item=2}] if score #samsung_money value matches 45.. run scoreboard players remove #samsung_money value 45
execute as @a[scores={buy_samsung_item=2}] if score #samsung_money value matches ..44 run tellraw @s [{text:"Error! You do not have enough money! ",color:red},{text:"[Try again]",color:green,"click_event":{action:"show_dialog",dialog:"samsung:store"}}]
execute as @a[scores={buy_samsung_item=2}] run scoreboard players set @s buy_samsung_item 0
# Ad Drone
execute as @a[scores={buy_samsung_item=3}] if score #samsung_money value matches 73.. run give @s minecraft:bat_spawn_egg[custom_name={"text":"Ad Drone","color":"gray","italic":false,"bold":true},lore=[[{"text":"Press ","color":"gray","italic":false},{"keybind":"key.use"}," to spawn Ad Drone!"]],max_stack_size=16,entity_data={id:"minecraft:bat",CustomName:{"text":"Ad Drone","color":"gray","bold":true},Tags:["samsung_ad_drone"],NoAI:0b,Silent:1b,PersistenceRequired:1b,Team:"samsung_worker",active_effects:[{id:"invisibility",duration:2147483647,show_particles:false},{id:"glowing",duration:2147483647,show_particles:false}],NoAI:true,Health:20,attributes:[{id:"max_health",base:20}]}]
execute as @a[scores={buy_samsung_item=3}] if score #samsung_money value matches 73.. run scoreboard players remove #samsung_money value 73
execute as @a[scores={buy_samsung_item=3}] if score #samsung_money value matches ..73 run tellraw @s [{text:"Error! You do not have enough money! ",color:red},{text:"[Try again]",color:green,"click_event":{action:"show_dialog",dialog:"samsung:store"}}]
execute as @a[scores={buy_samsung_item=3}] run scoreboard players set @s buy_samsung_item 0
# Upgrades

scoreboard players enable @a buy_upgrade
execute as @a[scores={buy_upgrade=1}] if score #samsung_money value matches 500.. unless score #wardrobe_level value matches 1.. run tellraw @s {text:"Coming Soon!",color:red}
execute as @a[scores={buy_upgrade=1}] at @s run playsound minecraft:entity.villager.no ui @s ~ ~ ~
execute as @a[scores={buy_upgrade=1}] run scoreboard players set @s buy_upgrade 0
# Tablets
execute as @a[scores={buy_upgrade=2}] if score #samsung_money value matches 250.. unless score #tablets_unlocked value matches 1.. run tellraw @a [{"selector":"@s"},{text:" unlocked "},{"text":"Tablets!",click_event:{"action":"show_dialog","dialog":"samsung:upgrades/devices/tablets"}}]
execute as @a[scores={buy_upgrade=2}] if score #samsung_money value matches 250.. unless score #tablets_unlocked value matches 1.. run advancement grant @s only samsung:buy_upgrade
execute as @a[scores={buy_upgrade=2}] if score #samsung_money value matches 250.. unless score #tablets_unlocked value matches 1.. run scoreboard players add #store_quality value 7
execute as @a[scores={buy_upgrade=2}] if score #samsung_money value matches 250.. unless score #tablets_unlocked value matches 1.. at @s run playsound minecraft:entity.player.levelup ui @s ~ ~ ~
execute as @a[scores={buy_upgrade=2}] unless score #samsung_money value matches 250.. unless score #tablets_unlocked value matches 1.. run tellraw @a {text:"Error! You do not have enough money!",color:red}
execute as @a[scores={buy_upgrade=2}] if score #samsung_money value matches 250.. unless score #tablets_unlocked value matches 1.. in samsung:samsung_store run forceload add -51 -31 -31 -15
execute as @a[scores={buy_upgrade=2}] if score #samsung_money value matches 250.. unless score #tablets_unlocked value matches 1.. in samsung:samsung_store run fill -39 99 -20 -34 99 -25 minecraft:light_blue_concrete
execute as @a[scores={buy_upgrade=2}] if score #samsung_money value matches 250.. unless score #tablets_unlocked value matches 1.. in samsung:samsung_store run setblock -36 100 -21 minecraft:command_block{Command:"function samsung:make_tablet"}
execute as @a[scores={buy_upgrade=2}] if score #samsung_money value matches 250.. unless score #tablets_unlocked value matches 1.. in samsung:samsung_store run setblock -36 101 -21 oak_button[face=floor,facing=west]
execute as @a[scores={buy_upgrade=2}] if score #samsung_money value matches 250.. unless score #tablets_unlocked value matches 1.. in samsung:samsung_store run setblock -35 100 -21 minecraft:oak_wall_sign[facing=east]{front_text:{messages:[{"text":"Make Tablet",color:yellow,bold:true},{"text":"",color:green,bold:true},{"text":"",color:green,bold:true},{"text":"",color:green,bold:true}]}}
execute as @a[scores={buy_upgrade=2}] if score #samsung_money value matches 250.. unless score #tablets_unlocked value matches 1.. in samsung:samsung_store run setblock -36 100 -23 minecraft:command_block{Command:"execute as @p run function samsung:sell_tablet"}
execute as @a[scores={buy_upgrade=2}] if score #samsung_money value matches 250.. unless score #tablets_unlocked value matches 1.. in samsung:samsung_store run setblock -36 101 -23 oak_button[face=floor,facing=west]
execute as @a[scores={buy_upgrade=2}] if score #samsung_money value matches 250.. unless score #tablets_unlocked value matches 1.. in samsung:samsung_store run setblock -35 100 -23 minecraft:oak_wall_sign[facing=east]{front_text:{messages:[{"text":"Sell Tablet",color:green,bold:true},{"text":"",color:green,bold:true},{"text":"",color:green,bold:true},{"text":"",color:green,bold:true}]}}
execute as @a[scores={buy_upgrade=2}] if score #samsung_money value matches 250.. unless score #tablets_unlocked value matches 1.. run scoreboard players remove #samsung_money value 250
execute as @a[scores={buy_upgrade=2}] if score #samsung_money value matches 250.. unless score #tablets_unlocked value matches 1.. run scoreboard players set #tablets_unlocked value 1
execute as @a[scores={buy_upgrade=2}] run scoreboard players set @s buy_upgrade 0
# Servers
execute as @a[scores={buy_upgrade=3}] unless score #servers_tier value matches 1.. run function samsung:upgrades/servers
execute as @a[scores={buy_upgrade=3}] run scoreboard players set @s buy_upgrade 0
execute as @a[predicate=samsung:servers/in_portal_entry] if score #servers_tier value matches 1.. in samsung:samsung_store run playsound entity.enderman.teleport master @s -48 0 -23
execute as @a[predicate=samsung:servers/in_portal_entry] if score #servers_tier value matches 1.. in samsung:samsung_store run tp @s -45 0 -23
execute as @a[predicate=samsung:servers/in_portal_exit] if score #servers_tier value matches 1.. in samsung:samsung_store run playsound entity.enderman.teleport master @s -45 0 -23
execute as @a[predicate=samsung:servers/in_portal_exit] if score #servers_tier value matches 1.. in samsung:samsung_store run tp @s -45 100 -23
# Samsung Accounts
execute as @a[scores={buy_upgrade=4}] unless score #samsung_accounts_unlocked value matches 1.. run function samsung:upgrades/samsung_accounts
execute as @a[scores={buy_upgrade=4}] run scoreboard players set @s buy_upgrade 0
# Galaxy AI
execute as @a[scores={buy_upgrade=5}] unless score #galaxy_ai_unlocked value matches 1.. run function samsung:upgrades/galaxy_ai
execute as @a[scores={buy_upgrade=5}] run scoreboard players set @s buy_upgrade 0