示例#1
0
        /// <summary>
        /// Registers a RecipeProto
        /// </summary>
        /// <param name="id">UNIQUE id of your recipe</param>
        /// <param name="type">Recipe type</param>
        /// <param name="time">Time in ingame ticks. How long item is being made</param>
        /// <param name="input">Array of input IDs</param>
        /// <param name="inCounts">Array of input COUNTS</param>
        /// <param name="output">Array of output IDs</param>
        /// <param name="outCounts">Array of output COUNTS</param>
        /// <param name="description">LocalizedKey of description of this item</param>
        /// <param name="techID">Tech id, which unlock this recipe</param>
        public static void registerRecipe(int id, ERecipeType type, int time, int[] input, int[] inCounts,
                                          int[] output,
                                          int[] outCounts, string description, int techID = 1)
        {
            if (output.Length > 0)
            {
                ItemProto first = items[output[0]];
                TechProto tech  = LDB.techs.Select(techID);

                RecipeProto proto = new RecipeProto
                {
                    Type         = type,
                    Handcraft    = true,
                    TimeSpend    = time,
                    Items        = input,
                    ItemCounts   = inCounts,
                    Results      = output,
                    ResultCounts = outCounts,
                    Description  = description,
                    GridIndex    = first.GridIndex,
                    IconPath     = first.IconPath,
                    Name         = first.Name + "Recipe",
                    preTech      = tech,
                    ID           = id
                };

                LDBTool.PreAddProto(ProtoType.Recipe, proto);
                recipes.Add(id, proto);
            }
        }
        public override void ProcessPacket(GameHistoryUnlockTechPacket packet, NebulaConnection conn)
        {
            Log.Info($"Unlocking tech (ID: {packet.TechId})");
            using (Multiplayer.Session.History.IsIncomingRequest.On())
            {
                // Let the default method give back the items
                GameMain.mainPlayer.mecha.lab.ManageTakeback();

                // Update techState
                TechProto techProto = LDB.techs.Select(packet.TechId);
                TechState techState = GameMain.history.techStates[packet.TechId];
                if (techState.curLevel >= techState.maxLevel)
                {
                    techState.curLevel     = techState.maxLevel;
                    techState.hashUploaded = techState.hashNeeded;
                    techState.unlocked     = true;
                }
                else
                {
                    techState.curLevel++;
                    techState.hashUploaded = 0L;
                    techState.hashNeeded   = techProto.GetHashNeeded(techState.curLevel);
                }
                // UnlockTech() unlocks tech to techState.maxLevel, so change it to curLevel temporarily
                int maxLevl = techState.maxLevel;
                techState.maxLevel = techState.curLevel;
                GameMain.history.techStates[packet.TechId] = techState;
                GameMain.history.UnlockTech(packet.TechId);
                techState.maxLevel = maxLevl;
                GameMain.history.techStates[packet.TechId] = techState;
                GameMain.history.DequeueTech();
            }
        }
示例#3
0
        private static void CalculateCarrierCapacity()
        {
            int logisticDroneCarries = 25 * GigaStationsPlugin.droneCapacityMultiplier;
            int logisticShipCarries  = 200 * GigaStationsPlugin.vesselCapacityMultiplier;

            void Accumulate(int type, double value, int levels)
            {
                int num = (int)Math.Round(value);

                if (type == 18)
                {
                    logisticDroneCarries += num * GigaStationsPlugin.droneCapacityMultiplier * levels;
                }
                else if (type == 19)
                {
                    logisticShipCarries += num * GigaStationsPlugin.vesselCapacityMultiplier * levels;
                }
            }

            int currentLevel = 0;

            for (int i = 3501; i <= 3510; i++)
            {
                if (GameMain.history.TechUnlocked(i))
                {
                    TechProto tech = LDB.techs.Select(i);

                    currentLevel = GameMain.history.techStates[i].curLevel;
                    int levelMul = 1;

                    if (tech.Level != tech.MaxLevel)
                    {
                        levelMul = currentLevel - tech.Level + 1;
                    }
                    for (int j = 0; j < tech.UnlockFunctions.Length; j++)
                    {
                        Accumulate(tech.UnlockFunctions[j], tech.UnlockValues[j], levelMul);
                    }
                }
            }

            GigaStationsPlugin.logger.LogInfo($"\nUnlocked Logistic carrier capacity Level {currentLevel}\nSetting Carrier Capacity Multipliers from settings...");
            GigaStationsPlugin.logger.LogInfo($"\nLevel {currentLevel}\nSetting Vessels Capacity: {logisticShipCarries}\nSetting Drones Capacity: {logisticDroneCarries}");

            GameMain.history.logisticDroneCarries = logisticDroneCarries;
            GameMain.history.logisticShipCarries  = logisticShipCarries;
        }
