local FISH = {}

FISH.ClassName = "bomb"
FISH.Model = "models/combine_helicopter/helicopter_bomb01.mdl"
FISH.Base = "fishing_fish_base_swimming"
FISH.Forward = Vector(0,0,0)

FISH.Description = [[
A fish that explodes when 
damaged. It might be useful for 
dynamite fishing.
]]

FISH.Rareness = 0.7

if CLIENT then
	local outfit = fishing.GetOutfit("bomb")
	
	pac.SetupENT(FISH)

	function FISH:PostInit()
		self:AttachPACPart(outfit)
		self:SetPACDrawDistance(0)
	end

	function FISH:OnRemove()
		self:RemovePACPart(outfit)
	end
end

if SERVER then
	function FISH:OnThink()
		local phys = self:GetPhysicsObject()
		phys:SetDamping(0,0)
	end

	function FISH:OnDeath()
		if not self.triggered then
			self.triggered = true

			for _, bomb in pairs(ents.FindInSphere(self:GetPos(), 128)) do
				if bomb:GetClass() == self:GetClass() then
					timer.Simple(2, function()
						if bomb:IsValid() then
							bomb:Ignite(1)
						end
					end)
				end
			end

			timer.Create("triggered_explode" .. self:EntIndex(), 2, 1, function()
				if not self:IsValid() then return end

				self:Remove()

				util.BlastDamage(self, self, self:GetPos(), 128, 250)

				local params = EffectData()
					params:SetStart(self:GetPos())
					params:SetOrigin(self:GetPos())
					params:SetScale(self:GetSize())
				util.Effect("HelicopterMegaBomb", params)

				sound.Play("ambient/explosions/explode_4.wav", self:GetPos(), 75, 100 / self:GetSize())
			end)
		end
	end
end

fishing.RegisterFish(FISH)