## Manages gradually adjusting a player's DisplayPrevForce score to match their PreviousForce score
## Runs conditionally from `end_force/player/manager` when there is a discrepancy between the Previous & Previous Display Force objectives
## @s = a player

## Calculates the offset between Current and Display
scoreboard objectives add temp dummy
scoreboard players operation @s temp = @s PreviousForce
scoreboard players operation @s temp -= @s DisplayPrevForce

## Removes 1 from DelayDisplay, which delays the time until more Display score can be removed
scoreboard players remove @s[scores={DelayDisplay=1..}] DelayDisplay 1

## If Delay=0, and a player's score is between -20 and 20, move it towards 0 by 1
execute if score @s[scores={DelayDisplay=0,DelayPrevDisplay=0}] temp matches 1..20 run scoreboard players add @s DisplayPrevForce 1
execute if score @s[scores={DelayDisplay=0,DelayPrevDisplay=0}] temp matches -20..-1 run scoreboard players remove @s DisplayPrevForce 1

## If Delay=0, and a player's score is between -6 and 6, delay the next removal by 1 tick (2 delay functionally represents 1 tick)
execute if score @s[scores={DelayDisplay=0,DelayPrevDisplay=0}] temp matches 1..6 run scoreboard players set @s DelayDisplay 2
execute if score @s[scores={DelayDisplay=0,DelayPrevDisplay=0}] temp matches -6..-1 run scoreboard players set @s DelayDisplay 2

## If Delay=0, and a player's score is between -30 and 30, move it towards 0 by 2
execute if score @s[scores={DelayDisplay=0,DelayPrevDisplay=0}] temp matches 21..30 run scoreboard players add @s DisplayPrevForce 2
execute if score @s[scores={DelayDisplay=0,DelayPrevDisplay=0}] temp matches -30..-21 run scoreboard players remove @s DisplayPrevForce 2

## If Delay=0, and a player's score is less than -30 or higher than 30, move it towards 0 by 4
execute if score @s[scores={DelayDisplay=0,DelayPrevDisplay=0}] temp matches 31.. run scoreboard players add @s DisplayPrevForce 4
execute if score @s[scores={DelayDisplay=0,DelayPrevDisplay=0}] temp matches ..-31 run scoreboard players remove @s DisplayPrevForce 4

## Displays the results by sending a title message to the UI
execute as @s[tag=!HideEndForceUI] run function end_force/player/title_ui

## Reset temp score
scoreboard players reset @s temp