示例#4
0
        //Post register fixups
        private static void onPostAdd()
        {
            foreach (var kv in models)
            {
                kv.Value.Preload();
                PrefabDesc pdesc = kv.Value.prefabDesc;

                Material[] mats = pdesc.materials;
                for (int i = 0; i < pdesc.lodCount; i++)
                {
                    for (int j = 0; j < pdesc.lodMaterials[i].Length; j++)
                    {
                        pdesc.lodMaterials[i][j] = mats[j];
                    }
                }

                LDB.models.modelArray[kv.Value.ID] = kv.Value;
            }

            foreach (var kv in items)
            {
                kv.Value.Preload(kv.Value.index);
            }

            foreach (var kv in recipes)
            {
                kv.Value.Preload(kv.Value.index);
            }

            foreach (var kv in techs)
            {
                kv.Value.Preload();
                kv.Value.Preload2();
            }

            foreach (var kv in techUpdateList)
            {
                TechProto OldTech = LDB.techs.Select(kv.Key);
                OldTech.postTechArray = OldTech.postTechArray.AddToArray(kv.Value);
            }

            onLoadingFinished?.Invoke();

            LogSource.LogInfo("Post loading is complete!");
        }
示例#5
0
        /// <summary>
        /// Registers a TechProto for a technology.
        /// Total amount of each jello is calculated like this: N = H*C/3600, where H - total hash count, C - items per minute of jello.
        /// </summary>
        /// <param name="id"> UNIQUE ID of the technology</param>
        /// <param name="name">LocalizedKey of name of the tech</param>
        /// <param name="description">LocalizedKey of description of the tech</param>
        /// <param name="conclusion">LocalizedKey of conclusion of the tech upon completion</param>
        /// <param name="PreTechs">Techs which lead to this tech</param>
        /// <param name="Jellos">Items required to research the tech</param>
        /// <param name="ItemPoints">Amount of items per minute required to research the tech</param>
        /// <param name="HashNeeded">Number of hashes needed required to research the tech</param>
        /// <param name="UnlockRecipes">Once the technology has completed, what recipes are unlocked</param>
        /// <param name="position">Vector2 position of the technology on the technology screen</param>

        public static TechProto registerTech(int id, String name, String description, String conclusion, int[] PreTechs, int[] Jellos, int[] ItemPoints, long HashNeeded,
                                             int[] UnlockRecipes, Vector2 position)

        {
            RecipeProto first = recipes.ContainsKey(UnlockRecipes[0]) ? recipes[UnlockRecipes[0]] : LDB.recipes.Select(UnlockRecipes[0]);

            bool isLabTech = Jellos.Any(itemId => LabComponent.matrixIds.Contains(itemId));


            TechProto proto = new TechProto
            {
                ID               = id,
                Name             = name,
                Desc             = description,
                Published        = true,
                Conclusion       = conclusion,
                IconPath         = first.IconPath,
                IsLabTech        = isLabTech,
                PreTechs         = PreTechs,
                Items            = Jellos,
                ItemPoints       = ItemPoints,
                HashNeeded       = HashNeeded,
                UnlockRecipes    = UnlockRecipes,
                AddItems         = new int[] { }, // what items to gift after research is done
                AddItemCounts    = new int[] { },
                Position         = position,
                PreTechsImplicit = new int[] { }, //Those funky implicit requirements
                UnlockFunctions  = new int[] { }, //Upgrades.
                UnlockValues     = new double[] { },
            };

            for (int i = 0; i < proto.PreTechs.Length; i++)
            {
                TechProto OldTech = LDB.techs.Select(PreTechs[i]);
                techUpdateList.Add(OldTech, proto); //OldTech = Tech whose PostTechArray needs editing
            }

            LDBTool.PreAddProto(ProtoType.Tech, proto);
            techs.Add(id, proto);

            return(proto);
        }
