コード例 #1
0
ファイル: BlockInfoDumper.cs プロジェクト: Aceba1/Misc-Mods
        public static int Dump()
        {
            bool RemoveSecret = !Input.GetKey((UnityEngine.KeyCode) 308);

            Console.WriteLine("Starting block dump...");

            var DUMP = new JObject
            {
                { "game_version", SKU.DisplayVersion }, // Display Version
                { "date", DateTime.Now.ToString() }     // Date of dump
            };                                          // Create DUMP, which will be outputted to a file

            var CHUNKS = new JArray();                  // Create CHUNKS array

            // Populate CHUNKS array with resource chunks
            foreach (ChunkTypes id in Enum.GetValues(typeof(ChunkTypes)))
            {
                var ITEM = new JObject()
                {
                    { "name", StringLookup.GetItemName(ObjectTypes.Chunk, (int)id) },
                    { "id", (int)id },
                    { "price", RecipeManager.inst.GetChunkPrice(id) }
                };
                GetRecipe(ITEM, (int)id, ObjectTypes.Chunk);
                CHUNKS.Add(ITEM);
            }

            DUMP.Add("data_chunks", CHUNKS); // Add CHUNKS array to DUMP

            var DATA = new JArray();         // Create DATA array
                                             // Populate DATA array with all blocks

            int NumExported = 0;

            foreach (BlockTypes id in Enum.GetValues(typeof(BlockTypes)))
            {
                var       ITEM  = new JObject(); // Create DATA entry
                TankBlock Block = ManSpawn.inst.GetBlockPrefab(id);
                if (Block == null)
                {
                    continue;                // Escape if block is empty
                }
                GameObject Base = Block.gameObject;
                if (Base == null)
                {
                    continue;               // Escape if object is empty. Redundant
                }
                int grade = ManLicenses.inst.GetBlockTier(id, true);
                if (RemoveSecret && grade > 127)
                {
                    continue;
                }
                FactionSubTypes corp     = ManSpawn.inst.GetCorporation(id);
                BlockCategories category = ManSpawn.inst.GetCategory(id);

                // Block name
                ITEM.Add("block", StringLookup.GetItemName(ObjectTypes.Block, (int)id));
                // Resource name
                ITEM.Add("resource_name", Base.name);
                // Description
                ITEM.Add("description", StringLookup.GetItemDescription(ObjectTypes.Block, (int)id));
                // ID
                ITEM.Add("id", (int)id);
                // Enum
                ITEM.Add("enum", id.ToString());
                // Mass
                ITEM.Add("mass", Block.m_DefaultMass);
                // Corp int
                ITEM.Add("corp_int", (int)corp);
                // Corp
                ITEM.Add("corp", StringLookup.GetCorporationName(corp));
                // Category int
                ITEM.Add("category_int", (int)category);
                // Category
                ITEM.Add("category", StringLookup.GetBlockCategoryName(category));
                // Grade
                ITEM.Add("grade", grade);
                // Price
                ITEM.Add("price", RecipeManager.inst.GetBlockBuyPrice(id, true));
                // Rarity
                ITEM.Add("rarity", Block.BlockRarity.ToString());
                // Rarity
                ITEM.Add("blocklimit_cost", ManBlockLimiter.inst.GetBlockCost(id));
                // Health
                var mdmg = Base.GetComponent <ModuleDamage>();
                if (mdmg) // Redundant check
                {
                    ITEM.Add("health", mdmg.maxHealth);
                    ITEM.Add("fragility", mdmg.m_DamageDetachFragility);

                    // Death Explosion
                    GetExplosionData(ITEM, mdmg.deathExplosion, "DeathExplosion");
                }
                // Damageability
                var dmgb = Block.GetComponent <Damageable>();
                if (dmgb) // Redundant check
                {
                    ITEM.Add("damageable_type", dmgb.DamageableType.ToString());
                    ITEM.Add("damageable_type_int", (int)dmgb.DamageableType);
                }
                try
                {
                    // Cells
                    ITEM.Add("cell_count", Block.filledCells.Length);
                    // APs
                    ITEM.Add("ap_count", Block.attachPoints.Length);
                }
                catch { }

                // Recipe
                GetRecipe(ITEM, (int)id);
                // FireData
                GetFireData(ITEM, Base);
                // ModuleWeapon
                GetWeaponData(ITEM, Base);
                // ModuleDrill
                GetDrillData(ITEM, Base);
                // ModuleHammer
                GetHammerData(ITEM, Base);
                // ModuleEnergyStore
                GetEnergyData(ITEM, Base);
                // ModuleFuelTank
                GetFuelData(ITEM, Base);
                // ModuleShieldGenerator
                GetShieldData(ITEM, Base);
                // ModuleHover
                GetHoverData(ITEM, Base);
                // ModuleBooster
                GetBoosterData(ITEM, Base);
                // ModuleWheels
                GetWheelData(ITEM, Base);

                // Add to DATA
                DATA.Add(ITEM);
                NumExported++;
            }

            DUMP.Add("data_blocks", DATA); // Add DATA array to DUMPwww

            System.IO.File.WriteAllText("_Export/BlockInfoDump.json", DUMP.ToString(Newtonsoft.Json.Formatting.Indented));
            return(NumExported);
        }