Esempio n. 1
0
        internal static void OpenGarageCEF(IPlayer player, int garageId)
        {
            try
            {
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();

                if (player == null || !player.Exists || garageId == 0)
                {
                    return;
                }
                int charId = User.GetPlayerOnline(player);
                if (charId <= 0)
                {
                    return;
                }
                var garageInfo  = ServerGarages.ServerGarages_.FirstOrDefault(x => x.id == garageId);
                var garageSlots = ServerGarages.ServerGarageSlots_.Where(x => x.garageId == garageId).ToList();
                if (garageInfo == null || !garageSlots.Any())
                {
                    return;
                }
                if (!player.Position.IsInRange(new Position(garageInfo.posX, garageInfo.posY, garageInfo.posZ), 2f))
                {
                    return;
                }
                var  charFaction     = ServerFactions.GetCharacterFactionId(charId);
                var  factionCut      = ServerFactions.GetFactionShortName(charFaction);
                bool charFactionDuty = ServerFactions.IsCharacterInFactionDuty(charId);
                var  inString        = "";
                var  outString       = "";
                var  garageName      = "";
                //0 Auto | 1 Boot | 2 Flugzeug | 3 Heli
                if (garageInfo.type == 0)
                {
                    garageName = $"Fahrzeuggarage: {garageInfo.name}";
                }
                else if (garageInfo.type == 1)
                {
                    garageName = $"Bootsgarage: {garageInfo.name}";
                }
                else if (garageInfo.type == 2)
                {
                    garageName = $"Flugzeuggarage: {garageInfo.name}";
                }
                else if (garageInfo.type == 3)
                {
                    garageName = $"Heligarage: {garageInfo.name}";
                }

                if (garageInfo.name.Contains("Fraktion"))
                {
                    if (charFaction <= 0)
                    {
                        HUDHandler.SendNotification(player, 4, 5000, $"Keine Berechtigung."); return;
                    }
                    var gFactionCut = garageInfo.name.Split(" ")[1]; //Fraktion LSPD Mission Row  <- Beispiel
                    if (gFactionCut != factionCut)
                    {
                        HUDHandler.SendNotification(player, 4, 5000, $"Keine Berechtigung [002]."); return;
                    }
                    /*if(!charFactionDuty) { HUDHandler.SendNotification(player, 4, 5000, $"Keine Berechtigung (nicht im Dienst)."); return; }*/
                    inString  = GetGarageParkInString(player, garageSlots, charId, garageId, true, factionCut, charFaction);
                    outString = GetGarageParkOutString(player, garageId, charId, true, factionCut);
                    player.EmitLocked("Client:Garage:OpenGarage", garageId, garageName, inString, outString);
                    stopwatch.Stop();
                    if (stopwatch.Elapsed.Milliseconds > 30)
                    {
                        Alt.Log($"{charId} - OpenGarageCEF benötigte {stopwatch.Elapsed.Milliseconds}ms");
                    }
                    return;
                }

                inString  = GetGarageParkInString(player, garageSlots, charId, garageId, false, "Zivilist", charFaction); //Array von Fahrzeugen die um die Garage rum zum Einparken stehen
                outString = GetGarageParkOutString(player, garageId, charId, false, "Zivilist");
                Global.mGlobal.VirtualAPI.TriggerClientEventSafe(player, "Client:Garage:OpenGarage", garageId, garageName, inString, outString);


                stopwatch.Stop();
                if (stopwatch.Elapsed.Milliseconds > 30)
                {
                    Alt.Log($"{charId} - OpenGarageCEF benötigte {stopwatch.Elapsed.Milliseconds}ms");
                }
            }
            catch (Exception e)
            {
                Alt.Log($"{e}");
            }
        }