示例#6
0
        /// <summary>
        /// Registers a TechProto for a technology.
        /// Total amount of each jello is calculated like this: N = H*C/3600, where H - total hash count, C - items per minute of jello.
        /// </summary>
        /// <param name="id"> UNIQUE ID of the technology. Note that if id > 2000 tech will be on upgrades page.</param>
        /// <param name="name">LocalizedKey of name of the tech</param>
        /// <param name="description">LocalizedKey of description of the tech</param>
        /// <param name="conclusion">LocalizedKey of conclusion of the tech upon completion</param>
        /// <param name="iconPath">Path to icon, starting from assets folder of your unity project</param>
        /// <param name="preTechs">Techs which lead to this tech</param>
        /// <param name="jellos">Items required to research the tech</param>
        /// <param name="jelloRate">Amount of items per minute required to research the tech</param>
        /// <param name="hashNeeded">Number of hashes needed required to research the tech</param>
        /// <param name="unlockRecipes">Once the technology has completed, what recipes are unlocked</param>
        /// <param name="position">Vector2 position of the technology on the technology screen</param>
        public static TechProto registerTech(int id, string name, string description, string conclusion,
                                             string iconPath, int[] preTechs, int[] jellos, int[] jelloRate, long hashNeeded,
                                             int[] unlockRecipes, Vector2 position)

        {
            bool isLabTech = jellos.Any(itemId => LabComponent.matrixIds.Contains(itemId));


            TechProto proto = new TechProto
            {
                ID               = id,
                Name             = name,
                Desc             = description,
                Published        = true,
                Conclusion       = conclusion,
                IconPath         = iconPath,
                IsLabTech        = isLabTech,
                PreTechs         = preTechs,
                Items            = jellos,
                ItemPoints       = jelloRate,
                HashNeeded       = hashNeeded,
                UnlockRecipes    = unlockRecipes,
                AddItems         = new int[] { }, // what items to gift after research is done
                AddItemCounts    = new int[] { },
                Position         = position,
                PreTechsImplicit = new int[] { }, //Those funky implicit requirements
                UnlockFunctions  = new int[] { }, //Upgrades.
                UnlockValues     = new double[] { },
            };

            foreach (int tech in preTechs)
            {
                //Do not do LDB.techs.Select here, proto could be not added yet.
                techUpdateList.Add(tech, proto);
            }

            LDBTool.PreAddProto(ProtoType.Tech, proto);
            techs.Add(id, proto);

            return(proto);
        }
示例#7
0
        public void ProcessPacket(GameHistoryTechRefundPacket packet, NebulaConnection conn)
        {
            //only refund if we have contributed
            if (packet.TechHashedContributed > 0)
            {
                Log.Info($"ProcessPacket: contributed {packet.TechHashedContributed} hashes to itemid {packet.TechIdContributed}");
                TechProto techProto = LDB.techs.Select(packet.TechIdContributed);
                int[]     items     = techProto.Items;
                int[]     array     = techProto.ItemPoints;

                //client should have the same research queued, seek currently needed itemIds and re-add points that were contributed
                for (int i = 0; i < array.Length; i++)
                {
                    int itemId           = items[i];
                    int contributedItems = (int)packet.TechHashedContributed * array[i];
                    GameMain.data.mainPlayer.mecha.lab.itemPoints.Alter(itemId, contributedItems);
                }
                //let the default method give back the items
                GameMain.mainPlayer.mecha.lab.ManageTakeback();
            }
        }
        public override void ProcessPacket(GameHistoryTechRefundPacket packet, NebulaConnection conn)
        {
            // TODO: TRY TO MERGE THESE BETTER

            if (IsHost)
            {
                //only refund if we have contributed
                if (packet.TechHashedContributed > 0)
                {
                    //client should have the same research queued, seek currently needed itemIds and re-add points that were contributed
                    ItemBundle itemPoints = GameMain.data.mainPlayer.mecha.lab.itemPoints;
                    foreach (KeyValuePair<int, int> item in itemPoints.items)
                    {
                        itemPoints.Alter(item.Key, (int)packet.TechHashedContributed * 3600);
                    }
                    //let the default method give back the items
                    GameMain.mainPlayer.mecha.lab.ManageTakeback();
                }
            }
            else
            {
                //only refund if we have contributed
                if (packet.TechHashedContributed > 0)
                {
                    TechProto techProto = LDB.techs.Select(packet.TechIdContributed);
                    int[] items = techProto.Items;
                    int[] array = techProto.ItemPoints;

                    //client should have the same research queued, seek currently needed itemIds and re-add points that were contributed
                    for (int i = 0; i < array.Length; i++)
                    {
                        int itemId = items[i];
                        int contributedItems = (int)packet.TechHashedContributed * array[i];
                        GameMain.data.mainPlayer.mecha.lab.itemPoints.Alter(itemId, contributedItems);
                    }
                    //let the default method give back the items
                    GameMain.mainPlayer.mecha.lab.ManageTakeback();
                }
            }
        }
