Exemple #1
0
        public async Task UseItem(ClassicPlayer player, string itemname, int itemAmount, string fromContainer)
        {
            try
            {
                string ECData     = null,
                       CarKeyData = null;
                if (player == null || !player.Exists || itemname == "" || itemAmount <= 0 || fromContainer == "" || User.GetPlayerOnline(player) == 0)
                {
                    return;
                }
                if (player.HasPlayerHandcuffs() || player.HasPlayerRopeCuffs())
                {
                    HUDHandler.SendNotification(player, 3, 5000, "Wie willst du das mit Handschellen/Fesseln machen?"); return;
                }
                if (ServerItems.IsItemUseable(ServerItems.ReturnNormalItemName(itemname)) == false)
                {
                    HUDHandler.SendNotification(player, 4, 5000, $"Dieser Gegenstand ist nicht benutzbar ({itemname})!"); return;
                }
                int charId = player.CharacterId;
                if (charId <= 0 || CharactersInventory.ExistCharacterItem(charId, itemname, fromContainer) == false)
                {
                    return;
                }
                if (CharactersInventory.GetCharacterItemAmount(charId, itemname, fromContainer) < itemAmount)
                {
                    HUDHandler.SendNotification(player, 4, 5000, $"Die angegeben zu nutzende Anzahl ist nicht vorhanden ({itemname})!"); return;
                }
                if (itemname.Contains("EC Karte"))
                {
                    string[] SplittedItemName = itemname.Split(' '); ECData = itemname.Replace("EC Karte ", ""); itemname = "EC Karte";
                }
                else if (itemname.Contains("Fahrzeugschluessel"))
                {
                    string[] SplittedItemName = itemname.Split(' '); CarKeyData = itemname.Replace("Fahrzeugschluessel ", ""); itemname = "Autoschluessel";
                }

                if (ServerItems.IsItemDesire(itemname))
                {
                    CharactersInventory.RemoveCharacterItemAmount(charId, itemname, itemAmount, fromContainer);
                    Characters.SetCharacterHunger(charId, Characters.GetCharacterHunger(charId) + ServerItems.GetItemDesireFood(itemname) * itemAmount);
                    Characters.SetCharacterThirst(charId, Characters.GetCharacterThirst(charId) + ServerItems.GetItemDesireDrink(itemname) * itemAmount);
                    player.EmitLocked("Client:HUD:UpdateDesire", Characters.GetCharacterHunger(charId), Characters.GetCharacterThirst(charId)); //HUD updaten
                }
                else if (itemname == "Beamtenschutzweste")
                {
                    CharactersInventory.RemoveCharacterItemAmount(charId, "Beamtenschutzweste", 1, fromContainer);
                    Characters.SetCharacterArmor(charId, 100);
                    player.Armor = 100;
                }
                if (itemname == "Rucksack" || itemname == "Tasche")
                {
                    if (fromContainer == "backpack")
                    {
                        HUDHandler.SendNotification(player, 3, 5000, "Kleidungen & Taschen können nicht aus dem Rucksack aus benutzt werden."); return;
                    }
                    if (Characters.GetCharacterBackpack(charId) == "Rucksack")
                    {
                        if (itemname == "Rucksack")
                        {
                            if (CharactersInventory.GetCharacterBackpackItemCount(charId) == 0)
                            {
                                Characters.SetCharacterBackpack(player, "None");
                                HUDHandler.SendNotification(player, 2, 5000, "Du hast deinen Rucksack ausgezogen.");
                            }
                            else
                            {
                                HUDHandler.SendNotification(player, 4, 5000, "Du hast zuviele Sachen im Rucksack, du kannst deinen Rucksack nicht ablegen.");
                            }
                        }
                        else
                        {
                            HUDHandler.SendNotification(player, 3, 5000, "Du hast bereits eine Tasche angelegt, lege diese vorher ab um deinen Rucksack anzulegen.");
                        }
                    }
                    else if (Characters.GetCharacterBackpack(charId) == "Tasche")
                    {
                        if (itemname == "Tasche")
                        {
                            if (CharactersInventory.GetCharacterBackpackItemCount(charId) == 0)
                            {
                                Characters.SetCharacterBackpack(player, "None");
                                HUDHandler.SendNotification(player, 2, 5000, "Du hast deine Tasche ausgezogen.");
                            }
                            else
                            {
                                HUDHandler.SendNotification(player, 4, 5000, "Du hast zuviele Sachen in deiner Tasche, du kannst deine Tasche nicht ablegen.");
                            }
                        }
                        else
                        {
                            HUDHandler.SendNotification(player, 3, 5000, "Du hast bereits einen Rucksack angelegt, lege diesen vorher ab um deine Tasche anzulegen.");
                        }
                    }
                    else if (Characters.GetCharacterBackpack(charId) == "None")
                    {
                        Characters.SetCharacterBackpack(player, itemname);
                        HUDHandler.SendNotification(player, 2, 5000, "Du hast deine Tasche / deinen Rucksack angezogen.");
                    }
                }
                else if (itemname == "EC Karte")
                {
                    var atmPos = ServerATM.ServerATM_.FirstOrDefault(x => player.Position.IsInRange(new Position(x.posX, x.posY, x.posZ), 1f));
                    if (atmPos == null || player.IsInVehicle)
                    {
                        HUDHandler.SendNotification(player, 3, 5000, "Du bist an keinem ATM oder sitzt in einem Auto."); return;
                    }
                    int usingAccountNumber = Convert.ToInt32(ECData);
                    if (CharactersBank.GetBankAccountLockStatus(usingAccountNumber))
                    {
                        if (CharactersInventory.ExistCharacterItem(charId, "EC Karte " + usingAccountNumber, "inventory"))
                        {
                            CharactersInventory.RemoveCharacterItemAmount(charId, "EC Karte " + usingAccountNumber, 1, "inventory");
                        }
                        HUDHandler.SendNotification(player, 3, 5000, $"Ihre EC Karte wurde einzogen da diese gesperrt ist."); return;
                    }
                    player.EmitLocked("Client:ATM:BankATMcreateCEF", CharactersBank.GetBankAccountPIN(usingAccountNumber), usingAccountNumber, atmPos.zoneName);
                }
                else if (ServerItems.GetItemType(itemname) == "weapon")
                {
                    if (itemname.Contains("Munitionsbox"))
                    {
                        string wName = itemname.Replace(" Munitionsbox", "");
                        CharactersInventory.RemoveCharacterItemAmount(charId, itemname, itemAmount, fromContainer);
                        CharactersInventory.AddCharacterItem(charId, $"{wName} Munition", 30 * itemAmount, fromContainer);
                    }
                    else if (itemname.Contains("Munition"))
                    {
                        WeaponHandler.EquipCharacterWeapon(player, "Ammo", itemname, itemAmount, fromContainer);
                    }
                    else
                    {
                        WeaponHandler.EquipCharacterWeapon(player, "Weapon", itemname, 0, fromContainer);
                    }
                }
                else if (itemname == "Brecheisen")
                {
                    var house = ServerHouses.ServerHouses_.FirstOrDefault(x => x.ownerId > 0 && x.isLocked && ((ClassicColshape)x.entranceShape).IsInRange((ClassicPlayer)player));
                    if (house != null)
                    {
                        HouseHandler.BreakIntoHouse(player, house.id);
                        return;
                    }
                }
                else if (itemname == "Verbandskasten")
                {
                    CharactersInventory.RemoveCharacterItemAmount(charId, "Verbandskasten", 1, fromContainer);
                    Characters.SetCharacterHealth(charId, 200);
                    player.Health = 200;
                }
                else if (itemname == "Benzinkanister" && player.IsInVehicle && player.Vehicle.Exists)
                {
                    if (ServerVehicles.GetVehicleFuel(player.Vehicle) >= ServerVehicles.GetVehicleFuelLimitOnHash(player.Vehicle.Model))
                    {
                        HUDHandler.SendNotification(player, 4, 2000, "Der Tank ist bereits voll."); return;
                    }
                    CharactersInventory.RemoveCharacterItemAmount(charId, "Benzinkanister", 1, fromContainer);
                    ServerVehicles.SetVehicleFuel(player.Vehicle, ServerVehicles.GetVehicleFuel(player.Vehicle) + 15.0f);
                    HUDHandler.SendNotification(player, 2, 2000, "Du hast das Fahrzeug erfolgreich aufgetankt.");
                }
                else if (itemname == "Weste")
                {
                    CharactersInventory.RemoveCharacterItemAmount(charId, "Weste", 1, fromContainer);
                    Characters.SetCharacterArmor(charId, 100);
                    player.Armor = 100;
                    if (Characters.GetCharacterGender(charId))
                    {
                        player.EmitLocked("Client:SpawnArea:setCharClothes", 9, 17, 2);
                    }
                    else
                    {
                        player.EmitLocked("Client:SpawnArea:setCharClothes", 9, 15, 2);
                    }
                }
                else if (itemname == "Pedalo")
                {
                    HUDHandler.SendNotification(player, 1, 3500, "Bruder muss los..");
                    player.EmitLocked("Client:Ragdoll:SetPedToRagdoll", true, 0);  //Ragdoll setzen
                    player.EmitLocked("Client:Ragdoll:SetPedToRagdoll", false, 0); //Ragdoll setzen
                }
                else if (itemname == "Kokain")
                {
                    CharactersInventory.RemoveCharacterItemAmount(charId, "Kokain", 1, fromContainer);
                    HUDHandler.SendNotification(player, 2, 2000, "Du hast Koks gezogen du bist nun 15 Minuten effektiver.");
                    player.EmitLocked("Client:Inventory:PlayEffect", "DrugsMichaelAliensFight", 900000);
                    Characters.SetCharacterFastFarm(charId, true, 15);
                }
                else if (itemname == "Joint")
                {
                    if (player.Armor >= 60)
                    {
                        HUDHandler.SendNotification(player, 3, 2000, "Weiter kannst du dich nicht selbst heilen."); return;
                    }
                    CharactersInventory.RemoveCharacterItemAmount(charId, "Joint", 1, fromContainer);
                    Characters.SetCharacterArmor(charId, 15);
                    player.Armor = +15;
                }
                else if (itemname == "Smartphone")
                {
                    Alt.Log("Phone benutzt.");
                    if (Characters.IsCharacterPhoneEquipped(charId))
                    {
                        Alt.Log("Phone benutzt2.");
                        player.EmitLocked("Client:Smartphone:equipPhone", false, Characters.GetCharacterPhonenumber(charId), Characters.IsCharacterPhoneFlyModeEnabled(charId));
                        HUDHandler.SendNotification(player, 2, 1500, "Smartphone ausgeschaltet.");
                    }
                    else
                    {
                        Alt.Log("Phone benutzt3.");
                        player.EmitLocked("Client:Smartphone:equipPhone", true, Characters.GetCharacterPhonenumber(charId), Characters.IsCharacterPhoneFlyModeEnabled(charId));
                        HUDHandler.SendNotification(player, 2, 1500, "Smartphone eingeschaltet.");
                    }
                    Characters.SetCharacterPhoneEquipped(charId, !Characters.IsCharacterPhoneEquipped(charId));
                    SmartphoneHandler.RequestLSPDIntranet((ClassicPlayer)player);
                }

                if (ServerItems.hasItemAnimation(ServerItems.ReturnNormalItemName(itemname)))
                {
                    InventoryAnimation(player, ServerItems.GetItemAnimationName(ServerItems.ReturnNormalItemName(itemname)), 0);
                }

                RequestInventoryItems(player);
                //HUDHandler.SendNotification(player, 2, 5000, $"DEBUG: Der Gegenstand {itemname} ({itemAmount}) wurde erfolgreich aus ({fromContainer}) benutzt.");
            }
            catch (Exception e)
            {
                Alt.Log($"{e}");
            }
        }