AddCSLuaFile()

ENT.PrintName = "Zone"
ENT.Base = "base_anim"

if SERVER then
    
    function ENT:Initialize()
        self:SetModel("models/hunter/blocks/cube025x025x025.mdl")
        self:SetNoDraw(true)
        self:SetNWFloat('radius', SuR.Config.Zone_Radius)
        self.DelayGasDamage = 0
    end

    function ENT:Think()
        self:SetNWFloat('radius', SuR.Config.Zone_Radius)
        if self.DelayGasDamage < CurTime() then
            self.DelayGasDamage = CurTime()+1
            local tab = player.GetAll()
            for i=1,#tab do
                local ply = tab[i]
                if ply:GetPos():DistToSqr(self:GetPos()) < SuR.Config.Zone_Radius^2 or !ply:Alive() then continue end
                if ply:Health() > 10 then
                    ply:TakeDamage(10, self)
                else
                    ply:SuR_MakeZombie()
                end
                ply:PlayVoiceLine("lowhp", 10)
            end
        end
    end

else

    function ENT:Think()
        if not self.GasEffect then
            self.GasEffect = 0
        end
        if self.GasEffect < CurTime() then
            self.GasEffect = CurTime()+0.5
            local gasEmitter = ParticleEmitter(self:GetPos())
            local radius = self:GetNWFloat('radius', 0)
            if IsValid(gasEmitter) and radius > 0 then
                for i=0, 360 do
                    local rad = radius+100
                    local angle = math.rad(i)
                    local x = rad * math.cos(angle)
                    local y = rad * math.sin(angle)
        
                    local particles = gasEmitter:Add("particle/particle_smokegrenade", self:GetPos() + Vector(x, y, 100))
                    particles:SetVelocity(Vector(0, 0, 0))
                    particles:SetDieTime(5)
                    particles:SetStartAlpha(100)
                    particles:SetEndAlpha(0)
                    particles:SetStartSize(200)
                    particles:SetEndSize(200)
                    particles:SetRoll(math.Rand(-180, 180))
                    particles:SetRollDelta(math.Rand(-0.5, 0.5))
                    particles:SetColor(0,50,0)
                end
                for i=0, 360, 10 do
                    local rad = radius+1000
                    local angle = math.rad(i)
                    local x = rad * math.cos(angle)
                    local y = rad * math.sin(angle)
        
                    local particles = gasEmitter:Add("particle/particle_smokegrenade", self:GetPos() + Vector(x, y, 500))
                    particles:SetVelocity(Vector(0, 0, 0))
                    particles:SetDieTime(10)
                    particles:SetStartAlpha(175)
                    particles:SetEndAlpha(0)
                    particles:SetStartSize(1000)
                    particles:SetEndSize(1000)
                    particles:SetRoll(math.Rand(-180, 180))
                    particles:SetRollDelta(math.Rand(-0.5, 0.5))
                    particles:SetColor(0,50,0)
                end
                for i=0, 360, 25 do
                    local rad = radius+3000
                    local angle = math.rad(i)
                    local x = rad * math.cos(angle)
                    local y = rad * math.sin(angle)
        
                    local particles = gasEmitter:Add("particle/particle_smokegrenade", self:GetPos() + Vector(x, y, 1500))
                    particles:SetVelocity(Vector(0, 0, 0))
                    particles:SetDieTime(10)
                    particles:SetStartAlpha(200)
                    particles:SetEndAlpha(0)
                    particles:SetStartSize(2500)
                    particles:SetEndSize(2500)
                    particles:SetRoll(math.Rand(-180, 180))
                    particles:SetRollDelta(math.Rand(-0.5, 0.5))
                    particles:SetColor(0,50,0)
                end
                gasEmitter:Finish()
            end
        end
    end
    
end