-----------------------------------------
-- FT BULLET CONTUSION (MILITARY RP)
-- Собственность Олега Закона и Scripty
-----------------------------------------

local function AddSuppression(amount)
    net.Start("FT_AddSuppression")
    net.WriteFloat(amount)
    net.SendToServer()
end

local punchVel = Angle()
local punchAng = Angle()

hook.Add("Think", "FT_CLViewPunchThink", function()
    local FT = FrameTime()

    punchAng = punchAng + punchVel * FT
    punchVel = punchVel * (1 - 10 * FT)
    punchVel = punchVel - punchAng * math.Clamp(600 * FT, 0, 2)
end)

hook.Add("CalcView", "FT_CLViewPunchCalc", function(ply, pos, ang)
    ang:Add(punchAng)
end)

local function FT_ViewPunch(a)
    punchVel:Add(a)
end

if not ConVarExists("suppression_vignette_size") then
    CreateConVar("suppression_vignette_size", 1, FCVAR_ARCHIVE)
end

local function PlayFlybySounds(pos)
    sound.Play("bul_snap/supersonic_snap_" .. math.random(1,18) .. ".wav", pos, 75, 100, 1)
    sound.Play("bul_flyby/subsonic_" .. math.random(1,27) .. ".wav", pos, 75, 100, 1)
end

local vignette = Material("vignette/vignette.png")

hook.Add("RenderScreenspaceEffects", "FT_SuppressionVignette", function()
    local a = LocalPlayer():GetNWFloat("FT_Suppression", 0)
    if a <= 0 then return end

    surface.SetDrawColor(255, 255, 255, a * 200)
    surface.SetMaterial(vignette)
    surface.DrawTexturedRect(0, 0, ScrW(), ScrH())
end)

net.Receive("BulletCloseToPlayer", function()
    local soundPath = net.ReadString()
    surface.PlaySound(soundPath)

    local pos = LocalPlayer():EyePos()

    sound.Play("bul_snap/supersonic_snap_" .. math.random(1,18) .. ".wav", pos, 75, 100, 0.01)
    sound.Play("bul_flyby/subsonic_" .. math.random(1,27) .. ".wav", pos, 75, 100, 0.01)

    AddSuppression(0.25)

    FT_ViewPunch(Angle(math.Rand(-1,1), math.Rand(-1,1), 0))

    util.ScreenShake(pos, 1, 1, 1.5, 200)
end)

-----------------------------------------
-- FT BULLET CONTUSION (MILITARY RP)
-- Собственность Олега Закона и Scripty
-----------------------------------------
