local PLUGIN = PLUGIN

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

AddCSLuaFile()

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

-- Assets: https://gamebanana.com/mods/208831

SWEP.SubCatTier = "2Operator"
SWEP.SubCatType = "3Submachine Gun"

SWEP.Description = "Compact polymer submachine gun packing lots of firepower in a small package."

SWEP.Trivia_Caliber = "9x19mm"
SWEP.Trivia_Manufacturer = "Brügger & Thomet"
SWEP.Trivia_Year = "2001"

SWEP.Faction = PLUGIN.FACTION_COALITION
SWEP.Credits = "Assets: Logger & The Expert \nSource: Gamebanana"

SWEP.ViewModel = "models/weapons/tacint_extras/v_mp9.mdl"
SWEP.WorldModel = "models/weapons/tacint_extras/w_mp9.mdl"

SWEP.Slot = 2

SWEP.BalanceStats = {
	[PLUGIN.BALANCE_SBOX] = {
	},
	[PLUGIN.BALANCE_TTT] = {
		Damage_Max = 12,
		Damage_Min = 6,

		Range_Min = 600,
		Range_Max = 1500,

		BodyDamageMultipliers = {
			[HITGROUP_HEAD] = 2,
			[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_PVE] = {
		Damage_Max = 9,
		Damage_Min = 4,
	},
	[PLUGIN.BALANCE_OLDSCHOOL] = {
		RecoilSpreadPenalty = 0.0035
	}
}

-- "ballistics"

SWEP.Damage_Max = 20
SWEP.Damage_Min = 8
SWEP.Range_Min = 700
SWEP.Range_Max = 2200
SWEP.Penetration = 3 -- units of metal this weapon can penetrate
SWEP.ArmorPenetration = 0.6

SWEP.MuzzleVelocity = 16000

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

-- misc. shooting

SWEP.Firemodes = {
	2,
	1
}

SWEP.RPM = 900

SWEP.Spread = 0.0075

SWEP.RecoilResetInstant = false
SWEP.RecoilPerShot = 1
SWEP.RecoilMaximum = 7
SWEP.RecoilResetTime = 0.02
SWEP.RecoilDissipationRate = 28
SWEP.RecoilFirstShotMult = 1.5

SWEP.RecoilVisualKick = 1.25
SWEP.RecoilKick = 3
SWEP.RecoilStability = 0.1

SWEP.RecoilSpreadPenalty = 0.003

SWEP.CanBlindFire = true

-- handling

SWEP.MoveSpeedMult = 0.975
SWEP.ShootingSpeedMult = 0.9
SWEP.SightedSpeedMult = 0.75

SWEP.ReloadSpeedMult = 0.5

SWEP.AimDownSightsTime = 0.29
SWEP.SprintToFireTime = 0.3

SWEP.Sway = 0.75
SWEP.ScopedSway = 0.25

SWEP.FreeAimMaxAngle = 3.5

-- 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, -4, -5)

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

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

SWEP.SightAng = Angle(0, 0, 0)
SWEP.SightPos = Vector(-3.25, -4, -2.9)

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

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


-- reload

SWEP.ClipSize = 30
SWEP.Ammo = "pistol"

SWEP.ReloadTimeMult = 1
SWEP.DropMagazineModel = "models/weapons/tacint_extras/magazines/mp9.mdl"
SWEP.DropMagazineImpact = "plastic"
SWEP.GestureReload = ACT_HL2MP_GESTURE_RELOAD_PISTOL

SWEP.ReloadUpInTime = 1.2
SWEP.DropMagazineTime = 0.4

-- sounds

local path = "tacrp/weapons/mp7/mp7_"
local path2 = "tacrp_extras/mp9/"

SWEP.Sound_Shoot = "^" .. path2 .. "fire-1.wav"
SWEP.Sound_Shoot_Silenced = path2 .. "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 = 1
-- ditto for shell
SWEP.QCA_Eject = 2

SWEP.MuzzleEffect = "muzzleflash_ak47"

-- anims

SWEP.AnimationTranslationTable = {
	["fire1"] = "fire1_M",
	["fire2"] = "fire2_M",
	["fire3"] = "fire3_M",
	["fire4"] = "fire4_M",
	["fire5"] = "fire5_M",
	["melee"] = { "melee1", "melee2" },
	["deploy"] = "deploy",
}

-- attachments

SWEP.DeployTimeMult = 1

SWEP.AttachmentElements = {
	["foldstock"] = {
		BGs_VM = {
			{ 1, 1 }
		},
		BGs_WM = {
			{ 1, 1 }
		},
	},
	["rail"] = {
		BGs_VM = {
			{ 2, 1 }
		},
		BGs_WM = {
			{ 2, 1 }
		},
	},
}

SWEP.Attachments = {
	[1] = {
		PrintName = "Optic",
		Category = { "optic_cqb", "optic_medium" },
		Bone = "ValveBiped.mp7_rootbone",
		AttachSound = "tacrp/weapons/optic_on.wav",
		DetachSound = "tacrp/weapons/optic_off.wav",
		InstalledElements = { "optic" },
		Pos_VM = Vector(-4.25, 0.05, 2),
		Pos_WM = Vector(5, 1.5, -6),
		Ang_VM = Angle(90, 0, 0),
		Ang_WM = Angle(0, -3.5, 180),
	},
	[2] = {
		PrintName = "Muzzle",
		Category = "silencer",
		Bone = "ValveBiped.mp7_rootbone",
		AttachSound = "tacrp/weapons/silencer_on.wav",
		DetachSound = "tacrp/weapons/silencer_off.wav",
		Pos_VM = Vector(-2.675, 0.05, 13),
		Pos_WM = Vector(18, 2, -4.25),
		Ang_VM = Angle(90, 0, 0),
		Ang_WM = Angle(0, -3.5, 180),
	},
	[3] = {
		PrintName = "Tactical",
		Category = "tactical",
		Bone = "ValveBiped.mp7_rootbone",
		AttachSound = "tacrp/weapons/flashlight_on.wav",
		DetachSound = "tacrp/weapons/flashlight_off.wav",
		InstalledElements = { "rail" },
		Pos_VM = Vector(-3, 0.8, 4),
		Pos_WM = Vector(8, 0.6, -4.5),
		Ang_VM = Angle(90, 0, 90),
		Ang_WM = Angle(0, -3.5, -90),
	},
	[4] = {
		PrintName = "Accessory",
		Category = { "acc", "acc_foldstock", "acc_sling", "acc_duffle", "acc_extmag_smg" },
		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_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_mp9.remove_clip", path2 .. "clipout.mp3")
addsound("tacint_extras_mp9.insert_clip", path2 .. "clipin.mp3")
addsound("tacint_extras_mp9.bolt_action", path .. "bolt_action.wav")
addsound("tacint_extras_mp9.forearm_deploy", "tacrp/weapons/uzi/" .. "foldingstock_back.wav")
