local PLUGIN = PLUGIN

SWEP.Base = "exp_tacrp_base"
SWEP.Spawnable = true

AddCSLuaFile()

-- names and stuff
SWEP.PrintName = "Colt M4A1"
SWEP.AbbrevName = "M4A1"
SWEP.Category = "Tactical RP" -- "Tactical RP (Extras)"

SWEP.SubCatTier = "2Operator"
SWEP.SubCatType = "4Assault Rifle"

SWEP.Description = "A true American classic boasting high fire rate and balanced performance."

SWEP.Trivia_Caliber = "5.56x45mm"
SWEP.Trivia_Manufacturer = "Colt"
SWEP.Trivia_Year = "1987"

SWEP.Faction = PLUGIN
	.FACTION_NEUTRAL -- This is older military kit so it's not uncommon to see some captured examples in the hands of bad guys.
SWEP.Credits = [[
Model/Texture: Twinke Masta, DMG
Sound: Teh Strelok
Animation: Tactical Intervention
]]

SWEP.ViewModel = "models/weapons/tacint_extras/v_m4a1.mdl"
SWEP.WorldModel = "models/weapons/tacint_extras/w_m4a1.mdl"

SWEP.Slot = 2

SWEP.BalanceStats = {
	[PLUGIN.BALANCE_SBOX] = {
	},
	[PLUGIN.BALANCE_TTT] = {
		Damage_Max = 14,
		Damage_Min = 8,
		Range_Min = 600,
		Range_Max = 2000,
		RPM = 750,

		RecoilSpreadPenalty = 0.0022,

		BodyDamageMultipliers = {
			[HITGROUP_HEAD] = 2.5,
			[HITGROUP_CHEST] = 1.25,
			[HITGROUP_STOMACH] = 1,
			[HITGROUP_LEFTARM] = 0.9,
			[HITGROUP_RIGHTARM] = 0.9,
			[HITGROUP_LEFTLEG] = 0.75,
			[HITGROUP_RIGHTLEG] = 0.75,
			[HITGROUP_GEAR] = 0.9
		},
	},
	[PLUGIN.BALANCE_PVE] = {
		Damage_Max = 9,
		Damage_Min = 5,
		Range_Min = 600,
		Range_Max = 2800,
		RPM = 800,

		RecoilSpreadPenalty = 0.0017,
	},
	[PLUGIN.BALANCE_OLDSCHOOL] = {
		RecoilMaximum = 15,
		RecoilPerShot = 1,
		RecoilDissipationRate = 10,
		RecoilSpreadPenalty = 0.005,
	}
}

-- "ballistics"

SWEP.Damage_Max = 22
SWEP.Damage_Min = 15
SWEP.Range_Min = 1000
SWEP.Range_Max = 2800
SWEP.Penetration = 7 -- units of metal this weapon can penetrate
SWEP.ArmorPenetration = 0.7

SWEP.BodyDamageMultipliers = {
	[HITGROUP_HEAD] = 5,
	[HITGROUP_CHEST] = 1,
	[HITGROUP_STOMACH] = 1.25,
	[HITGROUP_LEFTARM] = 1,
	[HITGROUP_RIGHTARM] = 1,
	[HITGROUP_LEFTLEG] = 0.9,
	[HITGROUP_RIGHTLEG] = 0.9,
	[HITGROUP_GEAR] = 0.9
}

SWEP.MuzzleVelocity = 25000

-- misc. shooting

SWEP.Firemodes = {
	2,
	1
}

SWEP.RPM = 800

SWEP.Spread = 0.0069

SWEP.ShootTimeMult = 0.5

SWEP.RecoilResetInstant = false
SWEP.RecoilPerShot = 1
SWEP.RecoilMaximum = 10
SWEP.RecoilResetTime = 0
SWEP.RecoilDissipationRate = 35
SWEP.RecoilFirstShotMult = 1

SWEP.RecoilVisualKick = 0.75

SWEP.RecoilKick = 4.5
SWEP.RecoilStability = 0.25

