public PrefabAttachment getAttachment(string attName)
        {
            PrefabAttachment prefabAtt = new PrefabAttachment();

            foreach (PrefabAttachment pa in PrefabAttachments)
            {
                if (pa.attachmentPoint == attName)
                {
                    prefabAtt = pa;
                }
            }
            return(prefabAtt);
        }
        public XElement addObjects(XElement el, Part part, Loadout loadout, string parentid, string partid, string layerid)
        {
            XElement Object = el;

            if (part.partClass == "AnimatedJoint")
            {
                partid      = parentid;
                Object.Name = "Node";
                Object.Add(new XAttribute("Name", part.name));
                Object.Add(new XAttribute("LinkedTo", parentid));
                Object.Add(new XAttribute("Id", partid));
            }

            if (part.partClass == "Animated")
            {
                if (i != 0)
                {
                    Object.Add(new XAttribute("LinkedTo", parentid));
                }
                Object.Add(new XAttribute("Name", part.name));
                Object.Add(new XAttribute("Id", partid));
                Object.Add(new XAttribute("LayerGUID", layerid));
                Object.Add(new XAttribute("Geometry", part.animatedFilename));
                Object.Add(new XAttribute("Layer", "Main"));
                Object.Add(new XAttribute("Type", "GeomEntity"));
                Object.Add(new XAttribute("EntityClass", "GeomEntity"));
                Object.Add(new XAttribute("LodRatio", "10"));
                if (part.helper != "")
                {
                    Object.Add(new XAttribute("AttachmentType", "CharacterBone"));
                }
                if (part.helper != "")
                {
                    Object.Add(new XAttribute("AttachmentTarget", part.helper));
                }

                XElement Components = new XElement("Components");
                XElement Component  = new XElement("Component");
                Component.Add(new XAttribute("typeId", "ec0cd266-a6d1-4774-b499-690bd6fb61ee"));
                Component.Add(new XAttribute("guid", genID()));
                Component.Add(new XAttribute("CryXmlVersion", "2"));
                Component.Add(new XAttribute("Geometry", part.animatedFilename));
                Component.Add(new XAttribute("Physicalize", "ePhysicalizationType_Static"));
                Component.Add(new XAttribute("ReceiveCollisionEvents", "false"));
                Component.Add(new XAttribute("Mass", "1"));
                Component.Add(new XAttribute("Animation", ""));
                Component.Add(new XAttribute("Speed", "1"));
                Component.Add(new XAttribute("Loop", "true"));
                Components.Add(Component);
                Object.Add(Components);
                i++;
            }
            if (part.partClass == "ItemPort")
            {
                ItemPort itemport = loadout.GetItemPort(part.name);
                Item     item     = exporter.GetItem(itemport.itemName);
                if (item.geometry != "" && item.itemclass != "VehicleItemMultiLight" && allowedItemClasses.Any(item.itemclass.Contains))
                {
                    Object.Add(new XAttribute("Name", part.name));
                    Object.Add(new XAttribute("LinkedTo", parentid));
                    Object.Add(new XAttribute("Id", partid));
                    Object.Add(new XAttribute("LayerGUID", layerid));
                    Object.Add(new XAttribute("Geometry", item.geometry));
                    Object.Add(new XAttribute("AttachmentType", "CharacterBone"));
                    Object.Add(new XAttribute("AttachmentTarget", itemport.portName));
                    Object.Add(new XAttribute("Layer", "Main"));
                    Object.Add(new XAttribute("Type", "GeomEntity"));
                    Object.Add(new XAttribute("EntityClass", "GeomEntity"));
                    Object.Add(new XAttribute("LodRatio", "10"));

                    XElement Components = new XElement("Components");
                    XElement Component  = new XElement("Component");
                    Component.Add(new XAttribute("typeId", "ec0cd266-a6d1-4774-b499-690bd6fb61ee"));
                    Component.Add(new XAttribute("guid", genID()));
                    Component.Add(new XAttribute("CryXmlVersion", "2"));
                    Component.Add(new XAttribute("Geometry", item.geometry));
                    Component.Add(new XAttribute("Physicalize", "ePhysicalizationType_Static"));
                    Component.Add(new XAttribute("ReceiveCollisionEvents", "false"));
                    Component.Add(new XAttribute("Mass", "1"));
                    Component.Add(new XAttribute("Animation", ""));
                    Component.Add(new XAttribute("Speed", "1"));
                    Component.Add(new XAttribute("Loop", "true"));
                    Components.Add(Component);
                    Object.Add(Components);

                    foreach (ItemPort ip in itemport.itemPorts)
                    {
                        Item     item2 = exporter.GetItem(ip.itemName);
                        XElement obj2  = new XElement("Object");
                        obj2.Add(new XAttribute("Name", ip.portName));
                        obj2.Add(new XAttribute("LinkedTo", partid));
                        obj2.Add(new XAttribute("Id", genID()));
                        obj2.Add(new XAttribute("LayerGUID", layerid));
                        obj2.Add(new XAttribute("Geometry", item2.geometry));
                        obj2.Add(new XAttribute("AttachmentType", "CharacterBone"));
                        obj2.Add(new XAttribute("AttachmentTarget", ip.portName));
                        obj2.Add(new XAttribute("Layer", "Main"));
                        obj2.Add(new XAttribute("Type", "GeomEntity"));
                        obj2.Add(new XAttribute("EntityClass", "GeomEntity"));
                        obj2.Add(new XAttribute("LodRatio", "10"));

                        XElement Components2 = new XElement("Components");
                        XElement Component2  = new XElement("Component");
                        Component2.Add(new XAttribute("typeId", "ec0cd266-a6d1-4774-b499-690bd6fb61ee"));
                        Component2.Add(new XAttribute("guid", genID()));
                        Component2.Add(new XAttribute("CryXmlVersion", "2"));
                        Component2.Add(new XAttribute("Geometry", item2.geometry));
                        Component2.Add(new XAttribute("Physicalize", "ePhysicalizationType_Static"));
                        Component2.Add(new XAttribute("ReceiveCollisionEvents", "false"));
                        Component2.Add(new XAttribute("Mass", "1"));
                        Component2.Add(new XAttribute("Animation", ""));
                        Component2.Add(new XAttribute("Speed", "1"));
                        Component2.Add(new XAttribute("Loop", "true"));
                        Components2.Add(Component2);
                        obj2.Add(Components2);

                        Object.Add(obj2);
                    }
                }
                if (item.itemclass == "VehicleItemMultiLight")
                {
                    foreach (AttachmentPoint at in part.attachmentPoints)
                    {
                        //Console.WriteLine(at.name);
                        XElement obj1  = new XElement("Object");
                        string   entid = genID();
                        obj1.Add(new XAttribute("Type", "GeomEntity"));
                        obj1.Add(new XAttribute("Name", at.bone));
                        obj1.Add(new XAttribute("LinkedTo", parentid));
                        obj1.Add(new XAttribute("Id", entid));
                        obj1.Add(new XAttribute("LayerGUID", layerid));
                        obj1.Add(new XAttribute("AttachmentType", "CharacterBone"));
                        obj1.Add(new XAttribute("AttachmentTarget", at.bone));
                        obj1.Add(new XAttribute("Layer", "Main"));
                        obj1.Add(new XAttribute("EntityClass", "GeomEntity"));
                        Object.Add(obj1);

                        //PrefabAttachment prefabAtt = item.getAttachment(at.name);
                        //XElement obj2 = getPrefab(prefabAtt.prefabLibrary, prefabAtt.prefabName);
                        XElement         obj2       = new XElement("Object");
                        PrefabAttachment prefabAtt  = item.getAttachment(at.name);
                        string           PrefabGUID = "";
                        try
                        {
                            PrefabGUID = getPrefabGUID(prefabAtt.prefabLibrary, prefabAtt.prefabName);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Error:");
                            Console.WriteLine("prefabLibrary: {0} prefabName: {1} attachmentPoint: {2}", prefabAtt.prefabLibrary, prefabAtt.prefabName, prefabAtt.attachmentPoint);
                            Console.WriteLine("at.name: {0}", at.name);
                            Console.WriteLine("item.name: {0}", item.name);
                            //throw e;
                        }
                        string prefid        = genID();
                        string prefablibname = Path.GetFileNameWithoutExtension(prefabAtt.prefabLibrary);
                        obj2.Add(new XAttribute("Type", "Prefab"));
                        obj2.Add(new XAttribute("Name", at.name));
                        obj2.Add(new XAttribute("LinkedTo", entid));
                        obj2.Add(new XAttribute("Id", prefid));
                        obj2.Add(new XAttribute("LayerGUID", layerid));
                        obj2.Add(new XAttribute("Layer", "Main"));
                        obj2.Add(new XAttribute("PrefabGUID", PrefabGUID));
                        obj2.Add(new XAttribute("PrefabLibrary", prefablibname));
                        obj2.Add(new XAttribute("PrefabName", prefabAtt.prefabName));
                        prefablib = prefabAtt.prefabLibrary;
                        prefabs.Add(getPrefab(prefabAtt.prefabLibrary, prefabAtt.prefabName));
                        Object.Add(obj2);
                    }
                }
            }

            foreach (Part pr in part.parts)
            {
                XElement obj = new XElement("Object");
                obj = addObjects(obj, pr, loadout, partid, genID(), layerid);
                //if (obj.Attribute("Name") != null)
                Object.Add(obj);
            }

            return(Object);
        }
