Ejemplo n.º 1
0
        public void InstallLoadout(StandardisedItemPort port, List <StandardisedLoadoutEntry> loadout)
        {
            var loadoutEntry = FindLoadoutEntry(port.PortName, loadout);

            if (String.IsNullOrEmpty(loadoutEntry?.ClassName))
            {
                return;
            }

            port.Loadout = loadoutEntry.ClassName;

            var item = entitySvc.GetByClassName(loadoutEntry.ClassName);

            if (item == null)
            {
                return;
            }

            var standardisedItem = itemBuilder.BuildItem(item);

            port.InstalledItem = standardisedItem;

            // Update the loadout with anything this item brings with it
            var newLoadout = loadoutLoader.Load(item);

            loadoutEntry.Entries.AddRange(newLoadout);

            InstallLoadout(standardisedItem.Ports, loadoutEntry.Entries);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            string scDataRoot = null;
            string outputRoot = null;
            string itemFile   = null;
            bool   shipsOnly  = false;

            var p = new OptionSet
            {
                { "scdata=", v => scDataRoot = v },
                { "input=", v => scDataRoot = v },
                { "output=", v => outputRoot = v },
                { "itemfile=", v => itemFile = v },
                { "shipsonly", v => shipsOnly = true }
            };

            var extra = p.Parse(args);

            var badArgs = false;

            if (extra.Count > 0)
            {
                badArgs = true;
            }
            else if (!String.IsNullOrEmpty(itemFile) && (!String.IsNullOrEmpty(scDataRoot) || !String.IsNullOrEmpty(outputRoot)))
            {
                badArgs = true;
            }
            else if (String.IsNullOrEmpty(itemFile) && (String.IsNullOrEmpty(scDataRoot) || String.IsNullOrEmpty(outputRoot)))
            {
                badArgs = true;
            }

            if (badArgs)
            {
                Console.WriteLine("Usage:");
                Console.WriteLine("    Loader.exe -input=<path to extracted Star Citizen data> -output=<path to JSON output folder>");
                Console.WriteLine(" or Loader.exe -itemfile=<path to an SCItem XML file>");
                Console.WriteLine();
                return;
            }

            JsonConvert.DefaultSettings = () => new JsonSerializerSettings
            {
                Formatting        = Formatting.Indented,
                NullValueHandling = NullValueHandling.Ignore
            };

            if (itemFile != null)
            {
                var entityParser = new ClassParser <scdb.Xml.Entities.EntityClassDefinition>();
                var entity       = entityParser.Parse(itemFile);
                var json         = JsonConvert.SerializeObject(entity);
                Console.WriteLine(json);
                return;
            }

            // Prep the output folder
            if (Directory.Exists(outputRoot) && !shipsOnly)
            {
                var info = new DirectoryInfo(outputRoot);
                foreach (var file in info.GetFiles())
                {
                    file.Delete();
                }
                foreach (var dir in info.GetDirectories())
                {
                    dir.Delete(true);
                }
            }
            else
            {
                Directory.CreateDirectory(outputRoot);
            }

            // A loadout loader to help with any XML loadouts we encounter while parsing entities
            var loadoutLoader = new LoadoutLoader
            {
                OutputFolder = outputRoot,
                DataRoot     = scDataRoot
            };

            // Localisation
            Console.WriteLine("Load Localisation");
            var labelLoader = new LabelsLoader
            {
                OutputFolder = outputRoot,
                DataRoot     = scDataRoot
            };
            var labels          = labelLoader.Load("english");
            var localisationSvc = new LocalisationService(labels);

            // Manufacturers
            Console.WriteLine("Load Manufacturers");
            var manufacturerLoader = new ManufacturerLoader(localisationSvc)
            {
                OutputFolder = outputRoot,
                DataRoot     = scDataRoot
            };
            var manufacturerIndex = manufacturerLoader.Load();

            // Ammunition
            Console.WriteLine("Load Ammunition");
            var ammoLoader = new AmmoLoader
            {
                OutputFolder = outputRoot,
                DataRoot     = scDataRoot
            };
            var ammoIndex = ammoLoader.Load();

            // Items
            if (!shipsOnly)
            {
                Console.WriteLine("Load Items");
                var itemLoader = new ItemLoader
                {
                    OutputFolder  = outputRoot,
                    DataRoot      = scDataRoot,
                    OnXmlLoadout  = path => loadoutLoader.Load(path),
                    Manufacturers = manufacturerIndex,
                    Ammo          = ammoIndex
                };
                itemLoader.Load();
            }

            // Ships and vehicles
            Console.WriteLine("Load Ships and Vehicles");
            var shipLoader = new ShipLoader
            {
                OutputFolder  = outputRoot,
                DataRoot      = scDataRoot,
                OnXmlLoadout  = path => loadoutLoader.Load(path),
                Manufacturers = manufacturerIndex
            };

            shipLoader.Load();

            // Prices
            if (!shipsOnly)
            {
                Console.WriteLine("Load Shops");
                var shopLoader = new ShopLoader(localisationSvc)
                {
                    OutputFolder = outputRoot,
                    DataRoot     = scDataRoot
                };
                shopLoader.Load();
            }

            // Starmap
            if (!shipsOnly)
            {
                Console.WriteLine("Load Starmap");
                var starmapLoader = new StarmapLoader(localisationSvc)
                {
                    OutputFolder = outputRoot,
                    DataRoot     = scDataRoot
                };
                starmapLoader.Load();
            }

            Console.WriteLine("Finished!");
        }
