示例#1
0
        private void InitCardPool(string cdbFile, int mainNum, int exNum)
        {
            List <string>    CardPoolLocal   = new List <string>();
            List <string>    CardPoolExLocal = new List <string>();
            SQLiteConnection sqlcon          = new SQLiteConnection($"Data Source={cdbFile}");

            sqlcon.Open();
            SQLiteCommand cmd    = new SQLiteCommand("SELECT id,type FROM datas", sqlcon);
            var           reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                string id   = reader["id"].ToString();
                long   type = (long)reader["type"];
                int    num  = 3;
                CardPoolLFList.Add(id, 0);
                if (LFList.ContainsKey(id))
                {
                    num = LFList[id];
                }
                if (((type & TYPE_FUSION) > 0) || ((type & TYPE_XYZ) > 0) ||
                    ((type & TYPE_LINK) > 0) || ((type & TYPE_SYNCHRO) > 0))
                {
                    for (int i = 0; i < num; i++)
                    {
                        CardPoolExLocal.Add(id);
                    }
                }
                else
                {
                    for (int i = 0; i < num; i++)
                    {
                        CardPoolLocal.Add(id);
                    }
                }
            }
            for (int i = 0; i < mainNum; i++)
            {
                int index = _rd.Next(0, CardPoolLocal.Count);
                CardPool.Add(CardPoolLocal[index]);
                CardPoolLocal.RemoveAt(index);
                if (!CardPoolLFList.ContainsKey(CardPoolLocal[index]))
                {
                    CardPoolLFList.Add(CardPoolLocal[index], 1);
                }
                else
                {
                    CardPoolLFList[CardPoolLocal[index]]++;
                }
            }
            for (int i = 0; i < exNum; i++)
            {
                int index = _rd.Next(0, CardPoolExLocal.Count);
                CardPoolEx.Add(CardPoolExLocal[index]);
                CardPoolLFList[CardPoolExLocal[index]]++;
                CardPoolExLocal.RemoveAt(index);
            }
            reader.Close();
            cmd.Dispose();
            sqlcon.Dispose();
            CardPoolLocal.Clear();
            CardPoolExLocal.Clear();
        }