Beispiel #3
0
 public void LoadItems(string path)
 {
     if (Directory.Exists(path))
     {
         foreach (var file in Directory.GetFiles(path, "*.xml", SearchOption.AllDirectories))
         {
             //Console.WriteLine(file);
             XDocument xml = XDocumentHelper.Load(file);
             IEnumerable <XElement> elements = xml.Elements();
             foreach (var el in elements)
             {
                 if (el.Name == "item")
                 {
                     Item item = new Item();
                     item.name      = el.Attribute("name").Value;
                     item.itemclass = el.Attribute("class").Value;
                     //Console.WriteLine(el.Name);
                     //Console.WriteLine(el.Element("geometry").Element("thirdperson"));
                     //Console.WriteLine(el.Descendants("geometry").Descendants("thirdperson"));
                     //foreach (XElement ell in el.Descendants("geometry").Descendants("thirdperson"))
                     //{
                     //    Console.WriteLine(ell);
                     //}
                     if (el.Element("geometry") != null)
                     {
                         if (el.Element("geometry").Element("thirdperson") != null)
                         {
                             item.geometry = el.Element("geometry").Element("thirdperson").Attribute("name").Value;
                             //Console.WriteLine(item.geometry);
                             //Console.WriteLine(el.Element("geometry").Element("thirdperson").Attribute("name").Value);
                         }
                     }
                     if (el.Attribute("interface") != null)
                     {
                         item.intrface = el.Attribute("interface").Value;
                         ItemInterface iteminterface = FindItemInterface(item.intrface);
                         if (iteminterface.geometry != "")
                         {
                             item.geometry = iteminterface.geometry;
                         }
                         //Console.WriteLine(item.geometry);
                     }
                     if (el.Element("PrefabAttachments") != null)
                     {
                         foreach (XElement ell in el.Element("PrefabAttachments").Descendants("PrefabAttachment"))
                         {
                             PrefabAttachment prefabAtt = new PrefabAttachment();
                             prefabAtt.attachmentPoint = ell.Attribute("attachmentPoint").Value;
                             prefabAtt.prefabLibrary   = ell.Attribute("prefabLibrary").Value;
                             prefabAtt.prefabName      = ell.Attribute("prefabName").Value;
                             item.PrefabAttachments.Add(prefabAtt);
                             // Console.WriteLine("prefabatt {0} {1} {2}", prefabAtt.attachmentPoint, prefabAtt.prefabLibrary, prefabAtt.prefabName);
                         }
                         //Console.WriteLine(item.PrefabAttachments.Count);
                     }
                     //Console.WriteLine(item.name);
                     items.Add(item);
                 }
             }
         }
     }
     else
     {
         Console.WriteLine("[ERROR] NOT FOUND: {0}", path);
         SuccessfullyLoaded = false;
     }
 }