Beispiel #1
0
        private void OnEntityExitColShape(ColShape colshape, NetHandle entity)
        {
            if (API.getEntityType(entity) != EntityType.Player)
            {
                return;
            }
            foreach (var gs in GasStation.GasStations)
            {
                if (gs.RefillArea1 != colshape && gs.RefillArea2 != colshape)
                {
                    continue;
                }
                if (API.getEntityType(entity) != EntityType.Player)
                {
                    continue;
                }
                Client player = API.getPlayerFromHandle(entity);
                Player p      = Player.PlayerData[player];

                API.triggerClientEvent(player, "OnLeaveGasStation");
                p.HasEnteredGasStation = 0;
                if (p.SelectedCash != null)
                {
                    InventoryRepository.UpdateAsync(p.SelectedCash);
                }
                else if (p.SelectedCardAccount != null)
                {
                    BankRepository.UpdateAsync(p.SelectedCardAccount);
                }
            }
        }
        private void GiveInventoryItem(Client sender, string partOfName)
        {
            Player player = Player.PlayerData[sender];

            if (player.ItemBeingGiven > 0)
            {
                Player target;
                target = Player.GetPlayerData(partOfName);
                if (target == null)
                {
                    Message.PlayerNotConnected(sender); return;
                }

                Inventory item = player.Inventory.First(i => i.Id == player.ItemBeingGiven);

                item.OwnerId   = target.Id;
                item.OwnerType = InventoryOwnerType.Player;

                player.Inventory.Remove(item);
                target.Inventory.Add(item);

                Message.Info(sender, $"You have given your {item.Name} to {target.Client.name}.");
                Message.Info(target.Client, $"You have been given a {item.Name} by {sender.name}.");

                InventoryRepository.UpdateAsync(item);

                UpdatePlayerInventory(player);
            }
        }
Beispiel #3
0
        public static void GaragePaymentCash(Player p, Inventory inv)
        {
            Vehicle veh = Vehicle.VehicleData[p.Client.vehicle];

            if (long.Parse(inv.Value) >= veh.RepairCost)
            {
                inv.Value = (long.Parse(inv.Value) - (long)veh.RepairCost).ToString();

                if (inv.Value == "0")
                {
                    p.Inventory.Remove(inv);
                    InventoryRepository.RemoveInventoryItem(inv);
                }
                else
                {
                    InventoryRepository.UpdateAsync(inv);
                }

                switch (veh.RepairType)
                {
                case VehicleRepairType.Engine: PerformEngineRepair(veh); break;

                case VehicleRepairType.Body: PerformBodyRepair(veh); break;

                case VehicleRepairType.Tyres: PerformTyreRepair(veh); break;
                }

                VehicleRepository.UpdateAsync(veh);

                p.Client.warpOutOfVehicle();
                veh.Entity.Delete(false);
                p.Client.position  = p.BusinessInteractingWith.EnterPosition;
                p.Client.dimension = 0;
                API.shared.triggerClientEvent(p.Client, "closeShopUI");
                InventoryManager.HidePlayerInventory(p);

                API.shared.ShowPopupMessage(p.Client, "Repair In Progress...",
                                            String.Format("Your {0} is now booked in for repair!<br />The vehicle should be available for collection anytime after {1}.", veh.Name, veh.RepairTime.ToString("dd/MM/yy HH:mm")));
                p.InEvent = PlayerEvent.None;
            }
            else
            {
                API.shared.SendErrorNotification(p.Client, "Insufficient funds.");
                API.shared.SendInfoNotification(p.Client, "Select new payment method:");
                InventoryManager.UpdatePlayerInventory(p);
            }
        }
Beispiel #4
0
        public static void ShopPaymentCash(Player p, Inventory inv)
        {
            if (p.ShoppingCart != null)
            {
                int total = p.ShoppingCart.Sum(sc => sc.Price * sc.Quantity);
                if (long.Parse(inv.Value) >= total)
                {
                    inv.Value = (long.Parse(inv.Value) - total).ToString();

                    foreach (ShopItem item in p.ShoppingCart)
                    {
                        for (int i = 0; i < item.Quantity; i++)
                        {
                            p.GiveInventoryItmeOfType(item.Type);
                        }

                        ShopItem shopItem = p.BusinessInteractingWith.BusinessItems.Single(bi => bi.Id == item.Id);
                        shopItem.ReservedStock -= item.Quantity;
                        shopItem.Quantity      -= item.Quantity;
                        ShopItemRepository.UpdateAsync(shopItem);
                    }
                    if (inv.Value == "0")
                    {
                        p.Inventory.Remove(inv);
                        InventoryRepository.RemoveInventoryItem(inv);
                    }
                    else
                    {
                        InventoryRepository.UpdateAsync(inv);
                    }
                }
                else
                {
                    API.shared.SendErrorNotification(p.Client, "Insufficient funds.");
                    API.shared.SendInfoNotification(p.Client, "Select new payment method:");
                    InventoryManager.UpdatePlayerInventory(p);
                }
            }
        }
