scoreboard players set #blue_captures temp 0
scoreboard players set #red_captures temp 0

$execute if entity @e[tag=blue_flag_dropoff,tag=captured_yellow,scores={map_id=$(map_id)}] run scoreboard players add #blue_captures temp 1
$execute if entity @e[tag=blue_flag_dropoff,tag=captured_light_purple,scores={map_id=$(map_id)}] run scoreboard players add #blue_captures temp 1

$execute if entity @e[tag=red_flag_dropoff,tag=captured_green,scores={map_id=$(map_id)}] run scoreboard players add #red_captures temp 1
$execute if entity @e[tag=red_flag_dropoff,tag=captured_aqua,scores={map_id=$(map_id)}] run scoreboard players add #red_captures temp 1

execute if score #blue_captures temp > #red_captures temp run tellraw @a[distance=..250] ["",{"text":"BLUE TEAM","bold":true,"color":"blue"},{"text":" wins by more flags captured!","color":"yellow"}]
execute if score #red_captures temp > #blue_captures temp run tellraw @a[distance=..250] ["",{"text":"RED TEAM","bold":true,"color":"red"},{"text":" wins by more flags captured!","color":"yellow"}]

$execute if score #blue_captures temp > #red_captures temp run return run function pctf:logic/game/end/blue_wins {map_id: "$(map_id)"}
$execute if score #red_captures temp > #blue_captures temp run return run function pctf:logic/game/end/red_wins {map_id: "$(map_id)"}

title @a[distance=..250] times 20 100 20
title @a[distance=..250] subtitle {"text":"Time over"}
title @a[distance=..250] title {"text":"- DRAW -","bold":true,"color":"gray"}

scoreboard players set #game_end temp 0

execute at @s as @a[tag=playing,distance=..250] run function pctf:logic/game/end/start