예제 #1
0
        public override void ProcessPacket(VegeMinedPacket packet, NebulaConnection conn)
        {
            if (GameMain.galaxy.PlanetById(packet.PlanetId)?.factory != null && GameMain.galaxy.PlanetById(packet.PlanetId)?.factory?.vegePool != null)
            {
                using (Multiplayer.Session.Planets.IsIncomingRequest.On())
                {
                    PlanetFactory factory = GameMain.galaxy.PlanetById(packet.PlanetId)?.factory;
                    if (packet.Amount == 0 && factory != null)
                    {
                        if (packet.IsVein)
                        {
                            VeinData  veinData  = factory.GetVeinData(packet.VegeId);
                            VeinProto veinProto = LDB.veins.Select((int)veinData.type);

                            factory.RemoveVeinWithComponents(packet.VegeId);

                            if (veinProto != null)
                            {
                                VFEffectEmitter.Emit(veinProto.MiningEffect, veinData.pos, Maths.SphericalRotation(veinData.pos, 0f));
                                VFAudio.Create(veinProto.MiningAudio, null, veinData.pos, true, 0, -1, -1L);
                            }
                        }
                        else
                        {
                            VegeData  vegeData  = factory.GetVegeData(packet.VegeId);
                            VegeProto vegeProto = LDB.veges.Select(vegeData.protoId);

                            factory.RemoveVegeWithComponents(packet.VegeId);

                            if (vegeProto != null)
                            {
                                VFEffectEmitter.Emit(vegeProto.MiningEffect, vegeData.pos, Maths.SphericalRotation(vegeData.pos, 0f));
                                VFAudio.Create(vegeProto.MiningAudio, null, vegeData.pos, true, 0, -1, -1L);
                            }
                        }
                    }
                    else if (factory != null)
                    {
                        VeinData veinData = factory.GetVeinData(packet.VegeId);
                        PlanetData.VeinGroup[] veinGroups = factory.planet.veinGroups;
                        short groupIndex = veinData.groupIndex;

                        // must be a vein/oil patch (i think the game treats them same now as oil patches can run out too)
                        factory.veinPool[packet.VegeId].amount          = packet.Amount;
                        factory.planet.veinAmounts[(int)veinData.type] -= 1L;
                        veinGroups[groupIndex].amount = veinGroups[groupIndex].amount - 1L;
                    }
                    else
                    {
                        Log.Warn("Received VegeMinedPacket but could not do as i was told :C");
                    }
                }
            }
        }
예제 #2
0
 public static bool GetMine(VeinData[] veinDatas, int index, float miningRate, PlanetFactory factory)
 {
     if (veinDatas.Length > index && veinDatas[index].productId > 0)
     {
         if (veinDatas[index].amount > 0)
         {
             bool flag = true;
             if (miningRate < 0.99999f)
             {
                 seed = (uint)((ulong)(seed % 2147483646U + 1U) * 48271UL % 2147483647UL) - 1U;
                 flag = (seed / 2147483646.0 < (double)miningRate);
             }
             if (flag)
             {
                 veinDatas[index].amount -= 1;
                 factory.planet.veinAmounts[(int)veinDatas[index].type] -= 1L;
                 if (veinDatas[index].amount <= 0)
                 {
                     PlanetData.VeinGroup[] veinGroups2 = factory.planet.veinGroups;
                     short groupIndex2 = veinDatas[index].groupIndex;
                     veinGroups2[(int)groupIndex2].count = veinGroups2[(int)groupIndex2].count - 1;
                     factory.RemoveVeinWithComponents(index);
                 }
             }
             return(true);
         }
         else
         {
             PlanetData.VeinGroup[] veinGroups2 = factory.planet.veinGroups;
             short groupIndex2 = veinDatas[index].groupIndex;
             veinGroups2[(int)groupIndex2].count = veinGroups2[(int)groupIndex2].count - 1;
             factory.RemoveVeinWithComponents(index);
             return(false);
         }
     }
     return(false);
 }
예제 #3
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);
        }