Ejemplo n.º 3
0
        public List <ItemIndexEntry> Load(string typeFilter = null)
        {
            Directory.CreateDirectory(Path.Combine(OutputFolder, "items"));
            Directory.CreateDirectory(Path.Combine(OutputFolder, "v2", "items"));

            var damageResistanceMacros = LoadDamageResistanceMacros();

            Console.WriteLine($"ItemLoader: Creating index...");
            var index = CreateIndex(typeFilter);

            // Once all the items have been loaded, we have to spin through them again looking for
            // any that use ammunition magazines so we can load the magazine and then load the ammunition it uses
            Console.WriteLine($"ItemLoader: Creating {index.Count} item files...");
            foreach (var item in index)
            {
                var entity = entitySvc.GetByClassName(item.className);

                // If uses an ammunition magazine, then load it
                EntityClassDefinition magazine = null;
                if (!String.IsNullOrEmpty(entity.Components?.SCItemWeaponComponentParams?.ammoContainerRecord))
                {
                    magazine = entitySvc.GetByReference(entity.Components.SCItemWeaponComponentParams.ammoContainerRecord);
                }

                // If it is an ammo container or if it has a magazine then load the ammo properties
                AmmoParams ammoEntry = null;
                var        ammoRef   = magazine?.Components?.SAmmoContainerComponentParams?.ammoParamsRecord ?? entity.Components?.SAmmoContainerComponentParams?.ammoParamsRecord;
                if (!String.IsNullOrEmpty(ammoRef))
                {
                    ammoEntry = ammoSvc.GetByReference(ammoRef);
                }

                DamageResistance damageResistances = null;
                if (!String.IsNullOrEmpty(entity.Components?.SCItemSuitArmorParams?.damageResistance))
                {
                    var damageMacro = damageResistanceMacros.Find(y => y.__ref == entity.Components.SCItemSuitArmorParams.damageResistance);
                    damageResistances = damageMacro?.damageResistance;
                }

                var stdItem = itemBuilder.BuildItem(entity);
                var loadout = loadoutLoader.Load(entity);
                itemInstaller.InstallLoadout(stdItem, loadout);

                stdItem.Classification = item.classification;
                item.stdItem           = stdItem;

                File.WriteAllText(Path.Combine(OutputFolder, "v2", "items", $"{entity.ClassName.ToLower()}.json"), JsonConvert.SerializeObject(stdItem));
                File.WriteAllText(Path.Combine(OutputFolder, "v2", "items", $"{entity.ClassName.ToLower()}-raw.json"), JsonConvert.SerializeObject(entity));

                // Write the JSON of this entity to its own file
                var jsonFilename = Path.Combine(OutputFolder, "items", $"{entity.ClassName.ToLower()}.json");
                var json         = JsonConvert.SerializeObject(new
                {
                    magazine = magazine,
                    ammo     = ammoEntry,
                    Raw      = new
                    {
                        Entity = entity,
                    },
                    damageResistances = damageResistances
                });
                File.WriteAllText(jsonFilename, json);
            }

            File.WriteAllText(Path.Combine(OutputFolder, "items.json"), JsonConvert.SerializeObject(index));

            // Create an index file for each different item type
            var typeIndicies = new Dictionary <string, List <ItemIndexEntry> >();

            foreach (var entry in index)
            {
                if (String.IsNullOrEmpty(entry.classification))
                {
                    continue;
                }

                var type = entry.classification.Split('.')[0];
                if (!typeIndicies.ContainsKey(type))
                {
                    typeIndicies.Add(type, new List <ItemIndexEntry>());
                }
                var typeIndex = typeIndicies[type];
                typeIndex.Add(entry);
            }
            foreach (var pair in typeIndicies)
            {
                File.WriteAllText(Path.Combine(OutputFolder, pair.Key.ToLower() + "-items.json"), JsonConvert.SerializeObject(pair.Value));
            }

            return(index);
        }