示例#1
0
        private static bool TryInsertItem(ref MinerComponent __instance, PlanetFactory factory, int slotId)
        {
            int insertTarget = GetInsertTarget(__instance, slotId);

            if (insertTarget <= 0)
            {
                return(false);
            }

            if (__instance.productCount > 0)
            {
                if (!factory.InsertInto(insertTarget, 0, __instance.productId))
                {
                    return(false);
                }

                __instance.productCount--;
                if (__instance.productCount == 0)
                {
                    __instance.productId = 0;
                }
                return(false);
            }

            __instance.lastUsedPort = slotId;
            return(true);
        }
示例#2
0
        public static bool InternalUpdatePatch(ref MinerComponent __instance, ref uint __result, ref PlanetFactory factory, ref VeinData[] veinPool, float power, ref float miningRate, ref float miningSpeed, ref int[] productRegister)
        {
            if (ActiveCustomizeRate.Value)
            {
                miningRate = CustomRate.Value;
            }
            if (power < 0.1f)
            {
                return(true);
            }
            //var _this = __instance;
            int gmProtoId = factory.entityPool[__instance.entityId].protoId;

            //如果是原始的采矿机,执行原始函数
            if (gmProtoId != 9446 && gmProtoId != 9447 && gmProtoId != 9448)
            {
                return(true);
            }
            else//否则是新增的采矿机
            {
                //根据采矿及类型决定熔炼产物
                Dictionary <int, int> mapDict;
                if (gmProtoId == 9446)
                {
                    mapDict = ProductMapA;
                }
                else if (gmProtoId == 9447)
                {
                    mapDict = ProductMapB;
                }
                else
                {
                    mapDict = ProductMapC;
                }

                __result = 0U;
                if (__instance.type == EMinerType.Vein)
                {
                    if (__instance.veinCount > 0)
                    {
                        int num1gm = __instance.veins[__instance.currentVeinIndex];
                        Assert.Positive(num1gm);
                        int oriid1  = veinPool[num1gm].productId;
                        int outid1  = oriid1;
                        int cratio1 = 1;
                        if (mapDict.ContainsKey(oriid1) && SmelterRatio.ContainsKey(mapDict[oriid1]))
                        {
                            outid1  = mapDict[oriid1];
                            cratio1 = SmelterRatio[mapDict[oriid1]];
                        }

                        if (__instance.time <= __instance.period)
                        {
                            __instance.time += (int)(power * (float)__instance.speed * miningSpeed * (float)__instance.veinCount / (float)cratio1);
                            __result         = 1U;
                        }
                        if (__instance.time >= __instance.period)
                        {
                            int num = __instance.veins[__instance.currentVeinIndex];
                            Assert.Positive(num);
                            if (veinPool[num].id == 0)
                            {
                                __instance.RemoveVeinFromArray(__instance.currentVeinIndex);
                                __instance.GetMinimumVeinAmount(factory, veinPool);
                                if (__instance.veinCount > 1)
                                {
                                    __instance.currentVeinIndex %= __instance.veinCount;
                                }
                                else
                                {
                                    __instance.currentVeinIndex = 0;
                                }
                                __instance.time += (int)(power * (float)__instance.speed * miningSpeed * (float)__instance.veinCount / (float)cratio1);

                                __result = 0U;
                                return(false);
                            }
                            //此处修改产物
                            int OriId        = veinPool[num].productId;
                            int OutputId     = OriId;
                            int ConsumeRatio = 1;

                            if (mapDict.ContainsKey(OriId) && SmelterRatio.ContainsKey(mapDict[OriId]))
                            {
                                OutputId     = mapDict[OriId];
                                ConsumeRatio = SmelterRatio[mapDict[OriId]];
                            }


                            if (__instance.productCount < 50 && (__instance.productId == 0 || __instance.productId == OutputId || __instance.productId == OriId))
                            {
                                __instance.productId = OutputId;
                                __instance.time     -= __instance.period;
                                if (veinPool[num].amount > 0)
                                {
                                    __instance.productCount++;
                                    productRegister[__instance.productId]++;

                                    for (int igm = 0; igm < ConsumeRatio; igm++)//一次产物输出采矿采几次
                                    {
                                        bool flag = true;
                                        if (miningRate < 0.99999f)
                                        {
                                            __instance.seed = (uint)((ulong)(__instance.seed % 2147483646U + 1U) * 48271UL % 2147483647UL) - 1U;
                                            flag            = (__instance.seed / 2147483646.0 < (double)miningRate);
                                        }
                                        if (flag)
                                        {
                                            int num2 = num;
                                            veinPool[num2].amount = veinPool[num2].amount - 1;
                                            if (veinPool[num].amount < __instance.minimumVeinAmount)
                                            {
                                                __instance.minimumVeinAmount = veinPool[num].amount;
                                            }
                                            factory.planet.veinAmounts[(int)veinPool[num].type] -= 1L;
                                            PlanetData.VeinGroup[] veinGroups = factory.planet.veinGroups;
                                            short groupIndex = veinPool[num].groupIndex;
                                            veinGroups[(int)groupIndex].amount = veinGroups[(int)groupIndex].amount - 1L;
                                            factory.veinAnimPool[num].time     = ((veinPool[num].amount < 20000) ? (1f - (float)veinPool[num].amount * 5E-05f) : 0f);
                                            if (veinPool[num].amount <= 0)
                                            {
                                                PlanetData.VeinGroup[] veinGroups2 = factory.planet.veinGroups;
                                                short groupIndex2 = veinPool[num].groupIndex;
                                                veinGroups2[(int)groupIndex2].count = veinGroups2[(int)groupIndex2].count - 1;
                                                factory.RemoveVeinWithComponents(num);
                                                __instance.RemoveVeinFromArray(__instance.currentVeinIndex);
                                                __instance.GetMinimumVeinAmount(factory, veinPool);
                                            }
                                            else
                                            {
                                                __instance.currentVeinIndex++;
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    __instance.RemoveVeinFromArray(__instance.currentVeinIndex);
                                    __instance.GetMinimumVeinAmount(factory, veinPool);
                                }
                                if (__instance.veinCount > 1)
                                {
                                    __instance.currentVeinIndex %= __instance.veinCount;
                                }
                                else
                                {
                                    __instance.currentVeinIndex = 0;
                                }
                            }
                        }
                    }
                }

                if (__instance.productCount > 0 && __instance.insertTarget > 0 && __instance.productId > 0 && factory.InsertInto(__instance.insertTarget, 0, __instance.productId))
                {
                    __instance.productCount--;
                    if (__instance.productCount == 0)
                    {
                        __instance.productId = 0;
                    }
                }
            }
            return(false);
        }