AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")

function ENT:Initialize()
	self:SetModel("models/sw/shared/airdrop_large.mdl")
	self:SetSolid(SOLID_VPHYSICS)
	self:PhysicsInit(SOLID_VPHYSICS)
	self:SetUseType(SIMPLE_USE)

	local phys = self:GetPhysicsObject()
	if (IsValid(phys)) then
		phys:Wake()
	end
end

function ENT:Use(activator)
	if (IsValid(activator) and activator:IsPlayer()) then
		if (self.opened) then return end
		self.opened = true

		local weaponClass = self.ixWeapon or "tacrp_m320"
		local character = activator:GetCharacter()
		local inventory = character and character:GetInventory()

		if (inventory and !isnumber(inventory) and ix.item.list[weaponClass]) then
			inventory:Add(weaponClass)
			ix.util.Notify("Вы получили " .. (ix.item.list[weaponClass].name or weaponClass) .. " из аирдропа.", activator)
		else
			activator:Give(weaponClass)
			ix.util.Notify("Вы получили " .. (self.ixWeapon or "неизвестное оружие") .. " из аирдропа.", activator)
		end

		if (IsValid(self.ixSmoke)) then
			self.ixSmoke:Remove()
		end

		local effect = EffectData()
		effect:SetOrigin(self:GetPos())
		effect:SetScale(1)
		util.Effect("Explosion", effect)

		self:Remove()
	end
end

function ENT:OnTakeDamage(damage)
	if (damage:GetDamage() > 50) then
		self:Use(damage:GetAttacker())
	end
end
