コード例 #1
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);
        }