SWEP.RecoilSpreadPenalty = 0.002
SWEP.HipFireSpreadPenalty = 0.04
SWEP.PeekPenaltyFraction = 0.2

SWEP.CanBlindFire = true

-- handling

SWEP.MoveSpeedMult = 0.925
SWEP.ShootingSpeedMult = 0.8
SWEP.SightedSpeedMult = 0.65

SWEP.ReloadSpeedMult = 0.5

SWEP.AimDownSightsTime = 0.36
SWEP.SprintToFireTime = 0.38 -- multiplies how long it takes to recover from sprinting

SWEP.Sway = 1.25
SWEP.ScopedSway = 0.15

SWEP.FreeAimMaxAngle = 4.5

-- hold types

SWEP.HoldType = "ar2"
SWEP.HoldTypeSprint = "passive"
SWEP.HoldTypeBlindFire = false

SWEP.GestureShoot = ACT_HL2MP_GESTURE_RANGE_ATTACK_AR2
SWEP.GestureReload = ACT_HL2MP_GESTURE_RELOAD_SMG1

SWEP.PassiveAng = Angle(0, 0, 0)
SWEP.PassivePos = Vector(0, -2, -6)

SWEP.BlindFireAng = Angle(0, 5, 0)
SWEP.BlindFirePos = Vector(3, -2, -5)

SWEP.SprintAng = Angle(30, -15, 0)
SWEP.SprintPos = Vector(5, 0, -2)

SWEP.SightAng = Angle(0.1, 0, 0)
SWEP.SightPos = Vector(-4.154, -7.5, -4.45)

SWEP.CorrectivePos = Vector(-0.05, 0, 0.05)
SWEP.CorrectiveAng = Angle(0.03, 0.45, 0)

SWEP.HolsterVisible = true
SWEP.HolsterSlot = PLUGIN.HOLSTER_SLOT_BACK
SWEP.HolsterPos = Vector(5, 0, -6)
SWEP.HolsterAng = Angle(0, 0, 0)

-- reload

SWEP.ClipSize = 30
SWEP.Ammo = "smg1"

SWEP.ReloadTimeMult = 1
SWEP.DropMagazineModel = "models/weapons/tacint/magazines/m4.mdl"
SWEP.DropMagazineImpact = "metal"

SWEP.ReloadUpInTime = 1.3
SWEP.DropMagazineTime = 0.4

-- sounds

local path = "TacRP/weapons/m4/m4_"
local path2 = "tacrp_extras/m4a1/m4a1_"

SWEP.Sound_Shoot = "^" .. path2 .. "fire-1.wav"
SWEP.Sound_Shoot_Silenced = path2 .. "fire_silenced-1.wav"

SWEP.Vol_Shoot = 120
SWEP.ShootPitchVariance = 2.5 -- amount to vary pitch by each shot

-- effects

-- the .qc attachment for the muzzle
SWEP.QCA_Muzzle = 1
-- ditto for shell
SWEP.QCA_Eject = 2

SWEP.MuzzleEffect = "muzzleflash_ak47"
SWEP.EjectEffect = 2

-- anims

SWEP.AnimationTranslationTable = {
	["fire_iron"] = "dryfire",
	["fire1"] = "fire1_M",
	["fire2"] = "fire2_M",
	["fire3"] = "fire3_M",
	["fire4"] = "fire4_M",
	["fire5"] = "fire5_M",
	["melee"] = { "melee1", "melee2" }
}

-- attachments

SWEP.AttachmentElements = {
	["sights"] = {
		BGs_VM = {
			{ 1, 1 }
		},
		BGs_WM = {
			{ 1, 1 }
		},
	},
	["chmount"] = {
		BGs_VM = {
			{ 1, 0 }
		},
		BGs_WM = {
			{ 1, 0 }
		},
		AttPosMods = {
			[1] = {
				Pos_VM = Vector(-7.7, -0.05, 4),
				Pos_WM = Vector(0.4, 3, 3.5),
			}
		},
		SortOrder = 2,
	},
}


