local PLUGIN = PLUGIN

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

AddCSLuaFile()

-- names and stuff
SWEP.PrintName = "SIG 1911 TACOPS" -- The model isn't actually a GSR + TACOPS sounds so badass
SWEP.AbbrevName = "SIG 1911"
SWEP.Category = "Tactical RP"

SWEP.SubCatTier = "3Security"
SWEP.SubCatType = "1Sidearm"

SWEP.Description =
"High damage pistol with low range and capacity.\nA tactical evolution, or some would call devolution, of a venerable classic."

SWEP.Trivia_Caliber = ".45 ACP"
SWEP.Trivia_Manufacturer = "SIG Sauer, Inc."
SWEP.Trivia_Year = "2004"

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

SWEP.ViewModel = "models/weapons/tacint/v_gsr1911.mdl"
SWEP.WorldModel = "models/weapons/tacint/w_gsr1911.mdl"

SWEP.Slot = 1

SWEP.BalanceStats = {
	[PLUGIN.BALANCE_SBOX] = {
		Damage_Max = 35,
		Damage_Min = 10,
		RPM = 380,
	},
	[PLUGIN.BALANCE_TTT] = {
		Damage_Max = 30,
		Damage_Min = 10,
		Range_Min = 400,
		Range_Max = 1800,
		RPM = 200,
		RPMMultSemi = 1,

		Spread = 0.007,

		RecoilResetInstant = true,
		RecoilMaximum = 3.5,
		RecoilResetTime = 0.24,
		RecoilDissipationRate = 6,
		RecoilFirstShotMult = 1,
		RecoilSpreadPenalty = 0.008,

		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
		},

		ReloadTimeMult = 1.05 * 1.25,
	},
	[PLUGIN.BALANCE_PVE] = {
		Damage_Max = 15,
		Damage_Min = 6,
		RPM = 300,

		RecoilResetInstant = true,
		HipFireSpreadPenalty = 0.015,
		RecoilSpreadPenalty = 0.005,
		RecoilMaximum = 3,
		RecoilResetTime = 0.25,
		RecoilDissipationRate = 5,
		RecoilFirstShotMult = 0.8,
	},
}

-- "ballistics"

SWEP.Damage_Max = 32
SWEP.Damage_Min = 8
SWEP.Range_Min = 400  -- distance for which to maintain maximum damage
SWEP.Range_Max = 1800 -- distance at which we drop to minimum damage
SWEP.Penetration = 3  -- units of metal this weapon can penetrate
SWEP.ArmorPenetration = 0.55
SWEP.ArmorBonus = 0.25

SWEP.MuzzleVelocity = 8400

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

-- misc. shooting

SWEP.Firemode = 1

SWEP.RPM = 420
SWEP.RPMMultSemi = 0.8

SWEP.Spread = 0.005
SWEP.RecoilSpreadPenalty = 0.006
SWEP.HipFireSpreadPenalty = 0.01

SWEP.ShootTimeMult = 0.5

SWEP.RecoilResetInstant = false
SWEP.RecoilPerShot = 1
SWEP.RecoilMaximum = 4
SWEP.RecoilResetTime = 0.01
SWEP.RecoilDissipationRate = 18
SWEP.RecoilFirstShotMult = 0.8

SWEP.RecoilVisualKick = 2

SWEP.RecoilKick = 8
SWEP.RecoilStability = 0.6

SWEP.CanBlindFire = true

-- handling

SWEP.MoveSpeedMult = 0.975
SWEP.ShootingSpeedMult = 0.8
SWEP.SightedSpeedMult = 0.8

SWEP.ReloadSpeedMult = 0.75

SWEP.AimDownSightsTime = 0.25
SWEP.SprintToFireTime = 0.25

-- hold types

SWEP.HoldType = "revolver"
SWEP.HoldTypeSprint = "normal"
SWEP.HoldTypeBlindFire = "pistol"

SWEP.GestureShoot = ACT_HL2MP_GESTURE_RANGE_ATTACK_PISTOL
SWEP.GestureReload = ACT_HL2MP_GESTURE_RELOAD_PISTOL

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

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

SWEP.BlindFireSuicideAng = Angle(-130, 0, 45)
SWEP.BlindFireSuicidePos = Vector(27, 17, -6)

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

SWEP.SightAng = Angle(0.04, -0.1, 0)
SWEP.SightPos = Vector(-3.3, 0, -3.7)

SWEP.HolsterVisible = true
SWEP.HolsterSlot = PLUGIN.HOLSTER_SLOT_PISTOL
SWEP.HolsterPos = Vector(0, 3, -4)
SWEP.HolsterAng = Angle(90, 0, 0)

