コード例 #1
0
 public static void UpdateFakeData(PlatformSystem __instance, int index)
 {
     if (currentFactory != null && currentFactory.index == __instance.factory.index)
     {
         fakeReformData[index] = __instance.reformData[index];
     }
 }
コード例 #2
0
 private void Awake()
 {
     _animator       = GetComponentInChildren <Animator>();
     _audioManager   = GetComponent <AudioManager>();
     _systems        = GameObject.FindWithTag("Systems");
     _platformSystem = _systems.GetComponent <PlatformSystem>();
 }
コード例 #3
0
        public static void ApplyColors(BuildTool_BlueprintPaste tool, Color[] colors)
        {
            PlatformSystem system = tool.factory.platformSystem;

            Array.Copy(colors, system.reformCustomColors, 16);
            system.RefreshColorsTexture();
        }
コード例 #4
0
        private bool CheckPlayerInReform()
        {
            PlanetData localPlanet = GameMain.galaxy.PlanetById(localPlanetId);
            bool       result      = false;

            if (localPlanet != null)
            {
                PlanetFactory factory = localPlanet.factory;
                if (factory != null)
                {
                    PlatformSystem platformSystem = factory.platformSystem;
                    if (platformSystem.reformData != null)
                    {
                        int reformIndexForPosition = platformSystem.GetReformIndexForPosition(rootTransform.position);
                        if (reformIndexForPosition > -1)
                        {
                            int reformType = platformSystem.GetReformType(reformIndexForPosition);
                            result = platformSystem.IsTerrainMapping(reformType);
                        }
                        else
                        {
                            result = true;
                        }
                    }
                    else
                    {
                        result = false;
                    }
                }
            }
            return(result);
        }
コード例 #5
0
    private void OnEnable()
    {
        ps = (PlatformSystem)target;
        if (ps.backgroundPage.GetComponent <PageGenerator>().ps == null)
        {
            ps.backgroundPage.GetComponent <PageGenerator>().ps = ps;
        }

        //Debug.Log("platforms: " + ps.platforms.Count);
    }
コード例 #6
0
        public static void AddColorData(BuildTool_BlueprintCopy __instance)
        {
            if (GameMain.localPlanet == null || GameMain.localPlanet.type == EPlanetType.Gas)
            {
                return;
            }

            PlatformSystem system = GameMain.localPlanet.factory.platformSystem;

            __instance.blueprint.customColors = new Color[16];

            Array.Copy(system.reformCustomColors, __instance.blueprint.customColors, 16);
        }
コード例 #7
0
        public void ProcessPacket(FoundationBuildUpdatePacket packet, NebulaConnection conn)
        {
            PlanetData    planet  = GameMain.galaxy.PlanetById(packet.PlanetId);
            PlanetFactory factory = GameMain.data.GetOrCreateFactory(planet);

            Vector3[] reformPoints      = new Vector3[100];
            Vector3   reformCenterPoint = new Vector3();

            //Check if some mandatory variables are missing
            if (factory.platformSystem.reformData == null)
            {
                factory.platformSystem.InitReformData();
            }

            if (planet.physics == null || planet.physics.colChunks == null)
            {
                planet.physics = new PlanetPhysics(planet);
                planet.physics.Init();
            }
            if (planet.aux == null)
            {
                planet.aux = new PlanetAuxData(planet);
            }

            //Perform terrain operation
            int reformPointsCount = factory.planet.aux.ReformSnap(packet.GroundTestPos.ToVector3(), packet.ReformSize, packet.ReformType, packet.ReformColor, reformPoints, packet.ReformIndices, factory.platformSystem, out reformCenterPoint);

            factory.ComputeFlattenTerrainReform(reformPoints, reformCenterPoint, packet.Radius, reformPointsCount, 3f, 1f);
            using (FactoryManager.EventFromClient.On())
            {
                factory.FlattenTerrainReform(reformCenterPoint, packet.Radius, packet.ReformSize, packet.VeinBuried, 3f);
            }
            int area = packet.ReformSize * packet.ReformSize;

            for (int i = 0; i < area; i++)
            {
                int            num71          = packet.ReformIndices[i];
                PlatformSystem platformSystem = factory.platformSystem;
                if (num71 >= 0)
                {
                    int type  = platformSystem.GetReformType(num71);
                    int color = platformSystem.GetReformColor(num71);
                    if (type != packet.ReformType || color != packet.ReformColor)
                    {
                        factory.platformSystem.SetReformType(num71, packet.ReformType);
                        factory.platformSystem.SetReformColor(num71, packet.ReformColor);
                    }
                }
            }
        }
