/// <summary> /// Deserializes an XML loadout text. /// </summary> /// <param name="text">The text.</param> /// <returns></returns> public static ILoadoutInfo DeserializeXmlFormat(string text) { SerializableXmlFittings fittings = Util.DeserializeXmlFromString <SerializableXmlFittings>(text); ILoadoutInfo loadoutInfo = new LoadoutInfo(); // Nothing to evaluate if (fittings == null) { return(loadoutInfo); } // Retrieve the ship loadoutInfo.Ship = StaticItems.GetItemByName(fittings.Fitting.ShipType.Name); if (loadoutInfo.Ship == null) { return(loadoutInfo); } // Special case to avoid displaying gzCLF block from Osmium if (fittings.Fitting.Description.Text.StartsWith("BEGIN gzCLF BLOCK", StringComparison.InvariantCultureIgnoreCase)) { fittings.Fitting.Description.Text = String.Empty; } Loadout loadout = new Loadout(fittings.Fitting.Name, fittings.Fitting.Description.Text); IEnumerable <Item> listOfItems = fittings.Fitting.FittingHardware .Where(hardware => hardware != null && hardware.Item != null && hardware.Slot != "drone bay") .Select(hardware => hardware.Item); IEnumerable <SerializableXmlFittingHardware> listOfXmlDrones = fittings.Fitting.FittingHardware .Where(hardware => hardware != null && hardware.Item != null && hardware.Slot == "drone bay"); var listOfDrones = new List <Item>(); foreach (SerializableXmlFittingHardware drone in listOfXmlDrones) { for (int i = 0; i < drone.Quantity; i++) { listOfDrones.Add(drone.Item); } } loadout.Items = listOfItems.Concat(listOfDrones); loadoutInfo.Loadouts.Add(loadout); return(loadoutInfo); }
/// <summary> /// Gets an item by its ID or its name. /// </summary> /// <param name="src"></param> /// <returns></returns> private static Item GetItem(SerializableOrderBase src) { // Try get item by its ID Item item = StaticItems.GetItemByID(src.ItemID); // We failed? Try get item by its name if (item == null) { item = StaticItems.GetItemByName(src.Item); } return(item); }
/// <summary> /// Gets an items ID either by source or by name. /// </summary> /// <param name="src"></param> /// <returns></returns> private static long GetItemID(SerializableOrderBase src) { // Try get item ID by source var itemID = src.ItemID; // We failed? Try get item ID by name if (itemID == 0) { var item = StaticItems.GetItemByName(src.Item); itemID = (item == null ? 0 : item.ID); } return(itemID); }
/// <summary> /// Parses one line of loadout text and adds the required /// skills for the items to the _SkillsToAdd list. /// </summary> /// <remarks> /// parsed items are also added to the TreeView. /// </remarks> /// <param name="line">Line of text to be parsed.</param> private void AddItem(string line) { // Retrieve the item and its charge string itemName = line.Contains(",") ? line.Substring(0, line.LastIndexOf(',')) : line; string chargeName = line.Contains(",") ? line.Substring(line.LastIndexOf(',') + 2) : null; // Look up if it's a drone itemName = itemName.Contains(" x") ? itemName.Substring(0, line.LastIndexOf(" x")) : itemName; Item item = StaticItems.GetItemByName(itemName); Item charge = !String.IsNullOrEmpty(chargeName) ? StaticItems.GetItemByName(chargeName) : null; // Regular item ? if (item != null) { // Retrieve the tree node name for the slot string nodeName = String.Empty; switch (item.FittingSlot) { case ItemSlot.High: nodeName = "High"; break; case ItemSlot.Medium: nodeName = "Med"; break; case ItemSlot.Low: nodeName = "Low"; break; } // Is it a rig? if (item.MarketGroup.BelongsIn(new int[] { DBConstants.ShipModificationsGroupID })) { nodeName = "Rigs"; } // Is it a subsystem? if (item.MarketGroup.BelongsIn(new int[] { DBConstants.AdvancedSubsystemsGroupID })) { nodeName = "Subsystems"; } // Is it a drone? if (item.MarketGroup.BelongsIn(new int[] { DBConstants.DronesGroupID })) { nodeName = "Drones"; } // Gets or create the node for the slot TreeNode slotNode = !ResultsTreeView.Nodes.ContainsKey(nodeName) ? ResultsTreeView.Nodes.Add(nodeName, nodeName) : ResultsTreeView.Nodes[nodeName]; // Add a new node TreeNode itemNode = new TreeNode(); itemNode.Text = item.Name; itemNode.Tag = item; slotNode.Nodes.Add(itemNode); } // Has charges ? if (charge != null) { TreeNode slotNode = !ResultsTreeView.Nodes.ContainsKey("Ammunition") ? ResultsTreeView.Nodes.Add("Ammunition", "Ammunition") : ResultsTreeView.Nodes["Ammunition"]; TreeNode ammoNode = new TreeNode(); ammoNode.Text = charge.Name; ammoNode.Tag = charge; slotNode.Nodes.Add(ammoNode); } // Add the item and its charge to the objects list if (item != null) { m_objects.Add(item); } if (charge != null) { m_objects.Add(charge); } }
/// <summary> /// Deserializes an EFT loadout text. /// </summary> /// <param name="text">The text.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException">text</exception> public static ILoadoutInfo DeserializeEftFormat(string text) { text.ThrowIfNull(nameof(text)); string[] lines = text.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); ILoadoutInfo loadoutInfo = new LoadoutInfo(); // Nothing to evaluate if (lines.Length == 0) { return(loadoutInfo); } var listOfItems = new List <Item>(); Loadout loadout = null; foreach (string line in lines.Where(line => !String.IsNullOrEmpty(line) && !line.Contains("empty") && !line.Contains("slot"))) { // Retrieve the ship if (line == lines.First()) { // Retrieve the loadout name int commaIndex = line.IndexOf(','); loadoutInfo.Ship = StaticItems.GetItemByName(line.Substring(1, commaIndex - 1)); if (loadoutInfo.Ship == null) { return(loadoutInfo); } loadout = new Loadout(line.Substring(commaIndex + 1, line.Length - commaIndex - 2).Trim(), String.Empty); continue; } // Retrieve the item (might be a drone) int lastX = line.LastIndexOf(" x", StringComparison.CurrentCulture); int lastComma = line.LastIndexOf(','); string itemName = lastComma >= 0 ? line.Substring(0, lastComma) : (lastX >= 0 ? line.Substring(0, lastX) : line); int quantity = lastX >= 0 ? int.Parse(line.Substring(lastX + 2, line.Length - (lastX + 2))) : 1; Item item = StaticItems.GetItemByName(itemName) ?? Item.UnknownItem; for (int i = 0; i < quantity; i++) { listOfItems.Add(item); } // Retrieve the charge string chargeName = lastComma >= 0 ? line.Substring(lastComma + 1).Trim() : null; if (String.IsNullOrEmpty(chargeName)) { continue; } Item charge = StaticItems.GetItemByName(chargeName) ?? Item.UnknownItem; listOfItems.Add(charge); } if (loadout == null) { return(loadoutInfo); } loadout.Items = listOfItems; loadoutInfo.Loadouts.Add(loadout); return(loadoutInfo); }