Exemple #1
0
        public ShipImplementation(XDocument xmlDoc, string pathFolder, List <Item> items)
        {
            itemsList = items;
            XElement el = xmlDoc.Root;

            if (el.Name == "Vehicle")
            {
                name = el.Attribute("name").Value;
                //Part part = new Part();
                foreach (XElement ell in el.Elements("Parts").Elements("Part"))
                {
                    Part part2 = new Part();
                    part2 = LoadParts(ell);
                    //part.parts.Add(part2);
                    parts.Add(part2);
                }
                foreach (XElement ell in el.Elements("Modifications").Elements("Modification"))
                {
                    Modification mod = new Modification();
                    mod.name = ell.Attribute("name").Value;
                    if (ell.Attribute("patchFile") != null)
                    {
                        mod.patchName = ell.Attribute("patchFile").Value;
                    }
                    if (mod.patchName != null)
                    {
                        if (mod.patchName != "")
                        {
                            mod.trueName = Path.GetFileName(mod.patchName);

                            if (File.Exists(pathFolder + "/" + mod.patchName + ".xml"))
                            {
                                XDocument xmlMod = XDocument.Load(File.OpenRead(pathFolder + "/" + mod.patchName + ".xml"));

                                if (xmlMod.Element("Modifications").Element("Parts") != null)
                                {
                                    foreach (XElement elPart in xmlMod.Element("Modifications").Elements("Parts").Elements("Part"))
                                    {
                                        //Console.WriteLine(elPart.Attribute("name").Value);
                                        Part part = new Part();
                                        part = LoadParts(elPart);
                                        mod.parts.Add(part);
                                    }
                                }
                                else
                                {
                                    //Console.WriteLine("No geometry Modifications for " + mod.trueName);
                                }
                                mod.objectContainers = LoadObjectContainers(xmlMod.Element("Modifications"));
                                modifications.Add(mod);
                            }
                            else
                            {
                                // Console.WriteLine("Not Found:" + pathFolder + "/" + mod.patchName + ".xml");
                            }
                        }
                    }
                }
                foreach (XElement ell in el.Elements("Paints").Elements("Paint"))
                {
                    Paint paint = new Paint();
                    paint.name     = ell.Attribute("name").Value;
                    paint.material = ell.Attribute("material").Value;
                    paints.Add(paint);
                }
                objectContainers = LoadObjectContainers(el);
                //ship.parts.Add(part);
            }

            // Console.WriteLine();
        }
        public XDocument GenerateShipOLD(GenerateOptions genOptions)
        {
            string             shipName = genOptions.shipName;
            ShipImplementation ship     = exporter.GetShipImplementation(shipName);
            Paint paint = ship.GetPaintByName(genOptions.paintName);
            //shipName = "AEGS_Gladius";
            XDocument xml         = new XDocument();
            string    loadoutName = null;

            if (genOptions.loadoutName != null)
            {
                loadoutName = genOptions.loadoutName;
            }
            else
            {
                loadoutName = "Default_Loadout_" + shipName;
            }

            string prefLibName = "";

            if (paint != null)
            {
                prefLibName = shipName + "-" + paint.name;
            }
            else
            {
                prefLibName = shipName;
            }
            prefLibName = "ships/" + prefLibName;
            XElement PrefabsLibrary = new XElement("PrefabsLibrary");

            //PrefabsLibrary.Attribute("Name").Value = shipName+"_Ship";
            //PrefabsLibrary.Add(new XAttribute("Name", shipName + "_Ship"));
            PrefabsLibrary.Add(new XAttribute("Name", prefLibName));

            XElement Prefab   = new XElement("Prefab");
            string   prefabId = GuidUtility.GenPrefabID(prefLibName);

            //Prefab.Add(new XAttribute("Name", shipName));
            Prefab.Add(new XAttribute("Name", "Ship"));
            Prefab.Add(new XAttribute("Id", prefabId));
            // Prefab.Add(new XAttribute("Library", shipName + "_Ship"));
            Prefab.Add(new XAttribute("Library", prefLibName));

            XElement Objects = new XElement("Objects");


            Loadout loadout = exporter.GetLoadout(loadoutName);

            Console.WriteLine(loadout.name);


            XElement Object = new XElement("Object");
            //string partid = GuidUtility.GenID("jhk777gt" + shipName  );
            //string layerid = GuidUtility.GenID("ghjg557kk" + shipName  );
            string partid   = GuidUtility.GenID();
            string layerid  = GuidUtility.GenID();
            string parentid = "0";

            parentid = partid;

            Object = AddObjects(Object, ship.parts.First(), loadout, parentid, partid, layerid, paint);
            i      = 0;
            //Object = AddPrefabsFromObjectContainers(Object, ship, parentid, layerid);
            Object = AddObjectsFromObjectContainers(Object, ship.objectContainers, parentid, layerid);

            if (Object.Attribute("Name") != null)
            {
                Objects.Add(Object);
            }
            //Objects.Add(Object);

            XElement ObjectsNew = new XElement("Objects");

            foreach (XElement obj in Objects.Descendants("Object"))
            {
                XElement ObjectNew = new XElement("Object");
                //ObjectNew.Add(new XElement("Properties"));
                if (obj.Element("Properties") != null)
                {
                    ObjectNew.Add(obj.Element("Properties"));
                }
                foreach (XAttribute atr in obj.Attributes())
                {
                    ObjectNew.Add(atr);
                }
                if (obj.Element("Components") != null)
                {
                    ObjectNew.Add(obj.Element("Components"));
                }

                if (obj.Element("Points") != null)
                {
                    ObjectNew.Add(obj.Element("Points"));
                }

                if (ObjectNew.Attribute("Name") != null)
                {
                    ObjectsNew.Add(ObjectNew);
                }
            }

            Prefab.Add(ObjectsNew);
            PrefabsLibrary.Add(Prefab);
            foreach (XElement pr in prefabs)
            {
                PrefabsLibrary.Add(pr);
            }
            xml.Add(PrefabsLibrary);

            //XDocument xmlpreflib = XDocument.Load(prefablib);
            //XElement preflibel = xmlpreflib.Element("PrefabsLibrary");
            //xml.Add(preflibel);

            return(xml);
        }
        public XElement AddObjects(XElement el, Part part, Loadout loadout, string parentid, string partid, string layerid, Paint paint = null)
        {
            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" || part.partClass == "SubPartWheel")
            {
                if (i == 0)
                {
                    if (paint != null)
                    {
                        Object.Add(new XAttribute("Material", paint.material));
                    }
                }
                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));
                if (part.animatedFilename != null)
                {
                    Object.Add(new XAttribute("Geometry", part.animatedFilename));
                }
                else
                {
                    Object.Add(new XAttribute("Geometry", ""));
                }
                Object.Add(new XAttribute("Layer", "Main"));
                Object.Add(new XAttribute("Type", "GeomEntity"));
                Object.Add(new XAttribute("EntityClass", "GeomEntity"));
                Object.Add(new XAttribute("LodRatio", lodRatio));
                if (part.partClass == "SubPartWheel")
                {
                    Object.Add(new XAttribute("AttachmentType", "CharacterBone"));
                    Object.Add(new XAttribute("AttachmentTarget", part.name));
                }
                else
                {
                    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", GuidUtility.GenID(part.name+loadout.name+part.animatedFilename)));
                Component.Add(new XAttribute("guid", GuidUtility.GenID()));
                Component.Add(new XAttribute("CryXmlVersion", "2"));
                if (part.animatedFilename != null)
                {
                    Component.Add(new XAttribute("Geometry", part.animatedFilename));
                }
                else
                {
                    Component.Add(new XAttribute("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);
                i++;
            }
            if (part.partClass == "ItemPort")
            {
                ItemPort itemport = loadout.GetItemPort(part.name);
                Item     item     = exporter.GetItem(itemport.itemName, loadout.name);
                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", lodRatio));

                    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", GuidUtility.GenID(part.name + loadout.name + part.animatedFilename+ itemport.portName)));
                    Component.Add(new XAttribute("guid", GuidUtility.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, loadout.name);
                        XElement obj2  = new XElement("Object");
                        obj2.Add(new XAttribute("Name", ip.portName));
                        obj2.Add(new XAttribute("LinkedTo", partid));
                        //obj2.Add(new XAttribute("Id", GuidUtility.GenID("skjdfu"+part.name + loadout.name + part.animatedFilename + ip.portName+item2.name)));
                        obj2.Add(new XAttribute("Id", GuidUtility.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", lodRatio));

                        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", GuidUtility.GenID(part.name + loadout.name + part.animatedFilename + ip.portName)));
                        Component2.Add(new XAttribute("guid", GuidUtility.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 = GuidUtility.GenID(at.name + at.bone + part.name + loadout.name);
                        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        = GuidUtility.GenID(at.name + at.bone + part.name + loadout.name + "prefab");
                        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");
                if (pr.partClass == "ItemPort")
                {
                    ItemPort itemport = loadout.GetItemPort(part.name);
                    if (itemport.itemName != "")
                    {
                        obj = AddObjects(obj, pr, loadout, partid, GuidUtility.GenID(pr.name + itemport.itemName + loadout.name + "kjhkh" + pr.animatedFilename), layerid);
                    }
                    else
                    {
                        obj = AddObjects(obj, pr, loadout, parentid, GuidUtility.GenID(pr.name + itemport.itemName + loadout.name + "5tyht" + pr.animatedFilename), layerid);
                    }
                }
                else
                {
                    obj = AddObjects(obj, pr, loadout, partid, GuidUtility.GenID(pr.name + loadout.name + "asddf" + pr.animatedFilename), layerid);
                }
                //if (obj.Attribute("Name") != null)
                Object.Add(obj);
            }

            return(Object);
        }
        public XDocument GenerateShip(ShipDefinition ship)
        {
            XDocument          xml                = new XDocument();
            string             shipName           = ship.GetShipName();
            ShipImplementation shipImplementation = ship.GetShipImplementation();

            if (shipImplementation != null)
            {
                Paint paint = ship.GetShipPaint();
                //shipName = "AEGS_Gladius";

                string prefLibName = "";
                prefLibName = shipName;
                prefLibName = ship.GetVehicleType() + "/" + ship.GetManufacturer() + "/" + prefLibName;
                XElement PrefabsLibrary = new XElement("PrefabsLibrary");
                //PrefabsLibrary.Attribute("Name").Value = shipName+"_Ship";
                //PrefabsLibrary.Add(new XAttribute("Name", shipName + "_Ship"));
                PrefabsLibrary.Add(new XAttribute("Name", prefLibName));

                XElement Prefab   = new XElement("Prefab");
                string   prefabId = GuidUtility.GenPrefabID(prefLibName);
                //Prefab.Add(new XAttribute("Name", shipName));
                Prefab.Add(new XAttribute("Name", "Ship"));
                Prefab.Add(new XAttribute("Id", prefabId));
                // Prefab.Add(new XAttribute("Library", shipName + "_Ship"));
                Prefab.Add(new XAttribute("Library", prefLibName));

                XElement Objects = new XElement("Objects");


                Loadout loadout = ship.GetLoadout();
                //Console.WriteLine(loadout.name);


                XElement Object = new XElement("Object");
                //string partid = GuidUtility.GenID("jhk777gt" + shipName  );
                //string layerid = GuidUtility.GenID("ghjg557kk" + shipName  );
                string partid   = GuidUtility.GenID();
                string layerid  = GuidUtility.GenID();
                string parentid = "0";
                parentid = partid;

                Object = AddObjects(Object, shipImplementation.parts.First(), loadout, parentid, partid, layerid, paint);
                i      = 0;
                //Object = AddPrefabsFromObjectContainers(Object, ship, parentid, layerid);
                Object = AddObjectsFromObjectContainers(Object, shipImplementation.objectContainers, parentid, layerid);

                if (Object.Attribute("Name") != null)
                {
                    Objects.Add(Object);
                }
                //Objects.Add(Object);

                XElement ObjectsNew = new XElement("Objects");
                foreach (XElement obj in Objects.Descendants("Object"))
                {
                    XElement ObjectNew = new XElement("Object");
                    //ObjectNew.Add(new XElement("Properties"));
                    if (obj.Element("Properties") != null)
                    {
                        ObjectNew.Add(obj.Element("Properties"));
                    }
                    foreach (XAttribute atr in obj.Attributes())
                    {
                        ObjectNew.Add(atr);
                    }
                    if (obj.Element("Components") != null)
                    {
                        ObjectNew.Add(obj.Element("Components"));
                    }

                    if (obj.Element("Points") != null)
                    {
                        ObjectNew.Add(obj.Element("Points"));
                    }

                    if (ObjectNew.Attribute("Name") != null)
                    {
                        ObjectsNew.Add(ObjectNew);
                    }
                }

                Prefab.Add(ObjectsNew);
                PrefabsLibrary.Add(Prefab);
                foreach (XElement pr in prefabs)
                {
                    PrefabsLibrary.Add(pr);
                }
                xml.Add(PrefabsLibrary);

                //XDocument xmlpreflib = XDocument.Load(prefablib);
                //XElement preflibel = xmlpreflib.Element("PrefabsLibrary");
                //xml.Add(preflibel);
            }

            return(xml);
        }
        public XDocument GenerateShipModification(GenerateOptions genOptions)
        {
            string shipName         = genOptions.shipName;
            string modificationName = genOptions.modificationName;

            XDocument xml = new XDocument();

            ShipImplementation ship           = exporter.GetShipImplementation(shipName);
            Paint        paint                = ship.GetPaintByName(genOptions.paintName);
            Modification shipModification     = ship.GetModificationByName(modificationName);
            string       modificationTrueName = shipModification.trueName;
            string       loadoutName          = null;

            if (genOptions.loadoutName != null)
            {
                loadoutName = genOptions.loadoutName;
            }
            else
            {
                loadoutName = "Default_Loadout_" + modificationTrueName;
            }
            Loadout loadout = exporter.GetLoadout(loadoutName);

            Console.WriteLine(loadout.name);

            string prefLibName = "";

            if (paint != null)
            {
                prefLibName = modificationTrueName + "-" + paint.name;
            }
            else
            {
                prefLibName = modificationTrueName;
            }
            prefLibName = "ships/Variants/" + prefLibName;
            XElement PrefabsLibrary = new XElement("PrefabsLibrary");

            PrefabsLibrary.Add(new XAttribute("Name", prefLibName));
            XElement Prefab   = new XElement("Prefab");
            string   prefabId = GuidUtility.GenPrefabID(prefLibName);

            Prefab.Add(new XAttribute("Name", "Ship"));
            Prefab.Add(new XAttribute("Id", prefabId));
            Prefab.Add(new XAttribute("Library", prefLibName));

            XElement Objects  = new XElement("Objects");
            XElement Object   = new XElement("Object");
            string   partid   = GuidUtility.GenID("werw34" + shipName + modificationName + prefLibName);
            string   layerid  = GuidUtility.GenID("dsfhf555hyyh" + shipName + modificationName + prefLibName);
            string   parentid = "0";

            parentid = partid;

            if (shipModification.parts.Count != 0)
            {
                Object = AddObjects(Object, shipModification.parts.First(), loadout, parentid, partid, layerid, paint);
                Object = AddObjectsFromObjectContainers(Object, shipModification.objectContainers, parentid, layerid);
            }
            else
            {
                Object = AddObjects(Object, ship.parts.First(), loadout, parentid, partid, layerid, paint);
                Object = AddObjectsFromObjectContainers(Object, ship.objectContainers, parentid, layerid);
            }
            i = 0;


            if (Object.Attribute("Name") != null)
            {
                Objects.Add(Object);
            }

            XElement ObjectsNew = new XElement("Objects");

            foreach (XElement obj in Objects.Descendants("Object"))
            {
                XElement ObjectNew = new XElement("Object");
                if (obj.Element("Properties") != null)
                {
                    ObjectNew.Add(obj.Element("Properties"));
                }
                foreach (XAttribute atr in obj.Attributes())
                {
                    ObjectNew.Add(atr);
                }
                if (obj.Element("Components") != null)
                {
                    ObjectNew.Add(obj.Element("Components"));
                }

                if (ObjectNew.Attribute("Name") != null)
                {
                    ObjectsNew.Add(ObjectNew);
                }
            }

            Prefab.Add(ObjectsNew);
            PrefabsLibrary.Add(Prefab);
            foreach (XElement pr in prefabs)
            {
                PrefabsLibrary.Add(pr);
            }
            xml.Add(PrefabsLibrary);

            return(xml);
        }