local PLUGIN = PLUGIN

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

AddCSLuaFile()

-- names and stuff
SWEP.PrintName = "SIG P250"
SWEP.AbbrevName = "P250"
SWEP.Category = "Tactical RP"

SWEP.SubCatTier = "2Operator"
SWEP.SubCatType = "1Sidearm"

SWEP.Description = "Powerful handgun that exchanges capacity for damage and precision."

SWEP.Trivia_Caliber = ".357 SIG"
SWEP.Trivia_Manufacturer = "SIG Sauer, Inc."
SWEP.Trivia_Year = "2007"

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

SWEP.ViewModel = "models/weapons/tacint/v_p250.mdl"
SWEP.WorldModel = "models/weapons/tacint/w_p250.mdl"

SWEP.Slot = 1

SWEP.BalanceStats = {
	[PLUGIN.BALANCE_SBOX] = {
		Damage_Max = 32,
		Damage_Min = 20,
		Range_Min = 900,
		Range_Max = 2800,
		ArmorPenetration = 0.65,

		BodyDamageMultipliers = {
			[HITGROUP_HEAD] = 3.25,
			[HITGROUP_CHEST] = 1,
			[HITGROUP_STOMACH] = 1,
			[HITGROUP_LEFTARM] = 1,
			[HITGROUP_RIGHTARM] = 1,
			[HITGROUP_LEFTLEG] = 0.75,
			[HITGROUP_RIGHTLEG] = 0.75,
			[HITGROUP_GEAR] = 0.9
		},
	},
	[PLUGIN.BALANCE_TTT] = {
		Description = "Powerful handgun that exchanges fire rate for damage and precision.",

		Damage_Max = 22,
		Damage_Min = 12,
		Range_Min = 800,
		Range_Max = 2000,
		RPM = 200,
		RPMMultSemi = 1,

		RecoilResetInstant = true,
		RecoilMaximum = 5,
		RecoilResetTime = 0.2,
		RecoilDissipationRate = 5.5,
		RecoilFirstShotMult = 0.8,
		RecoilSpreadPenalty = 0.012,

		BodyDamageMultipliers = {
			[HITGROUP_HEAD] = 2.5,
			[HITGROUP_CHEST] = 1,
			[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.1 * 1.25,
	},
	[PLUGIN.BALANCE_PVE] = {
		Damage_Max = 18,
		Damage_Min = 12,
		Range_Min = 900,
		Range_Max = 2800,
		RPM = 450,
	},
}

-- "ballistics"

SWEP.Damage_Max = 25
SWEP.Damage_Min = 14
SWEP.Range_Min = 800  -- distance for which to maintain maximum damage
SWEP.Range_Max = 2500 -- distance at which we drop to minimum damage
SWEP.Penetration = 7  -- units of metal this weapon can penetrate
SWEP.ArmorPenetration = 0.775
SWEP.ArmorBonus = 1

SWEP.MuzzleVelocity = 11000

SWEP.BodyDamageMultipliers = {
	[HITGROUP_HEAD] = 4.5,
	[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 = 500
SWEP.RPMMultSemi = 0.7

SWEP.Spread = 0.004

SWEP.ShootTimeMult = 0.5

SWEP.RecoilResetInstant = false
SWEP.RecoilPerShot = 1
SWEP.RecoilMaximum = 3
SWEP.RecoilResetTime = 0.02
SWEP.RecoilDissipationRate = 12
SWEP.RecoilFirstShotMult = 1

SWEP.RecoilVisualKick = 1.5
SWEP.RecoilKick = 5
SWEP.RecoilStability = 0.6

SWEP.RecoilSpreadPenalty = 0.0065

SWEP.CanBlindFire = true

-- handling

SWEP.MoveSpeedMult = 0.975
SWEP.ShootingSpeedMult = 0.9
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

-- 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(25, 15, -6)

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

SWEP.SightAng = Angle(0.02, 0.15, 0)
SWEP.SightPos = Vector(-3.45, 0, -3.35)

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.1

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

SWEP.ReloadUpInTime = 0.9
SWEP.DropMagazineTime = 0.2

-- sounds

local path = "TacRP/weapons/p250/p250_"

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.01, 0, 0),
		Ang_VM = Angle(0, 90, 180),
		Pos_WM = Vector(0, -1, -1),
		Ang_WM = Angle(0, -90, 0),
	},
	[2] = {
		PrintName = "Muzzle",
		Category = "silencer",
		Bone = "ValveBiped.barrel_assembly",
		WMBone = "Box01",
		AttachSound = "TacRP/weapons/silencer_on.wav",
		DetachSound = "TacRP/weapons/silencer_off.wav",
		VMScale = 0.5,
		WMScale = 0.5,
		Pos_VM = Vector(-0.6, 0.45, 6),
		Ang_VM = Angle(90, 0, 0),
		Pos_WM = Vector(0, 8, -1.5),
		Ang_WM = Angle(0, -90, 0),
	},
	[3] = {
		PrintName = "Tactical",
		Category = "tactical",
		Bone = "ValveBiped.p250_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, 5.25),
		Ang_VM = Angle(90, 0, 180),
		Pos_WM = Vector(0, 5, -2.75),
		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_p250.clip_in", path .. "clip_in.wav")
addsound("TacInt_p250.clip_in-mid", path .. "clip_in-mid.wav")
addsound("TacInt_p250.clip_out", path .. "clip_out.wav")
addsound("TacInt_p250.slide_action", path .. "slide_action.wav")
addsound("TacInt_p250.slide_shut", path .. "slide_shut.wav")
addsound("TacInt_p250.cock_hammer", path .. "cockhammer.wav")
