private IEnumerable <FittingHardwareAnalyzed> ObtenerFittingHardwareSlot(IEnumerable <string> lines, Enumerados.TipoSlot slot) { IDictionary <string, FittingHardwareAnalyzed> fwdicc = new Dictionary <string, FittingHardwareAnalyzed>(); string hwdname = null; foreach (var item in lines) { int initialUnits = 1; FittingHardwareAnalyzed fha = null; hwdname = item.Trim(); //Si es un Empty slot lo quitamos if (hwdname.ToLower().StartsWith("[empty")) { break; } //quitamos la coma para eliminar las ammo de los items que las admiten if (hwdname.Contains(',')) { hwdname = hwdname.Split(',').First(); } //si estamos en el slot de drones o bay, puede aparecer un multiplicador, lo quitamos y tomamos las unidades if (slot == Enumerados.TipoSlot.DroneBay || slot == Enumerados.TipoSlot.Cargo) { int posX = hwdname.LastIndexOf(" x"); if (posX >= 0) { string szunits = hwdname.Substring(posX + 2, hwdname.Length - posX - 2); if (int.TryParse(szunits, out initialUnits)) { hwdname = hwdname.Substring(0, posX); } } } if (!fwdicc.ContainsKey(hwdname)) { fha = new FittingHardwareAnalyzed(); fha.Name = hwdname; fha.Slot = (short)slot; fha.Units = (initialUnits - 1); fwdicc.Add(hwdname, fha); } else { fha = fwdicc[hwdname]; } fha.Units++; } return(fwdicc.Values); }
public eshFittingHardware MountFittingHardware(FittingHardwareAnalyzed fithwd, RepositorioItems repo) { invType tipo = repo.SelectItemTypePorName(fithwd.Name); if (tipo == null) { throw new ApplicationException(string.Format("{0}: {1}", Messages.err_nombreItemAnalizadaNoExiste, fithwd.Name)); } eshFittingHardware salida = new eshFittingHardware(); salida.typeID = tipo.typeID; salida.positionInSlot = 0; salida.slotID = fithwd.Slot; salida.units = fithwd.Units; salida.volume = RepositorioItems.GetVolume(tipo) * fithwd.Units; return(salida); }
private FittingAnalyzed ObtenerFit(XElement item) { FittingAnalyzed fit = new FittingAnalyzed(); fit.Name = item.Attribute("name").Value; //obtenemos la descripción XElement descXml = item.Descendants("description").FirstOrDefault(); fit.Description = descXml == null ? null : descXml.Value; //obtenemos el tipo de nave XElement shipXml = item.Descendants("shipType").FirstOrDefault(); fit.Ship = shipXml == null ? null : shipXml.Attribute("value").Value; IEnumerable <XElement> itemsHardwareXml = item.Descendants("hardware"); Dictionary <string, FittingHardwareAnalyzed> dicItems = new Dictionary <string, FittingHardwareAnalyzed>(); foreach (var itemHwdXml in itemsHardwareXml) { FittingHardwareAnalyzed fitHardware = null; fitHardware = ExtraerFittingHwdDesdeItemHwdXml(itemHwdXml); //Utilizamos el diccionario como caché para apilar las unidades de elementos con el mismo nombre if (dicItems.ContainsKey(fitHardware.Name)) { dicItems[fitHardware.Name].Units += fitHardware.Units; } else { dicItems.Add(fitHardware.Name, fitHardware); } } //Una vez obtenido el diccionario con las unidades apiladas, montamos la lista de salida foreach (var itemHwd in dicItems) { fit.Items.Add(itemHwd.Value); } return(fit); }
private IList <FittingHardwareAnalyzed> ObtenerFittingHardwareFromDNAModules(IList <DNAIntermediateFit.DNAItem> dnaItems) { List <int> typeIDs = new List <int>(); Dictionary <int, FittingHardwareAnalyzed> diccItemDnaSlots = new Dictionary <int, FittingHardwareAnalyzed>(); foreach (var item in dnaItems) { // we add the itemId to the types that we will have to search in database to get slot and name. typeIDs.Add(item.ID); // we initialize the dictionary of items. Name and real slot will be asigned later FittingHardwareAnalyzed fha = new FittingHardwareAnalyzed(); fha.Units = item.Units; fha.Slot = (short)Enumerados.TipoSlot.Cargo; diccItemDnaSlots.Add(item.ID, fha); } EveShoppingContext contexto = new EveShoppingContext(); var query = from it in contexto.invTypes join ig in contexto.invGroups on it.groupID equals ig.groupID join dte in contexto.dgmTypeEffects on it.typeID equals dte.typeID join de in contexto.dgmEffects on dte.effectID equals de.effectID where typeIDs.Contains(it.typeID) select new { typeID = it.typeID, dmgEffect = de.effectID }; //add names to dictionary AddNamesToDicc(diccItemDnaSlots, dnaItems); //complete de dictionary adding names and slots foreach (var item in query) { MergeDicDnaSlots(diccItemDnaSlots, item.typeID, item.dmgEffect); } return(diccItemDnaSlots.Values.OrderBy(fh => fh.Slot).ToList());; }
private FittingHardwareAnalyzed ExtraerFittingHwdDesdeItemHwdXml(XElement itemHwdXml) { FittingHardwareAnalyzed fitHardware = new FittingHardwareAnalyzed(); short qty = 1; if (itemHwdXml.Attribute("qty") != null) { qty = short.Parse(itemHwdXml.Attribute("qty").Value); } string htype = itemHwdXml.Attribute("type").Value; short posEnSlot = 0; Enumerados.TipoSlot tipoSlot = Enumerados.TipoSlot.High; if (itemHwdXml.Attribute("slot") != null) { tipoSlot = ObtenerTipoSlotPorNombreEVEXML(itemHwdXml.Attribute("slot").Value, out posEnSlot); } fitHardware.Units = qty; fitHardware.Slot = (short)tipoSlot; fitHardware.Name = htype; return(fitHardware); }