ENT.Type = "anim"
ENT.Base = "base_gmodentity"
ENT.PrintName = "Vehicle Terminal"
ENT.Author = "RefoselDev"
ENT.Category = "[FT] Система техники"
ENT.Spawnable = false
ENT.AdminSpawnable = true

function ENT:SetupDataTables()
    self:NetworkVar("String", 0, "TerminalType")
end

scripted_ents.Register({
    Type = "anim",
    Base = "base_gmodentity",
    PrintName = "Терминал наземной техники",
    Category = "[FT] Система техники",
    Author = "RefoselDev",
    Spawnable = true,
    AdminOnly = true,
    bNoPersist = true,
    Model = "models/props_c17/oildrum001.mdl",
    SetupDataTables = function(self)
        self:NetworkVar("String", 0, "TerminalType")
    end,
    Initialize = function(self)
        if (SERVER) then
            self:SetModel(self.Model)
            self:PhysicsInit(SOLID_VPHYSICS)
            self:SetMoveType(MOVETYPE_VPHYSICS)
            self:SetSolid(SOLID_VPHYSICS)
            self:SetUseType(SIMPLE_USE)
            self:SetTerminalType("ground")
            
            local phys = self:GetPhysicsObject()
            if phys:IsValid() then
                phys:Wake()
                phys:EnableMotion(false)
            end
        end
    end,
    Use = function(self, activator, caller)
        if (SERVER) then
            if not IsValid(activator) or not activator:IsPlayer() then return end
            
            local vehiclePlugin = ix.plugin.list["vehicles"]
            if vehiclePlugin and vehiclePlugin.GetFactionPoints then
                net.Start("LVS_SyncFactionPoints")
                    net.WriteUInt(activator:Team(), 8)
                    net.WriteUInt(vehiclePlugin:GetFactionPoints(activator:Team()) or 0, 32)
                net.Send(activator)
            end
            
            net.Start("LVS_OpenGroundMenu")
            net.Send(activator)
        end
    end,
    Draw = function(self)
        self:DrawModel()

        local pos = self:GetPos() + Vector(0, 0, 80)
        local ang = Angle(0, LocalPlayer():EyeAngles().y - 90, 90)

        cam.Start3D2D(pos, ang, 0.15)
            draw.SimpleText("НАЗЕМНАЯ ТЕХНИКА", "DermaLarge", 0, 0, color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
        cam.End3D2D()
    end
}, "ix_vehicle_terminal_ground")

scripted_ents.Register({
    Type = "anim",
    Base = "base_gmodentity", 
    PrintName = "Терминал воздушной техники",
    Category = "[FT] Система техники",
    Author = "RefoselDev",
    Spawnable = true,
    AdminOnly = true,
    bNoPersist = true,
    Model = "models/props_c17/oildrum001.mdl",
    SetupDataTables = function(self)
        self:NetworkVar("String", 0, "TerminalType")
    end,
    Initialize = function(self)
        if (SERVER) then
            self:SetModel(self.Model)
            self:PhysicsInit(SOLID_VPHYSICS)
            self:SetMoveType(MOVETYPE_VPHYSICS)
            self:SetSolid(SOLID_VPHYSICS)
            self:SetUseType(SIMPLE_USE)
            self:SetTerminalType("air")
            
            local phys = self:GetPhysicsObject()
            if phys:IsValid() then
                phys:Wake()
                phys:EnableMotion(false)
            end
        end
    end,
    Use = function(self, activator, caller)
        if (SERVER) then
            if not IsValid(activator) or not activator:IsPlayer() then return end
            
            local vehiclePlugin = ix.plugin.list["vehicles"]
            if vehiclePlugin and vehiclePlugin.GetFactionPoints then
                net.Start("LVS_SyncFactionPoints")
                    net.WriteUInt(activator:Team(), 8)
                    net.WriteUInt(vehiclePlugin:GetFactionPoints(activator:Team()) or 0, 32)
                net.Send(activator)
            end
            
            net.Start("LVS_OpenAirMenu")
            net.Send(activator)
        end
    end,
    Draw = function(self)
        self:DrawModel()

        if (not CLIENT) then return end

        local pos = self:GetPos() + self:GetUp() * 100
        local ang = LocalPlayer():EyeAngles()
        ang:RotateAroundAxis(ang:Right(), 90)
        ang:RotateAroundAxis(ang:Up(), -90)

        cam.Start3D2D(pos, ang, 0.1)
            draw.SimpleText("ВОЗДУШНАЯ ТЕХНИКА", "DermaLarge", 0, 0, color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
        cam.End3D2D()
    end
}, "ix_vehicle_terminal_air")