コード例 #8
0
        public void ProcessPacket(FoundationBuildUpdatePacket packet, NebulaConnection conn)
        {
            //Check if client has loaded planet
            PlanetData    planet  = GameMain.galaxy.PlanetById(packet.PlanetId);
            PlanetFactory factory = planet?.factory;

            if (factory != null)
            {
                Vector3 reformCenterPoint = new Vector3();
                for (int i = 0; i < reformPoints.Length; i++)
                {
                    reformPoints[i] = Vector3.zero;
                }
                if (factory.platformSystem.reformData == null)
                {
                    factory.platformSystem.InitReformData();
                }
                if (planet.physics == null || planet.physics.colChunks == null)
                {
                    planet.physics = new PlanetPhysics(planet);
                    planet.physics.Init();
                }
                if (planet.aux == null)
                {
                    planet.aux = new PlanetAuxData(planet);
                }
                int reformPointsCount = factory.planet.aux.ReformSnap(packet.GroundTestPos.ToVector3(), packet.ReformSize, packet.ReformType, packet.ReformColor, reformPoints, packet.ReformIndices, factory.platformSystem, out reformCenterPoint);
                factory.ComputeFlattenTerrainReform(reformPoints, reformCenterPoint, packet.Radius, reformPointsCount, 3f, 1f);
                using (FactoryManager.EventFromServer.On())
                {
                    factory.FlattenTerrainReform(reformCenterPoint, packet.Radius, packet.ReformSize, packet.VeinBuried, 3f);
                }
                int area = packet.ReformSize * packet.ReformSize;
                for (int i = 0; i < area; i++)
                {
                    int            num71          = packet.ReformIndices[i];
                    PlatformSystem platformSystem = factory.platformSystem;
                    if (num71 >= 0)
                    {
                        int type  = platformSystem.GetReformType(num71);
                        int color = platformSystem.GetReformColor(num71);
                        if (type != packet.ReformType || color != packet.ReformColor)
                        {
                            factory.platformSystem.SetReformType(num71, packet.ReformType);
                            factory.platformSystem.SetReformColor(num71, packet.ReformColor);
                        }
                    }
                }
            }
        }
コード例 #9
0
        public override void ProcessPacket(FoundationBuildUpdatePacket packet, NebulaConnection conn)
        {
            PlanetData    planet  = GameMain.galaxy.PlanetById(packet.PlanetId);
            PlanetFactory factory = IsHost ? GameMain.data.GetOrCreateFactory(planet) : planet?.factory;

            if (factory != null)
            {
                Array.Clear(reformPoints, 0, reformPoints.Length);

                //Check if some mandatory variables are missing
                if (factory.platformSystem.reformData == null)
                {
                    factory.platformSystem.InitReformData();
                }

                Multiplayer.Session.Factories.TargetPlanet = packet.PlanetId;
                Multiplayer.Session.Factories.AddPlanetTimer(packet.PlanetId);
                Multiplayer.Session.Factories.TargetPlanet = NebulaModAPI.PLANET_NONE;

                //Perform terrain operation
                int reformPointsCount = factory.planet.aux.ReformSnap(packet.GroundTestPos.ToVector3(), packet.ReformSize, packet.ReformType, packet.ReformColor, reformPoints, packet.ReformIndices, factory.platformSystem, out Vector3 reformCenterPoint);
                factory.ComputeFlattenTerrainReform(reformPoints, reformCenterPoint, packet.Radius, reformPointsCount, 3f, 1f);
                using (Multiplayer.Session.Factories.IsIncomingRequest.On())
                {
                    factory.FlattenTerrainReform(reformCenterPoint, packet.Radius, packet.ReformSize, packet.VeinBuried, 3f);
                }
                int area = packet.ReformSize * packet.ReformSize;
                for (int i = 0; i < area; i++)
                {
                    int            num71          = packet.ReformIndices[i];
                    PlatformSystem platformSystem = factory.platformSystem;
                    if (num71 >= 0)
                    {
                        int type  = platformSystem.GetReformType(num71);
                        int color = platformSystem.GetReformColor(num71);
                        if (type != packet.ReformType || color != packet.ReformColor)
                        {
                            factory.platformSystem.SetReformType(num71, packet.ReformType);
                            factory.platformSystem.SetReformColor(num71, packet.ReformColor);
                        }
                    }
                }
            }

            if (IsHost)
            {
                Multiplayer.Session.Network.SendPacketToStar(packet, planet.star.id);
            }
        }
コード例 #10
0
        public static bool GetReformIndexForPosition(ref PlatformSystem __instance, Vector3 pos, ref int __result)
        {
            pos.Normalize();
            var num1 = Mathf.Asin(pos.y);
            var num2 = Mathf.Atan2(pos.x, -pos.z);
            //float f1 = num1 / (2* (float)Math.PI) * (float) __instance.segment;
            var   f1 = num1 / 6.283185f * __instance.segment;
            float longitudeSegmentCount = PlatformSystem.DetermineLongitudeSegmentCount(Mathf.FloorToInt(Mathf.Abs(f1)), __instance.segment);
            // float f2 = num2 / (2* (float)Math.PI)  * longitudeSegmentCount;
            var f2   = num2 / 6.283185f * longitudeSegmentCount;
            var f3   = Mathf.Round(f1 * 10f);
            var f4   = Mathf.Round(f2 * 10f);
            var num3 = Mathf.Abs(f3);
            var num4 = Mathf.Abs(f4);

            if (num3 % 2.0 != 1.0)
            {
                num3 = Mathf.FloorToInt(Mathf.Abs(f1) * 10f);
                if (num3 % 2.0 != 1.0)
                {
                    ++num3;
                }
            }
            var num5 = (double)f3 < 0.0 ? -num3 : num3;

            if (num4 % 2.0 != 1.0)
            {
                num4 = Mathf.FloorToInt(Mathf.Abs(f2) * 10f);
                if (num4 % 2.0 != 1.0)
                {
                    ++num4;
                }
            }
            var num6          = (double)f4 < 0.0 ? -num4 : num4;
            var _latitudeSeg  = num5 / 10f;
            var _longitudeSeg = num6 / 10f;

            float num7 = __instance.latitudeCount / 10;

            __result = (double)_latitudeSeg >= (double)num7 || (double)_latitudeSeg <= -(double)num7 ? -1 : __instance.GetReformIndexForSegment(_latitudeSeg, _longitudeSeg);

            Patch.Debug("PlatformSystem - __result --> " + __result, LogLevel.Debug, true);

            return(false);
        }
