local PLUGIN = PLUGIN

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

AddCSLuaFile()

-- names and stuff
SWEP.PrintName = "Springfield M1A"
SWEP.AbbrevName = "M1A"
SWEP.Category = "Tactical RP"

SWEP.SubCatTier = "3Security"
SWEP.SubCatType = "6Precision Rifle"

SWEP.Description = "Semi-automatic rifle with a lethal headshot.\nEquipped with a 6x scope by default."

SWEP.Trivia_Caliber = "7.62x51mm"
SWEP.Trivia_Manufacturer = "Springfield Armory"
SWEP.Trivia_Year = "1971"

SWEP.Faction = PLUGIN.FACTION_NEUTRAL
SWEP.Credits = "Assets: Tactical Intervention"

SWEP.ViewModel = "models/weapons/tacint/v_m14.mdl"
SWEP.WorldModel = "models/weapons/tacint/w_m14.mdl"

SWEP.Slot = 2

SWEP.BalanceStats = {
	[PLUGIN.BALANCE_SBOX] = {
		Damage_Max = 32,
		Damage_Min = 55,
		Range_Min = 1200,
		Range_Max = 3000,
		ArmorPenetration = 0.95,
	},
	[PLUGIN.BALANCE_TTT] = {

		Description =
		"Semi-automatic rifle with excellent accuracy and a lethal headshot at long range.\nEquipped with a 6x scope by default.",

		Damage_Max = 25,
		Damage_Min = 34,
		Range_Min = 500,
		Range_Max = 2200,
		RPM = 150,

		RecoilResetInstant = true,
		RecoilResetTime = 0.18,
		RecoilDissipationRate = 3,
		RecoilMaximum = 3,
		RecoilSpreadPenalty = 0.01,
		RecoilFirstShotMult = 0.5,

		BodyDamageMultipliers = {
			[HITGROUP_HEAD] = 3.5,
			[HITGROUP_CHEST] = 1.25,
			[HITGROUP_STOMACH] = 1,
			[HITGROUP_LEFTARM] = 0.75,
			[HITGROUP_RIGHTARM] = 0.75,
			[HITGROUP_LEFTLEG] = 0.5,
			[HITGROUP_RIGHTLEG] = 0.5,
			[HITGROUP_GEAR] = 0.5
		},
	},
	[PLUGIN.BALANCE_PVE] = {
		Damage_Max = 15,
		Damage_Min = 34,
		Range_Min = 1200,
		Range_Max = 3000,
		RPM = 200,
	},
	[PLUGIN.BALANCE_OLDSCHOOL] = {
		HipFireSpreadPenalty = 0.015,
		RecoilSpreadPenalty = 0.01,
		RecoilMaximum = 10
	}
}

-- "ballistics"

SWEP.Damage_Max = 40  -- damage at minimum range
SWEP.Damage_Min = 32  -- damage at maximum range
SWEP.Range_Min = 1500 -- distance for which to maintain maximum damage
SWEP.Range_Max = 6000 -- distance at which we drop to minimum damage
SWEP.Penetration = 15 -- units of metal this weapon can penetrate
SWEP.ArmorPenetration = 0.85

SWEP.BodyDamageMultipliers = {
	[HITGROUP_HEAD] = 4,
	[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.75
}

SWEP.MuzzleVelocity = 32000

-- misc. shooting

SWEP.Firemode = 1

SWEP.RPM = 240

SWEP.Spread = 0.0002

SWEP.ShootTimeMult = 0.5

SWEP.RecoilResetInstant = false
SWEP.RecoilPerShot = 1
SWEP.RecoilMaximum = 3
SWEP.RecoilResetTime = 0
SWEP.RecoilDissipationRate = 6
SWEP.RecoilFirstShotMult = 0.7

SWEP.RecoilVisualKick = 1
SWEP.RecoilKick = 4.5
SWEP.RecoilStability = 0.75
SWEP.RecoilAltMultiplier = 50

SWEP.RecoilSpreadPenalty = 0.004
SWEP.HipFireSpreadPenalty = 0.075
SWEP.PeekPenaltyFraction = 0.1

SWEP.CanBlindFire = true

-- handling

SWEP.MoveSpeedMult = 0.85
SWEP.ShootingSpeedMult = 0.75
SWEP.SightedSpeedMult = 0.5

SWEP.ReloadSpeedMult = 0.4

SWEP.AimDownSightsTime = 0.4
SWEP.SprintToFireTime = 0.5

SWEP.Sway = 2
SWEP.ScopedSway = 0.1

SWEP.FreeAimMaxAngle = 7.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(7, -3, -2)

SWEP.SprintMidPoint = {
	Pos = Vector(4, 5, 2),
	Ang = Angle(0, -2, -45)
}

SWEP.SightAng = Angle(0, -0.2, 0)
SWEP.SightPos = Vector(-3.81, -7.5, -2.7)

SWEP.CorrectivePos = Vector(0.025, -7.5, 0.1)
SWEP.CorrectiveAng = Angle(0, 0, 0)

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

-- scope

SWEP.Scope = true
SWEP.ScopeOverlay = Material("tacrp/scopes/l96.png", "mips smooth") -- Material("path/to/overlay")
SWEP.ScopeFOV = 90 / 6
SWEP.ScopeLevels = 1                                                -- 2 = like CS:S
SWEP.ScopeHideWeapon = true

-- reload

SWEP.ClipSize = 20
SWEP.Ammo = "ar2"

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

SWEP.ReloadUpInTime = 1.85
SWEP.DropMagazineTime = 0.5

-- sounds

local path = "TacRP/weapons/m14/m14_"

SWEP.Sound_Shoot = "^" .. path .. "fire-1.wav"
SWEP.Sound_Shoot_Silenced = "TacRP/weapons/g36k/g36k_fire_silenced-1.wav"

SWEP.Vol_Shoot = 130
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"] = "shoot2",
	["deploy"] = "draw",
	["fire"] = { "shoot1", "shoot2" },
	["blind_fire"] = "blind_shoot1"
}

