Пример #1
0
        public static DBVehicle SelectVehicle(Ped playerPed)
        {
            DBVehicle dbVehicle = null;

            SQLiteConnection connection = new SQLiteConnection();

            connection.ConnectionString = "Data Source=" + DatabaseManager.dataSource;
            connection.Open();
            SQLiteCommand command = new SQLiteCommand(connection);

            command.CommandText = "SELECT * FROM DBVehicle WHERE vehiclePlate = @vehiclePlate";
            command.Parameters.Add(new SQLiteParameter("vehiclePlate", playerPed.CurrentVehicle.LicensePlate));
            SQLiteDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                string vehiclePlate = reader.GetString(0);
                string getTankful   = reader.GetString(1);
                float  tankful      = float.Parse(getTankful);
                dbVehicle = new DBVehicle(vehiclePlate, tankful, playerPed.CurrentVehicle);
            }
            reader.Close();
            reader.Dispose();
            command.Dispose();
            connection.Close();
            connection.Dispose();

            return(dbVehicle);
        }
Пример #2
0
        public static void UpdateVehicle(DBVehicle dbVehicle, float tankful)
        {
            SQLiteConnection connection = new SQLiteConnection();

            connection.ConnectionString = "Data Source=" + DatabaseManager.dataSource;
            connection.Open();
            SQLiteCommand command = new SQLiteCommand(connection);

            command.CommandText = "UPDATE DBVehicle SET tankful = @tankful " +
                                  "WHERE vehiclePlate = @vehiclePlate";
            command.Parameters.Add(new SQLiteParameter("vehiclePlate", dbVehicle.vehiclePlate));
            command.Parameters.Add(new SQLiteParameter("tankful", dbVehicle.tankful.ToString("G")));
            command.ExecuteNonQuery();

            command.Dispose();
            connection.Close();
            connection.Dispose();
            GameFiber.Yield();
        }
Пример #3
0
        public static void InsertVehicle(DBVehicle dbVehicle)
        {
            SQLiteConnection connection = new SQLiteConnection();

            connection.ConnectionString = "Data Source=" + DatabaseManager.dataSource;
            connection.Open();

            SQLiteCommand command = new SQLiteCommand(connection);

            command.CommandText = "INSERT INTO DBVehicle VALUES(@vehiclePlate, @tankful)";
            command.Parameters.Add(new SQLiteParameter("vehiclePlate", dbVehicle.vehiclePlate));
            command.Parameters.Add(new SQLiteParameter("tankful", dbVehicle.tankful.ToString("G")));
            command.ExecuteNonQuery();

            command.Dispose();
            connection.Close();
            connection.Dispose();
            GameFiber.Yield();
        }