コード例 #11
0
ファイル: ReformBPUtils.cs プロジェクト: kremnev8/DSP-Mods
        public static void ItterateOnReform(BuildTool_BlueprintCopy __instance, BPGratBox box, Action <int, ReformData> action, bool fullCircle = false)
        {
            if (Mathf.Abs(box.y - box.w) < 0.005f)
            {
                return;
            }

            PlatformSystem platform = __instance.factory.platformSystem;

            if (platform == null)
            {
                return;
            }
            platform.EnsureReformData();

            GetSegmentCount(box.startLatitudeRad, box.startLongitudeRad, out float startLatCount, out float startLongCount, out int startCount);
            GetSegmentCount(box.endLatitudeRad, box.endLongitudeRad, out float endLatCount, out float endLongCount, out int endCount);

            startLatCount  = GridSnappingPatches.Snap(startLatCount);
            startLongCount = GridSnappingPatches.Snap(startLongCount);
            endLatCount    = GridSnappingPatches.Snap(endLatCount);
            endLongCount   = GridSnappingPatches.Snap(endLongCount);

            startLatCount  = Mathf.Round(startLatCount * 10f);
            endLatCount    = Mathf.Round(endLatCount * 10f);
            startLongCount = Mathf.Round(startLongCount * 10f);
            endLongCount   = Mathf.Round(endLongCount * 10f);

            float latDelta = endLatCount - startLatCount;
            int   segmentCount;

            float longDelta;

            if (startCount != endCount)
            {
                Vector2 center = GetSphericalCenter(box.startLatitudeRad, box.startLongitudeRad, box.endLatitudeRad, box.endLongitudeRad);

                GetSegmentCount(center.x, center.y, out float _, out float _, out int midCount);
                segmentCount = midCount;
                if (startCount == midCount)
                {
                    GetSegmentCount(box.startLatitudeRad, box.endLongitudeRad, out float _, out float nlongCount);
                    nlongCount = Mathf.Round(nlongCount * 10f);
                    longDelta  = nlongCount - startLongCount;
                }
                else
                {
                    GetSegmentCount(box.endLatitudeRad, box.startLongitudeRad, out float _, out float nlongCount);
                    nlongCount     = Mathf.Round(nlongCount * 10f);
                    longDelta      = endLongCount - nlongCount;
                    startLongCount = nlongCount;
                }
            }
            else
            {
                segmentCount = startCount;
                longDelta    = endLongCount - startLongCount;
            }

            if (fullCircle)
            {
                longDelta = segmentCount * 10;
            }

            if (longDelta < 0)
            {
                longDelta = segmentCount * 10 + longDelta;
            }

            int latSize  = Mathf.RoundToInt(latDelta) / 2;
            int longSize = Mathf.RoundToInt(longDelta) / 2;

            if (latSize == 0)
            {
                latSize = 1;
            }
            if (longSize == 0)
            {
                longSize = 1;
            }

            startLatCount  += 1;
            startLongCount += 1;

            int latOffset   = 0;
            int longOffset  = 0;
            int longCounter = 0;

            float latCount = platform.latitudeCount / 10f;

            for (int i = 0; i < longSize * latSize; i++)
            {
                longCounter++;
                float currentLat  = (startLatCount + latOffset) / 10f;
                float currentLong = (startLongCount + longOffset) / 10f;

                currentLong = Mathf.Repeat(currentLong, segmentCount);

                float latRad  = (currentLat + 0.1f) / currentGrid.segment * 6.2831855f;
                float longRad = (currentLong + 0.1f) / segmentCount * 6.2831855f;

                longOffset += 2;
                if (longCounter % longSize == 0)
                {
                    longOffset = 0;
                    latOffset += 2;
                }

                if (currentLat >= latCount || currentLat <= -latCount)
                {
                    continue;
                }

                int reformIndex = platform.GetReformIndexForSegment(currentLat, currentLong);

                int reformType  = platform.GetReformType(reformIndex);
                int reformColor = platform.GetReformColor(reformIndex);

                if (!platform.IsTerrainReformed(reformType))
                {
                    continue;
                }

                ReformData reform = new ReformData
                {
                    latitude  = latRad,
                    longitude = longRad,
                    type      = reformType,
                    color     = reformColor
                };

                action(reformIndex, reform);
            }
        }