예제 #4
0
        public static bool FlattenTerrain(
            ref PlanetFactory __instance,
            ref int __result,
            ref Dictionary <int, int> ___tmp_levelChanges,
            ref int[] ___tmp_ids,
            Vector3 pos,
            Quaternion rot,
            Bounds bound,
            float fade0     = 6f,
            float fade1     = 1f,
            bool removeVein = false,
            bool lift       = false)
        {
            Debug.Log("FlattenTerrain -- Begining ");
            Patch.Debug("FlattenTerrain -- Begining ", LogLevel.Debug,
                        Patch.DebugPlanetFactory);
            if (___tmp_levelChanges == null)
            {
                ___tmp_levelChanges = new Dictionary <int, int>();
            }

            if (___tmp_ids == null)
            {
                ___tmp_ids = new int[1024];
            }

            ___tmp_levelChanges.Clear();
            Array.Clear(___tmp_ids, 0, ___tmp_ids.Length);
            bound.extents = new Vector3(bound.extents.x, bound.extents.y + 0.5f, bound.extents.z);
            var quaternion1 = rot;

            quaternion1.w = -quaternion1.w;
            var quaternion2 = Maths.SphericalRotation(pos, 22.5f);
            var realRadius  = __instance.planet.realRadius;

            Patch.Debug("realRadius --  " + realRadius, LogLevel.Debug,
                        Patch.DebugPlanetFactory);

            var areaRadius = bound.extents.magnitude + fade0;

            Patch.Debug("areaRadius --  " + areaRadius, LogLevel.Debug,
                        Patch.DebugPlanetFactory);
            var areaRadiusSq = areaRadius * areaRadius;

            Patch.Debug("areaRadiusSq --  " + areaRadiusSq, LogLevel.Debug,
                        Patch.DebugPlanetFactory);

            // Def something related to that that mess up everything
            //areaRadiusSq *= scaleFactor;

            Patch.Debug("Patching areaRadiusSq --  " + areaRadiusSq, LogLevel.Debug,
                        Patch.DebugPlanetFactory);
            var circlePeriphery = (float)(realRadius * 3.14159274101257 /
                                          (__instance.planet.precision * 2.0));

            Patch.Debug("circlePeriphery --  " + circlePeriphery, LogLevel.Debug,
                        Patch.DebugPlanetFactory);
            var levelAffected =
                Mathf.CeilToInt(
                    (float)(areaRadius * 1.41400003433228 / circlePeriphery + 0.5));

            Patch.Debug("levelAffected --  " + levelAffected, LogLevel.Debug,
                        Patch.DebugPlanetFactory);
            var vector3Array = new Vector3[9] {
                pos,
                pos + quaternion2 * (new Vector3(0.0f, 0.0f, 1.414f) * areaRadius),
                pos + quaternion2 * (new Vector3(0.0f, 0.0f, -1.414f) * areaRadius),
                pos + quaternion2 * (new Vector3(1.414f, 0.0f, 0.0f) * areaRadius),
                pos + quaternion2 * (new Vector3(-1.414f, 0.0f, 0.0f) * areaRadius),
                pos + quaternion2 * (new Vector3(1f, 0.0f, 1f) * areaRadius),
                pos + quaternion2 * (new Vector3(-1f, 0.0f, -1f) * areaRadius),
                pos + quaternion2 * (new Vector3(1f, 0.0f, -1f) * areaRadius),
                pos + quaternion2 * (new Vector3(-1f, 0.0f, 1f) * areaRadius)
            };


            var stride = __instance.planet.data.stride;

            Patch.Debug("stride --  " + stride, LogLevel.Debug,
                        Patch.DebugPlanetFactory);
            var dataLength = __instance.planet.data.dataLength;

            Patch.Debug("dataLength --  " + dataLength, LogLevel.Debug,
                        Patch.DebugPlanetFactory);
            var vertices = __instance.planet.data.vertices;

            Patch.Debug("vertices --  " + vertices, LogLevel.Debug,
                        Patch.DebugPlanetFactory);
            var heightData = __instance.planet.data.heightData;

            Patch.Debug("heightData --  " + heightData, LogLevel.Debug,
                        Patch.DebugPlanetFactory);
            var radiusHeight100 = (short)(__instance.planet.realRadius * 100.0);

            Patch.Debug("radiusHeight100 --  " + radiusHeight100, LogLevel.Debug,
                        Patch.DebugPlanetFactory);
            var fRoundToInt = 0;

            foreach (var vpos in vector3Array)
            {
                var posIndex = __instance.planet.data.QueryIndex(vpos);
                for (var index1 = -levelAffected; index1 <= levelAffected; ++index1)
                {
                    var strideIndex = posIndex + index1 * stride;
                    if (strideIndex >= 0 && strideIndex < dataLength)
                    {
                        for (var index2 = -levelAffected; index2 <= levelAffected; ++index2)
                        {
                            var index3 = strideIndex + index2;
                            if ((uint)index3 < dataLength &&
                                (lift || heightData[index3] > radiusHeight100))
                            {
                                Vector3 vector3_1;
                                vector3_1.x = vertices[index3].x * realRadius;
                                vector3_1.y = vertices[index3].y * realRadius;
                                vector3_1.z = vertices[index3].z * realRadius;
                                Vector3 vector3_2;
                                vector3_2.x = vector3_1.x - pos.x;
                                vector3_2.y = vector3_1.y - pos.y;
                                vector3_2.z = vector3_1.z - pos.z;
                                if (vector3_2.x * (double)vector3_2.x +
                                    vector3_2.y * (double)vector3_2.y +
                                    vector3_2.z * (double)vector3_2.z < areaRadiusSq &&
                                    !___tmp_levelChanges.ContainsKey(index3))
                                {
                                    Patch.Debug("vector3_2 less than areaRadiusSq --  " + vector3_2,
                                                LogLevel.Debug,
                                                Patch.DebugPlanetFactoryDeep);
                                    vector3_1 = quaternion1 * (vector3_1 - pos);

                                    Patch.Debug("vector3_1 less than areaRadiusSq --  " + vector3_1,
                                                LogLevel.Debug,
                                                Patch.DebugPlanetFactoryDeep);

                                    if (bound.Contains(vector3_1))
                                    {
                                        ___tmp_levelChanges[index3] = 3;
                                    }
                                    else
                                    {
                                        var boundDistance = Vector3.Distance(bound.ClosestPoint(vector3_1),
                                                                             vector3_1);
                                        var boundDistanceFade =
                                            (int)((fade0 - (double)boundDistance) /
                                                  (fade0 - (double)fade1) * 3.0 + 0.5);
                                        if (boundDistanceFade < 0)
                                        {
                                            boundDistanceFade = 0;
                                        }
                                        else if (boundDistanceFade > 3)
                                        {
                                            boundDistanceFade = 3;
                                        }

                                        var modLevel = __instance.planet.data.GetModLevel(index3);

                                        Patch.Debug("modLevel --  " + modLevel, LogLevel.Debug,
                                                    Patch.DebugPlanetFactoryDeep);
                                        var boundDiff = boundDistanceFade - modLevel;

                                        Patch.Debug("boundDiff --  " + boundDiff, LogLevel.Debug,
                                                    Patch.DebugPlanetFactoryDeep);
                                        if (boundDistanceFade >= modLevel && boundDiff != 0)
                                        {
                                            ___tmp_levelChanges[index3] = boundDistanceFade;
                                            var currentHeightData = heightData[index3] * 0.01f;

                                            Patch.Debug("currentHeightData --  " + currentHeightData,
                                                        LogLevel.Debug,
                                                        Patch.DebugPlanetFactoryDeep);

                                            var currentHeightDataOnRadius =
                                                realRadius - currentHeightData;

                                            Patch.Debug(
                                                "currentHeightDataOnRadius --  " + currentHeightDataOnRadius,
                                                LogLevel.Debug,
                                                Patch.DebugPlanetFactoryDeep);
                                            //anomaly here
                                            //currentHeightDataOnRadius *= scaleFactor;

                                            Patch.Debug(
                                                "Patching currentHeightDataOnRadius --  " +
                                                currentHeightDataOnRadius, LogLevel.Debug,
                                                Patch.DebugPlanetFactoryDeep);

                                            var f = (float)(100.0 * boundDiff *
                                                            currentHeightDataOnRadius *
                                                            0.333333313465118);

                                            Patch.Debug("f --  " + f, LogLevel.Debug,
                                                        Patch.DebugPlanetFactoryDeep);
                                            fRoundToInt += -Mathf.FloorToInt(f);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            var levelized = __instance.planet.levelized;
            var plane     = Mathf.RoundToInt(
                (float)((pos.magnitude - (double)__instance.planet.realRadius) /
                        1.33333325386047));


            Patch.Debug("plane --  " + plane, LogLevel.Debug,
                        Patch.DebugPlanetFactory);
            var num13 = plane * 133 + radiusHeight100 - 60;

            Patch.Debug("num13 --  " + num13, LogLevel.Debug,
                        Patch.DebugPlanetFactory);
            foreach (var tmpLevelChange in ___tmp_levelChanges)
            {
                if (tmpLevelChange.Value > 0)
                {
                    if (levelized)
                    {
                        if (heightData[tmpLevelChange.Key] >= num13)
                        {
                            if (__instance.planet.data.GetModLevel(tmpLevelChange.Key) < 3)
                            {
                                Patch.Debug("SetModPlane --  plane" + plane, LogLevel.Debug,
                                            Patch.DebugPlanetFactoryDeep);

                                Patch.Debug(
                                    "SetModPlane --  heightData[tmpLevelChange.Key]" +
                                    heightData[tmpLevelChange.Key], LogLevel.Debug,
                                    Patch.DebugPlanetFactoryDeep);
                                __instance.planet.data.SetModPlane(tmpLevelChange.Key, plane);
                            }


                            Patch.Debug(
                                "If AddHeightMapModLevel --  tmpLevelChange.Value" + tmpLevelChange.Value,
                                LogLevel.Debug,
                                Patch.DebugPlanetFactoryDeep);

                            Patch.Debug(
                                "If AddHeightMapModLevel --  heightData[tmpLevelChange.Key]" +
                                heightData[tmpLevelChange.Key], LogLevel.Debug,
                                Patch.DebugPlanetFactoryDeep);

                            __instance.planet.AddHeightMapModLevel(tmpLevelChange.Key, tmpLevelChange.Value);
                        }
                    }
                    else
                    {
                        Patch.Debug(
                            "Else AddHeightMapModLevel --  tmpLevelChange.Value" + tmpLevelChange.Value,
                            LogLevel.Debug,
                            Patch.DebugPlanetFactoryDeep);

                        Patch.Debug(
                            "Else AddHeightMapModLevel --  heightData[tmpLevelChange.Key]" +
                            heightData[tmpLevelChange.Key], LogLevel.Debug,
                            Patch.DebugPlanetFactoryDeep);

                        __instance.planet.AddHeightMapModLevel(tmpLevelChange.Key, tmpLevelChange.Value);
                    }
                }
            }

            var flag = __instance.planet.UpdateDirtyMeshes();

            if (GameMain.isRunning && flag)
            {
                __instance.RenderLocalPlanetHeightmap();
            }

            bound.extents += new Vector3(1.5f, 1.5f, 1.5f);
            var nearColliderLogic        = __instance.planet.physics.nearColliderLogic;
            var vegetablesInAreaNonAlloc =
                nearColliderLogic.GetVegetablesInAreaNonAlloc(pos, areaRadius, ___tmp_ids);

            for (var index = 0; index < vegetablesInAreaNonAlloc; ++index)
            {
                var tmpId = ___tmp_ids[index];
                var pos1  = __instance.vegePool[tmpId].pos;
                var point = quaternion1 * (pos1 - pos);
                if (bound.Contains(point))
                {
                    __instance.RemoveVegeWithComponents(tmpId);
                }
                else
                {
                    var num6 = __instance.planet.data.QueryModifiedHeight(__instance.vegePool[tmpId].pos);

                    Patch.Debug(
                        "num6 --  __instance.planet.data.QueryModifiedHeight(__instance.vegePool[tmpId].pos) - 0.03f + heightData[tmpLevelChange.Key]" +
                        num6, LogLevel.Debug,
                        Patch.DebugPlanetFactory);
                    __instance.vegePool[tmpId].pos = __instance.vegePool[tmpId].pos.normalized * num6;

                    Patch.Debug("__instance.vegePool[tmpId].pos --  _" + __instance.vegePool[tmpId].pos,
                                LogLevel.Debug,
                                Patch.DebugPlanetFactory);
                    GameMain.gpuiManager.AlterModel(__instance.vegePool[tmpId].modelIndex,
                                                    __instance.vegePool[tmpId].modelId, tmpId, __instance.vegePool[tmpId].pos,
                                                    __instance.vegePool[tmpId].rot,
                                                    false);
                }
            }

            var veinsInAreaNonAlloc = nearColliderLogic.GetVeinsInAreaNonAlloc(pos, areaRadius, ___tmp_ids);

            for (var index = 0; index < veinsInAreaNonAlloc; ++index)
            {
                var tmpId = ___tmp_ids[index];
                var pos1  = __instance.veinPool[tmpId].pos;
                if (removeVein && bound.Contains(pos1))
                {
                    __instance.RemoveVeinWithComponents(tmpId);
                }
                else if (pos1.magnitude > (double)__instance.planet.realRadius)
                {
                    var num6 = __instance.planet.data.QueryModifiedHeight(pos1) - 0.13f;
                    __instance.veinPool[tmpId].pos = pos1.normalized * num6;
                    GameMain.gpuiManager.AlterModel(__instance.veinPool[tmpId].modelIndex,
                                                    __instance.veinPool[tmpId].modelId, tmpId, __instance.veinPool[tmpId].pos, false);
                }
            }

            ___tmp_levelChanges.Clear();
            Array.Clear(___tmp_ids, 0, ___tmp_ids.Length);
            GameMain.gpuiManager.SyncAllGPUBuffer();
            __result = fRoundToInt;


            return(false);
        }