AddCSLuaFile()

ENT.Base = "base_gmodentity"
ENT.Type = "anim"
ENT.PrintName = "Landmine"
ENT.Spawnable = true


function ENT:Initialize()
	self:SetModel("models/surrounded/equipment/fieldupgrade_proximitymine.mdl")
	self:SetSolid(SOLID_VPHYSICS)
	self:PhysicsInit(SOLID_VPHYSICS)
	self:SetCollisionGroup(COLLISION_GROUP_DEBRIS_TRIGGER)

	timer.Simple(2, function()
		if !IsValid(self) then return end
		self:SetAngles(Angle(0,self:GetAngles().y,0))
	end)
end

function ENT:Think()
	if CLIENT then return end

	if not self.Done then
		for _, ent in ipairs(ents.FindInSphere(self:GetPos(), 72)) do
			if ent:IsNPC() and ent.IsZombie then
				self.Done = true 
				self:GetPhysicsObject():SetVelocity(Vector(0,0,256))
				timer.Simple(0.7, function()
					local effectData = EffectData()
					effectData:SetOrigin(self:GetPos())
					util.Effect("Explosion", effectData)

					util.BlastDamage(self, self, self:GetPos(), 192, 512)

					self:Remove()
				end)
			end
		end
	end
	
	self:NextThink(CurTime())
	return true
end