コード例 #12
0
        public static bool DetermineBuildPreviewsPrefix(ref PlayerAction_Build __instance)
        {
            CommandState cmd = __instance.controller.cmd;
            //__instance.waitConfirm = false;
            bool flag  = false;
            bool flag2 = false;

            if (__instance.handPrefabDesc == null)
            {
                if (cmd.mode == 4)
                {
                    int[] consumeRegister = GameMain.statistics.production.factoryStatPool[__instance.factory.index].consumeRegister;
                    if (__instance.reformSize < 1)
                    {
                        __instance.reformSize = 1;
                    }
                    else if (__instance.reformSize > 30)
                    {
                        __instance.reformSize = 30;
                    }
                    if ((__instance.reformCenterPoint - __instance.player.position).sqrMagnitude > __instance.player.mecha.buildArea * __instance.player.mecha.buildArea)
                    {
                        if (!VFInput.onGUI)
                        {
                            __instance.cursorText    = "目标超出范围".Translate();
                            __instance.cursorWarning = true;
                            UICursor.SetCursor(ECursor.Ban);
                        }
                    }
                    else
                    {
                        if (!VFInput.onGUI)
                        {
                            UICursor.SetCursor(ECursor.Reform);
                        }
                        bool flag24 = false;
                        if (VFInput._reformPlusKey.onDown)
                        {
                            if (__instance.reformSize < 30)
                            {
                                __instance.reformSize++;
                                flag24 = true;
                                for (int num61 = 0; num61 < __instance.reformSize * __instance.reformSize; num61++)
                                {
                                    __instance.reformIndices[num61] = -1;
                                }
                            }
                        }
                        else if (VFInput._reformMinusKey.onDown && __instance.reformSize > 1)
                        {
                            __instance.reformSize--;
                            flag24 = true;
                        }
                        float radius = 0.99094594f * (float)__instance.reformSize;
                        int   num62  = __instance.factory.ComputeFlattenTerrainReform(__instance.reformPoints, __instance.reformCenterPoint, radius, __instance.reformPointsCount, 3f, 1f);
                        if (__instance.cursorValid && !VFInput.onGUI)
                        {
                            if (num62 > 0)
                            {
                                string soilCount = num62.ToString();

                                if (FreeFoundationsFreeSoilPlugin.freeSoilEnabled)
                                {
                                    soilCount = "0";
                                }
                                //Debug.Log("IF");
                                __instance.cursorText = string.Concat(new string[]
                                {
                                    "沙土消耗".Translate(),
                                    " ",
                                    soilCount,
                                    " ",
                                    "个沙土".Translate(),
                                    "\n",
                                    "改造大小".Translate(),
                                    __instance.reformSize.ToString(),
                                    "x",
                                    __instance.reformSize.ToString(),
                                    (FreeFoundationsFreeSoilPlugin.freeSoilEnabled) ?       "\n       (Free Soil is Enabled)" : string.Empty,
                                    (FreeFoundationsFreeSoilPlugin.freeFoundationEnabled) ? "\n(Free Foundations is Enabled)" : string.Empty
                                });
                            }
                            else if (num62 == 0)
                            {
                                __instance.cursorText = "改造大小".Translate() + __instance.reformSize.ToString() + "x" + __instance.reformSize.ToString() +
                                                        ((FreeFoundationsFreeSoilPlugin.freeSoilEnabled) ?       "\n       (Free Soil is Enabled)" : string.Empty) +
                                                        ((FreeFoundationsFreeSoilPlugin.freeFoundationEnabled) ? "\n(Free Foundations is Enabled)" : string.Empty);
                            }
                            else
                            {
                                int num63 = -num62;



                                string soilCount = num63.ToString();

                                if (!FreeFoundationsFreeSoilPlugin.collectSoilEnabled)
                                {
                                    soilCount = "0";
                                }
                                //Debug.Log("ELSE");



                                __instance.cursorText = string.Concat(new string[]
                                {
                                    "沙土获得".Translate(),
                                    " ",
                                    soilCount,
                                    " ",
                                    "个沙土".Translate(),
                                    "\n",
                                    "改造大小".Translate(),
                                    __instance.reformSize.ToString(),
                                    "x",
                                    __instance.reformSize.ToString(),
                                    (FreeFoundationsFreeSoilPlugin.freeSoilEnabled) ?       "\n       (Free Soil is Enabled)" : string.Empty,
                                    (FreeFoundationsFreeSoilPlugin.freeFoundationEnabled) ? "\n(Free Foundations is Enabled)" : string.Empty
                                });
                            }
                            if (VFInput._buildConfirm.pressing)
                            {
                                bool flag25 = false;
                                if (VFInput._buildConfirm.onDown)
                                {
                                    flag25 = true;
                                    __instance.reformMouseOnDown = true;
                                }
                                if (__instance.reformMouseOnDown)
                                {
                                    __instance.inReformOperation = true;
                                    if (__instance.reformChangedPoint.x != __instance.reformCenterPoint.x || __instance.reformChangedPoint.y != __instance.reformCenterPoint.y || __instance.reformChangedPoint.z != __instance.reformCenterPoint.z || flag24)
                                    {
                                        bool doItFoundation = true;
                                        if (FreeFoundationsFreeSoilPlugin.freeFoundationEnabled)
                                        {
                                            doItFoundation = __instance.handItem.BuildMode == 4;
                                        }
                                        else
                                        {
                                            doItFoundation = __instance.handItem.BuildMode == 4 && __instance.player.package.GetItemCount(__instance.handItem.ID) + __instance.player.inhandItemCount >= __instance.reformPointsCount;
                                        }
                                        if (doItFoundation)
                                        {
                                            bool doItSoil = false;

                                            if (FreeFoundationsFreeSoilPlugin.freeSoilEnabled || !FreeFoundationsFreeSoilPlugin.collectSoilEnabled)
                                            {
                                                doItSoil = __instance.player.sandCount >= 0;
                                            }
                                            else
                                            {
                                                doItSoil = __instance.player.sandCount - num62 >= 0;
                                            }
                                            //num64 = 100000;
                                            if (doItSoil)
                                            {
                                                //Debug.Log(num62);
                                                __instance.factory.FlattenTerrainReform(__instance.reformCenterPoint, radius, __instance.reformSize, __instance.veinBuried, 3f);
                                                VFAudio.Create("reform-terrain", null, __instance.reformCenterPoint, true);

                                                if (num62 < 0)
                                                {
                                                    if (FreeFoundationsFreeSoilPlugin.collectSoilEnabled)
                                                    {
                                                        __instance.player.SetSandCount(__instance.player.sandCount - num62);
                                                    }
                                                    else
                                                    {
                                                        __instance.player.SetSandCount(__instance.player.sandCount);
                                                    }
                                                }
                                                else
                                                {
                                                    if (FreeFoundationsFreeSoilPlugin.freeSoilEnabled)
                                                    {
                                                        __instance.player.SetSandCount(__instance.player.sandCount);
                                                    }
                                                    else
                                                    {
                                                        __instance.player.SetSandCount(__instance.player.sandCount - num62);
                                                    }
                                                }

                                                int num65 = __instance.reformSize * __instance.reformSize;
                                                for (int num66 = 0; num66 < num65; num66++)
                                                {
                                                    int            num67          = __instance.reformIndices[num66];
                                                    PlatformSystem platformSystem = __instance.factory.platformSystem;
                                                    if (num67 >= 0)
                                                    {
                                                        int num68 = platformSystem.GetReformType(num67);
                                                        int num69 = platformSystem.GetReformColor(num67);
                                                        if (num68 != __instance.reformType || num69 != __instance.reformColor)
                                                        {
                                                            __instance.factory.platformSystem.SetReformType(num67, __instance.reformType);
                                                            __instance.factory.platformSystem.SetReformColor(num67, __instance.reformColor);
                                                        }
                                                    }
                                                }
                                                int num70 = __instance.reformPointsCount;
                                                if (__instance.player.inhandItemCount > 0)
                                                {
                                                    int num71 = (__instance.reformPointsCount >= __instance.player.inhandItemCount) ? __instance.player.inhandItemCount : __instance.reformPointsCount;
                                                    __instance.player.UseHandItems(num71);
                                                    num70 -= num71;
                                                }
                                                int id = __instance.handItem.ID;
                                                consumeRegister[id] += __instance.reformPointsCount;
                                                __instance.player.package.TakeTailItems(ref id, ref num70, false);
                                                GameMain.gameScenario.NotifyOnBuild(__instance.player.planetId, __instance.handItem.ID, 0);
                                            }
                                            else if (flag25)
                                            {
                                                //Debug.Log("No1");
                                                UIRealtimeTip.Popup("沙土不足".Translate(), true, 0);
                                            }
                                        }
                                        else if (flag25)
                                        {
                                            //Debug.Log("No2");
                                            UIRealtimeTip.Popup("物品不足".Translate(), true, 1);
                                        }
                                    }
                                }
                                else
                                {
                                    __instance.inReformOperation = false;
                                }
                                __instance.reformChangedPoint = __instance.reformCenterPoint;
                            }
                            else
                            {
                                __instance.inReformOperation  = false;
                                __instance.reformChangedPoint = Vector3.zero;
                                __instance.reformMouseOnDown  = false;
                            }
                        }
                    }
                }
                else
                {
                    // Just do original code instead
                    return(true);
                }
                __instance.ClearBuildPreviews();
            }
            else
            {
                return(true);
            }
            if (!flag)
            {
                UIRoot.instance.uiGame.CloseInserterBuildTip();
            }
            if (!flag2)
            {
                UIRoot.instance.uiGame.beltBuildTip.SetOutputEntity(0, -1);
                UIRoot.instance.uiGame.CloseBeltBuildTip();
            }


            // Don't execute original put original above instead?
            return(false);
        }
