local FISH = {}

FISH.ClassName = "tribal_figurines"
FISH.Base = "fishing_fish_base_swimming"
FISH.Model = "models/dav0r/hoverball.mdl"
FISH.Rareness = 0.8

--------------------------
FISH.Description = [[
An ancient fish that has
the ability to mimic 
the appearance of all the
player models.
]]

if SERVER then
	local materials = 
	{
		"models/humans/male/group01/joe_facemap",
		"models/humans/male/group01/van_facemap",
		"models/humans/male/group01/vance_facemap",
		"models/humans/male/group01/ted_facemap",
		"models/humans/male/group01/sandro_facemap",
		"models/humans/male/group01/mike_facemap",
		"models/humans/male/group01/eric_facemap",
		"models/humans/male/group01/erdim_facemap",
		"models/humans/male/group01/art_facemap",
		"models/police/barneyface",
		"models/monk/grigori_head",
		"models/kleiner/walter_face",
		"models/gman/gman_face_map3",
		"models/eli/eli_tex4z",	
		"models/humans/male/group01/art_facemap", 
		"models/odessa/odessa_face",
		"models/humans/female/group01/chau_facemap",
		"models/humans/female/group01/joey_facemap",
		"models/humans/female/group01/kim_facemap", 
		"models/humans/female/group01/lakeetra_facemap", 
		"models/alyx/alyx_faceandhair",
	}

	local sounds = 
	{
		"vo/npc/female01/hi01.wav",
		"vo/npc/female01/hi02.wav",
		"vo/npc/male01/hi01.wav",
		"vo/npc/male01/hi02.wav"
	}

	function FISH:PostInit()
		self:SetMaterial(table.Random(materials))
		
		local phys = self:GetPhysicsObject()
		phys:SetMass(10)
		phys:Wake()
		phys:SetBuoyancyRatio( 1.5 )
		phys:EnableGravity(false)
	end

	function FISH:PreMove(phys)
		if math.random() > 0.9 then self:EmitSound(table.Random(sounds), 70	, math.random(200,255)) end
		
		local figurines = 0
		local velocity = Vector(0)
		
		for key, figurine in pairs(ents.FindByClass("fishing_fish_tribal_figurines")) do
			if self:GetPos():Distance(figurine:GetPos()) < 2000 then
				velocity = velocity + (figurine:GetPos() - self:GetPos())
				figurines = figurines + 1
			end
		end
		
		if figurines > 1 then 
			velocity = velocity / figurines 
		end
		
		phys:AddVelocity(velocity + (VectorRand()*100)-(phys:GetVelocity()*0.05))
	end

end

fishing.RegisterFish(FISH)