Пример #1
0
        public static async void OnEntityTimer(object sender, ElapsedEventArgs e)
        {
            try
            {
                Console.WriteLine($"Timer - Thread = {Thread.CurrentThread.ManagedThreadId}");
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                foreach (IVehicle Veh in Alt.Server.GetVehicles().ToList())
                {
                    if (Veh == null || !Veh.Exists)
                    {
                        continue;
                    }
                    using (var vRef = new VehicleRef(Veh))
                    {
                        if (!vRef.Exists)
                        {
                            continue;
                        }
                        lock (Veh)
                        {
                            if (Veh == null || !Veh.Exists)
                            {
                                continue;
                            }
                            ulong vehID = Veh.GetVehicleId();
                            if (vehID <= 0)
                            {
                                continue;
                            }
                            ServerVehicles.SaveVehiclePositionAndStates(Veh);
                            if (Veh.EngineOn == true)
                            {
                                ServerVehicles.SetVehicleFuel(Veh, ServerVehicles.GetVehicleFuel(Veh) - 0.03f);
                            }
                        }
                    }
                }

                stopwatch.Stop();
                Alt.Log($"OnEntityTimer: Vehicle Foreach benötigte: {stopwatch.Elapsed}");

                stopwatch.Reset();
                stopwatch.Start();
                foreach (IPlayer player in Alt.Server.GetPlayers().ToList())
                {
                    if (player == null)
                    {
                        continue;
                    }
                    using (var playerReference = new PlayerRef(player))
                    {
                        if (!playerReference.Exists)
                        {
                            return;
                        }
                        if (player == null || !player.Exists)
                        {
                            continue;
                        }
                        lock (player)
                        {
                            if (player == null || !player.Exists)
                            {
                                continue;
                            }
                            int charId = User.GetPlayerOnline(player);
                            if (charId > 0)
                            {
                                Characters.SetCharacterLastPosition(charId, player.Position, player.Dimension);
                                if (User.IsPlayerBanned(player))
                                {
                                    player.kickWithMessage($"Du bist gebannt. (Grund: {User.GetPlayerBanReason(player)}).");
                                }
                                Characters.SetCharacterHealth(charId, player.Health);
                                Characters.SetCharacterArmor(charId, player.Armor);
                                WeatherHandler.SetRealTime(player);
                                if (player.IsInVehicle)
                                {
                                    player.EmitLocked("Client:HUD:GetDistanceForVehicleKM"); HUDHandler.SendInformationToVehicleHUD(player);
                                }
                                Characters.IncreaseCharacterPaydayTime(charId);

                                if (Characters.IsCharacterUnconscious(charId))
                                {
                                    int unconsciousTime = Characters.GetCharacterUnconsciousTime(charId);
                                    if (unconsciousTime > 0)
                                    {
                                        Characters.SetCharacterUnconscious(charId, true, unconsciousTime - 1);
                                    }
                                    else if (unconsciousTime <= 0)
                                    {
                                        Characters.SetCharacterUnconscious(charId, false, 0);
                                        DeathHandler.closeDeathscreen(player);
                                        player.Spawn(new Position(355.54285f, -596.33405f, 28.75768f));
                                        player.Health = player.MaxHealth;
                                    }
                                }

                                if (Characters.IsCharacterFastFarm(charId))
                                {
                                    int fastFarmTime = Characters.GetCharacterFastFarmTime(charId);
                                    if (fastFarmTime > 0)
                                    {
                                        Characters.SetCharacterFastFarm(charId, true, fastFarmTime - 1);
                                    }
                                    else if (fastFarmTime <= 0)
                                    {
                                        Characters.SetCharacterFastFarm(charId, false, 0);
                                    }
                                }

                                if (Characters.IsCharacterInJail(charId))
                                {
                                    int jailTime = Characters.GetCharacterJailTime(charId);
                                    if (jailTime > 0)
                                    {
                                        Characters.SetCharacterJailTime(charId, true, jailTime - 1);
                                    }
                                    else if (jailTime <= 0)
                                    {
                                        if (CharactersWanteds.HasCharacterWanteds(charId))
                                        {
                                            int jailTimes = CharactersWanteds.GetCharacterWantedFinalJailTime(charId);
                                            int jailPrice = CharactersWanteds.GetCharacterWantedFinalJailPrice(charId);
                                            if (CharactersBank.HasCharacterBankMainKonto(charId))
                                            {
                                                int accNumber = CharactersBank.GetCharacterBankMainKonto(charId);
                                                int bankMoney = CharactersBank.GetBankAccountMoney(accNumber);
                                                CharactersBank.SetBankAccountMoney(accNumber, bankMoney - jailPrice);
                                                HUDHandler.SendNotification(player, 1, 7500, $"Durch deine Inhaftierung wurden dir {jailPrice}$ vom Konto abgezogen.");
                                            }
                                            HUDHandler.SendNotification(player, 1, 7500, $"Du sitzt nun für {jailTimes} Minuten im Gefängnis.");
                                            Characters.SetCharacterJailTime(charId, true, jailTimes);
                                            CharactersWanteds.RemoveCharacterWanteds(charId);
                                            player.Position = new Position(1691.4594f, 2565.7056f, 45.556763f);
                                            if (Characters.GetCharacterGender(charId) == false)
                                            {
                                                player.EmitLocked("Client:SpawnArea:setCharClothes", 11, 5, 0);
                                                player.EmitLocked("Client:SpawnArea:setCharClothes", 3, 5, 0);
                                                player.EmitLocked("Client:SpawnArea:setCharClothes", 4, 7, 15);
                                                player.EmitLocked("Client:SpawnArea:setCharClothes", 6, 7, 0);
                                                player.EmitLocked("Client:SpawnArea:setCharClothes", 8, 1, 88);
                                            }
                                            else
                                            {
                                            }
                                        }
                                        else
                                        {
                                            Characters.SetCharacterJailTime(charId, false, 0);
                                            Characters.SetCharacterCorrectClothes(player);
                                            player.Position = new Position(1846.022f, 2585.8945f, 45.657f);
                                            HUDHandler.SendNotification(player, 1, 2500, "Du wurdest aus dem Gefängnis entlassen.");
                                        }
                                    }
                                }

                                if (Characters.GetCharacterPaydayTime(charId) >= 60)
                                {
                                    Characters.IncreaseCharacterPlayTimeHours(charId);
                                    Characters.ResetCharacterPaydayTime(charId);
                                    if (CharactersBank.HasCharacterBankMainKonto(charId))
                                    {
                                        int accountNumber = CharactersBank.GetCharacterBankMainKonto(charId);
                                        CharactersBank.SetBankAccountMoney(accountNumber, CharactersBank.GetBankAccountMoney(accountNumber) + 250); //250$ Stütze
                                        ServerBankPapers.CreateNewBankPaper(accountNumber, DateTime.Now.ToString("d", CultureInfo.CreateSpecificCulture("de-DE")), DateTime.Now.ToString("t", CultureInfo.CreateSpecificCulture("de-DE")), "Eingehende Überweisung", "Staat", "Arbeitslosengeld", "+250$", "Unbekannt");

                                        if (!Characters.IsCharacterCrimeFlagged(charId) && Characters.GetCharacterJob(charId) != "None" && DateTime.Now.Subtract(Convert.ToDateTime(Characters.GetCharacterLastJobPaycheck(charId))).TotalHours >= 12 && !ServerFactions.IsCharacterInAnyFaction(charId))
                                        {
                                            if (Characters.GetCharacterJobHourCounter(charId) >= ServerJobs.GetJobNeededHours(Characters.GetCharacterJob(charId)) - 1)
                                            {
                                                int jobCheck = ServerJobs.GetJobPaycheck(Characters.GetCharacterJob(charId));
                                                Characters.SetCharacterLastJobPaycheck(charId, DateTime.Now);
                                                Characters.ResetCharacterJobHourCounter(charId);
                                                CharactersBank.SetBankAccountMoney(accountNumber, CharactersBank.GetBankAccountMoney(accountNumber) + jobCheck);
                                                ServerBankPapers.CreateNewBankPaper(accountNumber, DateTime.Now.ToString("d", CultureInfo.CreateSpecificCulture("de-DE")), DateTime.Now.ToString("t", CultureInfo.CreateSpecificCulture("de-DE")), "Eingehende Überweisung", "Arbeitsamt", $"Gehalt: {Characters.GetCharacterJob(charId)}", $"+{jobCheck}$", "Unbekannt");
                                                HUDHandler.SendNotification(player, 1, 5000, $"Gehalt erhalten (Beruf: {Characters.GetCharacterJob(charId)} | Gehalt: {jobCheck}$)");
                                            }
                                            else
                                            {
                                                Characters.IncreaseCharacterJobHourCounter(charId);
                                            }
                                        }

                                        if (ServerFactions.IsCharacterInAnyFaction(charId) && ServerFactions.IsCharacterInFactionDuty(charId))
                                        {
                                            int factionid       = ServerFactions.GetCharacterFactionId(charId);
                                            int factionPayCheck = ServerFactions.GetFactionRankPaycheck(factionid, ServerFactions.GetCharacterFactionRank(charId));
                                            if (ServerFactions.GetFactionBankMoney(factionid) >= factionPayCheck)
                                            {
                                                ServerFactions.SetFactionBankMoney(factionid, ServerFactions.GetFactionBankMoney(factionid) - factionPayCheck);
                                                CharactersBank.SetBankAccountMoney(accountNumber, CharactersBank.GetBankAccountMoney(accountNumber) + factionPayCheck);
                                                HUDHandler.SendNotification(player, 1, 5000, $"Du hast deinen Lohn i.H.v. {factionPayCheck}$ erhalten ({ServerFactions.GetFactionRankName(factionid, ServerFactions.GetCharacterFactionRank(charId))})");
                                                ServerBankPapers.CreateNewBankPaper(accountNumber, DateTime.Now.ToString("d", CultureInfo.CreateSpecificCulture("de-DE")), DateTime.Now.ToString("t", CultureInfo.CreateSpecificCulture("de-DE")), "Eingehende Überweisung", $"{ServerFactions.GetFactionFullName(factionid)}", $"Gehalt: {ServerFactions.GetFactionRankName(factionid, ServerFactions.GetCharacterFactionRank(charId))}", $"+{factionPayCheck}$", "Dauerauftrag");
                                                LoggingService.NewFactionLog(factionid, charId, 0, "paycheck", $"{Characters.GetCharacterName(charId)} hat seinen Lohn i.H.v. {factionPayCheck}$ erhalten ({ServerFactions.GetFactionRankName(factionid, ServerFactions.GetCharacterFactionRank(charId))}).");
                                            }
                                            else
                                            {
                                                HUDHandler.SendNotification(player, 3, 5000, $"Deine Fraktion hat nicht genügend Geld um dich zu bezahlen ({factionPayCheck}$).");
                                            }
                                        }

                                        var playerVehicles = ServerVehicles.ServerVehicles_.Where(x => x.id > 0 && x.charid == charId && x.plate.Contains("NL"));
                                        int taxMoney       = 0;
                                        foreach (var i in playerVehicles)
                                        {
                                            if (!i.plate.Contains("NL"))
                                            {
                                                continue;
                                            }
                                            taxMoney += ServerAllVehicles.GetVehicleTaxes(i.hash);
                                        }

                                        if (playerVehicles != null && taxMoney > 0)
                                        {
                                            if (CharactersBank.GetBankAccountMoney(accountNumber) < taxMoney)
                                            {
                                                HUDHandler.SendNotification(player, 3, 5000, $"Deine Fahrzeugsteuern konnten nicht abgebucht werden ({taxMoney}$)");
                                            }
                                            else
                                            {
                                                CharactersBank.SetBankAccountMoney(accountNumber, CharactersBank.GetBankAccountMoney(accountNumber) - taxMoney);
                                                ServerBankPapers.CreateNewBankPaper(accountNumber, DateTime.Now.ToString("d", CultureInfo.CreateSpecificCulture("de-DE")), DateTime.Now.ToString("t", CultureInfo.CreateSpecificCulture("de-DE")), "Ausgehende Überweisung", "Zulassungsamt", $"Fahrzeugsteuer", $"-{taxMoney}$", "Bankeinzug");
                                                HUDHandler.SendNotification(player, 1, 5000, $"Du hast deine Fahrzeugsteuern i.H.v. {taxMoney}$ bezahlt.");
                                            }
                                        }
                                    }
                                    else
                                    {
                                        HUDHandler.SendNotification(player, 3, 5000, $"Dein Einkommen konnte nicht überwiesen werden da du kein Hauptkonto hast.");
                                    }
                                }
                            }
                        }
                    }
                }
                stopwatch.Stop();
                Alt.Log($"OnEntityTimer: Player Foreach benötigte: {stopwatch.Elapsed}");
            }
            catch (Exception ex)
            {
                Alt.Log($"{ex}");
            }
        }