SWEP.ProceduralIronFire = {
	vm_pos = Vector(0, -0.75, -0.12),
	vm_ang = Angle(0, 0.3, 0),
	t = 0.25,
	tmax = 0.25,
	bones = {
		{
			bone = "ValveBiped.bolt_handle",
			pos = Vector(0, 0, -3),
			t0 = 0.05,
			t1 = 0.2,
		},
	},
}

-- attachments

SWEP.AttachmentElements = {
	["sights"] = {
		BGs_VM = {
			{ 1, 1 }
		},
		BGs_WM = {
			{ 1, 1 }
		}
	},
}


SWEP.Attachments = {
	[1] = {
		PrintName = "Optic",
		Category = { "ironsights_sniper", "optic_cqb", "optic_medium", "optic_sniper" },
		Bone = "ValveBiped.m14_rootbone",
		InstalledElements = { "sights" },
		AttachSound = "TacRP/weapons/optic_on.wav",
		DetachSound = "TacRP/weapons/optic_off.wav",
		VMScale = 1,
		Pos_VM = Vector(-4.6, 0.2, 15),
		Pos_WM = Vector(14.5, 0.6, -9.1),
		Ang_VM = Angle(90, 0, 0),
		Ang_WM = Angle(-22.5, 5, 180),
	},
	[2] = {
		PrintName = "Muzzle",
		Category = "silencer",
		Bone = "ValveBiped.m14_rootbone",
		AttachSound = "TacRP/weapons/silencer_on.wav",
		DetachSound = "TacRP/weapons/silencer_off.wav",
		Pos_VM = Vector(-3.45, 0.2, 32.25),
		Pos_WM = Vector(30, 0, -14.5),
		Ang_VM = Angle(90, 0, 0),
		Ang_WM = Angle(-22.5, 5, 180),
		VMScale = 0.75
	},
	[3] = {
		PrintName = "Tactical",
		Category = "tactical",
		Bone = "ValveBiped.m14_rootbone",
		AttachSound = "TacRP/weapons/flashlight_on.wav",
		DetachSound = "TacRP/weapons/flashlight_off.wav",
		InstalledElements = { "tactical" },
		Pos_VM = Vector(-3, -0.35, 20),
		Pos_WM = Vector(23, 0, -11),
		Ang_VM = Angle(90, 0, -90),
		Ang_WM = Angle(-22.5, 5, 90),
	},
	[4] = {
		PrintName = "Accessory",
		Category = { "acc", "acc_extmag_rifle2", "acc_sling", "acc_duffle", "acc_bipod" },
		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",
	},
	[5] = {
		PrintName = "Bolt",
		Category = { "bolt_automatic" },
		AttachSound = "TacRP/weapons/flashlight_on.wav",
		DetachSound = "TacRP/weapons/flashlight_off.wav",
	},
	[6] = {
		PrintName = "Trigger",
		Category = { "trigger_semi" },
		AttachSound = "TacRP/weapons/flashlight_on.wav",
		DetachSound = "TacRP/weapons/flashlight_off.wav",
	},
	[7] = {
		PrintName = "Ammo",
		Category = { "ammo_sniper" },
		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_m14.remove_clip", path .. "remove_clip.wav")
addsound("TacInt_m14.insert_clip", path .. "insert_clip.wav")
addsound("TacInt_m14.insert_clip-mid", path .. "insert_clip-mid.wav")
addsound("TacInt_m14.bolt_back", path .. "bolt_back.wav")
addsound("TacInt_m14.bolt_release", path .. "bolt_release.wav")
addsound("TacInt_m14.safety", path .. "safety.wav")
