Gun = {}

Gun.actions = {

    shoot = function()

        if not UI_GAME then
            TimerRunTimer(timers.gun.shoot, {
                -- Functions to call.
                Gun.actions.createShot,
            }, false)
        end

        -- sounds.play.pour(GetCameraTransform().pos, 2)

    end,

    -- Creates a slime projectile.
    createShot = function()
        local toolTr = TransformCopy(GetBodyTransform(GetToolBody()))
        toolTr.pos = TransformToParentPoint(toolTr, Vec(0.7,0.2,-1))

        local spreadMult = (math.random() - 0.5) * regGetFloat('tool.pour.spread')
        local t = GetCameraTransform()
        local transform = TransformToParentVec(t, Vec(0, 0, -1))
        local hit, dist, normal, shape = QueryRaycast(t.pos, transform, 1000000)
        local targetPos = VecAdd(t.pos, VecScale(transform, 1000000))
        if hit then
            targetPos = VecAdd(t.pos, VecScale(transform, dist))
        end
        toolTr.rot = QuatLookAt(toolTr.pos, targetPos)
        toolTr.rot = QuatRotateQuat(
            toolTr.rot, 
            QuatEuler(
                math.random()*spreadMult,
                math.random()*spreadMult,
                math.random()*spreadMult))

        createProj(toolTr, projectiles, projPresets.motherSlime)

    end,

    reset = function()
        Slime.slimesList = {}
        projectiles = {}
        dbp('Slimes have been reset.' .. sfnTime(), true)
        beep()
    end,

    half = function()
        Slime.slimes.colony.markSlimesForRemoval()
        projectiles = {}
        dbp('Half of the slimes were removed.' .. sfnTime(), true)
        beep()
    end,

}