Beispiel #5
0
        private void OnClientBasePhoneEventTrigger(Client sender, string eventName, params object[] arguments)
        {
            if (eventName == "PhoneInsertSimCard")
            {
                Player p = Player.PlayerData[sender];

                if (p.PrimaryPhone.InstalledSim != -1)
                {
                    API.ShowPopupPrompt(sender, "RemoveCurrentSimCard", "Remove SIM?", "Are you sure you want to remove your current sim card from this device?");
                }
                else
                {
                    if (p.AccessingBank <= 0)
                    {
                        if (p.Inventory.Where(e => e.Type == InventoryType.SimCard).Select(e => e.Id).Any())
                        {
                            API.triggerClientEvent(sender, "selectSimCard", string.Join(",", p.Inventory.Where(e => e.Type == InventoryType.SimCard).Select(e => e.Id).ToList()),
                                                   string.Join(",", p.Inventory.Where(e => e.Type == InventoryType.SimCard).Select(e => e.Name).ToList()),
                                                   string.Join(".", p.Inventory.Where(e => e.Type == InventoryType.SimCard).Select(e => Inventory.GetInventoryImage[e.Type]).ToList()),
                                                   string.Join(",", p.Inventory.Where(e => e.Type == InventoryType.SimCard).Select(e => e.Quantity).ToList()));
                        }
                        API.SendErrorNotification(sender, "You don't have any sim card on you.", 8);
                    }
                }
            }
            else if (eventName == "onSimCardSelected")
            {
                Player p = Player.PlayerData[sender];

                SimCard sim = SimCardRepository.GetSimCardByNumber(p.Inventory.First(e => e.Id == (int)arguments[0]).Value);

                if (sim != null)
                {
                    Inventory inv = p.Inventory.FirstOrDefault(i => i.Value == sim.Number);

                    if (inv != null)
                    {
                        p.Inventory.Remove(inv);

                        p.PrimaryPhone.InstalledSim = sim.Id;

                        InventoryRepository.UpdateAsync(inv);
                        PlayerRepository.UpdateAsync(p);
                        PhoneRepository.UpdateAsync(p.PrimaryPhone);

                        API.SendInfoNotification(sender, "You have successfully installed a new sim card.");
                        API.triggerClientEvent(sender, "PhoneSimInstalled");
                    }
                }
            }
            else if (eventName == "RemoveCurrentSimCard")
            {
                if ((int)arguments[0] == 1)
                {
                    Player    p          = Player.PlayerData[sender];
                    SimCard   currentSim = SimCardRepository.GetSimCardById(p.PrimaryPhone.InstalledSim);
                    Inventory inv        = InventoryRepository.GetInventoryItemOfTypeByValue(InventoryType.SimCard, currentSim.Number);
                    if (!inv.AddToPlayer())
                    {
                        API.SendWarningNotification(sender, "You don't have space in your inventory for a sim card"); return;
                    }

                    p.PrimaryPhone.InstalledSim = -1;

                    inv.OwnerId   = p.Id;
                    inv.OwnerType = InventoryOwnerType.Player;
                    p.Inventory.Add(inv);

                    InventoryRepository.UpdateAsync(inv);
                    PlayerRepository.UpdateAsync(p);
                    PhoneRepository.UpdateAsync(p.PrimaryPhone);

                    API.SendInfoNotification(sender, "You have removed the sim card from your phone.");
                }
            }
            else if (eventName == "LoadPhoneHomeScreen")
            {
                Player p = Player.PlayerData[sender];
                p.PrimaryPhone.Home(sender);
            }
            else if (eventName == "ShowSettingsInfoPage")
            {
                Player  p          = Player.PlayerData[sender];
                SimCard currentSim = SimCardRepository.GetSimCardById(p.PrimaryPhone.InstalledSim);

                API.triggerClientEvent(sender, "LoadSettingsInfoPage", p.PrimaryPhone.IMEI.ToString(), currentSim.Number, currentSim.Credit.ToString("C0"));
            }
            else if (eventName == "PhoneMakeCall")
            {
                Player  p = Player.PlayerData[sender];
                SimCard simBeingCalled = SimCardRepository.GetSimCardByNumber(arguments[0].ToString());
                SimCard playerSim      = SimCardRepository.GetSimCardById(p.PrimaryPhone.InstalledSim);

                if (playerSim == null)
                {
                    API.triggerClientEvent(sender, "PhoneCallConnection", (int)PhoneCallConnectTypes.SimNotInstalled); return;
                }

                if (simBeingCalled == null)
                {
                    API.triggerClientEvent(sender, "PhoneCallConnection", (int)PhoneCallConnectTypes.NumberDoesntExist); return;
                }

                if (simBeingCalled.Number == playerSim.Number)
                {
                    API.triggerClientEvent(sender, "PhoneCallConnection", (int)PhoneCallConnectTypes.InCall); return;
                }
                if (simBeingCalled.Number == "911")
                {
                    EmergencyCallHandler.EmsCalled(p.Client, playerSim.Number); return;
                }
                Phone phoneCalled = PhoneRepository.GetPhoneBySim(simBeingCalled.Id);
                if (phoneCalled == null)
                {
                    API.triggerClientEvent(sender, "PhoneCallConnection", (int)PhoneCallConnectTypes.SimNotInstalled); return;
                }

                API.triggerClientEvent(sender, "PhoneCallConnection", (int)PhoneCallConnectTypes.Connected);

                Inventory phoneInv     = InventoryRepository.GetInventoryPhoneByIMEI(phoneCalled.IMEI.ToString());
                Player    playerCalled = Player.PlayerData.Values.FirstOrDefault(ph => ph.Id == phoneInv.OwnerId);

                if (playerCalled == null)
                {
                    API.triggerClientEvent(sender, "PhoneCallConnection", (int)PhoneCallConnectTypes.PlayerOffline); return;
                }

                if (!phoneCalled.PoweredOn)
                {
                    API.triggerClientEvent(sender, "PhoneCallConnection", (int)PhoneCallConnectTypes.PhoneOff); return;
                }

                PhoneContact contactOnCalled = PhoneContactRepository.GetPhoneContactByNumber(arguments[0].ToString(), phoneCalled);

                if (contactOnCalled != null && contactOnCalled.IsBlocked)
                {
                    API.triggerClientEvent(sender, "PhoneCallConnection", (int)PhoneCallConnectTypes.BlockedNumber); return;
                }

                if (phoneCalled.InCallWith != null)
                {
                    API.triggerClientEvent(sender, "PhoneCallConnection", (int)PhoneCallConnectTypes.InCall); return;
                }

                if (!phoneCalled.IsPrimary)
                {
                    InventoryManager.SetPhonePrimary(playerCalled.Client, phoneInv, true);
                }

                playerCalled.PrimaryPhone.InCallWith = p;
                p.PrimaryPhone.InCallWith            = playerCalled;
                p.PrimaryPhone.IsCaller            = true;
                playerCalled.PrimaryPhone.IsCaller = false;

                if (contactOnCalled != null)
                {
                    API.triggerClientEvent(playerCalled.Client, "IncomingPhoneCall", contactOnCalled.Name);
                }
                else
                {
                    API.triggerClientEvent(playerCalled.Client, "IncomingPhoneCall", playerSim.Number);
                }
                //API.sendNativeToPlayer(playerCalled.Client, Hash.PLAY_PED_RINGTONE, "Remote_Ring", playerCalled.Client, 1);
            }
            else if (eventName == "PhoneAnswerCall")
            {
                Player p = Player.PlayerData[sender];
                if (p.PrimaryPhone.InCallWith == null)
                {
                    return;
                }
                SimCard callerSim = SimCardRepository.GetSimCardById(p.PrimaryPhone.InCallWith.PrimaryPhone.InstalledSim);

                if (callerSim == null)
                {
                    API.triggerClientEvent(sender, "PhoneCallConnection", (int)PhoneCallConnectTypes.SimNotInstalled); return;
                }

                callerSim.Credit -= 1;

                p.PrimaryPhone.CallConnected = true;
                p.PrimaryPhone.InCallWith.PrimaryPhone.CallConnected = true;

                API.triggerClientEvent(p.PrimaryPhone.InCallWith.Client, "PhoneCallAnswered");
                API.triggerClientEvent(sender, "PhoneCallAnswered");
            }
            else if (eventName == "PhoneEndCall")
            {
                Player p = Player.PlayerData[sender];
                p.PrimaryPhone.Speakerphone = false;
                p.PrimaryPhone.MicMuted     = false;

                SimCard endedSim    = SimCardRepository.GetSimCardById(p.PrimaryPhone.InstalledSim);
                SimCard receiverSim = SimCardRepository.GetSimCardById(p.PrimaryPhone.InCallWith.PrimaryPhone.InstalledSim);

                PhoneLog callLog = new PhoneLog()
                {
                    IMEITo     = p.PrimaryPhone.IsCaller ? p.PrimaryPhone.InCallWith.PrimaryPhone.IMEI : p.PrimaryPhone.IMEI,
                    IMEIFrom   = p.PrimaryPhone.IsCaller ? p.PrimaryPhone.IMEI : p.PrimaryPhone.InCallWith.PrimaryPhone.IMEI,
                    NumberFrom = p.PrimaryPhone.IsCaller ? endedSim.Number : receiverSim.Number,
                    NumberTo   = p.PrimaryPhone.IsCaller ? receiverSim.Number : endedSim.Number,
                    Duration   = (int)arguments[0],
                    Type       = PhoneLogType.Call,
                    Message    = "",
                    SentAt     = Server.Date.AddSeconds(-((int)arguments[0])),
                    Viewed     = p.PrimaryPhone.CallConnected
                };

                if (p.PrimaryPhone.CallConnected)
                {
                    API.triggerClientEvent(p.PrimaryPhone.InCallWith.Client, "phoneTerminateCall");
                }

                PhoneLogRepository.AddPhoneLog(callLog);

                p.PrimaryPhone.CallConnected = false;
                p.PrimaryPhone.InCallWith.PrimaryPhone.CallConnected = false;
                p.PrimaryPhone.InCallWith.PrimaryPhone.Speakerphone  = false;
                p.PrimaryPhone.InCallWith.PrimaryPhone.MicMuted      = false;
                p.PrimaryPhone.InCallWith.PrimaryPhone.InCallWith    = null;
                p.PrimaryPhone.InCallWith = null;
            }
            else if (eventName == "PhoneToggleSpeaker")
            {
                Player p = Player.PlayerData[sender];
                p.PrimaryPhone.Speakerphone = !p.PrimaryPhone.Speakerphone;
            }
            else if (eventName == "PhoneToggleMic")
            {
                Player p = Player.PlayerData[sender];
                p.PrimaryPhone.MicMuted = !p.PrimaryPhone.MicMuted;
            }
            else if (eventName == "PhoneRecentCalls")
            {
                Player p = Player.PlayerData[sender];

                List <PhoneLog> recentCalls = PhoneLogRepository.GetPhoneLogsOfTypeByIMEI(PhoneLogType.Call, p.PrimaryPhone.IMEI);

                string callData = "";
                int    count    = 0;

                foreach (PhoneLog pl in recentCalls)
                {
                    PhoneContact pc;
                    if (pl.IMEIFrom == p.PrimaryPhone.IMEI)
                    {
                        pc = PhoneContactRepository.GetPhoneContactByNumber(pl.NumberTo, p.PrimaryPhone);
                        if (pc != null)
                        {
                            if (pc.Name.Length > 15)
                            {
                                callData += string.Format("{0},outbound,", pc.Name.Substring(0, 13) + "...");
                            }
                            else
                            {
                                callData += string.Format("{0},outbound,", pc.Name);
                            }
                        }
                        else
                        {
                            callData += string.Format("{0},outbound,", pl.NumberTo);
                        }
                    }
                    else
                    {
                        pc = PhoneContactRepository.GetPhoneContactByNumber(pl.NumberFrom, p.PrimaryPhone);
                        if (pc != null)
                        {
                            if (pc.Name.Length > 15)
                            {
                                callData += string.Format("{0},inbound,", pc.Name.Substring(0, 13) + "...");
                            }
                            else
                            {
                                callData += string.Format("{0},inbound,", pc.Name);
                            }
                        }
                        else
                        {
                            callData += string.Format("{0},inbound,", pl.NumberFrom);
                        }
                    }

                    if (pl.SentAt > Server.Date.AddDays(-1))
                    {
                        callData += pl.SentAt.ToString("HH:mm") + ",";
                    }
                    else if (pl.SentAt > Server.Date.AddDays(-7))
                    {
                        callData += pl.SentAt.ToString("dddd") + ",";
                    }
                    else
                    {
                        callData += pl.SentAt.ToString("dd/MM/yyyy") + ",";
                    }

                    if (pl.Viewed)
                    {
                        callData += "yes,";
                    }
                    else
                    {
                        callData += "no,";
                    }
                    count += 4;
                }

                API.triggerClientEvent(sender, "populateRecentCalls", callData, count);
            }
            else if (eventName == "PhoneContactList")
            {
                Player p = Player.PlayerData[sender];

                SimCard             playerSIM = SimCardRepository.GetSimCardById(p.PrimaryPhone.InstalledSim);
                List <PhoneContact> contactList;

                contactList = playerSIM != null?PhoneContactRepository.GetAllContactsOnPhoneAndSim(p.PrimaryPhone.Id, playerSIM.Id) : PhoneContactRepository.GetAllContactsOnPhoneAndSim(p.PrimaryPhone.Id, -1);

                API.triggerClientEvent(sender, "populateContactList", string.Join(",", contactList.OrderBy(e => e.Name).Select(e => e.Name)), false);
            }
            else if (eventName == "PhoneFavouriteList")
            {
                Player p = Player.PlayerData[sender];

                SimCard             playerSIM = SimCardRepository.GetSimCardById(p.PrimaryPhone.InstalledSim);
                List <PhoneContact> contactList;

                contactList = playerSIM != null?PhoneContactRepository.GetAllContactsOnPhoneAndSim(p.PrimaryPhone.Id, playerSIM.Id) : PhoneContactRepository.GetAllContactsOnPhoneAndSim(p.PrimaryPhone.Id, -1);

                API.triggerClientEvent(sender, "populateContactList", string.Join(",", contactList.Where(e => e.IsFavourite).OrderBy(e => e.Name).Select(e => e.Name)), true);
            }
            else if (eventName == "PhoneRecentCallSelect")
            {
                Player p = Player.PlayerData[sender];

                List <PhoneLog> recentCalls = PhoneLogRepository.GetPhoneLogsOfTypeByIMEI(PhoneLogType.Call, p.PrimaryPhone.IMEI);

                string recentCall = recentCalls[int.Parse(arguments[0].ToString())].IMEIFrom == p.PrimaryPhone.IMEI ?
                                    recentCalls[int.Parse(arguments[0].ToString())].NumberTo : recentCalls[int.Parse(arguments[0].ToString())].NumberFrom;
                API.triggerClientEvent(sender, "redialRecentCall", recentCall);
            }
            else if (eventName == "PhoneAddNewContact")
            {
                sender.ToggleCursorLock(true);
            }
            else if (eventName == "PhoneCreateNewContact")
            {
                Player p = Player.PlayerData[sender];

                PhoneContact contact = new PhoneContact()
                {
                    Name         = arguments[0].ToString(),
                    Number       = arguments[1].ToString(),
                    Address1     = arguments[2].ToString(),
                    Address2     = arguments[3].ToString(),
                    Address3     = arguments[4].ToString(),
                    Notes        = arguments[5].ToString(),
                    IsBlocked    = false,
                    IsFavourite  = false,
                    SavedTo      = p.PrimaryPhone.Id,
                    IsSimContact = false
                };

                PhoneContactRepository.AddPhoneContact(contact);

                OnClientBasePhoneEventTrigger(sender, "PhoneContactList", new object { });
                sender.ToggleCursorLock(false);
            }
            else if (eventName == "PhoneContactSelected")
            {
                Player              p           = Player.PlayerData[sender];
                int                 ind         = (int)arguments[0];
                bool                isFavourite = (bool)arguments[1];
                SimCard             playerSIM   = SimCardRepository.GetSimCardById(p.PrimaryPhone.InstalledSim);
                List <PhoneContact> contactList;

                contactList = playerSIM != null?PhoneContactRepository.GetAllContactsOnPhoneAndSim(p.PrimaryPhone.Id, playerSIM.Id) : PhoneContactRepository.GetAllContactsOnPhoneAndSim(p.PrimaryPhone.Id, -1);

                contactList = !isFavourite?contactList.OrderBy(e => e.Name).ToList() : contactList.Where(e => e.IsFavourite).OrderBy(e => e.Name).ToList();

                API.triggerClientEvent(sender, "displayPhoneContact", contactList[ind].Id, contactList[ind].Name, contactList[ind].Number, contactList[ind].Address1, contactList[ind].Address2,
                                       contactList[ind].Address3, contactList[ind].Notes, contactList[ind].IsFavourite, contactList[ind].IsBlocked, contactList[ind].IsSimContact);
            }
            else if (eventName == "PhoneUpdateContact")
            {
                Player p = Player.PlayerData[sender];

                PhoneContact pc = PhoneContactRepository.GetPhoneContactById(int.Parse(arguments[0].ToString()));

                pc.Name     = arguments[1].ToString();
                pc.Number   = arguments[2].ToString();
                pc.Address1 = arguments[3].ToString();
                pc.Address2 = arguments[4].ToString();
                pc.Address3 = arguments[5].ToString();
                pc.Notes    = arguments[6].ToString();

                PhoneContactRepository.UpdateAsync(pc);

                API.triggerClientEvent(sender, "displayPhoneContact", pc.Id, pc.Name, pc.Number, pc.Address1, pc.Address2, pc.Address3, pc.Notes, pc.IsFavourite, pc.IsBlocked, pc.IsSimContact);
            }
            else if (eventName == "PhoneSetFavouriteContact")
            {
                Player p = Player.PlayerData[sender];

                PhoneContact pc = PhoneContactRepository.GetPhoneContactById(int.Parse(arguments[0].ToString()));

                pc.IsFavourite = !pc.IsFavourite;

                PhoneContactRepository.UpdateAsync(pc);

                API.triggerClientEvent(sender, "displayPhoneContact", pc.Id, pc.Name, pc.Number, pc.Address1, pc.Address2, pc.Address3, pc.Notes, pc.IsFavourite, pc.IsBlocked, pc.IsSimContact);
            }
            else if (eventName == "PhoneBatteryChange")
            {
                Player p         = Player.PlayerData[sender];
                int    battLevel = Convert.ToInt32(float.Parse(arguments[0].ToString()));
                if (battLevel <= 100)
                {
                    p.PrimaryPhone.BatteryLevel = battLevel;
                }

                if (battLevel < 2)
                {
                    p.PrimaryPhone.TurnOff(sender);
                }

                PhoneRepository.UpdateAsync(p.PrimaryPhone);
            }
            else if (eventName == "PhoneDeleteContact")
            {
                Player p = Player.PlayerData[sender];
                p.DeletingContact = PhoneContactRepository.GetPhoneContactById(int.Parse(arguments[0].ToString()));

                API.ShowPopupPrompt(sender, "PhoneConfirmDeleteContact", "Delete " + p.DeletingContact.Name, "Are you sure you want to delete " + p.DeletingContact.Name + " from your contacts?");
            }

            else if (eventName == "PhoneConfirmDeleteContact")
            {
                Player p = Player.PlayerData[sender];
                if ((int)arguments[0] == 1)
                {
                    PhoneContactRepository.Delete(p.DeletingContact);
                    p.DeletingContact = null;

                    OnClientBasePhoneEventTrigger(sender, "PhoneContactList", new object { });
                }
            }

            else if (eventName == "PhoneBlockContact")
            {
                PhoneContact pc = PhoneContactRepository.GetPhoneContactById(int.Parse(arguments[0].ToString()));

                if (pc != null)
                {
                    pc.IsBlocked = !pc.IsBlocked;
                    PhoneContactRepository.UpdateAsync(pc);

                    API.triggerClientEvent(sender, "displayPhoneContact", pc.Id, pc.Name, pc.Number, pc.Address1, pc.Address2, pc.Address3, pc.Notes, pc.IsFavourite, pc.IsBlocked, pc.IsSimContact);
                }
            }
            else if (eventName == "PhoneChangeContactStorage")
            {
                Player       p  = Player.PlayerData[sender];
                PhoneContact pc = PhoneContactRepository.GetPhoneContactById(int.Parse(arguments[0].ToString()));

                if (pc != null)
                {
                    if (pc.IsSimContact)
                    {
                        pc.SavedTo = p.PrimaryPhone.Id;
                    }
                    else
                    {
                        if (p.PrimaryPhone.InstalledSim > 0)
                        {
                            int simContacts = PhoneContactRepository.GetAllContactsOnSim(p.PrimaryPhone.InstalledSim).Count;
                            if (simContacts < SimCard.CONTACT_CAPACITY)
                            {
                                pc.SavedTo = p.PrimaryPhone.InstalledSim;
                            }
                            else
                            {
                                API.SendErrorNotification(sender, "You have reached the limit of contacts stored to this SIM Card");
                            }
                        }
                    }

                    pc.IsSimContact = !pc.IsSimContact;

                    PhoneContactRepository.UpdateAsync(pc);
                    API.triggerClientEvent(sender, "displayPhoneContact", pc.Id, pc.Name, pc.Number, pc.Address1, pc.Address2, pc.Address3, pc.Notes, pc.IsFavourite, pc.IsBlocked, pc.IsSimContact);
                }
            }
            else if (eventName == "PhoneEnteredPasscode")
            {
                Player p = Player.PlayerData[sender];

                if (p.PrimaryPhone.Passcode != null)
                {
                    API.triggerClientEvent(sender, "phonePasscodeResult",
                                           Crypter.CheckPassword(arguments[0].ToString(), p.PrimaryPhone.Passcode) ? 4 : 0);
                }
            }
        }
        public void ToggleVehicleEngine(Client player)
        {
            Player user = Player.PlayerData[player];

            if (player.isInVehicle)
            {
                if (user.Inventory.Count(k => k.Value == Vehicle.VehicleData[player.vehicle].Key) == 1 || Vehicle.VehicleData[player.vehicle].FactionId == user.FactionId ||
                    Vehicle.VehicleData[player.vehicle].KeyInIgnition)
                {
                    Vehicle veh = Vehicle.VehicleData[player.vehicle];
                    if (veh.OwnerId != -1)
                    {
                        Inventory key = null;
                        if (!veh.IsEngineOn)
                        {
                            key = veh.TrunkItems.FirstOrDefault(k => k.Value == veh.Key && k.OwnerId == veh.Id && k.OwnerType == InventoryOwnerType.Vehicle);

                            if (key != null)
                            {
                                if (!key.AddToPlayer(user, true))
                                {
                                    API.SendWarningNotification(player, "You don't have enough space in your inventory for a this car key"); return;
                                }

                                key.OwnerId   = user.Id;
                                key.OwnerType = InventoryOwnerType.Player;

                                user.Inventory.Add(key);

                                if (user.OwnedVehicles.All(v => v.Id != veh.Id))
                                {
                                    API.SendInfoNotification(user.Client,
                                                             $"The key to this {veh.Entity.displayName} has been added to you inventory.");
                                }
                                veh.TrunkItems.Remove(key);
                                veh.KeyInIgnition = false;
                                veh.IsEngineOn    = false;
                                InventoryRepository.UpdateAsync(key);
                                VehicleRepository.UpdateAsync(veh);
                                return;
                            }

                            key = user.Inventory.FirstOrDefault(k => k.Value == veh.Key);

                            if (key != null)
                            {
                                if (veh.Fuel > 0 && veh.Health > 110)
                                {
                                    veh.CalculateTaintedFuel();
                                    veh.KeyInIgnition = true;

                                    key.OwnerId   = veh.Id;
                                    key.OwnerType = InventoryOwnerType.Vehicle;
                                    user.Inventory.Remove(key);
                                    veh.TrunkItems.Add(key);
                                    //API.triggerClientEvent(player, "dashboard_update_fuel", veh.Fuel);
                                }
                                else
                                {
                                    API.SendErrorNotification(player, "Engine failed to start..."); return;
                                }
                                InventoryRepository.UpdateAsync(key);
                            }
                        }
                        else
                        {
                            key = veh.TrunkItems.FirstOrDefault(k => k.Value == veh.Key && k.OwnerId == veh.Id && k.OwnerType == InventoryOwnerType.Vehicle);
                            if (key != null)
                            {
                                if (!key.AddToPlayer(user, true))
                                {
                                    API.SendWarningNotification(player, "You don't have enough space in your inventory for a this car key"); return;
                                }
                                key.OwnerId   = user.Id;
                                key.OwnerType = InventoryOwnerType.Player;

                                user.Inventory.Add(key);

                                if (user.OwnedVehicles.All(v => v.Id != veh.Id))
                                {
                                    API.sendNotificationToPlayer(user.Client,
                                                                 $"The key to this {veh.Entity.displayName} has been added to you inventory.");
                                }
                                veh.TrunkItems.Remove(key);

                                veh.KeyInIgnition = false;
                                InventoryRepository.UpdateAsync(key);
                            }
                        }
                    }

                    veh.IsEngineOn = !veh.IsEngineOn;
                    API.setVehicleEngineStatus(player.vehicle, veh.IsEngineOn);

                    API.sendNotificationToPlayer(player, veh.IsEngineOn ? "~g~Engine On" : "~r~Engine Off", true);

                    VehicleRepository.UpdateAsync(veh);
                }
                if (Vehicle.VehicleData[player.vehicle].SidejobUserId == user.Id)
                {
                    Vehicle veh = Vehicle.VehicleData[player.vehicle];
                    veh.IsEngineOn = !veh.IsEngineOn;
                    API.setVehicleEngineStatus(player.vehicle, veh.IsEngineOn);

                    API.sendNotificationToPlayer(player, veh.IsEngineOn ? "~g~Engine On" : "~r~Engine Off", true);

                    Vehicle.VehicleData[player.vehicle] = veh;
                    return;
                }
            }
        }
        private async void DropInventoryItem(Client sender, int id)
        {
            if (!sender.isInVehicle)
            {
                if (!sender.inFreefall && !sender.isParachuting && !sender.isOnLadder)
                {
                    Player    player = Player.PlayerData[sender];
                    Inventory item   = InventoryRepository.GetInventoryItemById(id);

                    API.playPlayerAnimation(player.Client, 0, "pickup_object", "putdown_low");

                    await Task.Run(() =>
                    {
                        Thread.Sleep(350);

                        item.DroppedPos       = Player.GetPositionInFrontOfPlayer(sender, 0.4f, -0.74);
                        item.DroppedRot       = Inventory.GetRotationForItem[item.Type];
                        item.OwnerId          = -1;
                        item.OwnerType        = InventoryOwnerType.Dropped;
                        item.DroppedDimension = sender.dimension;

                        item.DroppedObj = API.createObject(Inventory.GetObjectForItem[item.Type], item.DroppedPos, item.DroppedRot, item.DroppedDimension);
                        item.ApplyPhysics();

                        if (item.IsPhone())
                        {
                            Phone p = PhoneRepository.GetPhoneByIMEI(long.Parse(item.Value));
                            if (p.IsPrimary)
                            {
                                API.triggerClientEvent(sender, "hidePhoneUI");
                            }

                            p.IsPrimary = false;
                            PhoneRepository.UpdateAsync(p);
                        }
                        List <Inventory> inv = null;
                        if (player.InEvent == PlayerEvent.AccessingInventory)
                        {
                            if (player.VehicleInteractingWith != null)
                            {
                                inv = player.VehicleInteractingWith.TrunkItems;
                            }
                            else
                            {
                                inv = player.Inventory;
                            }
                        }
                        inv?.Remove(inv.FirstOrDefault(il => il.Id == item.Id));
                        InventoryRepository.UpdateAsync(item);
                        Inventory.DroppedItems.Add(item);

                        RefreshAfterDropChange(item);
                    });
                }
                else
                {
                    API.SendErrorNotification(sender, "You have to be on the ground to drop items.");
                }
            }
            else
            {
                API.SendErrorNotification(sender, "You drop items in a vehicle");
            }
        }
        private async void OnClientEventTrigger(Client sender, string eventName, params object[] arguments)
        {
            switch (eventName)
            {
            case "getInventoryTypeActions":
            {
                Inventory inv = InventoryRepository.GetInventoryItemById((int)arguments[0]);
                if (inv.IsPhone())
                {
                    Phone p = PhoneRepository.GetPhoneByIMEI(long.Parse(inv.Value));
                    API.triggerClientEvent(sender, "displayActionsForItem", inv.Id,
                                           p.IsPrimary
                                    ? JsonConvert.SerializeObject("GIVE,DROP,UNSET PRIMARY".Split(','))
                                    : JsonConvert.SerializeObject("GIVE,DROP,SET PRIMARY".Split(',')));
                    return;
                }

                API.triggerClientEvent(sender, "displayActionsForItem", inv.Id, JsonConvert.SerializeObject(Inventory.GetActionsByType[inv.Type]));
            }
            break;

            case "performActionOnItem":
            {
                Inventory inv = InventoryRepository.GetInventoryItemById((int)arguments[0]);
                switch (arguments[1].ToString())
                {
                case "USE":
                    UsePlayerInventoryItem(sender, (int)arguments[0]);
                    break;

                case "GIVE":
                    GetPlayerToGiveItem(sender, (int)arguments[0]);
                    break;

                case "DROP":
                    DropInventoryItem(sender, (int)arguments[0]);
                    break;

                case "SET PRIMARY":
                    SetPhonePrimary(sender, inv, true);
                    break;

                case "UNSET PRIMARY":
                    SetPhonePrimary(sender, inv, false);
                    break;

                case "RELEASE":
                    DestroyInventoryItem(sender, (int)arguments[0]);
                    break;
                }
            }
            break;

            case "giveItemToPlayer":
                if ((int)arguments[0] == 1)
                {
                    GiveInventoryItem(sender, arguments[1].ToString());
                }
                break;

            case "DisplayPlayerInventory":
            {
                Player p = Player.PlayerData[sender];
                UpdatePlayerInventory(p);
            }
            break;

            case "OnInventoryItemMoved":
            {
                Player    p = Player.PlayerData[sender];
                Inventory item;
                try
                {
                    item = p.Inventory.Single(i => i.Id == (int)arguments[0]);
                }
                catch
                {
                    item = Inventory.DroppedItems.Single(i => i.Id == (int)arguments[0]);
                    Inventory.DroppedItems.Remove(item);
                    API.deleteEntity(item.DroppedObj);

                    if (!Inventory.IsStackable(item))
                    {
                        item.OwnerId   = p.Id;
                        item.OwnerType = InventoryOwnerType.Player;
                        p.Inventory.Add(item);

                        API.SendInfoNotification(p.Client, String.Format("You have picked up a {0}", item.Name));
                        API.playPlayerAnimation(p.Client, 0, "pickup_object", "pickup_low");
                        RefreshAfterDropChange(item);
                    }
                }
                item.SlotPosition = int.Parse(arguments[1].ToString() + arguments[2].ToString());

                InventoryRepository.UpdateAsync(item);
            }
            break;

            case "OnFriskInventoryItemTaken":
            {
                Player    p    = Player.PlayerData[sender];
                Inventory item = null;
                try
                {
                    item = p.Inventory.Single(i => i.Id == (int)arguments[0]);
                }
                catch
                {
                    item = p.PlayerInteractingWith.Inventory.Single(i => i.Id == (int)arguments[0]);
                }

                if (item != null)
                {
                    int    newOwnerId = (int)arguments[1];
                    Player oldOwner   = Player.PlayerData.Values.FirstOrDefault(pl => pl.Id == item.OwnerId);
                    Player newOwner   = Player.PlayerData.Values.FirstOrDefault(pl => p.Id == newOwnerId);

                    API.SendCloseMessage(sender, 10.0f, "~#C2A2DA~",
                                         p != oldOwner
                                    ? string.Format("{0} {1} takes a {2} from {3}.", p.Faction.Ranks[p.FactionRank].Title,
                                                    API.getPlayerName(sender), item.Name, oldOwner.Username.Roleplay())
                                    : string.Format("{0} {1} places a {2} on {3}.", p.Faction.Ranks[p.FactionRank].Title,
                                                    API.getPlayerName(sender), item.Name, newOwner.Username.Roleplay()));

                    item.OwnerId      = newOwner.Id;
                    item.OwnerType    = InventoryOwnerType.Player;
                    item.SlotPosition = int.Parse(arguments[2].ToString() + arguments[3].ToString());

                    InventoryRepository.UpdateAsync(item);

                    RefreshPlayerInventory(p.PlayerInteractingWith);
                    ShowFriskInventory(p, p.PlayerInteractingWith);
                }
            }
            break;

            case "OnTrunkInventoryItemTaken":
            {
                int    oldOwnerId;
                Player p    = Player.PlayerData[sender];
                string type = arguments[2].ToString();

                Vehicle   vTo   = null;
                Player    from  = null;
                Vehicle   vFrom = null;
                Player    to    = null;
                Inventory item  = null;

                item = InventoryRepository.GetInventoryItemById((int)arguments[0]);
                Console.WriteLine(arguments[1].ToString());

                if (type == "trunk")
                {
                    vTo = Vehicle.VehicleData.Values.FirstOrDefault(
                        ve => ve.Id == int.Parse(arguments[1].ToString()));
                    from = p;
                }
                else
                {
                    to = Player.PlayerData.Values.FirstOrDefault(
                        pl => pl.Id == int.Parse(arguments[1].ToString()));
                    if (item.OwnerType == InventoryOwnerType.Vehicle)
                    {
                        vFrom = Vehicle.VehicleData.Values.FirstOrDefault(ve => ve.Id == item.OwnerId);
                    }
                }

                oldOwnerId = item.OwnerId;

                item.OwnerType = vTo != null
                            ? InventoryOwnerType.Vehicle
                            : to != null
                                ? InventoryOwnerType.Player
                                : InventoryOwnerType.Dropped;
                item.OwnerId      = vTo != null ? vTo.Id : to != null ? p.Id : -1;
                item.SlotPosition = int.Parse(arguments[3].ToString() + arguments[4].ToString());

                InventoryRepository.UpdateAsync(item);

                if (oldOwnerId == -1)
                {
                    Inventory.DroppedItems.Remove(Inventory.DroppedItems.Single(i => i.Id == (int)arguments[0]));
                    API.deleteEntity(item.DroppedObj);

                    API.SendInfoNotification(p.Client, String.Format("You have picked up a {0}", item.Name));
                    API.playPlayerAnimation(p.Client, 0, "pickup_object", "pickup_low");
                    RefreshAfterDropChange(item);
                }

                p.Inventory = await InventoryRepository.GetInventoryByOwnerIdAsync(p.Id);

                if (vFrom != null)
                {
                    vFrom.TrunkItems.Remove(vFrom.TrunkItems.FirstOrDefault(vl => vl.Id == item.Id));
                }
                if (item.OwnerType == InventoryOwnerType.Vehicle)
                {
                    if (oldOwnerId != item.OwnerId)
                    {
                        vTo.TrunkItems.Add(item);
                    }
                    else
                    {
                        vTo.TrunkItems.FirstOrDefault(vl => vl.Id == item.Id).SlotPosition = item.SlotPosition;
                    }
                }

                ShowTrunkInventory(p, p.VehicleInteractingWith);

                if (p == to)
                {
                    return;
                }

                string fromString = vTo != null ? $"{vTo.DisplayName}" : $"{vFrom.DisplayName}";
                API.SendCloseMessage(sender, 10.0f, "~#C2A2DA~",
                                     vTo == null
                                ? string.Format("{0} takes a {1} from the {2}.",
                                                API.getPlayerName(sender), item.Name, fromString)
                                : string.Format("{0} places a {1} on the {2}.",
                                                API.getPlayerName(sender), item.Name, fromString));
                break;
            }

            case "OnHeaderSlotItemSelected":
            {
                Player    p    = Player.PlayerData[sender];
                Inventory item = null;
                try
                {
                    item = p.Inventory.FirstOrDefault(i => i.Id == (int)arguments[0]);
                }
                catch
                {
                    Console.WriteLine("{0}: Error occurred when trying to open Header Slot with ID: {1}", Server.Date.ToString(), (int)arguments[0]);
                    return;
                }

                if (item != null)
                {
                    if (item.IsBag())
                    {
                    }
                }
            }
            break;

            case "OnInventoryClose":
            {
                Player p = Player.PlayerData[sender];
                if (p.AccessingBank != -1)
                {
                }
                p.InEvent = PlayerEvent.None;
            }
            break;
            }
        }
        public void DisconnectPlayer(Client player)
        {
            Player user = null;

            try
            {
                user = Player.PlayerData[player];
            }
            catch
            {
                user = Player.PlayerData.Values.FirstOrDefault(i => i.Username.Roleplay() == player.name);
            }

            if (user != null)
            {
                if (user.IsLogged)
                {
                    user.IsLogged     = false;
                    user.LastPosition = player.position;
                    user.LastRotation = player.rotation;
                    user.Health       = player.health;
                    user.Armour       = player.armor;
                    user.Dimension    = player.dimension;

                    user.ChatIndicatorLabel.text = "";
                    API.deleteEntity(user.ChatIndicatorLabel);

                    user.WeaponSkillData = string.Join(",", user.WeaponSkill.Values);

                    user.SavePlayerVehicles();

                    if (user.InEvent == PlayerEvent.VehicleDealership)
                    {
                        user.LastPosition = new Vector3(-257.5197 + (new Random().Next(-50, 50) / 20), 6211.149 + (new Random().Next(-50, 50) / 20), z: 31.48923);
                        user.LastRotZ     = 121.6988;
                    }
                    Vehicle ve = Vehicle.VehicleData.Values.FirstOrDefault(v => v.IsDealerVehicle && v.OwnerId == user.Id);

                    if (ve != null)
                    {
                        API.deleteEntity(ve.DealershipEmployee);
                        ve.Entity.Delete();
                    }

                    if (user.SelectedCash != null)
                    {
                        InventoryRepository.UpdateAsync(user.SelectedCash);
                    }
                    if (user.SelectedCardAccount != null)
                    {
                        BankRepository.UpdateAsync(user.SelectedCardAccount);
                    }

                    user.MasterAccount.ActiveConnectionLog.DisconnectTime = Server.Date;
                    ConnectionLogRepository.UpdateAsync(user.MasterAccount.ActiveConnectionLog);
                    WeaponRepository.UpdateAllAsync(user.Weapons);
                    PlayerRepository.UpdateAsync(user);
                    Player.PlayerData.Remove(user.Client);
                }
                else
                {
                    Player.PlayerData.Remove(user.Client);
                }
                Master.MasterData.Remove(user.MasterAccount);
            }
            player.FadeIn(0);
            API.triggerClientEvent(player, "onPlayerDisconnect");
        }