local PLUGIN = PLUGIN

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

AddCSLuaFile()

-- names and stuff
SWEP.PrintName = "DSA FAL SA58"
SWEP.AbbrevName = "SA58"
SWEP.Category = "Tactical RP"

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

SWEP.Description =
"Battle rifle with slow fire rate but very high damage and armor penetration. Has a grippod that provides some stability if deployed."

SWEP.Trivia_Caliber = "7.62x51mm"
SWEP.Trivia_Manufacturer = "DS Arms"
SWEP.Trivia_Year = "1956"

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

SWEP.ViewModel = "models/weapons/tacint/v_dsa58.mdl"
SWEP.WorldModel = "models/weapons/tacint/w_dsa58.mdl"

SWEP.Slot = 2

SWEP.BalanceStats = {
	[PLUGIN.BALANCE_SBOX] = {
		Damage_Max = 45,
		Damage_Min = 30,
	},
	[PLUGIN.BALANCE_TTT] = {
		Damage_Max = 38,
		Damage_Min = 22,
		Range_Min = 1000,
		Range_Max = 3000,
		RPM = 240,

		RecoilResetInstant = true,
		RecoilResetTime = 0.1,
		RecoilDissipationRate = 3,
		RecoilMaximum = 3,
		RecoilSpreadPenalty = 0.02,

		BodyDamageMultipliers = {
			[HITGROUP_HEAD] = 3,
			[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 = 16,
		Damage_Min = 9,
		RPM = 300,

		RecoilResetTime = 0.1,
		RecoilDissipationRate = 3,
		RecoilMaximum = 3,
		RecoilSpreadPenalty = 0.01,

		RecoilKick = 6,

		HipFireSpreadPenalty = 0.055,
	},
	[PLUGIN.BALANCE_OLDSCHOOL] = {
		RecoilDissipationRate = 30,
		RecoilSpreadPenalty = 0.006,
		HipFireSpreadPenalty = 0.009,
	}
}

-- "ballistics"

SWEP.Damage_Max = 40
SWEP.Damage_Min = 32
SWEP.Range_Min = 1500
SWEP.Range_Max = 5000
SWEP.Penetration = 15
SWEP.ArmorPenetration = 0.9

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

SWEP.MuzzleVelocity = 28000

-- misc. shooting

SWEP.Firemodes = {
	2,
	1
}

SWEP.RPM = 420

SWEP.Spread = 0.002

SWEP.RecoilResetInstant = false
SWEP.RecoilPerShot = 1
SWEP.RecoilMaximum = 5
SWEP.RecoilResetTime = 0
SWEP.RecoilDissipationRate = 20
SWEP.RecoilFirstShotMult = 0.85

SWEP.RecoilVisualKick = 1.25

SWEP.RecoilKick = 8
SWEP.RecoilStability = 0.75

SWEP.RecoilSpreadPenalty = 0.005
SWEP.HipFireSpreadPenalty = 0.05
SWEP.PeekPenaltyFraction = 0.25

SWEP.CanBlindFire = true

-- handling

SWEP.MoveSpeedMult = 0.875
SWEP.ShootingSpeedMult = 0.8
SWEP.SightedSpeedMult = 0.6

SWEP.ReloadSpeedMult = 0.4

SWEP.AimDownSightsTime = 0.42
SWEP.SprintToFireTime = 0.45

SWEP.Sway = 1.5
SWEP.ScopedSway = 0.1

SWEP.FreeAimMaxAngle = 6

SWEP.Bipod = true
SWEP.BipodRecoil = 0.5
SWEP.BipodKick = 0.4

-- hold types

SWEP.HoldType = "smg"
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, -4)

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

SWEP.SightAng = Angle(2.5, 0, 0)
SWEP.SightPos = Vector(-2.45, -4, -3.11)

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

SWEP.CorrectivePos = Vector(-0.675, 0, 0.15)
SWEP.CorrectiveAng = Angle(-2.5, 2.5, 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 = 20
SWEP.Ammo = "ar2"

SWEP.ReloadTimeMult = 1
SWEP.DropMagazineModel = "models/weapons/tacint/magazines/dsa58.mdl"
SWEP.DropMagazineImpact = "plastic"

SWEP.ReloadUpInTime = 1.1
SWEP.DropMagazineTime = 0.3

-- sounds

local path = "TacRP/weapons/dsa58/dsa58_"

SWEP.Sound_Shoot = "^" .. path .. "fire-1.wav"
SWEP.Sound_Shoot_Silenced = "^" .. path .. "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_g3"
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.Attachments = {
	[1] = {
		PrintName = "Optic",
		Category = { "optic_cqb", "optic_medium", "optic_sniper" },
		Bone = "ValveBiped.dsa58_rootbone",
		WMBone = "Box01",
		AttachSound = "TacRP/weapons/optic_on.wav",
		DetachSound = "TacRP/weapons/optic_off.wav",
		VMScale = 1,
		Pos_VM = Vector(-5.6, 0.15, 4),
		Ang_VM = Angle(90, 0, 0),
		Pos_WM = Vector(0, 6, 0.5),
		Ang_WM = Angle(0, -90, 0),
	},
	[2] = {
		PrintName = "Muzzle",
		Category = "silencer",
		Bone = "ValveBiped.dsa58_rootbone",
		WMBone = "Box01",
		AttachSound = "TacRP/weapons/silencer_on.wav",
		DetachSound = "TacRP/weapons/silencer_off.wav",
		Pos_VM = Vector(-3.6, 0.15, 26),
		Ang_VM = Angle(90, 0, 0),
		Pos_WM = Vector(0, 24, -1.2),
		Ang_WM = Angle(0, -90, 0),
	},
	[3] = {
		PrintName = "Tactical",
		Category = "tactical",
		Bone = "ValveBiped.dsa58_rootbone",
		WMBone = "Box01",
		AttachSound = "TacRP/weapons/flashlight_on.wav",
		DetachSound = "TacRP/weapons/flashlight_off.wav",
		InstalledElements = { "tactical" },
		Pos_VM = Vector(-4.1, -0.75, 15),
		Ang_VM = Angle(90, 0, -90),
		Pos_WM = Vector(0.75, 14, -0.75),
		Ang_WM = Angle(0, -90, -60),
	},
	[4] = {
		PrintName = "Accessory",
		Category = { "acc", "acc_sling", "acc_duffle", "acc_extmag_rifle2", "acc_bipod" },
		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_dsa58.insert_clip", path .. "insert_clip.wav")
addsound("tacint_dsa58.insert_clip-mid", path .. "insert_clip-mid.wav")
addsound("tacint_dsa58.remove_clip", path .. "remove_clip.wav")
addsound("tacint_dsa58.Handle_FoldDown", path .. "handle_folddown.wav")
addsound("tacint_dsa58.bolt_back", path .. "bolt_back.wav")
addsound("tacint_dsa58.bolt_release", path .. "bolt_shut.wav")
