Example #1
0
        List <AmmoIndexEntry> Load(string entityFolder)
        {
            var index = new List <AmmoIndexEntry>();

            foreach (var entityFilename in Directory.EnumerateFiles(Path.Combine(DataRoot, entityFolder), "*.xml", SearchOption.AllDirectories))
            {
                Console.WriteLine(entityFilename);

                var parser = new ClassParser <AmmoParams>();
                var entity = parser.Parse(entityFilename);
                if (entity == null)
                {
                    continue;
                }

                var jsonFilename = Path.Combine(OutputFolder, "ammo", $"{entity.__ref.ToLower()}.json");
                var json         = JsonConvert.SerializeObject(new
                {
                    Raw = new
                    {
                        Entity = entity,
                    }
                });

                File.WriteAllText(jsonFilename, json);

                BulletProjectileParams projectiles = entity.projectileParams.BulletProjectileParams;

                var indexEntry = new AmmoIndexEntry
                {
                    className        = entity.ClassName,
                    reference        = entity.__ref,
                    damage           = Damage.FromDamageInfo(projectiles != null && projectiles.damage.Length > 0 ? projectiles.damage[0] : new DamageInfo()),
                    speed            = entity.speed,
                    range            = entity.lifetime * entity.speed,
                    detonates        = entity.projectileParams.BulletProjectileParams?.detonationParams?.ProjectileDetonationParams?.explosionParams != null,
                    detonationDamage = Damage.FromDamageInfo(entity.projectileParams.BulletProjectileParams?.detonationParams?.ProjectileDetonationParams?.explosionParams?.damage[0])
                };

                index.Add(indexEntry);
            }

            return(index);
        }
Example #2
0
        public List <ItemIndexEntry> Load()
        {
            Directory.CreateDirectory(Path.Combine(OutputFolder, "items"));

            var damageResistanceMacros = LoadDamageResistanceMacros();

            var index = new List <ItemIndexEntry>();

            index.AddRange(Load(@"Data\Libs\Foundry\Records\entities\scitem"));

            // 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
            foreach (var item in index)
            {
                var entity = ClassParser <EntityClassDefinition> .ClassByNameCache[item.className];

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

                // If it is an ammo container or if it has a magazine then load the ammo properties
                AmmoIndexEntry ammoEntry = null;
                var            ammoRef   = magazine?.Components?.SAmmoContainerComponentParams?.ammoParamsRecord ?? entity.Components?.SAmmoContainerComponentParams?.ammoParamsRecord;
                if (!String.IsNullOrEmpty(ammoRef))
                {
                    ammoEntry = Ammo.FirstOrDefault(x => x.reference == 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;
                }

                // 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);
        }