public static bool CreatePrebuilds_Prefix(BuildTool __instance)
        {
            if (!Multiplayer.IsActive)
            {
                return(true);
            }

            List <BuildPreview> previews = __instance.buildPreviews;

            if (__instance is BuildTool_BlueprintPaste)
            {
                BuildTool_BlueprintPaste bpInstance = __instance as BuildTool_BlueprintPaste;
                previews = bpInstance.bpPool.Take(bpInstance.bpCursor).ToList();
            }
            if (__instance is BuildTool_PathAddon)
            {
                // traffic monitors & sprayers cannot be drag build atm, so its always only one.
                previews = new List <BuildPreview>();
                previews.Add(((BuildTool_PathAddon)__instance).handbp);
            }

            // Host will just broadcast event to other players
            if (Multiplayer.Session.LocalPlayer.IsHost)
            {
                int planetId   = Multiplayer.Session.Factories.EventFactory?.planetId ?? GameMain.localPlanet?.id ?? -1;
                int authorId   = Multiplayer.Session.Factories.PacketAuthor == NebulaModAPI.AUTHOR_NONE ? Multiplayer.Session.LocalPlayer.Id : Multiplayer.Session.Factories.PacketAuthor;
                int prebuildId = Multiplayer.Session.Factories.GetNextPrebuildId(planetId);
                Multiplayer.Session.Network.SendPacketToStar(new CreatePrebuildsRequest(planetId, previews, authorId, __instance.GetType().ToString(), prebuildId), GameMain.galaxy.PlanetById(planetId).star.id);
            }

            //If client builds, he need to first send request to the host and wait for reply
            if (!Multiplayer.Session.LocalPlayer.IsHost && !Multiplayer.Session.Factories.IsIncomingRequest.Value)
            {
                if (Multiplayer.Session.BuildTools.InitialCheck(previews[0].lpos))
                {
                    int authorId = Multiplayer.Session.Factories.PacketAuthor == NebulaModAPI.AUTHOR_NONE ? Multiplayer.Session.LocalPlayer.Id : Multiplayer.Session.Factories.PacketAuthor;
                    Multiplayer.Session.Network.SendPacket(new CreatePrebuildsRequest(GameMain.localPlanet?.id ?? -1, previews, authorId, __instance.GetType().ToString(), -1));
                }
                return(false);
            }
            return(true);
        }
示例#2
0
        public static bool CreatePrebuilds_Prefix(BuildTool __instance)
        {
            if (!SimulatedWorld.Initialized)
            {
                return(true);
            }


            List <BuildPreview> previews = __instance.buildPreviews;

            if (__instance is BuildTool_BlueprintPaste)
            {
                BuildTool_BlueprintPaste bpInstance = __instance as BuildTool_BlueprintPaste;
                previews = bpInstance.bpPool.Take(bpInstance.bpCursor).ToList();
            }

            // Host will just broadcast event to other players
            if (LocalPlayer.IsMasterClient)
            {
                int planetId = FactoryManager.EventFactory?.planetId ?? GameMain.localPlanet?.id ?? -1;
                LocalPlayer.SendPacketToStar(new CreatePrebuildsRequest(planetId, previews, FactoryManager.PacketAuthor == FactoryManager.AUTHOR_NONE ? LocalPlayer.PlayerId : FactoryManager.PacketAuthor, __instance.GetType().ToString()), GameMain.galaxy.PlanetById(planetId).star.id);
            }

            //If client builds, he need to first send request to the host and wait for reply
            if (!LocalPlayer.IsMasterClient && !FactoryManager.IsIncomingRequest)
            {
                LocalPlayer.SendPacket(new CreatePrebuildsRequest(GameMain.localPlanet?.id ?? -1, previews, FactoryManager.PacketAuthor == FactoryManager.AUTHOR_NONE ? LocalPlayer.PlayerId : FactoryManager.PacketAuthor, __instance.GetType().ToString()));
                return(false);
            }
            return(true);
        }
        public static bool CreatePrebuilds_Prefix(BuildTool __instance)
        {
            if (!SimulatedWorld.Initialized)
            {
                return(true);
            }

            // Host will just broadcast event to other players
            if (LocalPlayer.IsMasterClient)
            {
                int planetId = FactoryManager.EventFactory?.planetId ?? GameMain.localPlanet?.id ?? -1;
                LocalPlayer.SendPacketToStar(new CreatePrebuildsRequest(planetId, __instance.buildPreviews, FactoryManager.PacketAuthor == -1 ? LocalPlayer.PlayerId : FactoryManager.PacketAuthor, __instance.GetType().ToString()), GameMain.galaxy.PlanetById(planetId).star.id);
            }

            //If client builds, he need to first send request to the host and wait for reply
            if (!LocalPlayer.IsMasterClient && !FactoryManager.EventFromServer)
            {
                LocalPlayer.SendPacket(new CreatePrebuildsRequest(GameMain.localPlanet?.id ?? -1, __instance.buildPreviews, FactoryManager.PacketAuthor == -1 ? LocalPlayer.PlayerId : FactoryManager.PacketAuthor, __instance.GetType().ToString()));
                return(false);
            }
            return(true);
        }