コード例 #13
0
        public static bool ReformSnapTo(
            ref PlanetGrid __instance,
            Vector3 pos,
            int reformSize,
            int reformType,
            int reformColor,
            Vector3[] reformPoints,
            int[] reformIndices,
            PlatformSystem platform,
            out Vector3 reformCenter,
            ref int __result)
        {
            pos.Normalize();

            var num1 = Mathf.Asin(pos.y);
            var num2 = Mathf.Atan2(pos.x, -pos.z);
            //float f1 = num1 / ( 2 * (float)Math.PI) * (float) __instance.segment;
            var f1 = num1 / 6.283185f * __instance.segment;
            var longitudeSegmentCount = PlanetGrid.DetermineLongitudeSegmentCount(Mathf.RoundToInt(Mathf.Abs(f1)), __instance.segment);


            float num3 = longitudeSegmentCount;
            var   f2   = num2 / 6.283185f * num3;
            //float f2 = num2 / ( 2 * (float)Math.PI) * num3;
            var f3   = Mathf.Round(f1 * 10f);
            var f4   = Mathf.Round(f2 * 10f);
            var num4 = Mathf.Abs(f3);
            var num5 = Mathf.Abs(f4);
            var num6 = reformSize % 2;

            if (num4 % 2.0 != num6)
            {
                num4 = Mathf.FloorToInt(Mathf.Abs(f1) * 10f);
                if (num4 % 2.0 != num6)
                {
                    ++num4;
                }
            }

            var num7 = (double)f3 < 0.0 ? -num4 : num4;

            if (num5 % 2.0 != num6)
            {
                num5 = Mathf.FloorToInt(Mathf.Abs(f2) * 10f);
                if (num5 % 2.0 != num6)
                {
                    ++num5;
                }
            }


            var num8 = (double)f4 < 0.0 ? -num5 : num5;
            // float f5 = (float) ((double) num7 / 10.0 / (double) __instance.segment * 2 * (float)Math.PI);
            // float f6 = (float) ((double) num8 / 10.0 / (double) num3 * 2 * (float)Math.PI);
            var f5    = (float)(num7 / 10.0 / __instance.segment * 6.28318548202515);
            var f6    = (float)(num8 / 10.0 / num3 * 6.28318548202515);
            var y1    = Mathf.Sin(f5);
            var num9  = Mathf.Cos(f5);
            var num10 = Mathf.Sin(f6);
            var num11 = Mathf.Cos(f6);

            reformCenter = new Vector3(num9 * num10, y1, num9 * -num11);
            var   num12  = 1 - reformSize;
            var   num13  = 1 - reformSize;
            var   index1 = 0;
            var   num14  = 0;
            float num15  = platform.latitudeCount / 10;

            for (var index2 = 0; index2 < reformSize * reformSize; ++index2)
            {
                ++num14;
                var num16         = (float)((num7 + (double)num12) / 10.0);
                var _longitudeSeg = (float)((num8 + (double)num13) / 10.0);

                num13 += 2;
                if (num14 % reformSize == 0)
                {
                    num13  = 1 - reformSize;
                    num12 += 2;
                }

                if (num16 >= (double)num15 || num16 <= -(double)num15)
                {
                    reformIndices[index2] = -1;
                }
                else
                {
                    var latitudeIndex = Mathf.RoundToInt(Mathf.Abs(num16));

                    if (longitudeSegmentCount != PlanetGrid.DetermineLongitudeSegmentCount(latitudeIndex, __instance.segment))
                    {
                        reformIndices[index2] = -1;
                    }
                    else
                    {
                        var reformIndexForSegment = platform.GetReformIndexForSegment(num16, _longitudeSeg);


                        reformIndices[index2] = reformIndexForSegment;
                        var reformType1  = platform.GetReformType(reformIndexForSegment);
                        var reformColor1 = platform.GetReformColor(reformIndexForSegment);
                        if (!platform.IsTerrainReformed(reformType1) && (reformType1 != reformType || reformColor1 != reformColor))
                        {
                            var f7 = (float)(num16 / (double)__instance.segment * 6.28318548202515);
                            // float f7 = (float) ((double) num16 / (double) __instance.segment *  ( 2 * (float)Math.PI));
                            var f8 = (float)(_longitudeSeg / (double)num3 * 6.28318548202515);
                            //float f8 = (float) ((double) _longitudeSeg / (double) num3 *  ( 2 * (float)Math.PI));
                            var y2    = Mathf.Sin(f7);
                            var num17 = Mathf.Cos(f7);
                            var num18 = Mathf.Sin(f8);
                            var num19 = Mathf.Cos(f8);
                            reformPoints[index1] = new Vector3(num17 * num18, y2, num17 * -num19);
                            ++index1;
                        }
                    }
                }
            }

            __result = index1;

            return(false);
        }
