You simply want to apply the rotation matrix.
Assuming you use a cartesian metric for your game, and your gun is pointing in direction \$ \vec{A} = (x,y,z) \$, and you rotate around the vertical axis \$ \vec{B} = (0, 0, 1) \$. Then the rotation \$ R_z \$ by and angle \$ \theta \$ is defined as $$ R_z(\theta) = \left(\begin{array}{ccc}\cos \theta, & -\sin \theta,& 0\\\sin\theta, &\cos \theta,& 0\\0,&0,&0
\end{array}\right) $$
Thus the rotated vector \$\vec{A}^\prime = \vec{A} \cdot R_z = (x\cos\theta-y\sin\theta, x\sin\theta + y\cos\theta, 0)\$
For a more elaborate treatise around general axis, consult a book on algebra or have a look on the wikipedia article on rotation:
The matrix of a proper rotation \$R\$ by angle \$\theta\$ around the axis \$\vec u =(u_{x},u_{y},u_{z})\$, a unit vector with \$u_{x}^{2}+u_{y}^{2}+u_{z}^{2}=1\$, is given by:[3]
$$\small {R = \begin{bmatrix}\cos \theta +u_{x}^{2}\left(1-\cos \theta \right)&u_{x}u_{y}\left(1-\cos \theta \right)-u_{z}\sin \theta &u_{x}u_{z}\left(1-\cos \theta \right)+u_{y}\sin \theta \\u_{y}u_{x}\left(1-\cos \theta \right)+u_{z}\sin \theta &\cos \theta +u_{y}^{2}\left(1-\cos \theta \right)&u_{y}u_{z}\left(1-\cos \theta \right)-u_{x}\sin \theta \\u_{z}u_{x}\left(1-\cos \theta \right)-u_{y}\sin \theta &u_{z}u_{y}\left(1-\cos \theta \right)+u_{x}\sin \theta &\cos \theta +u_{z}^{2}\left(1-\cos \theta \right)\end{bmatrix}}$$