Пример #4
0
        public static void Progress()
        {
            GameFiber.StartNew(delegate
            {
                Game.DisplayNotification("[~b~Police~s~Life~r~S~s~]: ~b~Please wait ...");
                GameFiber.Sleep(5000);
                PlayerAuthenticate.Login();
                CreateStations.CreateGasStations();
                while (true)
                {
                    try
                    {
                        var player = Game.LocalPlayer.Character;
                        if (player != null)
                        {
                            if (player.IsAlive)
                            {
                                HungerFactory.ConsumptionsHitPoints(myPlayer);
                                DrawTexture.changePlayerLifeTexture(myPlayer);
                                CalloutManagement.checkisCalloutRunning();

                                if (ScreenWidth != Game.Resolution.Width || ScreenHeight != Game.Resolution.Height)
                                {
                                    //Reinitalisiere Texturen, wenn Auflösung sich ändert
                                    ScreenWidth  = Game.Resolution.Width;
                                    ScreenHeight = Game.Resolution.Height;
                                    DrawTexture.initTextures();
                                }
                            }

                            if (player.IsInAnyVehicle(false))
                            {
                                var currentVehicle = player.CurrentVehicle;
                                if (currentVehicle != null)
                                {
                                    currentVehicle.Metadata.BrakeEnable = (Game.IsKeyDownRightNow(ReadIniFile.HandBrakeKey) ? true : false);

                                    if (Game.IsKeyDown(ReadIniFile.ToggleEngineKey))
                                    {
                                        currentVehicle.IsEngineOn = !currentVehicle.IsEngineOn;
                                    }

                                    if (Game.IsKeyDown(Keys.F9))
                                    {
                                        if (!DrawTexture.getTextureVisible("policeRadio"))
                                        {
                                            var policeRadio = DrawTexture.getDrawObject("policeRadio");
                                            if (policeRadio != null)
                                            {
                                                if (policeRadio.texture == null)
                                                {
                                                    policeRadio.texture = DrawTexture.getTextureFromResource(Resources.policeradio);
                                                    policeRadio.x       = policeRadio.texture.Size.Width * 2;
                                                    policeRadio.y       = Game.Resolution.Height - policeRadio.texture.Size.Height;
                                                    policeRadio.width   = policeRadio.texture.Size.Width;
                                                    policeRadio.height  = policeRadio.texture.Size.Height;
                                                }
                                                DrawTexture.setTextureVisible("policeRadio", true);
                                            }
                                            else
                                            {
                                                Game.DisplayNotification("[~b~Police~s~Life~r~S~s~]: ~r~PoliceRadio Texture Initialization Error");
                                            }
                                        }
                                        else
                                        {
                                            DrawTexture.setTextureVisible("policeRadio", false);
                                        }
                                    }

                                    if (Game.IsKeyDown(ReadIniFile.IndicatorLeftKey))
                                    {
                                        if (currentVehicle.Metadata.IndicatorLeft != null && currentVehicle.Metadata.IndicatorLeft)
                                        {
                                            currentVehicle.Metadata.IndicatorLeft  = false;
                                            currentVehicle.Metadata.IndicatorRight = false;
                                            DrawTexture.blinkTimer.Stop();
                                            DrawTexture.blinkStatus = false;
                                            currentVehicle.IndicatorLightsStatus = VehicleIndicatorLightsStatus.Off;
                                        }
                                        else
                                        {
                                            currentVehicle.Metadata.IndicatorLeft  = true;
                                            currentVehicle.Metadata.IndicatorRight = false;
                                            DrawTexture.blinkTimer.Start();
                                            currentVehicle.IndicatorLightsStatus = VehicleIndicatorLightsStatus.LeftOnly;
                                        }
                                    }
                                    else if (Game.IsKeyDown(ReadIniFile.IndicatorRightKey))
                                    {
                                        if (currentVehicle.Metadata.IndicatorRight != null && currentVehicle.Metadata.IndicatorRight)
                                        {
                                            currentVehicle.Metadata.IndicatorRight = false;
                                            currentVehicle.Metadata.IndicatorLeft  = false;
                                            DrawTexture.blinkTimer.Stop();
                                            DrawTexture.blinkStatus = false;
                                            currentVehicle.IndicatorLightsStatus = VehicleIndicatorLightsStatus.Off;
                                        }
                                        else
                                        {
                                            currentVehicle.Metadata.IndicatorRight = true;
                                            currentVehicle.Metadata.IndicatorLeft  = false;
                                            DrawTexture.blinkTimer.Start();
                                            currentVehicle.IndicatorLightsStatus = VehicleIndicatorLightsStatus.RightOnly;
                                        }
                                    }
                                    else if (Game.IsKeyDown(ReadIniFile.IndicatorBothKey))
                                    {
                                        if (currentVehicle.Metadata.IndicatorRight != null && currentVehicle.Metadata.IndicatorRight && currentVehicle.Metadata.IndicatorLeft != null && currentVehicle.Metadata.IndicatorLeft)
                                        {
                                            currentVehicle.Metadata.IndicatorRight = false;
                                            currentVehicle.Metadata.IndicatorLeft  = false;
                                            DrawTexture.blinkTimer.Stop();
                                            DrawTexture.blinkStatus = false;
                                            currentVehicle.IndicatorLightsStatus = VehicleIndicatorLightsStatus.Off;
                                        }
                                        else
                                        {
                                            currentVehicle.Metadata.IndicatorRight = true;
                                            currentVehicle.Metadata.IndicatorLeft  = true;
                                            DrawTexture.blinkTimer.Start();
                                            currentVehicle.IndicatorLightsStatus = VehicleIndicatorLightsStatus.Both;
                                        }
                                    }
                                }
                                // If the player increases the first time in the vehicle
                                if (playerEnterVehicle == false)
                                {
                                    playerEnterVehicle = true; // Then there is no longer the first time
                                    dbVehicle          = DBVehicleManager.SelectVehicle(player);
                                    // When he got no DBVehicle
                                    if (dbVehicle == null)
                                    {
                                        // We use DBVehicle - We store the vehicle in the database
                                        DBVehicleManager.InsertVehicle(DBVehicleFactory.GetRandomVehicle(player.CurrentVehicle.LicensePlate));
                                        dbVehicle = DBVehicleManager.SelectVehicle(player);
                                    }
                                    // We know this vehicle, this vehicle is in our database
                                    if (dbVehicle != null)
                                    {
                                    }
                                    GameFiber.Yield();
                                }
                                // We start to calculate the tank
                                fuelConsumption.PlayerIsDriving(player, dbVehicle);
                                // Displays only the tank level when the player moves more than 5Kmh
                                if (DrawTexture.getTextureVisible("SpeedoMeter") == false && NativeFunction.CallByName <int>("GET_FOLLOW_PED_CAM_VIEW_MODE") != 4 && !player.IsDead)
                                {
                                    //Enable Speedo if in Vehicle
                                    DrawTexture.toggleSpeedoTexture(true);
                                }
                                else if (NativeFunction.CallByName <int>("GET_FOLLOW_PED_CAM_VIEW_MODE") == 4 && !player.IsDead)
                                {
                                    if (ReadIniFile.viewInCockpit)
                                    {
                                        //Enable Speedo if in Vehicle and Cockpit View if enabled
                                        DrawTexture.toggleSpeedoTexture(true);
                                    }
                                    else
                                    {
                                        //Disable Speedo if in Vehicle and Cockpit View if wanted
                                        DrawTexture.toggleSpeedoTexture(false);
                                    }
                                }
                                else if (DrawTexture.getTextureVisible("SpeedoMeter") == true && player.IsDead)
                                {
                                    //Disable Speedo, because Player Dead
                                    DrawTexture.toggleSpeedoTexture(false);
                                }
                                DrawTexture.changeSpeedoTexture(dbVehicle);
                            }
                            if (!player.IsInAnyVehicle(false) && playerEnterVehicle)
                            {
                                // Then we set this field to False
                                // So the next boarding is his first time
                                playerEnterVehicle = false;
                                DrawTexture.toggleSpeedoTexture(false);

                                // Memory the vehicle tank when the player leaves the vehicle
                                DBVehicleManager.UpdateVehicle(dbVehicle, dbVehicle.tankful);

                                GameFiber.Yield();
                            }

                            if (Game.IsKeyDownRightNow(ReadIniFile.ViewOverlayKey))
                            {
                                DrawTexture.setTextureVisible("Hungery", true);
                                DrawText.DrawMoneyStatus();
                                if (DutyState && ShiftWork.inShiftWork)
                                {
                                    DrawText.DrawShiftWorkStatus();
                                }
                            }
                            else
                            {
                                DrawTexture.setTextureVisible("Hungery", false);
                            }

                            if (DutyState)
                            {
                                if (Game.IsKeyDown(Keys.F7))
                                {
                                    /* if (!DrawTexture.getTextureVisible("policeRadio"))
                                     * {
                                     *   DrawTexture.setTextureVisible("policeRadio", true);
                                     *   DrawTexture.setTextureVisible("policeRadioInner", true);
                                     * }
                                     * else
                                     * {
                                     *   DrawTexture.setTextureVisible("policeRadio", false);
                                     *   DrawTexture.setTextureVisible("policeRadioInner", false);
                                     * }
                                     * Vehicle v = null;
                                     * vehicles.TryTake(out v);
                                     * if(v != null)
                                     * {
                                     *  Game.LocalPlayer.Character.Position = v.RearPosition;
                                     * }*/
                                }

                                var position = player.Position;
                                for (int i = 0; i < CreateStations.stations.Count; i++)
                                {
                                    // If the position of the player to a station is less than
                                    if (position.DistanceTo(CreateStations.stations[i].position) <= 30)
                                    {
                                        CreateStations.stations[i].TryUse(player, dbVehicle, myPlayer);
                                    }
                                    if (position.DistanceTo(CreateStations.stations[i].position) <= 3000f)
                                    {
                                        CreateStations.stations[i].iconBlip.Alpha = 1.0f;
                                    }
                                    else
                                    {
                                        CreateStations.stations[i].iconBlip.Alpha = 0.0f;
                                    }
                                }
                                foreach (Vector3 sPed in ShiftWork.shiftPed)
                                {
                                    if (Vector3.Distance(sPed, position) <= 1 && !ShiftWork.inShiftWork)
                                    {
                                        Game.DisplayHelp("Want to start your shift work? ~g~(" + (new KeysConverter()).ConvertToString(ReadIniFile.ShiftWorkStartKey) + ") Yes~s~ - ~r~(" + (new KeysConverter()).ConvertToString(ReadIniFile.ShiftWorkCancelKey) + ") No");
                                        if (Game.IsKeyDown(ReadIniFile.ShiftWorkStartKey))
                                        {
                                            ShiftWork.arrestedPeds = 0;
                                            ShiftWork.inShiftWork  = true;
                                            ShiftWork.Start();
                                            LiveTicker.AddTicker("I started my shift work");
                                        }
                                        break;
                                    }
                                    else if (Vector3.Distance(sPed, position) <= 1 && ShiftWork.inShiftWork)
                                    {
                                        Game.DisplayHelp("Want to cancel your shift work? ~g~(" + (new KeysConverter()).ConvertToString(ReadIniFile.ShiftWorkStartKey) + ") Yes~s~ - ~r~(" + (new KeysConverter()).ConvertToString(ReadIniFile.ShiftWorkCancelKey) + ") No");
                                        if (Game.IsKeyDown(ReadIniFile.ShiftWorkStartKey))
                                        {
                                            ShiftWork.inShiftWork = false;
                                            LiveTicker.AddTicker("I canceled my shift work");
                                            ShiftWork.timer.Stop();
                                            NotificationManager.addNotification("[~b~Police~s~Life~r~S~s~]: Your shift was ~r~canceled by yourself");
                                        }
                                        break;
                                    }
                                }

                                // if the player is in a shiftwork
                                if (ShiftWork.inShiftWork)
                                {
                                    if (player.IsDead && !playerDeath)
                                    {
                                        playerDeath           = true;
                                        ShiftWork.inShiftWork = false;
                                        LiveTicker.AddTicker("Dies while his shift work");
                                        ShiftWork.timer.Stop();
                                        NotificationManager.addNotification("[~b~Police~s~Life~r~S~s~]: The shift work was ~r~terminated~s~ because ~r~you died.");
                                    }
                                }

                                if (player.IsAlive && playerDeath)
                                {
                                    playerDeath = false;
                                }
                            }
                        }
                    }catch (Exception ex)
                    {
                        Game.LogTrivial(ex.ToString());
                    }
                    GameFiber.Yield();
                }
            });

            GameFiber.StartNew(delegate
            {
                while (true)
                {
                    var player = Game.LocalPlayer.Character;
                    if (player != null)
                    {
                        if (PlayerAuthenticate.isLogged)
                        {
                            LiveTicker.SendTickerToServer();

                            var nearbyPeds = player.GetNearbyPeds(10);
                            if (nearbyPeds.Count() > 0)
                            {
                                int arrested = 0;
                                var position = player.Position;
                                foreach (Ped np in nearbyPeds)
                                {
                                    if (!np.IsValid())
                                    {
                                        continue;
                                    }
                                    if (np.IsDead)
                                    {
                                        continue;
                                    }

                                    if (Vector3.Distance(np.Position, position) <= 20)
                                    {
                                        if (Functions.IsPedArrested(np) && Functions.GetPedArrestingOfficer(np) == player)
                                        {
                                            if (!arrestedPeds.Contains(np))
                                            {
                                                arrestedPeds.Add(np);
                                                if (ShiftWork.inShiftWork)
                                                {
                                                    ShiftWork.arrestedPeds += 1;
                                                }
                                                arrested++;
                                            }
                                        }
                                    }
                                }
                                if (arrested > 0)
                                {
                                    ExperienceManager.addArrestedPeds(arrested, ShiftWork.inShiftWork);
                                }
                            }

                            if (arrestedPeds.Count() > 0)
                            {
                                for (int i = arrestedPeds.Count - 1; i >= 0; i--)
                                {
                                    if (!arrestedPeds[i].IsValid())
                                    {
                                        arrestedPeds.RemoveAt(i);
                                        continue;
                                    }
                                    if (!arrestedPeds[i].IsDead)
                                    {
                                        continue;
                                    }

                                    ExperienceManager.UpdateExp(-20, "Suspect Died in your presence");
                                    arrestedPeds.RemoveAt(i);
                                }
                            }
                        }
                    }
                    NotificationManager.TakeNotification();
                    GameFiber.Sleep(2000);
                }
            });
        }