if ( SERVER ) then
	AddCSLuaFile( "shared.lua" );
end;

if ( CLIENT ) then
	SWEP.Slot				= 1;
	SWEP.SlotPos			= 1;
	SWEP.ViewModelFOV		= 60;
	SWEP.DrawAmmo = false;
end;

SWEP.Base = "eps_base";

SWEP.PrintName			= "Hands";
SWEP.Author				= "Chewgum";
SWEP.Instructions = "Left click to punch someone.\nRight click to knock on a door.";

SWEP.AdminSpawnable	= true;

SWEP.WorldModel = Model( "models/weapons/w_fists.mdl" );
SWEP.ViewModel = Model( "models/weapons/v_fists.mdl" );

SWEP.Primary.ClipSize		= - 1;
SWEP.Primary.Delay			= 1;
SWEP.Primary.DefaultClip	= 0;
SWEP.Primary.Automatic		= true;
SWEP.Primary.Ammo			= "";

SWEP.Secondary.ClipSize		= - 1;
SWEP.Secondary.DefaultClip	= 0;
SWEP.Secondary.Automatic	= true;
SWEP.Secondary.Ammo			= "";

function SWEP:Initialize()
	self.HitSounds = 
	{
		Sound( "npc/vort/foot_hit.wav" ),
		Sound( "weapons/crossbow/hitbod1.wav" ),
		Sound( "weapons/crossbow/hitbod2.wav" )
	};
	
	self.SwingSounds = 
	{
		Sound( "npc/vort/claw_swing1.wav" ),
		Sound( "npc/vort/claw_swing2.wav" )
	};
end;

function SWEP:PrimaryAttack()
	self.Weapon:SetNextPrimaryFire( CurTime() + .6 );
	local tr = self.Owner:EyeTrace( 80 );
	
	self.Weapon:SendWeaponAnim( ACT_VM_HITCENTER );
	self.Owner:SetAnimation( PLAYER_ATTACK1 );

	if ( tr.Entity:IsValid() ) then
		if ( tr.Entity:IsPlayer() or tr.Entity:IsNPC() ) then
			if ( SERVER ) then
				local Normal = ( tr.Entity:GetPos() - self.Owner:GetPos() ):Normalize();
				local Push = 128 * Normal;
				
				tr.Entity:SetVelocity( Push );
				tr.Entity:TakeDamage( math.random( 1, 10 ), self.Owner, self.Weapon );
			end;
			
			self.Weapon:EmitSound( self.HitSounds[ math.random( 1, #self.HitSounds ) ] );
		elseif ( tr.HitWorld or tr.Hit ) then
			self.Weapon:EmitSound( self.HitSounds[ math.random( 1, #self.HitSounds ) ] );
		end;
	end;
	
	self.Weapon:EmitSound( self.SwingSounds[ math.random( 1, #self.SwingSounds ) ] );
end;

function SWEP:SecondaryAttack()
	self.Weapon:SetNextSecondaryFire( CurTime() + .3 );
	
	local Door = self.Owner:TraceDoor( 80 );
	
	if ( Door ) then
		self.Owner:SetAnimation( PLAYER_ATTACK1 );
		self.Weapon:EmitSound( Sound( "physics/wood/wood_crate_impact_hard2.wav" ) );
	end;
end;