SWEP.Attachments = {
	[1] = {
		PrintName = "Optic",
		Category = { "optic_cqb", "optic_medium", "optic_sniper", "optic_ar" },
		InstalledElements = { "sights" },
		Bone = "ValveBiped.m4_rootbone",
		WMBone = "Box01",
		AttachSound = "TacRP/weapons/optic_on.wav",
		DetachSound = "TacRP/weapons/optic_off.wav",
		VMScale = 1,
		Pos_VM = Vector(-5.6, -0.075, 4),
		Pos_WM = Vector(0.4, 3, 1.15),
		Ang_VM = Angle(90, 0, 0),
		Ang_WM = Angle(0, -90 + 3.5, 0),
	},
	[2] = {
		PrintName = "Muzzle",
		Category = "silencer",
		Bone = "ValveBiped.m4_rootbone",
		WMBone = "Box01",
		AttachSound = "TacRP/weapons/silencer_on.wav",
		DetachSound = "TacRP/weapons/silencer_off.wav",
		VMScale = 0.9,
		Pos_VM = Vector(-3.95, 0, 25.65),
		Pos_WM = Vector(1.4, 26, -0.5),
		Ang_VM = Angle(90, 0, 0),
		Ang_WM = Angle(0, -90 + 3.5, 0),
	},
	[3] = {
		PrintName = "Tactical",
		Category = "tactical",
		Bone = "ValveBiped.m4_rootbone",
		WMBone = "Box01",
		AttachSound = "TacRP/weapons/flashlight_on.wav",
		DetachSound = "TacRP/weapons/flashlight_off.wav",
		Pos_VM = Vector(-3.9, -1.2, 13.5),
		Pos_WM = Vector(2, 13, -0.5),
		Ang_VM = Angle(90, 0, -90),
		Ang_WM = Angle(-90, -90 + 3.5, 0),
	},
	[4] = {
		PrintName = "Accessory",
		Category = { "acc", "acc_sling", "acc_duffle", "perk_extendedmag" },
		AttachSound = "tacrp/weapons/flashlight_on.wav",
		DetachSound = "tacrp/weapons/flashlight_off.wav",
	},
	[5] = {
		PrintName = "Bolt",
		Category = { "bolt_automatic" },
		AttachSound = "TacRP/weapons/flashlight_on.wav",
		DetachSound = "TacRP/weapons/flashlight_off.wav",
	},
	[6] = {
		PrintName = "Trigger",
		Category = { "trigger_auto" },
		AttachSound = "TacRP/weapons/flashlight_on.wav",
		DetachSound = "TacRP/weapons/flashlight_off.wav",
	},
	[7] = {
		PrintName = "Ammo",
		Category = { "ammo_rifle" },
		AttachSound = "TacRP/weapons/flashlight_on.wav",
		DetachSound = "TacRP/weapons/flashlight_off.wav",
	},
	[8] = {
		PrintName = "Perk",
		Category = { "perk", "perk_melee", "perk_shooting", "perk_reload" },
		AttachSound = "tacrp/weapons/flashlight_on.wav",
		DetachSound = "tacrp/weapons/flashlight_off.wav",
	},
}

local function addsound(name, spath)
	sound.Add({
		name = name,
		channel = 16,
		volume = 1.0,
		sound = spath
	})
end

addsound("tacint_extras_m4a1.Remove_Clip", path2 .. "clipout.mp3")
addsound("tacint_extras_m4a1.Insert_Clip", path2 .. "clipin.mp3")
addsound("tacint_extras_m4a1.Insert_Clip-mid", path .. "insert_clip-mid.wav")
addsound("tacint_extras_m4a1.bolt_action", path .. "bolt_action.wav")
addsound("tacint_extras_m4a1.bolt_slap", path .. "bolt_slap.wav")
addsound("tacint_extras_m4a1.throw_catch", path .. "throw_catch.wav")
