override public MyObjectBuilder_Base Clone() { MyObjectBuilder_Ore clone = MyObjectBuilderSerializer.Clone(this) as MyObjectBuilder_Ore; clone.MaterialTypeName = MaterialTypeName; return(clone); }
/// <summary> /// Find the physical object of the specified name or partial name. /// </summary> /// <param name="itemName">The name of the physical object to find.</param> /// <param name="objectBuilder">The object builder of the physical object, ready for use.</param> /// <param name="options">Returns a list of potential matches if there was more than one of the same or partial name.</param> /// <returns>Returns true if a single exact match was found.</returns> public static bool FindPhysicalParts(string itemName, out MyObjectBuilder_Base objectBuilder, out Dictionary<string, MyDefinitionBase> options) { BuildComponentLists(); itemName = itemName.Trim(); var itemNames = itemName.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); // prefix the search term with 'ore' to find this ore name. if (itemNames.Length > 1 && itemNames[0].Equals("ore", StringComparison.InvariantCultureIgnoreCase)) { var findName = itemName.Substring(4).Trim(); var exactMatchOres = _oreList.Where(ore => ore.Value.Id.SubtypeName.Equals(findName, StringComparison.InvariantCultureIgnoreCase)).ToDictionary(kvp => kvp.Key, kvp => kvp.Value); if (exactMatchOres.Count == 1) { objectBuilder = new MyObjectBuilder_Ore() { SubtypeName = exactMatchOres.First().Value.Id.SubtypeName }; options = new Dictionary<string, MyDefinitionBase>(); return true; } if (exactMatchOres.Count > 1) { objectBuilder = null; options = exactMatchOres; return false; } var partialMatchOres = _oreList.Where(ore => ore.Value.Id.SubtypeName.IndexOf(findName, StringComparison.InvariantCultureIgnoreCase) >= 0).ToDictionary(kvp => kvp.Key, kvp => kvp.Value); if (partialMatchOres.Count == 1) { objectBuilder = new MyObjectBuilder_Ore() { SubtypeName = partialMatchOres.First().Value.Id.SubtypeName }; options = new Dictionary<string, MyDefinitionBase>(); return true; } if (partialMatchOres.Count > 1) { objectBuilder = null; options = partialMatchOres; return false; } objectBuilder = null; options = new Dictionary<string, MyDefinitionBase>(); return false; } // prefix the search term with 'ingot' to find this ingot name. if (itemNames.Length > 1 && itemNames[0].Equals("ingot", StringComparison.InvariantCultureIgnoreCase)) { var findName = itemName.Substring(6).Trim(); var exactMatchIngots = _ingotList.Where(ingot => ingot.Value.Id.SubtypeName.Equals(findName, StringComparison.InvariantCultureIgnoreCase)).ToDictionary(kvp => kvp.Key, kvp => kvp.Value); if (exactMatchIngots.Count == 1) { objectBuilder = new MyObjectBuilder_Ingot() { SubtypeName = exactMatchIngots.First().Value.Id.SubtypeName }; options = new Dictionary<string, MyDefinitionBase>(); return true; } if (exactMatchIngots.Count > 1) { objectBuilder = null; options = exactMatchIngots; return false; } var partialMatchIngots = _ingotList.Where(ingot => ingot.Value.Id.SubtypeName.IndexOf(findName, StringComparison.InvariantCultureIgnoreCase) >= 0).ToDictionary(kvp => kvp.Key, kvp => kvp.Value); if (partialMatchIngots.Count == 1) { objectBuilder = new MyObjectBuilder_Ingot() { SubtypeName = partialMatchIngots.First().Value.Id.SubtypeName }; options = new Dictionary<string, MyDefinitionBase>(); return true; } if (partialMatchIngots.Count > 1) { objectBuilder = null; options = partialMatchIngots; return false; } objectBuilder = null; options = new Dictionary<string, MyDefinitionBase>(); return false; } // full name match. var res = _physicalItemNames.FirstOrDefault(s => s.Key != null && s.Key.Equals(itemName, StringComparison.InvariantCultureIgnoreCase)); // need a good method for finding partial name matches. if (res.Key == null) { var matches = _physicalItemNames.Where(s => s.Key != null && s.Key.StartsWith(itemName, StringComparison.InvariantCultureIgnoreCase)).Distinct().ToDictionary(kvp => kvp.Key, kvp => kvp.Value); if (matches.Count == 1) { res = matches.FirstOrDefault(); } else { matches = _physicalItemNames.Where(s => s.Key != null && s.Key.IndexOf(itemName, StringComparison.InvariantCultureIgnoreCase) >= 0).Distinct().ToDictionary(kvp => kvp.Key, kvp => kvp.Value); if (matches.Count == 1) { res = matches.FirstOrDefault(); } else if (matches.Count > 1) { objectBuilder = null; options = matches; return false; } } } if (res.Key != null) { if (res.Value != null) { objectBuilder = MyObjectBuilderSerializer.CreateNewObject(res.Value.Id.TypeId, res.Value.Id.SubtypeName); options = new Dictionary<string, MyDefinitionBase>(); return true; } } objectBuilder = null; options = new Dictionary<string, MyDefinitionBase>(); return false; }