コード例 #14
0
ファイル: VeinPlanter.cs プロジェクト: g82tt/DSPPlugins_ALT
        public int ReformSnap(Vector3 pos, int reformSize, int reformType, int reformColor, Vector3[] reformPoints, int[] reformIndices, PlatformSystem platform, out Vector3 reformCenter, float localPlanetRadius)
        {
            int   num  = veinGardenerState.localPlanet.aux.mainGrid.ReformSnapTo(pos, reformSize, reformType, reformColor, reformPoints, reformIndices, platform, out reformCenter);
            float num2 = localPlanetRadius - 50.2f;

            for (int i = 0; i < num; i++)
            {
                reformPoints[i].x *= num2;
                reformPoints[i].y *= num2;
                reformPoints[i].z *= num2;
            }
            reformCenter *= num2;
            return(num);
        }
コード例 #15
0
        public static void OnUpdate(BuildTool_BlueprintPaste __instance)
        {
            if (!BlueprintCopyExtension.isEnabled)
            {
                return;
            }
            if (reformPreviews.Count <= 0)
            {
                return;
            }
            if (__instance.cannotBuild)
            {
                return;
            }

            tickCounter++;
            if (tickCounter >= 30)
            {
                tickCounter = 0;
                Vector3 center = Vector3.zero;
                tmpPoints.Clear();

                PlatformSystem platformSystem = __instance.factory.platformSystem;

                foreach (ReformData preview in reformPreviews)
                {
                    ReformBPUtils.GetSegmentCount(preview.latitude, preview.longitude, out float latCount, out float longCount, out int segmentCount);
                    longCount = Mathf.Repeat(longCount, segmentCount);

                    int reformIndex = platformSystem.GetReformIndexForSegment(latCount, longCount);
                    if (reformIndex < 0)
                    {
                        continue;
                    }

                    int type = platformSystem.GetReformType(reformIndex);
                    if (platformSystem.IsTerrainReformed(type))
                    {
                        continue;
                    }

                    Vector3 pos = BlueprintUtils.GetDir(preview.longitude, preview.latitude);
                    pos *= GameMain.localPlanet.realRadius + 0.2f;
                    tmpPoints.Add(pos);
                    center += pos;
                }

                lastCost = ReformBPUtils.ComputeFlattenTerrainReform(__instance.factory, tmpPoints, center);
            }

            string message = "";
            int    playerFoundationCount = __instance.player.package.GetItemCount(PlatformSystem.REFORM_ID);

            if (playerFoundationCount < tmpPoints.Count)
            {
                message = Format("NotEnoughFoundationsMessage".Translate(), tmpPoints.Count - playerFoundationCount) + "\n";
            }
            else
            {
                message = Format("FoundCountMessage".Translate(), tmpPoints.Count) + "\n";
            }



            if (__instance.cursorValid && !VFInput.onGUIOperate)
            {
                if (lastCost > 0)
                {
                    __instance.actionBuild.model.cursorText = $"{message}{"沙土消耗".Translate()} {lastCost} {"个沙土".Translate()}";
                }
                else if (lastCost == 0)
                {
                    __instance.actionBuild.model.cursorText = $"{message}";
                }
                else
                {
                    int num2 = -lastCost;
                    __instance.actionBuild.model.cursorText = $"{message}{"沙土获得".Translate()} {num2} {"个沙土".Translate()}";
                }
            }
        }