示例#9
0
        /// <summary>
        /// Registers a RecipeProto
        /// </summary>
        /// <param name="id">UNIQUE id of your recipe</param>
        /// <param name="type">Recipe type</param>
        /// <param name="time">Time in ingame ticks. How long item is being made</param>
        /// <param name="input">Array of input IDs</param>
        /// <param name="inCounts">Array of input COUNTS</param>
        /// <param name="output">Array of output IDs</param>
        /// <param name="outCounts">Array of output COUNTS</param>
        /// <param name="description">LocalizedKey of description of this item</param>
        /// <param name="techID">Tech id, which unlock this recipe</param>
        public static RecipeProto registerRecipe(int id, ERecipeType type, int time, int[] input, int[] inCounts,
                                                 int[] output,
                                                 int[] outCounts, string description, int techID = 0)
        {
            if (output.Length > 0)
            {
                ItemProto first = items.ContainsKey(output[0]) ? items[output[0]] : LDB.items.Select(output[0]);

                TechProto tech = null;
                if (techID != 0 && LDB.techs.Exist(techID))
                {
                    tech = LDB.techs.Select(techID);
                }

                RecipeProto proto = new RecipeProto
                {
                    Type         = type,
                    Handcraft    = true,
                    TimeSpend    = time,
                    Items        = input,
                    ItemCounts   = inCounts,
                    Results      = output,
                    ResultCounts = outCounts,
                    Description  = description,
                    GridIndex    = first.GridIndex,
                    IconPath     = first.IconPath,
                    Name         = first.Name + "Recipe",
                    preTech      = tech,
                    ID           = id
                };

                LDBTool.PreAddProto(ProtoType.Recipe, proto);
                recipes.Add(id, proto);

                return(proto);
            }

            throw new ArgumentException("Output array must not be empty");
        }
示例#10
0
        private static void UnlockTechRecursive(int techId, GameHistoryData history)
        {
            TechState state = history.TechState(techId);
            TechProto proto = LDB.techs.Select(techId);

            foreach (var techReq in proto.PreTechs)
            {
                if (!history.TechState(techReq).unlocked)
                {
                    UnlockTechRecursive(techReq, history);
                }
            }
            foreach (var techReq in proto.PreTechsImplicit)
            {
                if (!history.TechState(techReq).unlocked)
                {
                    UnlockTechRecursive(techReq, history);
                }
            }
            foreach (var itemReq in proto.itemArray)
            {
                if (itemReq.preTech is not null && !history.TechState(itemReq.preTech.ID).unlocked)
                {
                    UnlockTechRecursive(itemReq.preTech.ID, history);
                }
            }

            int current = state.curLevel;

            for (; current < state.maxLevel; current++)
            {
                for (int j = 0; j < proto.UnlockFunctions.Length; j++)
                {
                    history.UnlockTechFunction(proto.UnlockFunctions[j], proto.UnlockValues[j], current);
                }
            }

            history.UnlockTech(techId);
        }