示例#2
0
        public async Task OnTick()
        {
            await Task.FromResult(0);

            try
            {
                PP.LastFlatbed(PP.Position.GetNearestFlatbed());

                if (PP.CurrentVehicle == LF)
                {
                    Game.DisableControlThisFrame(0, Control.VehicleMoveUpDown);
                    if (!LF.IsControlOutside())
                    {
                        if (manualControl)
                        {
                            if (Game.IsControlPressed(0, liftKey))
                            {
                                LF.DropBedManually(true);
                            }
                            if (Game.IsControlPressed(0, lowerKey))
                            {
                                LF.DropBedManually(false);
                            }
                        }
                        else
                        {
                            if (Game.IsControlJustPressed(0, hookKey))
                            {
                                await LF.DropBed();
                            }
                        }
                    }
                    FreezeEntityPosition(LF.Handle, false);
                    LF.IsPersistent = false;

                    if (LF.CurrentTowingVehicle().Handle != 0 && PP.IsInVehicle(LF))
                    {
                        if (Game.IsControlPressed(2, Control.VehicleAccelerate))
                        {
                            ApplyForceToEntity(Game.Player.LastVehicle.Handle, 3, 0F, -0.04F, 0F, 0F, 0F, 0F, 0, true, true, true, true, true);
                        }
                        if (Game.IsControlPressed(2, Control.VehicleBrake))
                        {
                            ApplyForceToEntity(Game.Player.LastVehicle.Handle, 3, 0F, 0.04F, 0F, 0F, 0F, 0F, 0, true, true, true, true, true);
                        }
                    }
                }
                else
                {
                    LF.IsPersistent = true;
                }

                if (PP.IsInVehicle())
                {
                    if (PP.CurrentVehicle.IsOnAllWheels)
                    {
                        if (DecorGetFloat(PP.CurrentVehicle.Handle, gHeightDecor) == 0f)
                        {
                            DecorSetFloat(PP.CurrentVehicle.Handle, gHeightDecor, PP.CurrentVehicle.HeightAboveGround);
                        }
                    }
                    if (PP.CurrentVehicle.IsThisFlatbed3() && !LFList.Contains(PP.CurrentVehicle))
                    {
                        LFList.Add(PP.CurrentVehicle);
                    }
                }

                if (LF.Exists())
                {
                    if (!PP.IsInVehicle(LF) && LF.IsControlOutside() && (PP.Position.DistanceTo(LF.ControlDummyPos()) <= 2f | PP.Position.DistanceTo(LF.ControlDummy2Pos()) <= 2f))
                    {
                        if (manualControl)
                        {
                            DisplayHelpTextThisFrame(String.Format(GetLangEntry("INM_FB_HELP", "Press {0} to lift/lower the bed."), $"{liftKey.GetButtonIcon()} {lowerKey.GetButtonIcon()}"));
                            if (Game.IsControlPressed(0, liftKey))
                            {
                                LF.DropBedManually(true);
                            }
                            if (Game.IsControlPressed(0, lowerKey))
                            {
                                LF.DropBedManually(false);
                            }
                        }
                        else
                        {
                            DisplayHelpTextThisFrame(String.Format(GetLangEntry("INM_FB_HELP", "Press {0} to lift/lower the bed."), hookKey.GetButtonIcon()));
                            if (Game.IsControlJustPressed(0, hookKey))
                            {
                                await LF.DropBed();
                            }
                        }
                    }

                    if (!DecorGetBool(LF.Handle, helpDecor) && LV.IsThisFlatbed3())
                    {
                        if (manualControl)
                        {
                            DisplayHelpTextThisFrame(String.Format(GetLangEntry("INM_FB_HELP", "Press {0} to lift/lower the bed."), $"{liftKey.GetButtonIcon()} {lowerKey.GetButtonIcon()}"));
                        }
                        else
                        {
                            DisplayHelpTextThisFrame(String.Format(GetLangEntry("INM_FB_HELP", "Press {0} to lift/lower the bed."), hookKey.GetButtonIcon()));
                        }
                        DecorSetBool(LF.Handle, helpDecor, true);
                    }

                    if (marker)
                    {
                        LF.DrawMarkerTick();
                    }
                    if (LF.IsFlatbedDropped())
                    {
                        LF.TurnOnIndicators();
                    }
                    else
                    {
                        LF.TurnOffIndicators();
                    }

                    if (LF.CurrentTowingVehicle().Handle != 0)
                    {
                        if (!LF.CurrentTowingVehicle().IsAttachedTo(LF))
                        {
                            LF.CurrentTowingVehicle(null);
                            TriggerServerEvent("flatbed:SetTowingVehicle", PP.Handle, LF.Handle, 0);
                        }
                    }

                    if (DoesEntityExist(GetEntityAttachedTo(LF.Handle)) && LF.CurrentTowingVehicle().Handle == 0)
                    {
                        LF.CurrentTowingVehicle(GetEntityAttachedTo(LF.Handle));
                        TriggerServerEvent("flatbed:SetTowingVehicle", PP.Handle, LF.Handle, GetEntityAttachedTo(LF.Handle));
                    }

                    if (PP.IsInVehicle()) //Player is in vehicle
                    {
                        //Detach towing vehicle if player is inside towing vehicle
                        if (PP.CurrentVehicle == LF.CurrentTowingVehicle())
                        {
                            if (LV.IsVehicleFacingFlatbed(LF))
                            {
                                await LF.CurrentTowingVehicle().DetachToFix(false);
                            }
                            else
                            {
                                await LF.CurrentTowingVehicle().DetachToFix(true);
                            }
                            LF.CurrentTowingVehicle().IsPersistent = false;
                            LF.CurrentTowingVehicle(null);
                            TriggerServerEvent("flatbed:SetTowingVehicle", PP.Handle, LF.Handle, 0);
                        }

                        //Load vehicle while player is pressing hookkey on bed
                        if (LV.IsAlive && LV.Position.DistanceTo(LF.AttachDummyPos()) <= 2f)
                        {
                            if (!LV.IsThisFlatbed3() && LF.CurrentTowingVehicle().Handle == 0 && AC.Contains(LV.ClassType))
                            {
                                DisplayHelpTextThisFrame(String.Format(GetLangEntry("INM_FB_HOOK", "Press {0} to load {1}."), hookKey.GetButtonIcon(), PP.CurrentVehicle.LocalizedName));
                                if (Game.IsControlJustPressed(0, hookKey))
                                {
                                    LF.CurrentTowingVehicle(PP.CurrentVehicle);
                                    TriggerServerEvent("flatbed:SetTowingVehicle", PP.Handle, LF.Handle, PP.CurrentVehicle.Handle);
                                    PP.CurrentVehicle.IsEngineRunning = false;
                                    PP.CurrentVehicle.IsPersistent    = true;
                                    if (PP.CurrentVehicle == LF.CurrentTowingVehicle())
                                    {
                                        PP.Task.LeaveVehicle(LF.CurrentTowingVehicle(), true);
                                    }
                                    await Delay(3000);

                                    if (LV.IsVehicleFacingFlatbed(LF))
                                    {
                                        LV.AttachToFix(LF, LF.AttachDummyIndex(), LV.AttachCoords(), Vector3.Zero);
                                    }
                                    else
                                    {
                                        LV.AttachToFix(LF, LF.AttachDummyIndex(), LV.AttachCoords(), new Vector3(0f, 0f, 180f));
                                    }
                                }
                            }
                        }

                        //Load vehicle while player is pressing hookkey on attach marker
                        if (LF.AttachPosition().IsAnyVehicleNearAttachPosition(2f))
                        {
                            if (!LV.IsThisFlatbed3() && LF.CurrentTowingVehicle().Handle == 0 && LF.IsFlatbedDropped() && AC.Contains(LV.ClassType))
                            {
                                if (LV.Model != LF.Model)
                                {
                                    DisplayHelpTextThisFrame(String.Format(GetLangEntry("INM_FB_HOOK", "Press {0} to load {1}."), hookKey.GetButtonIcon(), LV.LocalizedName));
                                    if (Game.IsControlJustPressed(0, hookKey))
                                    {
                                        LF.CurrentTowingVehicle(LV);
                                        TriggerServerEvent("flatbed:SetTowingVehicle", PP.Handle, LF.Handle, LV.Handle);
                                        LV.IsPersistent = true;
                                        if (DecorGetFloat(LF.CurrentTowingVehicle().Handle, gHeightDecor) == 0f && LV.IsOnAllWheels)
                                        {
                                            DecorSetFloat(LF.CurrentTowingVehicle().Handle, gHeightDecor, LF.CurrentTowingVehicle().HeightAboveGround);
                                        }
                                        FreezeEntityPosition(LF.Handle, true);
                                        if (PP.CurrentVehicle == LV)
                                        {
                                            PP.Task.LeaveVehicle();
                                        }

                                        if (LV.IsVehicleFacingFlatbed(LF))
                                        {
                                            do
                                            {
                                                PP.Task.GoTo(LV.GetRopeHook());
                                                await Delay(100);
                                            } while (!(PP.Position.DistanceTo(LV.GetRopeHook()) <= 1.5f));
                                        }
                                        else
                                        {
                                            do
                                            {
                                                PP.Task.GoTo(LV.GetRopeHookRear());
                                                await Delay(100);
                                            } while (!(PP.Position.DistanceTo(LV.GetRopeHookRear()) <= 1.5f));
                                        }

                                        PP.Task.ClearAll();

                                        //Vehicle heading is almost same as Flatbed
                                        if (LV.IsVehicleFacingFlatbed(LF))
                                        {
                                            TriggerServerEvent("flatbed:AddRope", PP.Handle, LF.Handle, LV.Handle);
                                            ES = false;
                                            Rope rope = World.AddRope((RopeType)6, LF.WinchDummyPos(), Vector3.Zero, LF.WinchDummyPos().DistanceTo(LV.GetRopeHook()), 0.1f, false);
                                            rope.AttachEntities(LF, LF.WinchDummyPos(), LV, LV.GetRopeHook(), LF.WinchDummyPos().DistanceTo(LV.GetRopeHook()));
                                            rope.ActivatePhysics();
                                            do
                                            {
                                                if (ES == true)
                                                {
                                                    ES = false;
                                                    rope.StopWinding();
                                                    rope.DetachEntity(LF);
                                                    rope.DetachEntity(LV);
                                                    rope.Delete();
                                                    return;
                                                }
                                                if (!LV.IsAnyPedBlockingVehicle(LF))
                                                {
                                                    rope.StartWinding();
                                                    Game.DisableControlThisFrame(0, Control.VehicleMoveUpDown);
                                                }
                                                await Delay(5);
                                            } while (!(rope.Length <= 1.9f));
                                            rope.StopWinding();
                                            rope.DetachEntity(LF);
                                            rope.DetachEntity(LV);
                                            rope.Delete();
                                            FreezeEntityPosition(LF.Handle, false);
                                            LV.AttachToFix(LF, LF.AttachDummyIndex(), LV.AttachCoords(), Vector3.Zero);
                                        }
                                        //Vehicle heading is the opposite of Flatbed
                                        else
                                        {
                                            TriggerServerEvent("flatbed:AddRope", PP.Handle, LF.Handle, LV.Handle);
                                            ES = false;
                                            Rope rope = World.AddRope((RopeType)6, LF.WinchDummyPos(), Vector3.Zero, LF.WinchDummyPos().DistanceTo(LV.GetRopeHookRear()), 0.1f, false);
                                            rope.AttachEntities(LF, LF.WinchDummyPos(), LV, LV.GetRopeHookRear(), LF.WinchDummyPos().DistanceTo(LV.GetRopeHookRear()));
                                            rope.ActivatePhysics();
                                            do
                                            {
                                                if (ES == true)
                                                {
                                                    ES = false;
                                                    rope.StopWinding();
                                                    rope.DetachEntity(LF);
                                                    rope.DetachEntity(LV);
                                                    rope.Delete();
                                                    return;
                                                }
                                                if (!LV.IsAnyPedBlockingVehicle(LF))
                                                {
                                                    rope.StartWinding();
                                                    Game.DisableControlThisFrame(0, Control.VehicleMoveUpDown);
                                                }
                                                await Delay(5);
                                            } while (!(rope.Length <= 1.9f));
                                            rope.StopWinding();
                                            rope.DetachEntity(LF);
                                            rope.DetachEntity(LV);
                                            rope.Delete();
                                            FreezeEntityPosition(LF.Handle, false);
                                            LV.AttachToFix(LF, LF.AttachDummyIndex(), LV.AttachCoords(), Vector3.Zero);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else //Player is not in vehicle
                    {
                        //Unload vehicle while flatbed is lowered
                        if (LF.IsFlatbedDropped() && PP.Position.DistanceTo(LF.AttachDummyPos()) <= 3f)
                        {
                            if (World.GetDistance(LF.CurrentTowingVehicle().Position, PP.Position) <= 3f)
                            {
                                DisplayHelpTextThisFrame(String.Format(GetLangEntry("INM_FB_UNHOOK", "Press {0} to unload {1}."), hookKey.GetButtonIcon(), LF.CurrentTowingVehicle().LocalizedName));
                                if (Game.IsControlJustPressed(0, hookKey))
                                {
                                    Vehicle towVeh = LF.CurrentTowingVehicle();
                                    FreezeEntityPosition(LF.Handle, true);
                                    towVeh.SteeringScale = 0f;
                                    if (towVeh.IsVehicleFacingFlatbed(LF))
                                    {
                                        await towVeh.DetachToFix(false);
                                    }
                                    else
                                    {
                                        await towVeh.DetachToFix(true);
                                    }
                                    await Delay(1000);

                                    if (towVeh.IsDriveable2())
                                    {
                                        PP.Task.EnterVehicle(towVeh, VehicleSeat.Driver, 5000, 1f);
                                        do
                                        {
                                            Game.DisableControlThisFrame(0, Control.VehicleMoveUpDown);
                                            await Delay(5);
                                        } while (!(towVeh.Position.DistanceTo(LF.AttachPosition()) <= 2f));
                                    }
                                    else
                                    {
                                        do
                                        {
                                            if (towVeh.IsVehicleFacingFlatbed(LF))
                                            {
                                                towVeh.PushVehicleBack();
                                            }
                                            else
                                            {
                                                towVeh.PushVehicleForward();
                                            }
                                            Game.DisableControlThisFrame(0, Control.VehicleMoveUpDown);
                                            await Delay(5);
                                        } while (!(towVeh.Position.DistanceTo(LF.AttachPosition()) <= 2f));
                                    }

                                    FreezeEntityPosition(LF.Handle, false);
                                    towVeh.IsPersistent = false;
                                    LF.CurrentTowingVehicle(null);
                                    TriggerServerEvent("flatbed:SetTowingVehicle", PP.Handle, LF.Handle, 0);
                                }
                            }
                        }

                        if (LF.CurrentTowingVehicle().Handle == 0 && LF.IsFlatbedDropped() && LF.AttachPosition().IsAnyVehicleNearAttachPosition(2f))
                        {
                            Vehicle thatVehicle = PP.Position.WorldGetClosestVehicle();
                            //Vehicle heading is almost same as Flatbed
                            if (thatVehicle.Model != LF.Model && AC.Contains(thatVehicle.ClassType) && PP.Position.DistanceTo(thatVehicle.GetRopeHook()) <= 1.5f)
                            {
                                DisplayHelpTextThisFrame(String.Format(GetLangEntry("INM_FB_HOOK", "Press {0} to load {1}."), hookKey.GetButtonIcon(), thatVehicle.LocalizedName));
                                if (Game.IsControlJustPressed(0, hookKey))
                                {
                                    LF.CurrentTowingVehicle(thatVehicle);
                                    TriggerServerEvent("flatbed:SetTowingVehicle", PP.Handle, LF.Handle, thatVehicle.Handle);
                                    thatVehicle.IsPersistent = true;
                                    if (thatVehicle.IsOnAllWheels)
                                    {
                                        if (DecorGetFloat(thatVehicle.Handle, gHeightDecor) == 0f)
                                        {
                                            DecorSetFloat(thatVehicle.Handle, gHeightDecor, thatVehicle.HeightAboveGround);
                                        }
                                    }
                                    FreezeEntityPosition(LF.Handle, true);
                                    TriggerServerEvent("flatbed:AddRope", PP.Handle, LF.Handle, LV.Handle);
                                    ES = false;
                                    Rope rope = World.AddRope((RopeType)6, LF.WinchDummyPos(), Vector3.Zero, LF.WinchDummyPos().DistanceTo(thatVehicle.GetRopeHook()), 0.1f, false);
                                    rope.AttachEntities(LF, LF.WinchDummyPos(), thatVehicle, thatVehicle.GetRopeHook(), LF.WinchDummyPos().DistanceTo(thatVehicle.GetRopeHook()));
                                    rope.ActivatePhysics();
                                    do
                                    {
                                        if (ES == true)
                                        {
                                            ES = false;
                                            rope.StopWinding();
                                            rope.DetachEntity(LF);
                                            rope.DetachEntity(thatVehicle);
                                            rope.Delete();
                                            return;
                                        }
                                        if (!thatVehicle.IsAnyPedBlockingVehicle(LF))
                                        {
                                            rope.StartWinding();
                                            Game.DisableControlThisFrame(0, Control.VehicleMoveUpDown);
                                        }
                                        await Delay(5);
                                    } while (!(rope.Length <= 1.9f));
                                    rope.StopWinding();
                                    rope.DetachEntity(LF);
                                    rope.DetachEntity(thatVehicle);
                                    rope.Delete();
                                    FreezeEntityPosition(LF.Handle, false);
                                    thatVehicle.AttachToFix(LF, LF.GetBoneIndex("misc_a"), thatVehicle.AttachCoords(), Vector3.Zero);
                                }
                            }

                            //Vehicle heading is the opposite of Flatbed
                            if (thatVehicle.Model != LF.Model && AC.Contains(thatVehicle.ClassType) && PP.Position.DistanceTo(thatVehicle.GetRopeHookRear()) <= 1.5f)
                            {
                                DisplayHelpTextThisFrame(String.Format(GetLangEntry("INM_FB_HOOK", "Press {0} to load {1}."), hookKey.GetButtonIcon(), thatVehicle.LocalizedName));
                                if (Game.IsControlJustPressed(0, hookKey))
                                {
                                    LF.CurrentTowingVehicle(thatVehicle);
                                    TriggerServerEvent("flatbed:SetTowingVehicle", PP.Handle, LF.Handle, thatVehicle.Handle);
                                    thatVehicle.IsPersistent = true;
                                    if (thatVehicle.IsOnAllWheels)
                                    {
                                        if (DecorGetFloat(thatVehicle.Handle, gHeightDecor) == 0f)
                                        {
                                            DecorSetFloat(thatVehicle.Handle, gHeightDecor, thatVehicle.HeightAboveGround);
                                        }
                                    }
                                    FreezeEntityPosition(LF.Handle, true);
                                    TriggerServerEvent("flatbed:AddRope", PP.Handle, LF.Handle, LV.Handle);
                                    ES = false;
                                    Rope rope = World.AddRope((RopeType)6, LF.WinchDummyPos(), Vector3.Zero, LF.WinchDummyPos().DistanceTo(thatVehicle.GetRopeHookRear()), 0.1f, false);
                                    rope.AttachEntities(LF, LF.WinchDummyPos(), thatVehicle, thatVehicle.GetRopeHookRear(), LF.WinchDummyPos().DistanceTo(thatVehicle.GetRopeHookRear()));
                                    rope.ActivatePhysics();
                                    do
                                    {
                                        if (ES == true)
                                        {
                                            ES = false;
                                            rope.StopWinding();
                                            rope.DetachEntity(LF);
                                            rope.DetachEntity(thatVehicle);
                                            rope.Delete();
                                            return;
                                        }
                                        if (!thatVehicle.IsAnyPedBlockingVehicle(LF))
                                        {
                                            rope.StartWinding();
                                            Game.DisableControlThisFrame(0, Control.VehicleMoveUpDown);
                                        }
                                        await Delay(5);
                                    } while (!(rope.Length <= 1.9f));
                                    rope.StopWinding();
                                    rope.DetachEntity(LF);
                                    rope.DetachEntity(thatVehicle);
                                    rope.Delete();
                                    FreezeEntityPosition(LF.Handle, false);
                                    thatVehicle.AttachToFix(LF, LF.GetBoneIndex("misc_a"), thatVehicle.AttachCoords(), new Vector3(0f, 0f, 180f));
                                }
                            }
                        }
                    }

                    if (World.GetDistance(LF.CurrentTowingVehicle().Position, LF.Position) >= 20f)
                    {
                        LF.CurrentTowingVehicle().IsPersistent = false;
                        LF.CurrentTowingVehicle(null);
                        TriggerServerEvent("flatbed:SetTowingVehicle", PP.Handle, LF.Handle, 0);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"{ex.Message}{ex.StackTrace}");
            }
        }