# Companion Journey — Announce a sub has departed (SP4 §4.1)
# @s = player. Inputs (set by journey/send): #j_type ec.temp, #j_dur ec.temp, #j_send_idx ec.temp.
# Centered NON-BOLD toasts (popup-law: never bold — center popups overflow the screen if bold).
# Forked from expedition/announce_sent; name rendered via macro substitution like the letter system.

# Theme name → storage journey.theme.
function evercraft:companions/journey/theme_name

# Sub display name → storage journey.subname (fallback first, then macro-read).
data modify storage evercraft:companions journey.subname set value "Your companion"
scoreboard players operation #Search companion.id = @s companion.id
execute store result storage evercraft:companions temp.journey_slot int 1 run scoreboard players get #j_send_idx ec.temp
function evercraft:companions/journey/get_subname with storage evercraft:companions temp

# Approx minutes = duration ticks / 1200 (20 ticks/s × 60). Used for the "back in ~N min" readout.
scoreboard players operation #j_mins ec.temp = #j_dur ec.temp
scoreboard players operation #j_mins ec.temp /= #1200 companion.calc
execute store result storage evercraft:companions journey.mins int 1 run scoreboard players get #j_mins ec.temp

# Line 1 + 2 via macro (subname + theme + mins are all string/int substitutions).
function evercraft:companions/journey/display_sent with storage evercraft:companions journey

# Line 3: active count (no macro needed — live score).
data modify storage evercraft:notify stage.c set value [{text:"Active journeys: ",color:"gray"},{score:{name:"@s",objective:"companion.jrny_cnt"},color:"yellow"},{text:"/2",color:"gray"}]
scoreboard players set #ndur ec.temp 40
function evercraft:util/notify/emit

execute if score @s ec.fx_snd matches 1.. run playsound minecraft:entity.villager.celebrate master @s ~ ~ ~ 0.7 1.2
execute if score @s ec.fx_snd matches 1.. run playsound minecraft:item.trident.throw master @s ~ ~ ~ 0.5 0.8