示例#11
0
            public static void Postfix(TechProto __instance)
            {
                var name = DSP_RecipeDumper.Translate.Get("tech" + __instance.ID);

                DSP_RecipeDumper.Logger.Log("[tech." + name + "]");
                DSP_RecipeDumper.Logger.Log("name = \'" + __instance.name + "\'");
                DSP_RecipeDumper.Logger.Log("description = '''" + __instance.description.Trim() + "'''");
                DSP_RecipeDumper.Logger.Log("isLabTech = " + __instance.IsLabTech.ToString().ToLower());
                DSP_RecipeDumper.Logger.Log("hashNeeded = " + __instance.HashNeeded);
                DSP_RecipeDumper.Logger.Log("iconPath = \'" + __instance.IconPath + "\'");
                if (__instance.PreTechs.Length > 0)
                {
                    DSP_RecipeDumper.Logger.Log("preTechs = [");
                    for (int i = 0; i < __instance.PreTechs.Length; i++)
                    {
                        DSP_RecipeDumper.Logger.Log("\'" + DSP_RecipeDumper.Translate.Get("tech" + __instance.PreTechs[i]) + "\', ");
                    }
                    DSP_RecipeDumper.Logger.Log("]");
                }
                if (__instance.Items.Length > 0)
                {
                    DSP_RecipeDumper.Logger.Log("[tech." + name + ".items]");
                    for (int i = 0; i < __instance.Items.Length; i++)
                    {
                        DSP_RecipeDumper.Logger.Log(DSP_RecipeDumper.Translate.Get("item" + __instance.Items[i]) + " = " + __instance.ItemPoints[i]);
                    }
                }
                if (__instance.AddItems.Length > 0)
                {
                    DSP_RecipeDumper.Logger.Log("[tech." + name + ".addItems]");
                    for (int i = 0; i < __instance.AddItems.Length; i++)
                    {
                        DSP_RecipeDumper.Logger.Log(DSP_RecipeDumper.Translate.Get("item" + __instance.AddItems[i]) + " = " + __instance.AddItemCounts[i]);
                    }
                }
            }
示例#12
0
 public static string GetSignalDisplayName(int signalId)
 {
     if (signalId < 1000)
     {
         SignalProto signal = LDB.signals.Select(signalId);
         return(signal.name);
         //return $"signal-{signalId}";
     }
     if (signalId < 20000)
     {
         ItemProto proto = LDB.items.Select(signalId);
         return(proto.name);
     }
     if (signalId < 40000)
     {
         RecipeProto proto = LDB.recipes.Select(signalId - 20000);
         return(proto.name);
     }
     else
     {
         TechProto proto = LDB.techs.Select(signalId - 40000);
         return(proto.name);
     }
 }
