private void SellCardealerVehicle([FromSource] Player _player, string _seshKey, string _sellgarageItem, NetworkCallbackDelegate _networkCallback) { if (_seshKey == null) { Utils.WriteLine("Session key is missing!"); return; } Session foundSesh = Sessions.Find(s => s.Player.Handle == _player.Handle); if (foundSesh == null || foundSesh.SessionKey != _seshKey) { Utils.WriteLine("Session either doesn't exist or the session key doesn't match up"); return; } GarageItem sellgarageItem = JsonConvert.DeserializeObject <GarageItem>(_sellgarageItem); foreach (GarageItem gI in foundSesh.selectedCharacter.Garage.garageItems) { if (gI.garageID == sellgarageItem.garageID) { foreach (string key in ConfigManager.MarkerConfig.Keys) { //Find the cardealers within the markers if (key.ToLower().Contains("dealer")) { //Loop through vehicle dealer marker data foreach (string dataKey in ConfigManager.MarkerConfig[key].MarkerData.Keys) { //Get the vehicles if (dataKey.ToLower().Contains("vehicles")) { string markerDataString = JsonConvert.SerializeObject(ConfigManager.MarkerConfig[key].MarkerData[dataKey]); Dictionary <string, CardealerItem> markerData = JsonConvert.DeserializeObject <Dictionary <string, CardealerItem> >(markerDataString); foreach (string dataKey2 in markerData.Keys) { if (dataKey2.ToLower().Contains(gI.vehicleModel)) { //We have found the vehicle //We need to save the car to the garage and the garage to the database string jsonString = JsonConvert.SerializeObject(markerData[dataKey2]); CardealerItem cardealerItem = JsonConvert.DeserializeObject <CardealerItem>(jsonString); foundSesh.selectedCharacter.SellItem(cardealerItem.Price); foundSesh.selectedCharacter.SellVehicle(gI); foundSesh.UpdateCharacters(CharacterDBManager.UpdateCharacter(_player, foundSesh.User, foundSesh.selectedCharacter.Id)); Utils.WriteLine("Updated character!"); try { _networkCallback(true, JsonConvert.SerializeObject(gI), cardealerItem.Price); return; } catch (Exception _ex) { Utils.Throw(_ex); } } } } } } } } } _networkCallback(false, null, 0); }
private void BuyCardealerVehicle([FromSource] Player _player, string _seshKey, string _vehicleModel, NetworkCallbackDelegate _networkCallback) { Utils.WriteLine("Buying Cardealer vehicle!"); if (_seshKey == null) { Utils.WriteLine("Session key is missing!"); return; } Session foundSesh = Sessions.Find(s => s.Player.Handle == _player.Handle); if (foundSesh == null || foundSesh.SessionKey != _seshKey) { Utils.WriteLine("Session either doesn't exist or the session key doesn't match up"); return; } Utils.WriteLine("Searching markers"); foreach (string key in ConfigManager.MarkerConfig.Keys) { //Find the cardealers within the markers if (key.ToLower().Contains("dealer")) { foreach (string dataKey in ConfigManager.MarkerConfig[key].MarkerData.Keys) { if (dataKey.ToLower().Contains("vehicles")) { string markerDataString = JsonConvert.SerializeObject(ConfigManager.MarkerConfig[key].MarkerData[dataKey]); Dictionary <string, CardealerItem> markerData = JsonConvert.DeserializeObject <Dictionary <string, CardealerItem> >(markerDataString); foreach (string dataKey2 in markerData.Keys) { if (dataKey2.ToLower().Contains(_vehicleModel)) { //We have found the vehicle //We need to save the car to the garage and the garage to the database string jsonString = JsonConvert.SerializeObject(markerData[dataKey2]); CardealerItem cardealerItem = JsonConvert.DeserializeObject <CardealerItem>(jsonString); if (!foundSesh.selectedCharacter.BuyItem(cardealerItem.Price)) { Utils.WriteLine($"Player doesn't have enough money![{foundSesh.Player.Name}]"); _networkCallback(false, null); return; } int garageID = foundSesh.selectedCharacter.Garage.garageItems.Count + 1; GarageItem garageItem = new GarageItem(garageID, foundSesh.selectedCharacter.Id, cardealerItem.CarName, cardealerItem.CarModel, Utils.CreateVehicleNumberPlate(), false, false, new Dictionary <string, int>()); if (ConfigManager.ServerConfig.RPImpound) { garageItem.setImpounded(false); } else { garageItem.setImpounded(true); } garageItem.setStored(false); foundSesh.selectedCharacter.Garage.garageItems.Add(garageItem); foundSesh.UpdateCharacters(CharacterDBManager.UpdateCharacter(_player, foundSesh.User, foundSesh.selectedCharacter.Id)); _networkCallback(true, JsonConvert.SerializeObject(garageItem)); } } } } } } }