local PLUGIN = PLUGIN

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

AddCSLuaFile()

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

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

SWEP.Description = "Tactical pistol with good damage and range for its capacity."
SWEP.Description_Quote = "The weapon of choice for free men."

SWEP.Trivia_Caliber = ".40 S&W"
SWEP.Trivia_Manufacturer = "Heckler & Koch"
SWEP.Trivia_Year = "1993"

SWEP.Faction = PLUGIN.FACTION_COALITION
SWEP.Credits = [[
Model: Thanez, Racer445
Texture: Thanez, fxdarkloki
Sound: Vunsunta, BlitzBoaR
Animation: Tactical Intervention
]]

SWEP.ViewModel = "models/weapons/tacint_extras/v_usp.mdl"
SWEP.WorldModel = "models/weapons/tacint_extras/w_usp.mdl"

SWEP.Slot = 1


SWEP.BalanceStats = {
	[PLUGIN.BALANCE_SBOX] = {
		Damage_Max = 32,
		Damage_Min = 12,
		RPM = 400,
	},
	[PLUGIN.BALANCE_TTT] = {
		Damage_Max = 24,
		Damage_Min = 8,
		Range_Min = 500,
		Range_Max = 2200,
		RPM = 250,
		RPMMultSemi = 1,

		RecoilResetInstant = true,
		RecoilMaximum = 5,
		RecoilResetTime = 0.2,
		RecoilDissipationRate = 6,
		RecoilFirstShotMult = 0.8,
		RecoilSpreadPenalty = 0.01,

		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.25 * 1.25,
	},
	[PLUGIN.BALANCE_PVE] = {
		Damage_Max = 15,
		Damage_Min = 6,
		RPM = 320,

		RecoilResetInstant = true,
		RecoilMaximum = 4,
		RecoilResetTime = 0.15,
		RecoilDissipationRate = 5,
		RecoilFirstShotMult = 0.8,
		RecoilSpreadPenalty = 0.006,
	},
}

-- "ballistics"

SWEP.Damage_Max = 30
SWEP.Damage_Min = 10
SWEP.Range_Min = 450  -- distance for which to maintain maximum damage
SWEP.Range_Max = 1900 -- distance at which we drop to minimum damage
SWEP.Penetration = 5  -- units of metal this weapon can penetrate
SWEP.ArmorPenetration = 0.575
SWEP.ArmorBonus = 0.4

SWEP.MuzzleVelocity = 9000

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 = 400
SWEP.RPMMultSemi = 0.8

SWEP.Spread = 0.004
SWEP.RecoilSpreadPenalty = 0.006
SWEP.HipFireSpreadPenalty = 0.021

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

SWEP.RecoilVisualKick = 1.5
SWEP.RecoilKick = 7
SWEP.RecoilStability = 0.5

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

SWEP.Sway = 1
SWEP.ScopedSway = 0.5

SWEP.FreeAimMaxAngle = 3.25

-- hold types

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

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(-125, 0, 45)
SWEP.BlindFireSuicidePos = Vector(25, 12, -6)

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

SWEP.SightAng = Angle(-0.01, 0.14, 0)
SWEP.SightPos = Vector(-3.48, 0, -3.5)

SWEP.CorrectivePos = Vector(0, 0, 0)
SWEP.CorrectiveAng = Angle(0, 0, 0)

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

-- reload

SWEP.ClipSize = 12
SWEP.Ammo = "pistol"

SWEP.ReloadTimeMult = 1.25

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

SWEP.ReloadUpInTime = 0.85

-- sounds

local path = "tacrp_extras/usp/"

SWEP.Sound_Shoot = "^" .. path .. "Fire.wav"
SWEP.Sound_Shoot_Silenced = path .. "Supressed.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_iron"] = "new_shoot1",
	["fire"] = "new_shoot1", -- {"shoot1", "shoot2", "shoot3"},
	["lastshot"] = "new_lastshot",
	["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.NoIdle = false

SWEP.ShootTimeMult = 0.5

SWEP.LastShot = true

-- attachments

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

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.2,
		Pos_VM = Vector(0.035, 0, -0.2),
		Ang_VM = Angle(0, 90, 180),
		Pos_WM = Vector(0, -1, -0.8),
		Ang_WM = Angle(0, -90, 0),
	},
	[2] = {
		PrintName = "Muzzle",
		Category = { "comp_usp", "silencer" },
		Bone = "ValveBiped.barrel_assembly",
		WMBone = "Box01",
		AttachSound = "tacrp/weapons/silencer_on.wav",
		DetachSound = "tacrp/weapons/silencer_off.wav",
		VMScale = 0.6,
		WMScale = 0.5,
		Pos_VM = Vector(-0.5, 0.39, 7),
		Ang_VM = Angle(90, 0, 0),
		Pos_WM = Vector(0, 8.5, -1.5),
		Ang_WM = Angle(0, -90, 0),
	},
	[3] = {
		PrintName = "Tactical",
		Category = "tactical",
		Bone = "ValveBiped.p2000_rootbone",
		WMBone = "Box01",
		AttachSound = "tacrp/weapons/flashlight_on.wav",
		DetachSound = "tacrp/weapons/flashlight_off.wav",
		VMScale = 1.1,
		WMScale = 1.3,
		Pos_VM = Vector(-2, 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_pistol", "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_extras_usp.clip_in", path .. "clipin.wav")
addsound("tacint_extras_usp.clip_in-mid", path .. "clipin.wav")
addsound("tacint_extras_usp.clip_out", path .. "clipout.wav")

addsound("tacint_extras_usp.slide_action", path .. "SlideBack.wav")

addsound("tacint_extras_usp.slide_open", path .. "magshove.mp3")
addsound("tacint_extras_usp.slide_shut", path .. "boltrelease.wav")