示例#13
0
        public void AddSmelterMk2Data()
        {
            var smelter  = LDB.items.Select(2302);
            var smelterr = LDB.recipes.Select(56);

            // Copy the Protos to a new Storage Mk III building
            ItemProto   smelterMk2  = smelter.Copy();
            RecipeProto smelterMk2r = smelterr.Copy();

            Traverse.Create(smelterMk2).Field("_iconSprite").SetValue(smelter.iconSprite);
            Traverse.Create(smelterMk2r).Field("_iconSprite").SetValue(smelterr.iconSprite);

            smelterMk2r.ID          = 10001;
            smelterMk2r.Name        = "Smelter MK. II";
            smelterMk2r.name        = "Smelter MK. II".Translate();
            smelterMk2r.Description = "1.5x the speed of a Smelter MK. I";
            smelterMk2r.description = "1.5x the speed of a Smelter MK. I".Translate();
            smelterMk2r.Items       = new int[] { 2302, 1107, 1303, 1202 }; // The items required to craft it (Smelter, titanium alloy, processor, magnetic coil)
            //smelterMk2r.Items = new int[] { 1001 };   // The items required to craft it
            smelterMk2r.ItemCounts = new int[] { 1, 4, 4, 8 };
            //smelterMk2r.ItemCounts = new int[] { 1 };
            smelterMk2r.Results    = new int[] { 10001 }; // The result (Smelter MK 2)
            smelterMk2r.GridIndex  = 2405;                // Where the recipe is located on the replicator. Format xyzz where x is the page, y is the row, and zz is the column
            smelterMk2r.SID        = smelterMk2r.GridIndex.ToString();
            smelterMk2r.sid        = smelterMk2r.GridIndex.ToString();
            smelterMk2.Name        = "Smelter MK. II";
            smelterMk2.name        = "Smelter MK. II".Translate();
            smelterMk2.Description = "1.5x the speed of a Smelter MK. I";
            smelterMk2.description = "1.5x the speed of a Smelter MK. I".Translate();
            smelterMk2.ID          = 10001;
            smelterMk2.makes       = new List <RecipeProto>();
            smelterMk2.BuildIndex  = 508;
            smelterMk2.GridIndex   = smelterMk2r.GridIndex;
            smelterMk2.handcraft   = smelterMk2r;
            smelterMk2.maincraft   = smelterMk2r;
            smelterMk2.handcrafts  = new List <RecipeProto>()
            {
                smelterMk2r
            };
            smelterMk2.recipes = new List <RecipeProto>()
            {
                smelterMk2r
            };
            smelterMk2.prefabDesc                     = smelter.prefabDesc.Copy();
            smelterMk2.prefabDesc.modelIndex          = smelterMk2.ModelIndex;
            smelterMk2.prefabDesc.isAssembler         = true;
            smelterMk2.prefabDesc.assemblerSpeed      = 15000; // default is 10000
            smelterMk2.prefabDesc.assemblerRecipeType = ERecipeType.Smelt;
            smelterMk2.prefabDesc.idleEnergyPerTick   = 250;   // desired watts / 60
            smelterMk2.prefabDesc.workEnergyPerTick   = 10667; // desired watts / 60
            smelterMk2.Grade     = 2;
            smelterMk2.Upgrades  = new int[] { 2302, 10001, 10002 };
            smelterMk2.StackSize = 50;

            var processor  = LDB.techs.Select(1302);
            var metallugry = LDB.techs.Select(1401);

            TechProto mk2 = processor.Copy();

            Traverse.Create(mk2).Field("_iconSprite").SetValue(metallugry.iconSprite);

            mk2.name             = "Improved Metallurgy";
            mk2.Name             = "Improved Metallurgy";
            mk2.ID               = 505;
            mk2.SID              = "";
            mk2.sid              = "";
            mk2.Desc             = "Advances in computer components allow you to smelt items faster";
            mk2.description      = "Advances in computer components allow you to smelt items faster";
            mk2.Conclusion       = "";   // the message that appears when you unlock
            mk2.Published        = true; // false = accelerants
            mk2.Level            = 0;
            mk2.MaxLevel         = 0;
            mk2.Position         = new Vector2(33f, -4.75f);
            mk2.PreTechsImplicit = new int[] { 1401 };
            mk2.postTechArray    = new TechProto[] { };

            // I have no f*****g clue how exactly the amount of items is calculated, but this works so I'm sticking with it
            // What I did for now is just take the values for High-speed processing and manipulate them.
            // So the total blue for High-speed is 600, I wanted 800 for this research. 800 / 600 * 108000 (the HashNeeded for high-speed) = 144000
            // Set the items to blue and red jelly
            mk2.Items     = new int[] { 6001, 6002 };
            mk2.itemArray = new ItemProto[] { LDB.items.Select(6001), LDB.items.Select(6002) };
            // Time the labs take to use an item?
            mk2.ItemPoints = new int[] { 20, 10 };
            // Total hash
            mk2.HashNeeded = 144000;

            processor.postTechArray = new TechProto[] { LDB.techs.Select(1202), LDB.techs.Select(1312), mk2 };

            // Load the required technology to access it
            mk2.unlockRecipeArray = new RecipeProto[] { };
            mk2.UnlockRecipes     = new int[] { };
            smelterMk2r.preTech   = mk2;  // Set the required technology to be able to access the recipe

            LDBTool.PostAddProto(ProtoType.Tech, mk2);
            LDBTool.PostAddProto(ProtoType.Recipe, smelterMk2r);
            LDBTool.PostAddProto(ProtoType.Item, smelterMk2);
        }
