-- Original name: zNS_SoundIncrease.lua
-- Original author: Nihilist Penguin (https://steamcommunity.com/id/bickback/)

-- Copyright 2023 Nihilist Penguin. This item is not authorized for posting on Steam,
-- except under the Steam account named Nihilist Penguin, or with the copyright holder's explicit permission.
-- Redistribution of this mod without explicit permission from the original creator is prohibited under any circumstances.
-- This includes, but not limited to, uploading these mods to the Steam Workshop or any other site,
-- distribution as part of another mod or modpack, and distribution of modified versions.

if not NSGlobal then
	print("NSGlobal not found, skipping zNS_SoundIncrease.lua")
	return
end

local print_debug = NSGlobal.utils.register.print_debug

local fn = function()
	local _get_ammo_type_sound_increase = NSGlobal.utils.register.get_ammo_type_sound_increase
	local details = NSGlobal.system.rweapon_details

	for full_name, detail in pairs(details) do
		local sound_increase = _get_ammo_type_sound_increase(detail.ammo_type)
		if sound_increase and detail.sound_volume > 0 and detail.sound_radius > 0 then
			detail.sound_volume = detail.sound_volume + sound_increase
			detail.sound_radius = detail.sound_radius + sound_increase
			local script_item = ScriptManager.instance:getItem(full_name)
			script_item:setSoundVolume(detail.sound_volume)
			script_item:setSoundRadius(detail.sound_radius)
			-- stylua: ignore
			print_debug("[Sound] name: " .. full_name .. " | ammo: " .. detail.ammo_type .. " | new v: " .. detail.sound_volume .. " | new r: " .. detail.sound_radius)
		end
	end

	NSGlobal.system.increased_sounds = true
end

Events.OnGameStart.Add(fn) -- sp
Events.OnServerStarted.Add(fn) -- mp