コード例 #16
0
        public static bool CalculatePositions(BuildTool_BlueprintPaste tool, List <ReformData> reforms, Color[] colors)
        {
            ReformBPUtils.currentGrid = tool.factory.planet.aux.mainGrid;
            PlanetData     planet         = tool.factory.planet;
            PlatformSystem platformSystem = tool.factory.platformSystem;

            Vector3 center = Vector3.zero;

            tmpPoints.Clear();

            foreach (ReformData preview in reforms)
            {
                ReformBPUtils.GetSegmentCount(preview.latitude, preview.longitude, out float latCount, out float longCount, out int segmentCount);
                longCount = Mathf.Repeat(longCount, segmentCount);

                int reformIndex = platformSystem.GetReformIndexForSegment(latCount, longCount);
                if (reformIndex < 0)
                {
                    continue;
                }

                int type = platformSystem.GetReformType(reformIndex);
                if (platformSystem.IsTerrainReformed(type))
                {
                    continue;
                }

                Vector3 pos = BlueprintUtils.GetDir(preview.longitude, preview.latitude);
                pos *= planet.realRadius + 0.2f;
                tmpPoints.Add(pos);
                center += pos;
            }

            int cost = ReformBPUtils.ComputeFlattenTerrainReform(tool.factory, tmpPoints, center);

            if (NebulaModAPI.IsMultiplayerActive)
            {
                IMultiplayerSession session = NebulaModAPI.MultiplayerSession;
                if (!session.Factories.IsIncomingRequest.Value && !CheckItems(tool, cost, tmpPoints.Count))
                {
                    return(false);
                }

                if (session.LocalPlayer.IsHost)
                {
                    int planetId = session.Factories.EventFactory?.planetId ?? GameMain.localPlanet?.id ?? -1;
                    session.Network.SendPacketToStar(new ReformPasteEventPacket(planetId, reforms, colors, session.Factories.PacketAuthor == NebulaModAPI.AUTHOR_NONE ? session.LocalPlayer.Id : session.Factories.PacketAuthor), GameMain.galaxy.PlanetById(planetId).star.id);
                }

                //If client builds, he need to first send request to the host and wait for reply
                if (!session.LocalPlayer.IsHost && !session.Factories.IsIncomingRequest.Value)
                {
                    session.Network.SendPacket(new ReformPasteEventPacket(GameMain.localPlanet?.id ?? -1, reforms, colors, session.Factories.PacketAuthor == NebulaModAPI.AUTHOR_NONE ? session.LocalPlayer.Id : session.Factories.PacketAuthor));
                    return(true);
                }
            }
            else
            {
                if (!CheckItems(tool, cost, tmpPoints.Count))
                {
                    return(false);
                }
            }

            if (colors != null && colors.Length > 0)
            {
                ApplyColors(tool, colors);
            }

            ReformBPUtils.FlattenTerrainReform(tool.factory, tmpPoints, center);
            VFAudio.Create("reform-terrain", null, center, true, 4);

            foreach (ReformData preview in reforms)
            {
                ReformBPUtils.GetSegmentCount(preview.latitude, preview.longitude, out float latCount, out float longCount, out int segmentCount);
                longCount = Mathf.Repeat(longCount, segmentCount);

                int reformIndex = platformSystem.GetReformIndexForSegment(latCount, longCount);

                if (reformIndex < 0)
                {
                    continue;
                }

                int reformType  = platformSystem.GetReformType(reformIndex);
                int reformColor = platformSystem.GetReformColor(reformIndex);
                if (reformType == preview.type && reformColor == preview.color)
                {
                    continue;
                }

                platformSystem.SetReformType(reformIndex, preview.type);
                platformSystem.SetReformColor(reformIndex, preview.color);
            }

            return(true);
        }