Пример #2
0
        public async Task CharacterSelectedSpawnPlace(ClassicPlayer client, string spawnstr, string charcid)
        {
            if (client == null || !client.Exists || spawnstr == null || charcid == null)
            {
                return;
            }
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            int charid = Convert.ToInt32(charcid);

            if (charid <= 0)
            {
                return;
            }
            string charName = Characters.GetCharacterName(charid);
            await User.SetPlayerOnline(client, charid); //Online Feld = CharakterID

            client.CharacterId = charid;

            if (Characters.GetCharacterFirstJoin(charid) && Characters.GetCharacterFirstSpawnPlace(client, charid) == "unset")
            {
                Characters.SetCharacterFirstSpawnPlace(client, charid, spawnstr);
                CharactersInventory.AddCharacterItem(charid, "Bargeld", 10000, "inventory");
                CharactersInventory.AddCharacterItem(charid, "Tasche", 1, "inventory");
                Characters.SetCharacterBackpack(client, "Tasche");
                CharactersInventory.AddCharacterItem(charid, "Sandwich", 3, "backpack"); //ToDo: Trinken hinzufuegen
                CharactersInventory.AddCharacterItem(charid, "Tablet", 1, "inventory");
                CharactersInventory.AddCharacterItem(charid, "Smartphone", 1, "inventory");

                switch (spawnstr)
                {
                case "lsairport":
                    Characters.CreateCharacterLastPos(charid, Constants.Positions.SpawnPos_Airport, 0);
                    break;

                case "beach":
                    Characters.CreateCharacterLastPos(charid, Constants.Positions.SpawnPos_Beach, 0);
                    break;

                case "sandyshores":
                    Characters.CreateCharacterLastPos(charid, Constants.Positions.SpawnPos_SandyShores, 0);
                    break;

                case "paletobay":
                    Characters.CreateCharacterLastPos(charid, Constants.Positions.SpawnPos_PaletoBay, 0);
                    break;

                case null:
                    Characters.CreateCharacterLastPos(charid, Constants.Positions.SpawnPos_Airport, 0);
                    break;
                }
            }


            if (Characters.GetCharacterGender(charid))
            {
                client.Model = 0x9C9EFFD8;
            }
            else
            {
                client.Model = 0x705E61F2;
            }

            client.EmitLocked("Client:ServerBlips:LoadAllBlips", ServerBlips.GetAllServerBlips());
            client.EmitLocked("Client:ServerMarkers:LoadAllMarkers", ServerBlips.GetAllServerMarkers());
            client.EmitLocked("Client:SpawnArea:setCharSkin", Characters.GetCharacterSkin("facefeatures", charid), Characters.GetCharacterSkin("headblendsdata", charid), Characters.GetCharacterSkin("headoverlays", charid));
            Position dbPos = Characters.GetCharacterLastPosition(charid);

            client.Position = dbPos;
            client.Spawn(dbPos, 0);
            client.Dimension = Characters.GetCharacterLastDimension(charid);
            client.Health    = (ushort)(Characters.GetCharacterHealth(charid) + 100);
            client.Armor     = (ushort)Characters.GetCharacterArmor(charid);
            HUDHandler.CreateHUDBrowser(client); //HUD erstellen
            WeatherHandler.SetRealTime(client);  //Echtzeit setzen
            Characters.SetCharacterCorrectClothes(client);
            Characters.SetCharacterLastLogin(charid, DateTime.Now);
            Characters.SetCharacterCurrentFunkFrequence(charid, null);
            Alt.Log($"Eingeloggt {client.Name}");
            Alt.Emit("PlayerLoggedIn", client);
            client.EmitLocked("SaltyChat_OnConnected");
            if (Characters.IsCharacterUnconscious(charid))
            {
                DeathHandler.openDeathscreen(client);
            }
            if (Characters.IsCharacterFastFarm(charid))
            {
                var fastFarmTime = Characters.GetCharacterFastFarmTime(charid) * 60000;
                client.EmitLocked("Client:Inventory:PlayEffect", "DrugsMichaelAliensFight", fastFarmTime);
                HUDHandler.SendNotification(client, 2, 2000, $"Du bist durch dein Koks noch {fastFarmTime} Minuten effektiver.");
            }
            ServerAnimations.RequestAnimationMenuContent(client);
            if (Characters.IsCharacterPhoneEquipped(charid) && CharactersInventory.ExistCharacterItem(charid, "Smartphone", "inventory") && CharactersInventory.GetCharacterItemAmount(charid, "Smartphone", "inventory") > 0)
            {
                client.EmitLocked("Client:Smartphone:equipPhone", true, Characters.GetCharacterPhonenumber(charid), Characters.IsCharacterPhoneFlyModeEnabled(charid));
                Characters.SetCharacterPhoneEquipped(charid, true);
            }
            else if (!Characters.IsCharacterPhoneEquipped(charid) || !CharactersInventory.ExistCharacterItem(charid, "Smartphone", "inventory") || CharactersInventory.GetCharacterItemAmount(charid, "Smartphone", "inventory") <= 0)
            {
                client.EmitLocked("Client:Smartphone:equipPhone", false, Characters.GetCharacterPhonenumber(charid), Characters.IsCharacterPhoneFlyModeEnabled(charid));
                Characters.SetCharacterPhoneEquipped(charid, false);
            }
            SmartphoneHandler.RequestLSPDIntranet(client);
            await setCefStatus(client, false);

            AltAsync.Do(() => {
                client.SetStreamSyncedMetaData("sharedUsername", $"{charName} ({Characters.GetCharacterAccountId(charid)})");
                client.SetSyncedMetaData("ADMINLEVEL", client.AdminLevel());
                client.SetSyncedMetaData("PLAYER_SPAWNED", true);
            });

            if (Characters.IsCharacterInJail(charid))
            {
                HUDHandler.SendNotification(client, 1, 2500, $"Du befindest dich noch {Characters.GetCharacterJailTime(charid)} Minuten im Gefängnis.", 8000);
                client.Position = new Position(1691.4594f, 2565.7056f, 45.556763f);
                if (Characters.GetCharacterGender(charid) == false)
                {
                    client.EmitLocked("Client:SpawnArea:setCharClothes", 11, 5, 0);
                    client.EmitLocked("Client:SpawnArea:setCharClothes", 3, 5, 0);
                    client.EmitLocked("Client:SpawnArea:setCharClothes", 4, 7, 15);
                    client.EmitLocked("Client:SpawnArea:setCharClothes", 6, 7, 0);
                    client.EmitLocked("Client:SpawnArea:setCharClothes", 8, 1, 88);
                }
                else
                {
                }
            }
            client.updateTattoos();
            stopwatch.Stop();
            if (stopwatch.Elapsed.Milliseconds > 30)
            {
                Alt.Log($"{charid} - CharacterSelectedSpawnPlace benötigte {stopwatch.Elapsed.Milliseconds}ms");
            }
            await Task.Delay(5000);

            Model.ServerTattoos.GetAllTattoos(client);
        }