private int GetVehicleTunningComponent(int vehicleId, int slot) { // Get the component on the specified slot TunningModel tunning = tunningList.Where(tunningModel => tunningModel.vehicle == vehicleId && tunningModel.slot == slot).FirstOrDefault(); return(tunning == null ? 255 : tunning.component); }
public void CalculateTunningCostEvent(Client player) { int totalProducts = 0; // Get the vehicle int vehicleId = player.Vehicle.GetData(EntityData.VEHICLE_ID); for (int i = 0; i < 49; i++) { int vehicleMod = player.Vehicle.GetMod(i); if (vehicleMod > 0) { TunningModel tunningModel = GetVehicleTunningComponent(vehicleId, i, vehicleMod); if (tunningModel == null) { totalProducts += Constants.TUNNING_PRICE_LIST.Where(x => x.slot == i).First().products; } } } // Send the price to the player string priceMessage = string.Format(Messages.INF_TUNNING_PRODUCTS, totalProducts); player.SendChatMessage(Constants.COLOR_INFO + priceMessage); }
public static int AddTunning(TunningModel tunning) { var tunningId = 0; using (var connection = Database.GetConnection()) { try { connection.Open(); var command = connection.CreateCommand(); command.CommandText = "INSERT INTO tunning (vehicle, slot, component) VALUES (@vehicle, @slot, @component)"; command.Parameters.AddWithValue("@vehicle", tunning.vehicle); command.Parameters.AddWithValue("@slot", tunning.slot); command.Parameters.AddWithValue("@component", tunning.component); command.ExecuteNonQuery(); tunningId = (int)command.LastInsertedId; } catch (Exception ex) { NAPI.Util.ConsoleOutput("[EXCEPTION AddTunning] " + ex.Message); NAPI.Util.ConsoleOutput("[EXCEPTION AddTunning] " + ex.StackTrace); } } return(tunningId); }
public static List <TunningModel> LoadAllTunning() { var tunningList = new List <TunningModel>(); using (var connection = Database.GetConnection()) { connection.Open(); var command = connection.CreateCommand(); command.CommandText = "SELECT * FROM tunning"; using (var reader = command.ExecuteReader()) { while (reader.Read()) { var tunning = new TunningModel(); { tunning.id = reader.GetInt32("id"); tunning.vehicle = reader.GetInt32("vehicle"); tunning.slot = reader.GetInt32("slot"); tunning.component = reader.GetInt32("component"); } tunningList.Add(tunning); } } } return(tunningList); }
public void CalculateTunningCostEvent(Client player, params object[] arguments) { // Inicializamos productos int totalProducts = 0; // Obtenemos el vehículo Vehicle vehicle = NAPI.Entity.GetEntityFromHandle <Vehicle>(NAPI.Player.GetPlayerVehicle(player)); int vehicleId = NAPI.Data.GetEntityData(vehicle, EntityData.VEHICLE_ID); for (int i = 0; i < 49; i++) { // Obtenemos el componente int vehicleMod = NAPI.Vehicle.GetVehicleMod(vehicle, i); if (vehicleMod > 0) { TunningModel tunningModel = GetVehicleTunningComponent(vehicleId, i, vehicleMod); if (tunningModel == null) { totalProducts += Constants.TUNNING_PRICE_LIST.Where(x => x.slot == i).First().products; } } } // Enviamos al jugador el precio en productos String priceMessage = String.Format(Messages.INF_TUNNING_PRODUCTS, totalProducts); NAPI.Chat.SendChatMessageToPlayer(player, Constants.COLOR_INFO + priceMessage); }
private TunningModel GetVehicleTunningComponent(int vehicleId, int slot, int component) { TunningModel tunning = null; foreach (TunningModel tunningModel in tunningList) { if (tunningModel.vehicle == vehicleId && tunningModel.slot == slot && tunningModel.component == component) { tunning = tunningModel; break; } } return(tunning); }
public void ConfirmVehicleModificationEvent(Client player, int slot, int mod) { // Get the vehicle's id int vehicleId = player.Vehicle.GetData(EntityData.VEHICLE_ID); // Get player's product amount int playerId = player.GetData(EntityData.PLAYER_SQL_ID); ItemModel item = Globals.GetPlayerItemModelFromHash(playerId, Constants.ITEM_HASH_BUSINESS_PRODUCTS); // Calculate the cost for the tunning int totalProducts = Constants.TUNNING_PRICE_LIST.Where(x => x.slot == slot).First().products; if (item != null && item.amount >= totalProducts) { // Add component to database TunningModel tunningModel = new TunningModel(); { tunningModel.slot = slot; tunningModel.component = mod; tunningModel.vehicle = vehicleId; } Task.Factory.StartNew(() => { NAPI.Task.Run(() => { tunningModel.id = Database.AddTunning(tunningModel); tunningList.Add(tunningModel); // Remove consumed products item.amount -= totalProducts; // Update the amount into the database Database.UpdateItem(item); // Confirmation message player.SendChatMessage(Constants.COLOR_INFO + InfoRes.vehicle_tunning); }); }); } else { string message = string.Format(ErrRes.not_required_products, totalProducts); player.SendChatMessage(Constants.COLOR_ERROR + message); } }
public void CancelVehicleModificationEvent(Client player) { int vehicleId = player.Vehicle.GetData(EntityData.VEHICLE_ID); for (int i = 0; i < 49; i++) { int vehicleMod = player.Vehicle.GetMod(i); TunningModel tunningModel = GetVehicleTunningComponent(vehicleId, i, vehicleMod); if (tunningModel == null) { player.Vehicle.RemoveMod(i); } else { player.Vehicle.SetMod(i, vehicleMod); } } }
public void CancelVehicleModificationEvent(Client player) { Vehicle vehicle = NAPI.Player.GetPlayerVehicle(player); int vehicleId = NAPI.Data.GetEntityData(vehicle, EntityData.VEHICLE_ID); for (int i = 0; i < 49; i++) { int vehicleMod = NAPI.Vehicle.GetVehicleMod(vehicle, i); TunningModel tunningModel = GetVehicleTunningComponent(vehicleId, i, vehicleMod); if (tunningModel == null) { NAPI.Vehicle.RemoveVehicleMod(vehicle, i); } else { NAPI.Vehicle.SetVehicleMod(vehicle, i, vehicleMod); } } }
public void CancelVehicleModificationEvent(Client player, params object[] arguments) { // Obtenemos el vehículo Vehicle vehicle = NAPI.Entity.GetEntityFromHandle <Vehicle>(NAPI.Player.GetPlayerVehicle(player)); int vehicleId = NAPI.Data.GetEntityData(vehicle, EntityData.VEHICLE_ID); // Obtenemos el gasto for (int i = 0; i < 49; i++) { // Obtenemos el componente int vehicleMod = NAPI.Vehicle.GetVehicleMod(vehicle, i); TunningModel tunningModel = GetVehicleTunningComponent(vehicleId, i, vehicleMod); if (tunningModel == null) { NAPI.Vehicle.RemoveVehicleMod(vehicle, i); } else { NAPI.Vehicle.SetVehicleMod(vehicle, i, vehicleMod); } } }
public void ConfirmVehicleModificationEvent(Client player) { int totalProducts = 0; int vehicleId = player.Vehicle.GetData(EntityData.VEHICLE_ID); // Get player's product amount int playerId = player.GetData(EntityData.PLAYER_SQL_ID); ItemModel item = Globals.GetPlayerItemModelFromHash(playerId, Constants.ITEM_HASH_BUSINESS_PRODUCTS); for (int i = 0; i < 49; i++) { int vehicleMod = player.Vehicle.GetMod(i); if (vehicleMod > 0) { TunningModel tunningModel = GetVehicleTunningComponent(vehicleId, i, vehicleMod); if (tunningModel == null) { totalProducts += Constants.TUNNING_PRICE_LIST.Where(x => x.slot == i).First().products; } } } if (item != null && item.amount >= totalProducts) { for (int i = 0; i < 49; i++) { int vehicleMod = player.Vehicle.GetMod(i); if (vehicleMod > 0) { TunningModel tunningModel = GetVehicleTunningComponent(vehicleId, i, vehicleMod); if (tunningModel == null) { // Add component to database tunningModel = new TunningModel(); tunningModel.slot = i; tunningModel.component = vehicleMod; tunningModel.vehicle = vehicleId; Task.Factory.StartNew(() => { tunningModel.id = Database.AddTunning(tunningModel); tunningList.Add(tunningModel); }); } } } // Remove consumed products item.amount -= totalProducts; Task.Factory.StartNew(() => { // Update the amount into the database Database.UpdateItem(item); }); // Close tunning menu player.TriggerEvent("closeTunningMenu"); // Confirmation message player.SendChatMessage(Constants.COLOR_INFO + Messages.INF_VEHICLE_TUNNING); } else { string message = string.Format(Messages.ERR_NOT_REQUIRED_PRODUCTS, totalProducts); player.SendChatMessage(Constants.COLOR_ERROR + message); } }
public void ConfirmVehicleModificationEvent(Client player, params object[] arguments) { // Inicializamos productos int totalProducts = 0; // Obtenemos el vehículo Vehicle vehicle = NAPI.Entity.GetEntityFromHandle <Vehicle>(NAPI.Player.GetPlayerVehicle(player)); int vehicleId = NAPI.Data.GetEntityData(vehicle, EntityData.VEHICLE_ID); // Obtenemos los productos del jugador int playerId = NAPI.Data.GetEntityData(player, EntityData.PLAYER_SQL_ID); ItemModel item = Globals.GetPlayerItemModelFromHash(playerId, Constants.ITEM_HASH_BUSINESS_PRODUCTS); // Obtenemos el gasto for (int i = 0; i < 49; i++) { // Obtenemos el componente int vehicleMod = NAPI.Vehicle.GetVehicleMod(vehicle, i); if (vehicleMod > 0) { TunningModel tunningModel = GetVehicleTunningComponent(vehicleId, i, vehicleMod); if (tunningModel == null) { totalProducts += Constants.TUNNING_PRICE_LIST.Where(x => x.slot == i).First().products; } } } if (item != null && item.amount >= totalProducts) { for (int i = 0; i < 49; i++) { // Obtenemos el componente int vehicleMod = NAPI.Vehicle.GetVehicleMod(vehicle, i); if (vehicleMod > 0) { TunningModel tunningModel = GetVehicleTunningComponent(vehicleId, i, vehicleMod); if (tunningModel == null) { // Añadimos la pieza tunningModel = new TunningModel(); tunningModel.slot = i; tunningModel.component = vehicleMod; tunningModel.vehicle = vehicleId; tunningModel.id = Database.AddTunning(tunningModel); tunningList.Add(tunningModel); } } } // Descontamos los productos item.amount -= totalProducts; Database.UpdateItem(item); // Cerramos la ventana de tunning NAPI.ClientEvent.TriggerClientEvent(player, "closeTunningMenu"); // Mandamos el mensaje NAPI.Chat.SendChatMessageToPlayer(player, Constants.COLOR_INFO + Messages.INF_VEHICLE_TUNNING); } else { String message = String.Format(Messages.ERR_NOT_REQUIRED_PRODUCTS, totalProducts); NAPI.Chat.SendChatMessageToPlayer(player, Constants.COLOR_ERROR + message); } }