if SERVER then
    AddCSLuaFile()
end

local MAPSCRIPT = {}
MAPSCRIPT.PlayersLocked = false

MAPSCRIPT.DefaultLoadout = {
    Weapons = {"weapon_lambda_medkit", "weapon_crowbar", "weapon_pistol", "weapon_smg1", "weapon_357"},
    Ammo = {
        ["Pistol"] = 18,
        ["SMG1"] = 45,
        ["357"] = 6
    },
    Armor = 0,
    HEV = true
}

MAPSCRIPT.InputFilters = {
    ["gate1"] = {"EnableMotion"}
}

MAPSCRIPT.EntityFilterByClass = {}

MAPSCRIPT.EntityFilterByName = {
    ["global_newgame_spawner_suit"] = true,
    ["global_newgame_spawner_crowbar"] = true,
    ["global_newgame_spawner_pistol"] = true,
    ["global_newgame_spawner_smg"] = true,
    ["global_newgame_spawner_357"] = true,
    ["relay_guncave_gate_exit_close"] = true,
    ["filter_invulnerable"] = true
}

MAPSCRIPT.ImportantPlayerNPCNames = {
    ["npc_vort_gun"] = true,
    ["npc_cit_gate"] = true,
    ["npc_cit_briefer"] = true
}

MAPSCRIPT.Checkpoints = {
    { -- Airboat gun upgrade
        Pos = Vector(6457.725586, 4986.333984, -953.968750),
        Ang = Angle(0, 180, 0),
        Vehicle = {
            Pos = Vector(6363.024902, 4874.115234, -967.214539),
            Ang = Angle(0, 90, 0)
        },
        Trigger = {
            Pos = Vector(6338.301270, 5018.617188, -953.968750),
            Mins = Vector(-100, -100, 0),
            Maxs = Vector(100, 100, 180)
        }
    }
}

MAPSCRIPT.VehicleGuns = false

function MAPSCRIPT:PostInit()
    if SERVER then
        GAMEMODE:WaitForInput("door_guncave_exit", "Open", function()
            ents.WaitForEntityByName("npc_vort_gun", function(ent)
                GAMEMODE:UnregisterMissionCriticalNPC(ent)
            end)

            ents.WaitForEntityByName("npc_cit_gate", function(ent)
                GAMEMODE:UnregisterMissionCriticalNPC(ent)
            end)

            ents.WaitForEntityByName("npc_cit_briefer", function(ent)
                GAMEMODE:UnregisterMissionCriticalNPC(ent)
            end)
        end)

        self.VehicleGuns = false

        GAMEMODE:WaitForInput("global_newgame_spawner_airboat", "Unlock", function(ent)
            self.VehicleGuns = true
        end)

        ents.WaitForEntityByName("teleport_guncave_airboat", function(ent)
            -- This should fix the issue where airboats gone missing, also it properly lines em up
            -- given by our specific stack mode within point_teleport
            ent:SetKeyValue("stackmode", "1")
            ent:SetKeyValue("stackdir", util.TypeToString(ent:GetAngles():Right()))
            ent:SetKeyValue("stacklength", "200")
            ent:SetPos(Vector(5992.192383, 4864.584473, -926.774841))
        end)
    end
end

function MAPSCRIPT:PostPlayerSpawn(ply)
    --DbgPrint("PostPlayerSpawn")
end

return MAPSCRIPT