local PLUGIN = PLUGIN

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

AddCSLuaFile()

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

SWEP.SubCatTier = "3Security"
SWEP.SubCatType = "3Submachine Gun"

SWEP.Description =
"Boxy SMG developed with low production costs in mind.\nHigh damage up close, but range and rate of fire is low."
SWEP.Description_Quote = "Flat as a cutting board, but keep that to yourself."

SWEP.Trivia_Caliber = ".45 ACP"
SWEP.Trivia_Manufacturer = "Heckler & Koch"
SWEP.Trivia_Year = "2000"

SWEP.Faction = PLUGIN.FACTION_COALITION
SWEP.Credits = "Assets: Hellspike, Logger & Cyper \nSource: Gamebanana"

SWEP.ViewModel = "models/weapons/tacint_extras/v_ump45.mdl"
SWEP.WorldModel = "models/weapons/tacint_extras/w_ump45.mdl"

SWEP.Slot = 2

SWEP.BalanceStats = {
	[PLUGIN.BALANCE_SBOX] = {
		Damage_Max = 26,
		Damage_Min = 9,
	},
	[PLUGIN.BALANCE_TTT] = {
		Damage_Max = 18,
		Damage_Min = 6,

		Range_Min = 150,
		Range_Max = 1500,

		RecoilMaximum = 12,
		RecoilSpreadPenalty = 0.003,
		HipFireSpreadPenalty = 0.02,

		BodyDamageMultipliers = {
			[HITGROUP_HEAD] = 2,
			[HITGROUP_CHEST] = 1.25,
			[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 = 10,
		Damage_Min = 4,
	},
	[PLUGIN.BALANCE_OLDSCHOOL] = {
		RecoilMaximum = 25,
		RecoilDissipationRate = 22,
		RecoilSpreadPenalty = 0.003,
	}
}

-- "ballistics"

SWEP.Damage_Max = 24
SWEP.Damage_Min = 7
SWEP.Range_Min = 600
SWEP.Range_Max = 1800
SWEP.Penetration = 4 -- units of metal this weapon can penetrate
SWEP.ArmorPenetration = 0.55

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

SWEP.MuzzleVelocity = 11000

-- misc. shooting

SWEP.Firemodes = {
	2,
	-2,
	1
}

SWEP.RPM = 600
SWEP.RPMMultBurst = 1.25

SWEP.Spread = 0.004

SWEP.ShootTimeMult = 0.5

SWEP.RecoilResetInstant = false
SWEP.RecoilPerShot = 1
SWEP.RecoilMaximum = 6
SWEP.RecoilResetTime = 0.03
SWEP.RecoilDissipationRate = 24
SWEP.RecoilFirstShotMult = 0.8

SWEP.RecoilVisualKick = 0.5
SWEP.RecoilKick = 4
SWEP.RecoilStability = 0.35
SWEP.RecoilAltMultiplier = 150

SWEP.RecoilSpreadPenalty = 0.0022

SWEP.CanBlindFire = true

-- handling

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

SWEP.ReloadSpeedMult = 0.5

SWEP.AimDownSightsTime = 0.33
SWEP.SprintToFireTime = 0.35

SWEP.Sway = 0.75
SWEP.ScopedSway = 0.25

SWEP.FreeAimMaxAngle = 4.5

-- hold types

SWEP.HoldType = "ar2"
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(8, -1, -2)

SWEP.SightAng = Angle(-0, 0, 0)
SWEP.SightPos = Vector(-4.5, -7.5, -3.26)

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, 0, -6)
SWEP.HolsterAng = Angle(0, 0, 0)

-- reload

SWEP.ClipSize = 25
SWEP.Ammo = "pistol"

SWEP.ReloadTimeMult = 1
SWEP.DropMagazineModel = "models/weapons/tacint_extras/magazines/ump45.mdl"
SWEP.DropMagazineImpact = "plastic"

SWEP.ReloadUpInTime = 1.55
SWEP.DropMagazineTime = 1

-- sounds

local path = "TacRP/weapons/mp5/mp5_"
local path2 = "tacrp_extras/ump45/ump45_"

SWEP.Sound_Shoot = "^" .. path2 .. "1.wav"
SWEP.Sound_Shoot_Silenced = "TacRP/weapons/superv/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 = {
	["fire_iron"] = "dryfire",
	["fire1"] = "fire1_M",
	["fire2"] = "fire2_M",
	["fire3"] = "fire3_M",
	["fire4"] = "fire4_M",
	["fire5"] = "fire5_M",
	["melee"] = { "melee1", "melee2" }
}

-- attachments

SWEP.AttachmentElements = {
	["foldstock"] = {
		BGs_VM = {
			{ 1, 1 }
		},
		BGs_WM = {
			{ 1, 1 }
		}
	},
	["optic"] = {
		BGs_VM = {
			{ 2, 1 }
		},
	},
	["tactical"] = {
		BGs_VM = {
			{ 3, 1 }
		},
	},
}

SWEP.Attachments = {
	[1] = {
		PrintName = "Optic",
		Category = { "optic_cqb", "optic_medium" },
		Bone = "ValveBiped.mp5_rootbone",
		AttachSound = "TacRP/weapons/optic_on.wav",
		DetachSound = "TacRP/weapons/optic_off.wav",
		InstalledElements = { "optic" },
		Pos_VM = Vector(-6, -0.35, 4.5),
		Pos_WM = Vector(7, 1.6, -7),
		Ang_VM = Angle(90, 0, 0),
		Ang_WM = Angle(0, -3.5, 180),
	},
	[2] = {
		PrintName = "Muzzle",
		Category = "silencer",
		Bone = "ValveBiped.mp5_rootbone",
		AttachSound = "TacRP/weapons/silencer_on.wav",
		DetachSound = "TacRP/weapons/silencer_off.wav",
		VMScale = 0.8,
		Pos_VM = Vector(-3.95, -0.34, 20),
		Pos_WM = Vector(26, 2.5, -5),
		Ang_VM = Angle(90, 0, 0),
		Ang_WM = Angle(0, -3.5, 180),
	},
	[3] = {
		PrintName = "Tactical",
		Category = "tactical",
		Bone = "ValveBiped.mp5_rootbone",
		AttachSound = "TacRP/weapons/flashlight_on.wav",
		DetachSound = "TacRP/weapons/flashlight_off.wav",
		InstalledElements = { "tactical" },
		Pos_VM = Vector(-4, 0.5, 11),
		Pos_WM = Vector(14, 1.3, -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_4pos" },
		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_ump45.remove_clip1", path2 .. "clipout1.mp3")
addsound("tacint_extras_ump45.insert_clip1", path2 .. "clipin1.mp3")
addsound("tacint_extras_ump45.remove_clip2", path2 .. "clipout2.mp3")
addsound("tacint_extras_ump45.insert_clip2", path2 .. "clipin2.mp3")
addsound("tacint_extras_ump45.insert_clip-mid", path .. "insert_clip-mid.wav")
addsound("tacint_extras_ump45.HK_Slap", path2 .. "boltslap.mp3")
addsound("tacint_extras_ump45.bolt_back", path .. "bolt_back.wav")
addsound("tacint_extras_ump45.fire_select", {
	path .. "fire_select-1.wav",
	path .. "fire_select-2.wav",
	path .. "fire_select-3.wav",
})
