--[==[
bot; bot; bot; lua_run gamemode.Call("SetWaveActive", true)
lua_run local meta,old=FindMetaTable([[Player]]) old=meta.GetBossZombieIndex meta.GetBossZombieIndex = function(self) return self.ForceBossIndex or old(self) end
lua_run local p,ae = Entity(1),[[Ancient Evil]] p.ForceBossIndex = GAMEMODE.ZombieClasses[ae].Index GAMEMODE:SpawnBossZombie(p)
]==]--

local CLASS = table.Copy(GAMEMODE.ZombieClasses["Crow"])

CLASS.Name = "Ancient Evil"
CLASS.TranslationName = "Ancient Evil"
CLASS.Health = 2500
CLASS.Points = 35
CLASS.Speed = 125
CLASS.JumpPower = 750
CLASS.SWEP = "weapon_zs_supercrow"
CLASS.FearPerInstance = 4
CLASS.VoicePitch = 0.5
CLASS.ModelScale = 8
CLASS.CameraDistance = 175
--CLASS.Hull = {Vector(-24, -24, 0), Vector(24, 24, 54)}
--CLASS.HullDuck = CLASS.Hull
CLASS.ViewOffset = Vector(0,0,80)
CLASS.ViewOffsetDucked = CLASS.ViewOffset

CLASS.Index = nil
CLASS.NoDeathMessage = nil
CLASS.NoDeaths = nil
CLASS.NoGibs = nil
CLASS.DoesntGiveFear = nil
CLASS.NeverAlive = nil
CLASS.ScalePlayerDamage = nil
CLASS.NoUse = nil
CLASS.Mass = nil
CLASS.NoCollideAll = nil
CLASS.OnKilled = nil
CLASS.AllowTeamDamage = nil

function CLASS:UpdateAnimation(pl, velocity, maxseqgroundspeed)
	pl:FixModelAngles(velocity)
	pl:SetPlaybackRate(0.6)
	return true
end

local left_sounds = {"npc/headcrab_poison/ph_step1.wav", "npc/headcrab_poison/ph_step3.wav"}
local right_sounds = {"npc/headcrab_poison/ph_step2.wav", "npc/headcrab_poison/ph_step4.wav"}
function CLASS:PlayerFootstep(pl, vFootPos, iFoot, strSoundName, fVolume, pFilter)
	if iFoot == 0 then
		pl:EmitSound(table.Random(left_sounds), 90, math.random(50, 75))
	else
		pl:EmitSound(table.Random(right_sounds), 90, math.random(50, 75))
	end

	return true
end

local classtab = GAMEMODE.ZombieClasses[CLASS.Name]
if classtab then
	local index = classtab.Index
	table.CopyFromTo(CLASS, classtab)
	classtab.Index = index
else
	GAMEMODE:RegisterZombieClass(CLASS.Name, CLASS)
end


local SWEP = {}

SWEP.Base = "weapon_zs_crow"

if SERVER then

function SWEP:PrimaryAttack()
	if CurTime() < self:GetNextPrimaryFire() or not self.Owner:IsOnGround() then return end
	self:SetNextPrimaryFire(CurTime() + self.Primary.Delay)

	self.Owner:EmitSound("NPC_Crow.Squawk")
	self.Owner.EatAnim = CurTime() + 2

	self:SetPeckEndTime(CurTime() + 1)

	self.Owner:SetSpeed(1)
end

SWEP.WaveRadius = 675
SWEP.WaveForce = 700
SWEP.WaveForceNailBreak = 450
SWEP.WaveSounds = {"npc/crow/alert2.wav", "npc/crow/alert3.wav", "npc/crow/pain1.wav", "npc/crow/pain2.wav"}
SWEP.WaveExSounds = {"ambient/explosions/exp3.wav", "ambient/explosions/exp4.wav"}
function SWEP:SecondaryAttack()
	if CurTime() < self:GetNextSecondaryFire() then return end
	local owner = self.Owner
	self:SetNextSecondaryFire(CurTime() + 5.55)

	for i=1,4 do
		owner:EmitSound(table.Random(self.WaveSounds), 120, math.random(45,65))
	end
	
	owner:EmitSound(table.Random(self.WaveExSounds), 100, math.random(85,100))
	owner:EmitSound(table.Random(self.WaveExSounds), 100, math.random(75,95))
	
	local pos = owner:GetPos()
	local props = {}
	
	for _,e in pairs(ents.FindInSphere(pos, self.WaveRadius)) do
		if e ~= owner then
			local force = self.WaveForce * (1 - math.min(pos:Distance(e:NearestPoint(pos))/self.WaveRadius, 1))
			if force > self.WaveForceNailBreak and e:GetClass() == "prop_nail" then
				e:Remove()
			else
				table.insert(props, {e, force})
			end
		end
	end
	
	for _,tab in pairs(props) do
		tab[1]:ThrowFromPosition(pos, tab[2])
		tab[1]:TakeSpecialDamage(6, DMG_BLAST, owner, self)
	end
	
	local ed = EffectData()
	ed:SetOrigin(pos)
	ed:SetScale(250)
	util.Effect("ThumperDust", ed, true, true)
	
	util.ScreenShake(pos, 6.25, 2, 1, self.WaveRadius)
end

function SWEP:Reload()
	return false
end

end

weapons.Register(SWEP, "weapon_zs_supercrow")
