local PLUGIN = PLUGIN

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

AddCSLuaFile()

-- names and stuff
SWEP.PrintName = "Ingram MAC-10"
SWEP.AbbrevName = "MAC-10"
SWEP.Category = "Tactical RP" -- "Tactical RP (Extras)"

SWEP.SubCatTier = "4Consumer"
SWEP.SubCatType = "2Machine Pistol"

SWEP.Description = "A bullet hose best used for point blank spray-and-pray."

SWEP.Trivia_Caliber = "9x19mm"
SWEP.Trivia_Manufacturer = "Military Armament Corporation"
SWEP.Trivia_Year = "1970"

SWEP.Faction = PLUGIN.FACTION_MILITIA
SWEP.Credits = [[
Model/Texture: Enron
Sound: Vunsunta,  Erick F
Animations: Tactical Intervention]]

SWEP.ViewModel = "models/weapons/tacint_extras/v_mac10.mdl"
SWEP.WorldModel = "models/weapons/tacint_extras/w_mac10.mdl"

SWEP.Slot = 1

SWEP.BalanceStats = {
	[PLUGIN.BALANCE_SBOX] = {
		Damage_Max = 20,
		Damage_Min = 5,
		ClipSize = 40,

		RecoilKick = 4,
	},
	[PLUGIN.BALANCE_TTT] = {
		Damage_Max = 10,
		Damage_Min = 4,
		Range_Min = 100,
		Range_Max = 1400,
		RPM = 900,

		Spread = 0.014,
		HipFireSpreadPenalty = 0.01,
		RecoilSpreadPenalty = 0.0035,
		RecoilMaximum = 18,
		RecoilDissipationRate = 30,
		RecoilResetTime = 0.15,
		RecoilFirstShotMult = 2,

		BodyDamageMultipliers = {
			[HITGROUP_HEAD] = 2,
			[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
		},
	},
	[PLUGIN.BALANCE_PVE] = {
		Damage_Max = 5,
		Damage_Min = 2,

		RecoilKick = 2,
		RecoilMaximum = 18,
	},
	[PLUGIN.BALANCE_OLDSCHOOL] = {
		RecoilSpreadPenalty = 0.004,
		RecoilMaximum = 25
	}
}

-- "ballistics"

SWEP.Damage_Max = 18
SWEP.Damage_Min = 5
SWEP.Range_Min = 300
SWEP.Range_Max = 1500
SWEP.Penetration = 3
SWEP.ArmorPenetration = 0.45
SWEP.ArmorBonus = 0.25

SWEP.MuzzleVelocity = 10000

SWEP.BodyDamageMultipliers = {
	[HITGROUP_HEAD] = 1.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 = 2

SWEP.RPM = 1000

SWEP.Spread = 0.012

SWEP.HipFireSpreadPenalty = 0.01

SWEP.RecoilResetInstant = false
SWEP.RecoilPerShot = 1
SWEP.RecoilMaximum = 15
SWEP.RecoilResetTime = 0     -- time after you stop shooting for recoil to start dissipating
SWEP.RecoilDissipationRate = 45
SWEP.RecoilFirstShotMult = 1 -- multiplier for the first shot's recoil amount

SWEP.RecoilVisualKick = 1.5

SWEP.RecoilKick = 2.5
SWEP.RecoilStability = 0.15

SWEP.RecoilSpreadPenalty = 0.002
SWEP.HipFireSpreadPenalty = 0.025

SWEP.CanBlindFire = true

-- handling

SWEP.MoveSpeedMult = 0.95
SWEP.ShootingSpeedMult = 0.5
SWEP.SightedSpeedMult = 0.7

SWEP.ReloadSpeedMult = 0.6

SWEP.AimDownSightsTime = 0.275
SWEP.SprintToFireTime = 0.30

SWEP.Sway = 0.9
SWEP.ScopedSway = 0.4

SWEP.FreeAimMaxAngle = 4

-- 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(-135, 0, 45)
SWEP.BlindFireSuicidePos = Vector(27, 20, -5)

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

SWEP.SightAng = Angle(-0.05, 0.12, 0)
SWEP.SightPos = Vector(-3.4, -6, -4.05)

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

-- reload

SWEP.ClipSize = 32
SWEP.Ammo = "pistol"

SWEP.ReloadTimeMult = 1.2

SWEP.DropMagazineModel = "models/weapons/tacint_extras/magazines/mac10.mdl"
SWEP.DropMagazineImpact = "pistol"

SWEP.ReloadUpInTime = 1
SWEP.DropMagazineTime = 0.3

-- sounds

local path = "tacrp_extras/mac10/"

SWEP.Sound_Shoot = "^" .. path .. "mac10-2.wav"
SWEP.Sound_Shoot_Silenced = path .. "mac10-suppressed-1.wav"

SWEP.Vol_Shoot = 110
SWEP.Pitch_Shoot = 100
SWEP.Loudness_Shoot = 1
SWEP.ShootPitchVariance = 3

-- effects

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

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.15),
	vm_ang = Angle(0, 1, 0),
	t = 0.2,
	tmax = 0.2,
	bones = {
		{
			bone = "xd45_rig.slide",
			pos = Vector(0, 0, -3),
			t0 = 0,
			t1 = 0.1,
		},
		{
			bone = "xd45_rig.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.ShootTimeMult = 0.5

SWEP.LastShot = false

-- attachmentsc

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

SWEP.Attachments = {
	[1] = {
		PrintName = "Muzzle",
		Category = { "comp_mac10", "silencer" },
		Bone = "xd45_rig.xd45_ROOT",
		WMBone = "Box01",
		AttachSound = "tacrp/weapons/silencer_on.wav",
		DetachSound = "tacrp/weapons/silencer_off.wav",
		VMScale = 0.7,
		WMScale = 0.75,
		Pos_VM = Vector(-2.8, 0, 10),
		Ang_VM = Angle(90, 0, 0),
		Pos_WM = Vector(0, 10, -1.6),
		Ang_WM = Angle(0, -90, 0),
	},
	[2] = {
		PrintName = "Tactical",
		Category = "tactical",
		Bone = "xd45_rig.xd45_ROOT",
		WMBone = "Box01",
		AttachSound = "tacrp/weapons/flashlight_on.wav",
		DetachSound = "tacrp/weapons/flashlight_off.wav",
		VMScale = 0.8,
		WMScale = 1,
		Pos_VM = Vector(-1.6, 0, 6),
		Ang_VM = Angle(90, 0, 180),
		Pos_WM = Vector(0, 4, -2.75),
		Ang_WM = Angle(0, -90, 180),
	},
	[3] = {
		PrintName = "Accessory",
		Category = { "acc", "acc_foldstock", "acc_extmag_smg", "acc_holster" },
		AttachSound = "TacRP/weapons/flashlight_on.wav",
		DetachSound = "TacRP/weapons/flashlight_off.wav",
	},
	[4] = {
		PrintName = "Bolt",
		Category = { "bolt_automatic" },
		AttachSound = "TacRP/weapons/flashlight_on.wav",
		DetachSound = "TacRP/weapons/flashlight_off.wav",
	},
	[5] = {
		PrintName = "Trigger",
		Category = { "trigger_auto" },
		AttachSound = "TacRP/weapons/flashlight_on.wav",
		DetachSound = "TacRP/weapons/flashlight_off.wav",
	},
	[6] = {
		PrintName = "Ammo",
		Category = { "ammo_pistol" },
		AttachSound = "TacRP/weapons/flashlight_on.wav",
		DetachSound = "TacRP/weapons/flashlight_off.wav",
	},
	[7] = {
		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_mac10.clip_in", path .. "mac10_clipin.wav")
addsound("tacint_extras_mac10.clip_out", path .. "mac10_clipout.wav")
addsound("tacint_extras_mac10.slide_back", path .. "mac10_boltpull.wav")
addsound("tacint_extras_mac10.slide_forward", path .. "mac10_boltpull2.wav")
addsound("tacint_extras_mac10.slide_shut", path .. "mac10_boltpull2.wav")
