Пример #1
0
        public static void Postfix(int entityId, ItemProto newProto, PlanetFactory __instance)
        {
            if (entityId == 0 || __instance.entityPool[entityId].id == 0)
            {
                return;
            }
            if (__instance.entityPool[entityId].minerId <= 0)
            {
                return;
            }
            MinerComponent component = __instance.factorySystem.minerPool[__instance.entityPool[entityId].minerId];

            if (component.type != EMinerType.Vein)
            {
                return;
            }

            PrefabDesc desc   = newProto.prefabDesc;
            float      radius = DSPAdvancedMiner.getMinerRadius(desc);

            radius *= radius;

            Pose pose;

            pose.position = __instance.entityPool[entityId].pos;
            pose.rotation = __instance.entityPool[entityId].rot;

            int[]        tmp_ids             = new int[256];
            Vector3      vector2             = pose.position + pose.forward * -1.2f;
            Vector3      rhs                 = -pose.forward;
            Vector3      vector3             = pose.up;
            int          veinsInAreaNonAlloc = __instance.planet.physics.nearColliderLogic.GetVeinsInAreaNonAlloc(vector2, DSPAdvancedMiner.getMinerRadius(desc) + 4, tmp_ids);
            PrebuildData prebuildData        = default(PrebuildData);

            prebuildData.InitParametersArray(veinsInAreaNonAlloc);
            VeinData[] veinPool   = __instance.planet.factory.veinPool;
            int        paramCount = 0;

            for (int j = 0; j < veinsInAreaNonAlloc; j++)
            {
                if (tmp_ids[j] != 0 && veinPool[tmp_ids[j]].id == tmp_ids[j])
                {
                    if (veinPool[tmp_ids[j]].type != EVeinType.Oil)
                    {
                        Vector3 vector4 = veinPool[tmp_ids[j]].pos - vector2;
                        float   num2    = Vector3.Dot(vector3, vector4);
                        vector4 -= vector3 * num2;
                        float sqrMagnitude = vector4.sqrMagnitude;
                        float num3         = Vector3.Dot(vector4.normalized, rhs);
                        if (sqrMagnitude <= radius && num3 >= 0.73f && Mathf.Abs(num2) <= 2f)
                        {
                            prebuildData.parameters[paramCount++] = tmp_ids[j];
                        }
                    }
                }
                else
                {
                    Assert.CannotBeReached();
                }
            }

            component.InitVeinArray(paramCount);
            if (paramCount > 0)
            {
                Array.Copy(prebuildData.parameters, component.veins, paramCount);
            }

            for (int i = 0; i < component.veinCount; i++)
            {
                __instance.RefreshVeinMiningDisplay(component.veins[i], component.entityId, 0);
            }

            component.ArrangeVeinArray();
            __instance.factorySystem.minerPool[__instance.entityPool[entityId].minerId] = component;
        }
Пример #2
0
        public static void Postfix(int id, ItemProto newProto, PlanetFactory __instance)
        {
            if (id == 0 || __instance.entityPool[id].id == 0)
            {
                return;
            }
            if (__instance.entityPool[id].minerId <= 0)
            {
                return;
            }
            MinerComponent component = __instance.factorySystem.minerPool[__instance.entityPool[id].minerId];

            if (component.type != EMinerType.Vein)
            {
                return;
            }

            PrefabDesc desc = newProto.prefabDesc;

            Pose pose;

            pose.position = __instance.entityPool[id].pos;
            pose.rotation = __instance.entityPool[id].rot;

            int[]   tmp_ids             = new int[256];
            Vector3 vector3             = pose.position + pose.forward * -1.2f;
            Vector3 rhs                 = -pose.forward;
            Vector3 up                  = pose.up;
            int     veinsInAreaNonAlloc =
                __instance.planet.physics.nearColliderLogic.GetVeinsInAreaNonAlloc(vector3, DSPAdvancedMiner.getMinerRadius(desc) + 4, tmp_ids);

            int[] refArray = new int[veinsInAreaNonAlloc];

            VeinData[] veinPool = __instance.planet.factory.veinPool;
            int        refCount = 0;

            for (int j = 0; j < veinsInAreaNonAlloc; j++)
            {
                if (tmp_ids[j] != 0 && veinPool[tmp_ids[j]].id == tmp_ids[j])
                {
                    if (veinPool[tmp_ids[j]].type != EVeinType.Oil)
                    {
                        Vector3 pos     = veinPool[tmp_ids[j]].pos;
                        Vector3 vector4 = pos - vector3;
                        float   num8    = Vector3.Dot(up, vector4);
                        vector4 -= up * num8;
                        float sqrMagnitude = vector4.sqrMagnitude;
                        float num9         = Vector3.Dot(vector4.normalized, rhs);
                        float radius       = DSPAdvancedMiner.getMinerRadius(desc);
                        if (sqrMagnitude <= radius * radius && num9 >= 0.73f && Mathf.Abs(num8) <= 2f)
                        {
                            refArray[refCount++] = tmp_ids[j];
                        }
                    }
                }
            }

            component.InitVeinArray(refCount);
            if (refCount > 0)
            {
                Array.Copy(refArray, component.veins, refCount);
            }

            for (int i = 0; i < component.veinCount; i++)
            {
                __instance.RefreshVeinMiningDisplay(component.veins[i], component.entityId, 0);
            }

            component.ArrageVeinArray();
            __instance.factorySystem.minerPool[__instance.entityPool[id].minerId] = component;
        }