示例#14
0
        public static void ParallelizeFactoryGameTick(ILContext il)
        {
            ILCursor c = new ILCursor(il);

            int forIndex     = 3;
            var factoriesFld = typeof(GameData).GetField(nameof(GameData.factories), BindingFlags.Public | BindingFlags.Instance);

            Func <Instruction, bool>[] searchArray = new Func <Instruction, bool>[]
            {
                x => x.MatchLdcI4(0),
                x => x.MatchStloc(out forIndex),
                x => x.MatchBr(out _),
                x => x.MatchLdarg(0),
                x => x.MatchLdfld(factoriesFld),
                x => x.MatchLdloc(forIndex),
                x => x.MatchLdelemRef(),
                x => x.MatchBrfalse(out _),
                x => x.MatchLdarg(0),
                x => x.MatchLdfld(factoriesFld),
                x => x.MatchLdloc(forIndex),
                x => x.MatchLdelemRef(),
                x => x.MatchLdarg(1),
                x => x.MatchCallOrCallvirt(typeof(PlanetFactory).GetMethod(nameof(PlanetFactory.GameTick), BindingFlags.Public | BindingFlags.Instance)),
                x => x.MatchLdloc(forIndex),
                x => x.MatchLdcI4(1),
                x => x.MatchAdd(),
                x => x.MatchStloc(forIndex),
                x => x.MatchLdloc(forIndex),
                x => x.MatchLdarg(0),
                x => x.MatchLdfld(typeof(GameData).GetField(nameof(GameData.factoryCount), BindingFlags.Public | BindingFlags.Instance)),
                x => x.MatchBlt(out _)
            };

            c.GotoNext(MoveType.Before, searchArray);

            var retLabel = c.MarkLabel();

            c.Index -= 1;

            c.Emit(OpCodes.Ldarg_0);
            c.Emit(OpCodes.Ldarg_1);

            c.EmitDelegate <Func <GameData, long, bool> >((data, time) =>
            {
                bool flag           = false;
                int currentTech     = data.history.currentTech;
                TechProto techProto = LDB.techs.Select(currentTech);
                TechState techState = default(TechState);
                if (currentTech > 0 && techProto != null && techProto.IsLabTech && GameMain.history.techStates.ContainsKey(currentTech))
                {
                    techState = data.history.techStates[currentTech];
                    flag      = true;
                }
                if (flag && Math.Abs(techState.hashUploaded - techState.hashNeeded) < 7200L)
                {
                    return(true);
                }
                else
                {
                    Parallel.ForEach(data.factories, (factory) => { if (factory is not null)
                                                                    {
                                                                        factory.GameTick(time);
                                                                    }
                                     });

                    return(false);
                }
            });

            c.Index += searchArray.Length;
            var branchLabel = c.MarkLabel();

            c.GotoLabel(retLabel, MoveType.Before);

            c.Emit(OpCodes.Brfalse, branchLabel);
        }
