public void OnPlayerBoughtVehicleHandler(Client sender, params object[] arguments) { //arguments[0] to nazwa pojazdu if (!Enum.TryParse(arguments[0].ToString(), out VehicleHash vehicleHash)) { return; } CarshopVehicleModel vehicle = Vehicles.First(v => v.Name == arguments[0].ToString()); CharacterEntity character = sender.GetAccountEntity().CharacterEntity; if (character.HasMoney(vehicle.Cost)) { character.RemoveMoney(vehicle.Cost); VehicleEntity.Create(new FullPosition(new Vector3(-50, -1680, 29.5), new Vector3(0, 0, 0)), vehicleHash, "", 0, null, ApiExtensions.GetRandomColor(), ApiExtensions.GetRandomColor(), 0f, 0f, sender.GetAccountEntity().CharacterEntity.DbModel); sender.SendInfo($"Pojazd {vehicleHash.ToString()} zakupiony pomyślnie."); } else { sender.SendError("Nie posiadasz wystarczającej ilości gotówki."); } }
public void AddVehicleToCarshop(Client sender, VehicleHash hash, VehicleClass vehicleClass, decimal cost, string type, string type2 = "Empty") { if (!sender.HasRank(ServerRank.AdministratorRozgrywki2)) { sender.SendWarning("Nie posiadasz uprawnień do tworzenia pojazdu w salonie."); return; } if (Vehicles.Any(v => v.Hash == hash)) { sender.SendError("Podany pojazd jest już dodany."); return; } MoneyValidator validator = new MoneyValidator(); if (!validator.IsValid(cost)) { sender.SendError("Wprowadzona kwota gotówki jest nieprawidłowa."); return; } CarshopType endType = CarshopType.Empty; CarshopType endType2 = CarshopType.Empty; var carshopTypes = ((CarshopType[])Enum.GetValues(typeof(CarshopType))).ToList(); if (carshopTypes.All(carshopType => carshopType.GetDescription() != type && carshopType.GetDescription() != type2)) { sender.SendError("Wprowadzony typ salonu jest nieprawidłowy."); } foreach (CarshopType item in carshopTypes) { if (item.GetDescription() == type) { endType = item; } if (item.GetDescription() == type2) { endType2 = item; } } if (endType2 != CarshopType.Empty) { endType = endType | endType2; } CarshopVehicleModel vehicle = new CarshopVehicleModel(hash.ToString(), hash, vehicleClass, cost, endType) { CreatorForumName = sender.GetAccountEntity().DbModel.Name }; XmlHelper.AddXmlObject(vehicle, Path.Combine(Utils.XmlDirectory, "CarshopVehicles"), vehicle.Name); }