コード例 #17
0
        public static void Update(UIBuildingGrid __instance)
        {
            if (!BlueprintCopyExtension.isEnabled)
            {
                return;
            }

            Player mainPlayer = GameMain.mainPlayer;

            PlanetFactory planetFactory = GameMain.localPlanet?.factory;

            if (planetFactory == null)
            {
                return;
            }

            if (GameMain.localPlanet.type == EPlanetType.Gas)
            {
                return;
            }

            PlayerAction_Build actionBuild = mainPlayer?.controller.actionBuild;

            if (actionBuild == null)
            {
                return;
            }

            if (__instance.reformCursorMap == null)
            {
                return;
            }

            int            maxLen = __instance.reformCursorMap.Length;
            PlatformSystem system = planetFactory.platformSystem;

            if (system == null)
            {
                return;
            }
            system.EnsureReformData();

            if (actionBuild.blueprintMode == EBlueprintMode.None)
            {
                __instance.material.SetColor(cursorColor, Color.white);
                return;
            }

            float realRadius = GameMain.localPlanet.realRadius;

            __instance.displayScale = (realRadius + 0.2f) * 2f;

            if (currentFactory == null || currentFactory.index != planetFactory.index)
            {
                currentFactory = planetFactory;

                fakeReformData = new byte[system.maxReformCount];
                Array.Copy(system.reformData, fakeReformData, system.maxReformCount);
            }

            if (actionBuild.blueprintMode == EBlueprintMode.Copy)
            {
                bool any = false;
                if (BlueprintCopyExtension.reformSelection.Count > 0)
                {
                    __instance.material.SetColor(cursorColor, displayColor);
                    foreach (var kv in BlueprintCopyExtension.reformSelection)
                    {
                        int index = kv.Key;
                        if (index >= 0 && index < maxLen)
                        {
                            if (BlueprintCopyExtension.reformPreSelection.Count == 0)
                            {
                                fakeReformData[index] = 0;
                            }

                            __instance.reformCursorMap[index] = 1;
                        }
                    }
                    any = true;
                }

                if (BlueprintCopyExtension.reformPreSelection.Count > 0)
                {
                    __instance.material.SetColor(cursorColor, selectColor);

                    foreach (var kv in BlueprintCopyExtension.reformPreSelection)
                    {
                        int index = kv.Key;
                        if (index >= 0 && index < maxLen)
                        {
                            fakeReformData[index]             = 0;
                            __instance.reformCursorMap[index] = 1;
                        }
                    }
                    any = true;
                }

                if (any)
                {
                    __instance.material.SetColor(tintColor, Color.clear);
                    __instance.gridRnd.enabled = true;
                    __instance.material.SetFloat(reformMode, 1f);
                    __instance.material.SetFloat(zMin, -1.5f);
                    __instance.reformCursorBuffer.SetData(__instance.reformCursorMap);
                    __instance.material.SetBuffer(cursorBuffer, __instance.reformCursorBuffer);

                    ComputeBuffer reformDataBuffer = system.reformDataBuffer;
                    reformDataBuffer.SetData(fakeReformData);
                    __instance.material.SetBuffer(dataBuffer, reformDataBuffer);

                    foreach (var kv in BlueprintCopyExtension.reformSelection)
                    {
                        int index = kv.Key;
                        if (index >= 0 && index < maxLen)
                        {
                            if (BlueprintCopyExtension.reformPreSelection.Count == 0)
                            {
                                fakeReformData[index] = system.reformData[index];
                            }

                            __instance.reformCursorMap[index] = 0;
                        }
                    }

                    foreach (var kv in BlueprintCopyExtension.reformPreSelection)
                    {
                        int index = kv.Key;
                        if (index >= 0 && index < maxLen)
                        {
                            fakeReformData[index]             = system.reformData[index];
                            __instance.reformCursorMap[index] = 0;
                        }
                    }
                }
            }

            if (actionBuild.blueprintMode == EBlueprintMode.Paste)
            {
                ReformBPUtils.currentGrid = GameMain.localPlanet.aux.mainGrid;

                __instance.material.SetColor(cursorColor, displayColor);
                __instance.gridRnd.enabled = true;
                PlatformSystem platformSystem = __instance.reformMapPlanet.factory.platformSystem;
                if (BlueprintPasteExtension.reformPreviews.Count > 0)
                {
                    foreach (ReformData reformPreview in BlueprintPasteExtension.reformPreviews)
                    {
                        ReformBPUtils.GetSegmentCount(reformPreview.latitude, reformPreview.longitude, out float latCount, out float longCount, out int segmentCount);
                        longCount = Mathf.Repeat(longCount, segmentCount);

                        int index = platformSystem.GetReformIndexForSegment(latCount, longCount);
                        if (index >= 0 && index < maxLen)
                        {
                            __instance.reformCursorMap[index] = 1;
                        }
                    }

                    __instance.material.SetColor(tintColor, Color.clear);
                    __instance.material.SetFloat(reformMode, 1f);
                    __instance.material.SetFloat(zMin, -1.5f);
                    __instance.reformCursorBuffer.SetData(__instance.reformCursorMap);
                    __instance.material.SetBuffer(cursorBuffer, __instance.reformCursorBuffer);

                    foreach (ReformData reformPreview in BlueprintPasteExtension.reformPreviews)
                    {
                        ReformBPUtils.GetSegmentCount(reformPreview.latitude, reformPreview.longitude, out float latCount, out float longCount, out int segmentCount);
                        longCount = Mathf.Repeat(longCount, segmentCount);

                        int index = platformSystem.GetReformIndexForSegment(latCount, longCount);
                        if (index >= 0 && index < maxLen)
                        {
                            __instance.reformCursorMap[index] = 0;
                        }
                    }
                }
            }
        }
コード例 #18
0
 private void Awake()
 {
     platformSystem = GameObject.FindGameObjectWithTag("PlatformSystem").GetComponent <PlatformSystem>();
 }