示例#15
0
        public void AddSmelterMk3Data()
        {
            var smelter  = LDB.items.Select(2302);
            var smelterr = LDB.recipes.Select(56);

            // Copy the Protos to a new Storage Mk III building
            ItemProto   smelterMk3  = smelter.Copy();
            RecipeProto smelterMk3r = smelterr.Copy();

            Traverse.Create(smelterMk3).Field("_iconSprite").SetValue(smelter.iconSprite);
            Traverse.Create(smelterMk3r).Field("_iconSprite").SetValue(smelterr.iconSprite);

            smelterMk3r.ID          = 10002;
            smelterMk3r.Name        = "Smelter MK. III";
            smelterMk3r.name        = "Smelter MK. III".Translate();
            smelterMk3r.Description = "2x the speed of a Smelter MK. I";
            smelterMk3r.description = "2x the speed of a Smelter MK. I".Translate();
            smelterMk3r.Items       = new int[] { 10001, 1206, 1305, 1202 }; // The items required to craft it
            //smelterMk3r.Items = new int[] { 1001 };
            smelterMk3r.ItemCounts = new int[] { 1, 8, 2, 20 };
            //smelterMk3r.ItemCounts = new int[] { 1 };
            smelterMk3r.Results    = new int[] { 10002 };
            smelterMk3r.GridIndex  = 2406;    // Where the recipe is located on the replicator. Format xyzz where x is the page, y is the row, and zz is the column
            smelterMk3r.SID        = smelterMk3r.GridIndex.ToString();
            smelterMk3r.sid        = smelterMk3r.GridIndex.ToString();
            smelterMk3.Name        = "Smelter MK. III";
            smelterMk3.name        = "Smelter MK. III".Translate();
            smelterMk3.Description = "2x the speed of a Smelter MK. I";
            smelterMk3.description = "2x the speed of a Smelter MK. I".Translate();
            smelterMk3.ID          = 10002;
            smelterMk3.makes       = new List <RecipeProto>();
            smelterMk3.BuildIndex  = 10002;
            smelterMk3.GridIndex   = smelterMk3r.GridIndex;
            smelterMk3.handcraft   = smelterMk3r;
            smelterMk3.maincraft   = smelterMk3r;
            smelterMk3.handcrafts  = new List <RecipeProto>()
            {
                smelterMk3r
            };
            smelterMk3.recipes = new List <RecipeProto>()
            {
                smelterMk3r
            };
            smelterMk3.prefabDesc                     = smelter.prefabDesc.Copy();
            smelterMk3.prefabDesc.modelIndex          = smelterMk3.ModelIndex;
            smelterMk3.prefabDesc.isAssembler         = true;
            smelterMk3.prefabDesc.assemblerSpeed      = 20000;
            smelterMk3.prefabDesc.assemblerRecipeType = ERecipeType.Smelt;
            smelterMk3.prefabDesc.idleEnergyPerTick   = 300;   // desired watts / 60
            smelterMk3.prefabDesc.workEnergyPerTick   = 15000; // desired watts / 60
            smelterMk3.Grade     = 3;
            smelterMk3.Upgrades  = new int[] { 2302, 10001, 10002 };
            smelterMk3.StackSize = 50;

            var quantum    = LDB.techs.Select(1303);
            var metallurgy = LDB.techs.Select(1401);

            TechProto mk3 = quantum.Copy();

            Traverse.Create(mk3).Field("_iconSprite").SetValue(metallurgy.iconSprite);

            mk3.name             = "Quantum Metallurgy";
            mk3.Name             = "Quantum Metallurgy";
            mk3.ID               = 506;
            mk3.SID              = "";
            mk3.sid              = "";
            mk3.Desc             = "Quantum mechanics can be utilised to smelt at super speeds";
            mk3.description      = "Quantum mechanics can be utilised to smelt at super speeds";
            mk3.Conclusion       = "";
            mk3.Published        = true;
            mk3.Level            = 0;
            mk3.MaxLevel         = 0;
            mk3.Position         = new Vector2(49f, -15f);
            mk3.PreTechsImplicit = new int[] { };
            mk3.postTechArray    = new TechProto[] { };
            mk3.PreTechsImplicit = new int[] { 505 };
            mk3.PreTechs         = new int[] { 1303 };
            mk3.Items            = new int[] { 6001, 6002, 6003, 6004 };
            mk3.itemArray        = new ItemProto[] { LDB.items.Select(6001), LDB.items.Select(6002), LDB.items.Select(6003), LDB.items.Select(6004) };
            mk3.ItemPoints       = new int[] { 10, 10, 10, 10 };
            mk3.HashNeeded       = 432000;

            quantum.postTechArray = new TechProto[] { LDB.techs.Select(1705), LDB.techs.Select(1203), mk3 };

            // Load the required technology to access it
            mk3.unlockRecipeArray = new RecipeProto[] { };
            mk3.UnlockRecipes     = new int[] { };
            smelterMk3r.preTech   = mk3;  // Set the required technology to be able to access the recipe

            LDBTool.PostAddProto(ProtoType.Tech, mk3);
            LDBTool.PostAddProto(ProtoType.Recipe, smelterMk3r);
            LDBTool.PostAddProto(ProtoType.Item, smelterMk3);
        }