SWEP.Sway = 1
SWEP.ScopedSway = 0.5

SWEP.FreeAimMaxAngle = 3.5

-- reload

SWEP.ClipSize = 8
SWEP.Ammo = "pistol"

SWEP.ReloadTimeMult = 1.05

SWEP.DropMagazineModel = "models/weapons/tacint/magazines/gsr1911.mdl"
SWEP.DropMagazineImpact = "pistol"

SWEP.ReloadUpInTime = 1
SWEP.DropMagazineTime = 0.2

-- sounds

local path = "TacRP/weapons/gsr1911/gsr1911_"

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

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

-- effects

-- the .qc attachment for the muzzle
SWEP.QCA_Muzzle = 4

SWEP.MuzzleEffect = "muzzleflash_pistol"

-- anims

SWEP.AnimationTranslationTable = {
	["deploy"] = "draw",
	["fire"] = { "shoot1", "shoot2", "shoot3" },
	["blind_fire"] = { "blind_shoot1", "blind_shoot2", "blind_shoot3" },
	["melee"] = { "melee1", "melee2" }
}

SWEP.ProceduralIronFire = {
	vm_pos = Vector(0, -0.5, -0.6),
	vm_ang = Angle(0, 2, 0),
	t = 0.2,
	tmax = 0.2,
	bones = {
		{
			bone = "ValveBiped.slide",
			pos = Vector(0, 0, -3),
			t0 = 0,
			t1 = 0.1,
		},
		{
			bone = "ValveBiped.hammer",
			ang = Angle(-15, 0, 0),
			t0 = 0,
			t1 = 0.15,
		},
		{
			bone = "ValveBiped.Bip01_R_Finger1",
			ang = Angle(0, -15, 0),
			t0 = 0,
			t1 = 0.2,
		},
		{
			bone = "ValveBiped.Bip01_R_Finger11",
			ang = Angle(-35, 0, 0),
			t0 = 0,
			t1 = 0.15,
		},
	},
}

SWEP.LastShot = true

-- attachments

SWEP.Attachments = {
	[1] = {
		PrintName = "Optic",
		Category = "optic_pistol",
		Bone = "ValveBiped.slide",
		WMBone = "Box01",
		AttachSound = "TacRP/weapons/optic_on.wav",
		DetachSound = "TacRP/weapons/optic_off.wav",
		VMScale = 1,
		WMScale = 1,
		Pos_VM = Vector(-0.05, 1.75, 0),
		Ang_VM = Angle(0, 90, 180),
		Pos_WM = Vector(0, -1, -0.85),
		Ang_WM = Angle(0, -90, 0),
	},
	[2] = {
		PrintName = "Muzzle",
		Category = { "silencer", "pistol_muzzle" },
		Bone = "ValveBiped.barrel",
		WMBone = "Box01",
		AttachSound = "TacRP/weapons/silencer_on.wav",
		DetachSound = "TacRP/weapons/silencer_off.wav",
		VMScale = 0.5,
		WMScale = 0.5,
		Pos_VM = Vector(-0.76, 0.7, 7.35),
		Ang_VM = Angle(90, 0, 0),
		Pos_WM = Vector(0, 9.25, -1.5),
		Ang_WM = Angle(0, -90, 0),
	},
	[3] = {
		PrintName = "Tactical",
		Category = "tactical",
		Bone = "ValveBiped.GSR1911_rootbone",
		WMBone = "Box01",
		AttachSound = "TacRP/weapons/flashlight_on.wav",
		DetachSound = "TacRP/weapons/flashlight_off.wav",
		VMScale = 1.1,
		WMScale = 1.3,
		Pos_VM = Vector(-1.7, 0, 6),
		Ang_VM = Angle(90, 0, 180),
		Pos_WM = Vector(0, 5, -3),
		Ang_WM = Angle(0, -90, 180),
	},
	[4] = {
		PrintName = "Accessory",
		Category = { "acc", "acc_extmag_pistol2", "acc_holster", "acc_brace" },
		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_pistol" },
		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_GSR1911.clip_in", path .. "clip_in.wav")
addsound("TacInt_GSR1911.clip_in-mid", path .. "clip_in-mid.wav")
addsound("TacInt_GSR1911.clip_out", path .. "clip_out.wav")
addsound("TacInt_GSR1911.slide_action", path .. "slide_action.wav")
addsound("TacInt_GSR1911.slide_shut", path .. "slide_shut.wav")
addsound("TacInt_GSR1911.cock_hammer", path .. "cockhammer.wav")
