示例#1
0
        public async Task VehicleTrunkStorageItem(ClassicPlayer player, int vehId, int charId, string itemName, int itemAmount, string fromContainer, string type)
        {
            try
            {
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                if (player == null || !player.Exists || vehId <= 0 || charId <= 0 || itemName == "" || itemAmount <= 0 || fromContainer == "none" || fromContainer == "")
                {
                    return;
                }
                if (player.HasPlayerHandcuffs() || player.HasPlayerRopeCuffs())
                {
                    HUDHandler.SendNotification(player, 3, 5000, "Wie willst du das mit Handschellen/Fesseln machen?"); return;
                }
                if (type != "trunk" && type != "glovebox")
                {
                    return;
                }
                int cCharId = player.CharacterId;
                if (cCharId != charId)
                {
                    return;
                }
                var targetVehicle = Alt.Server.GetVehicles().ToList().FirstOrDefault(x => x.GetVehicleId() == (ulong)vehId);
                if (targetVehicle == null || !targetVehicle.Exists)
                {
                    return;
                }
                if (!player.Position.IsInRange(targetVehicle.Position, 5f))
                {
                    HUDHandler.SendNotification(player, 4, 5000, "Fehler: Du bist zu weit entfernt."); return;
                }
                if (type == "trunk")
                {
                    if (player.IsInVehicle)
                    {
                        HUDHandler.SendNotification(player, 3, 5000, "Wie willst du von Innen an den Kofferraum kommen?"); return;
                    }
                    if (!targetVehicle.GetVehicleTrunkState())
                    {
                        HUDHandler.SendNotification(player, 4, 5000, "Fehler: Der Kofferraum ist nicht geöffnet."); return;
                    }
                }
                else if (type == "glovebox")
                {
                    if (!player.IsInVehicle)
                    {
                        HUDHandler.SendNotification(player, 4, 5000, "Fehler: Du bist in keinem Fahrzeug."); return;
                    }
                }
                if (!CharactersInventory.ExistCharacterItem(charId, itemName, fromContainer))
                {
                    HUDHandler.SendNotification(player, 4, 5000, "Fehler: Diesen Gegenstand besitzt du nicht."); return;
                }
                if (CharactersInventory.GetCharacterItemAmount(charId, itemName, fromContainer) < itemAmount)
                {
                    HUDHandler.SendNotification(player, 4, 5000, "Fehler: Du hast nicht genügend Gegenstände davon dabei."); return;
                }
                if (CharactersInventory.IsItemActive(player, itemName))
                {
                    HUDHandler.SendNotification(player, 4, 5000, "Fehler: Ausgerüstete Gegenstände können nicht umgelagert werden."); return;
                }
                float itemWeight   = ServerItems.GetItemWeight(itemName) * itemAmount;
                float curVehWeight = 0f;
                float maxVehWeight = 0f;

                if (type == "trunk")
                {
                    curVehWeight = ServerVehicles.GetVehicleVehicleTrunkWeight(vehId, false);
                    maxVehWeight = ServerVehicles.GetVehicleTrunkCapacityOnHash(targetVehicle.Model);
                }
                else if (type == "glovebox")
                {
                    curVehWeight = ServerVehicles.GetVehicleVehicleTrunkWeight(vehId, true);
                    maxVehWeight = 5f;
                }

                if (curVehWeight + itemWeight > maxVehWeight)
                {
                    HUDHandler.SendNotification(player, 3, 5000, $"Fehler: Soviel passt hier nicht rein (Aktuell: {curVehWeight} |  Maximum: {maxVehWeight})."); return;
                }
                CharactersInventory.RemoveCharacterItemAmount(charId, itemName, itemAmount, fromContainer);

                if (type == "trunk")
                {
                    ServerVehicles.AddVehicleTrunkItem(vehId, itemName, itemAmount, false);
                    HUDHandler.SendNotification(player, 2, 2500, $"Du hast den Gegenstand '{itemName} ({itemAmount}x)' in den Kofferraum gelegt.");
                    stopwatch.Stop();
                    Alt.Log($"{charId} - VehicleTrunkStorageItem benötigte {stopwatch.Elapsed.Milliseconds}ms");
                    return;
                }
                else if (type == "glovebox")
                {
                    ServerVehicles.AddVehicleTrunkItem(vehId, itemName, itemAmount, true);
                    HUDHandler.SendNotification(player, 2, 2500, $"Du hast den Gegenstand '{itemName} ({itemAmount}x)' in das Handschuhfach gelegt.");
                    stopwatch.Stop();
                    Alt.Log($"{charId} - VehicleTrunkStorageItem benötigte {stopwatch.Elapsed.Milliseconds}ms");
                    return;
                }
            }
            catch (Exception e)
            {
                Alt.Log($"{e}");
            }
        }