private bool SaveGridToFile(string path, string filename, List <MyObjectBuilder_CubeGrid> objectBuilders)
        {
            MyObjectBuilder_ShipBlueprintDefinition definition =
                MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_ShipBlueprintDefinition>();

            definition.Id = new MyDefinitionId(new MyObjectBuilderType(typeof(MyObjectBuilder_ShipBlueprintDefinition)),
                                               filename);
            definition.CubeGrids = objectBuilders.Select(x => (MyObjectBuilder_CubeGrid)x.Clone()).ToArray();

            /* Reset ownership as it will be different on the new server anyway */
            foreach (MyObjectBuilder_CubeGrid cubeGrid in definition.CubeGrids)
            {
                foreach (MyObjectBuilder_CubeBlock cubeBlock in cubeGrid.CubeBlocks)
                {
                    cubeBlock.Owner   = 0L;
                    cubeBlock.BuiltBy = 0L;
                }
            }

            MyObjectBuilder_Definitions builderDefinition =
                MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_Definitions>();

            builderDefinition.ShipBlueprints = new MyObjectBuilder_ShipBlueprintDefinition[] { definition };


            return(MyObjectBuilderSerializer.SerializeXML(path, false, builderDefinition));
        }
Esempio n. 2
0
        private bool LoadShipBlueprint(MyObjectBuilder_ShipBlueprintDefinition shipBlueprint, Vector3D TargetLocation, bool keepOriginalLocation, Chat chat, Hangar Plugin, bool force = false)
        {
            var grids = shipBlueprint.CubeGrids;

            if (grids == null || grids.Length == 0)
            {
                chat.Respond("No grids in blueprint!");
                return(false);
            }

            try
            {
                MyIdentity IDentity = MySession.Static.Players.TryGetPlayerIdentity(new MyPlayer.PlayerId(SteamID));

                if (Plugin.GridBackup != null)
                {
                    Plugin.GridBackup.GetType().GetMethod("BackupGridsManuallyWithBuilders", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance, null, new Type[2] {
                        typeof(List <MyObjectBuilder_CubeGrid>), typeof(long)
                    }, null).Invoke(Plugin.GridBackup, new object[] { grids.ToList(), IDentity.IdentityId });
                    Log.Warn("Successfully BackedUp grid!");
                }
            }
            catch (Exception e)
            {
                Log.Fatal(e);
            }

            //For loading in the same location



            ParallelSpawner Spawner = new ParallelSpawner(grids, chat);

            return(Spawner.Start(keepOriginalLocation, TargetLocation));
        }
Esempio n. 3
0
        public static bool SaveGrid(string path, string filename, bool keepOriginalOwner, bool keepProjection, List <MyObjectBuilder_CubeGrid> objectBuilders)
        {
            MyObjectBuilder_ShipBlueprintDefinition definition = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_ShipBlueprintDefinition>();

            definition.Id        = new MyDefinitionId(new MyObjectBuilderType(typeof(MyObjectBuilder_ShipBlueprintDefinition)), filename);
            definition.CubeGrids = objectBuilders.Select(x => (MyObjectBuilder_CubeGrid)x.Clone()).ToArray();

            /* Reset ownership as it will be different on the new server anyway */
            foreach (MyObjectBuilder_CubeGrid cubeGrid in definition.CubeGrids)
            {
                foreach (MyObjectBuilder_CubeBlock cubeBlock in cubeGrid.CubeBlocks)
                {
                    if (!keepOriginalOwner)
                    {
                        cubeBlock.Owner   = 0L;
                        cubeBlock.BuiltBy = 0L;
                    }

                    /* Remove Projections if not needed */
                    if (!keepProjection)
                    {
                        if (cubeBlock is MyObjectBuilder_ProjectorBase projector)
                        {
                            projector.ProjectedGrids = null;
                        }
                    }

                    /* Remove Pilot and Components (like Characters) from cockpits */
                    if (cubeBlock is MyObjectBuilder_Cockpit cockpit)
                    {
                        cockpit.Pilot = null;

                        if (cockpit.ComponentContainer != null)
                        {
                            var components = cockpit.ComponentContainer.Components;

                            if (components != null)
                            {
                                for (int i = components.Count - 1; i >= 0; i--)
                                {
                                    var component = components[i];

                                    if (component.TypeId == "MyHierarchyComponentBase")
                                    {
                                        components.RemoveAt(i);
                                        continue;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            MyObjectBuilder_Definitions builderDefinition = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_Definitions>();

            builderDefinition.ShipBlueprints = new MyObjectBuilder_ShipBlueprintDefinition[] { definition };

            return(MyObjectBuilderSerializer.SerializeXML(path, false, builderDefinition));
        }
Esempio n. 4
0
        public static bool SaveGrid(string path, string filename, string ip, bool keepOriginalOwner, bool keepProjection, List <MyObjectBuilder_CubeGrid> objectBuilders)
        {
            MyObjectBuilder_ShipBlueprintDefinition definition = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_ShipBlueprintDefinition>();

            definition.Id        = new MyDefinitionId(new MyObjectBuilderType(typeof(MyObjectBuilder_ShipBlueprintDefinition)), filename);
            definition.CubeGrids = objectBuilders.Select(x => (MyObjectBuilder_CubeGrid)x.Clone()).ToArray();
            List <ulong> playerIds = new List <ulong>();

            /* Reset ownership as it will be different on the new server anyway */
            foreach (MyObjectBuilder_CubeGrid cubeGrid in definition.CubeGrids)
            {
                foreach (MyObjectBuilder_CubeBlock cubeBlock in cubeGrid.CubeBlocks)
                {
                    if (!keepOriginalOwner)
                    {
                        cubeBlock.Owner   = 0L;
                        cubeBlock.BuiltBy = 0L;
                    }

                    /* Remove Projections if not needed */
                    if (!keepProjection)
                    {
                        if (cubeBlock is MyObjectBuilder_ProjectorBase projector)
                        {
                            projector.ProjectedGrids = null;
                        }
                    }

                    /* Remove Pilot and Components (like Characters) from cockpits */
                    if (cubeBlock is MyObjectBuilder_Cockpit cockpit)
                    {
                        if (cockpit.Pilot != null)
                        {
                            var playersteam = cockpit.Pilot.PlayerSteamId;
                            var player      = PlayerUtils.GetIdentityByNameOrId(playersteam.ToString());
                            playerIds.Add(playersteam);
                            ModCommunication.SendMessageTo(new JoinServerMessage(ip), playersteam);
                        }
                    }
                }
            }

            MyObjectBuilder_Definitions builderDefinition = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_Definitions>();

            builderDefinition.ShipBlueprints = new MyObjectBuilder_ShipBlueprintDefinition[] { definition };
            foreach (var playerId in playerIds)
            {
                var player = PlayerUtils.GetIdentityByNameOrId(playerId.ToString());
                player.Character.EnableBag(false);
                Sandbox.Game.MyVisualScriptLogicProvider.SetPlayersHealth(player.IdentityId, 0);
                player.Character.Delete();
            }
            return(MyObjectBuilderSerializer.SerializeXML(path, false, builderDefinition));
        }
        private static bool SaveGridToFile(string Path, string Name, IEnumerable <MyObjectBuilder_CubeGrid> GridBuilders)
        {
            MyObjectBuilder_ShipBlueprintDefinition definition = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_ShipBlueprintDefinition>();

            definition.Id        = new MyDefinitionId(new MyObjectBuilderType(typeof(MyObjectBuilder_ShipBlueprintDefinition)), Name);
            definition.CubeGrids = GridBuilders.ToArray();
            PrepareGridForSave(definition);

            MyObjectBuilder_Definitions builderDefinition = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_Definitions>();

            builderDefinition.ShipBlueprints = new MyObjectBuilder_ShipBlueprintDefinition[] { definition };

            return(MyObjectBuilderSerializer.SerializeXML(Path, false, builderDefinition));
        }
        private static bool SaveGridToFile(string SavePath, string GridName, IEnumerable <MyObjectBuilder_CubeGrid> GridBuilders)
        {
            MyObjectBuilder_ShipBlueprintDefinition definition = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_ShipBlueprintDefinition>();

            definition.Id        = new MyDefinitionId(new MyObjectBuilderType(typeof(MyObjectBuilder_ShipBlueprintDefinition)), GridName);
            definition.CubeGrids = GridBuilders.ToArray();
            //PrepareGridForSave(definition);

            MyObjectBuilder_Definitions builderDefinition = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_Definitions>();

            builderDefinition.ShipBlueprints = new MyObjectBuilder_ShipBlueprintDefinition[] { definition };



            Log.Warn("Saving grid @" + Path.Combine(SavePath, GridName + ".sbc"));
            return(MyObjectBuilderSerializer.SerializeXML(Path.Combine(SavePath, GridName + ".sbc"), false, builderDefinition));
        }
        private static void PrepareGridForSave(MyObjectBuilder_ShipBlueprintDefinition GridDefinition)
        {
            foreach (MyObjectBuilder_CubeGrid cubeGrid in GridDefinition.CubeGrids)
            {
                Parallel.ForEach(cubeGrid.CubeBlocks, CubeBlock => {
                    if (!KeepOriginalOwner)
                    {
                        CubeBlock.Owner   = 0L;
                        CubeBlock.BuiltBy = 0L;
                    }

                    /* Remove Projections if not needed */
                    if (!KeepProjectionsOnSave)
                    {
                        if (CubeBlock is MyObjectBuilder_ProjectorBase projector)
                        {
                            projector.ProjectedGrids = null;
                        }
                    }

                    /* Remove Pilot and Components (like Characters) from cockpits */
                    if (CubeBlock is MyObjectBuilder_Cockpit cockpit)
                    {
                        cockpit.Pilot = null;
                        if (cockpit.ComponentContainer != null)
                        {
                            var components = cockpit.ComponentContainer.Components;
                            if (components != null)
                            {
                                for (int i = components.Count - 1; i >= 0; i--)
                                {
                                    var component = components[i];
                                    if (component.TypeId == "MyHierarchyComponentBase")
                                    {
                                        components.RemoveAt(i);
                                        continue;
                                    }
                                }
                            }
                        }
                    }
                });
            }
        }
        private bool LoadShipBlueprint(MyObjectBuilder_ShipBlueprintDefinition shipBlueprint,
                                       Vector3D PlayerLocation)
        {
            var grids = shipBlueprint.CubeGrids;

            if (grids == null || grids.Length == 0)
            {
                Log.Info("No grids in blueprint!");
                return(false);
            }

            Vector3D TargetLocation = PlayerLocation;
            bool     AlignToGravity = true;


            ParallelSpawner Spawner = new ParallelSpawner(grids, AlignToGravity);

            Log.Info("Attempting Grid Spawning @" + TargetLocation.ToString());
            return(Spawner.Start(TargetLocation));
        }
        private bool LoadShipBlueprint(MyObjectBuilder_ShipBlueprintDefinition shipBlueprint, Vector3D GridSaveLocation, Vector3D SpawningPlayerLocation, bool keepOriginalLocation, Chat chat)
        {
            var grids = shipBlueprint.CubeGrids;

            if (grids == null || grids.Length == 0)
            {
                Chat?.Respond("No grids in blueprint!");
                return(false);
            }


            MyIdentity Identity = MySession.Static.Players.TryGetPlayerIdentity(new MyPlayer.PlayerId(SteamID));


            if (Identity != null)
            {
                PluginDependencies.BackupGrid(grids.ToList(), Identity.IdentityId);
            }


            Vector3D TargetLocation;
            bool     AlignToGravity = false;

            if (keepOriginalLocation || SpawningPlayerLocation == Vector3D.Zero)
            {
                TargetLocation = GridSaveLocation;
            }
            else
            {
                AlignToGravity = true;
                TargetLocation = SpawningPlayerLocation;
            }

            ParallelSpawner Spawner = new ParallelSpawner(grids, chat, AlignToGravity);

            Log.Info("Attempting Grid Spawning @" + TargetLocation.ToString());
            return(Spawner.Start(keepOriginalLocation, TargetLocation));
        }
Esempio n. 10
0
        public void Wormholetransferout(string sendto, double xgate, double ygate, double zgate)
        {
            Vector3D        gatepoint = new Vector3D(xgate, ygate, zgate);
            BoundingSphereD gate      = new BoundingSphereD(gatepoint, Config.RadiusGate);

            foreach (var grid in MyAPIGateway.Entities.GetTopMostEntitiesInSphere(ref gate).OfType <IMyCubeGrid>())
            {
                var WormholeDrives = new List <IMyJumpDrive>();

                var gts = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(grid);

                if (gts == null)
                {
                    continue;
                }

                gts.GetBlocksOfType(WormholeDrives);

                if (WormholeDrives.Count <= 0)
                {
                    continue;
                }

                foreach (var WormholeDrive in WormholeDrives)
                {
                    if (!Config.JumpDriveSubid.Split(',').Any(s => s.Trim() == WormholeDrive.BlockDefinition.SubtypeId) && !Config.WorkWithAllJD)
                    {
                        continue;
                    }

                    Request request = default;
                    try
                    {
                        request = MyAPIGateway.Utilities.SerializeFromXML <Request>(WormholeDrive.CustomData);
                    }
                    catch { }

                    string pickeddestination = default;

                    if (request != null)
                    {
                        if (request.PluginRequest)
                        {
                            if (request.Destination != null)
                            {
                                if (sendto.Split(',').Any(s => s.Trim() == request.Destination.Trim()))
                                {
                                    pickeddestination = request.Destination.Trim();
                                }
                            }
                            Request reply = new Request
                            {
                                PluginRequest = false,
                                Destination   = null,
                                Destinations  = sendto.Split(',').Select(s => s.Trim()).ToArray()
                            };
                            WormholeDrive.CustomData = MyAPIGateway.Utilities.SerializeToXML <Request>(reply);
                        }
                    }
                    else
                    {
                        Request reply = new Request
                        {
                            PluginRequest = false,
                            Destination   = null,
                            Destinations  = sendto.Split(',').Select(s => s.Trim()).ToArray()
                        };
                        WormholeDrive.CustomData = MyAPIGateway.Utilities.SerializeToXML <Request>(reply);
                    }

                    if (Config.AutoSend && sendto.Split(',').Length == 1)
                    {
                        pickeddestination = sendto.Split(',')[0].Trim();
                    }

                    if (pickeddestination == null)
                    {
                        continue;
                    }

                    if (!WormholeDrive.IsWorking || WormholeDrive.CurrentStoredPower != WormholeDrive.MaxStoredPower)
                    {
                        continue;
                    }

                    var playerInCharge = MyAPIGateway.Players.GetPlayerControllingEntity(grid);
                    if (playerInCharge == null || !Utilities.HasRightToMove(playerInCharge, grid as MyCubeGrid))
                    {
                        continue;
                    }

                    WormholeDrive.CurrentStoredPower = 0;
                    foreach (var DisablingWormholeDrive in WormholeDrives)
                    {
                        if (Config.JumpDriveSubid.Split(',').Any(s => s.Trim() == DisablingWormholeDrive.BlockDefinition.SubtypeId) || Config.WorkWithAllJD)
                        {
                            DisablingWormholeDrive.Enabled = false;
                        }
                    }
                    List <MyCubeGrid> grids = Utilities.FindGridList(grid.EntityId.ToString(), playerInCharge as MyCharacter, Config.IncludeConnectedGrids);

                    if (grids == null)
                    {
                        return;
                    }

                    if (grids.Count == 0)
                    {
                        return;
                    }

                    MyVisualScriptLogicProvider.CreateLightning(gatepoint);

                    //NEED TO DROP ENEMY GRIDS
                    if (Config.WormholeGates.Any(s => s.Name.Trim() == pickeddestination.Split(':')[0]))
                    {
                        foreach (WormholeGate internalwormhole in Config.WormholeGates)
                        {
                            if (internalwormhole.Name.Trim() == pickeddestination.Split(':')[0].Trim())
                            {
                                var box         = WormholeDrive.GetTopMostParent().WorldAABB;
                                var togatepoint = new Vector3D(internalwormhole.X, internalwormhole.Y, internalwormhole.Z);
                                var togate      = new BoundingSphereD(togatepoint, Config.RadiusGate);
                                Utilities.UpdateGridsPositionAndStopLive(WormholeDrive.GetTopMostParent(), Utilities.FindFreePos(togate, (float)(Vector3D.Distance(box.Center, box.Max) + 50)));
                                MyVisualScriptLogicProvider.CreateLightning(togatepoint);
                            }
                        }
                    }
                    else
                    {
                        var destination = pickeddestination.Split(':');

                        var filename = $"{destination[0]}_{playerInCharge.SteamUserId}_{Utilities.LegalCharOnly(playerInCharge.DisplayName)}_{Utilities.LegalCharOnly(grid.DisplayName)}_{DateTime.Now:yyyy_MM_dd_HH_mm_ss}";

                        List <MyObjectBuilder_CubeGrid> objectBuilders = new List <MyObjectBuilder_CubeGrid>();
                        foreach (MyCubeGrid mygrid in grids)
                        {
                            if (!(mygrid.GetObjectBuilder(true) is MyObjectBuilder_CubeGrid objectBuilder))
                            {
                                throw new ArgumentException(mygrid + " has a ObjectBuilder thats not for a CubeGrid");
                            }
                            objectBuilders.Add(objectBuilder);
                        }
                        MyObjectBuilder_ShipBlueprintDefinition definition = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_ShipBlueprintDefinition>();

                        definition.Id = new MyDefinitionId(new MyObjectBuilderType(typeof(MyObjectBuilder_ShipBlueprintDefinition)), filename);

                        definition.CubeGrids = objectBuilders.Select(x => (MyObjectBuilder_CubeGrid)x.Clone()).ToArray();

                        List <ulong> playerIds = new List <ulong>();
                        foreach (MyObjectBuilder_CubeGrid cubeGrid in definition.CubeGrids)
                        {
                            foreach (MyObjectBuilder_CubeBlock cubeBlock in cubeGrid.CubeBlocks)
                            {
                                cubeBlock.Owner   = 0L;
                                cubeBlock.BuiltBy = 0L;
                                if (!Config.ExportProjectorBlueprints)
                                {
                                    if (cubeBlock is MyObjectBuilder_ProjectorBase projector)
                                    {
                                        projector.ProjectedGrids = null;
                                    }
                                }
                                if (cubeBlock is MyObjectBuilder_Cockpit cockpit)
                                {
                                    if (cockpit.Pilot != null)
                                    {
                                        var playersteam = cockpit.Pilot.PlayerSteamId;
                                        var player      = Utilities.GetIdentityByNameOrId(playersteam.ToString());
                                        playerIds.Add(playersteam);
                                        ModCommunication.SendMessageTo(new JoinServerMessage(destination[1] + ":" + destination[2]), playersteam);
                                    }
                                }
                            }
                        }

                        MyObjectBuilder_Definitions builderDefinition = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_Definitions>();
                        builderDefinition.ShipBlueprints = new[] { definition };
                        foreach (var playerId in playerIds)
                        {
                            var player = Utilities.GetIdentityByNameOrId(playerId.ToString());
                            player.Character.EnableBag(false);
                            MyVisualScriptLogicProvider.SetPlayersHealth(player.IdentityId, 0);
                            player.Character.Close();
                        }
                        if (MyObjectBuilderSerializer.SerializeXML(Utilities.CreateBlueprintPath(Path.Combine(Config.Folder, admingatesfolder), filename), false, builderDefinition))
                        {
                            grids.ForEach(b => b.Close());
                        }
                    }
                }
            }
        }
Esempio n. 11
0
        private bool LoadShipBlueprint(MyObjectBuilder_ShipBlueprintDefinition shipBlueprint,
                                       Vector3D playerPosition, bool keepOriginalLocation, Chat chat, bool force = false)
        {
            var grids = shipBlueprint.CubeGrids;

            if (grids == null || grids.Length == 0)
            {
                Hangar.Debug("No grids in blueprint!");
                chat.Respond("No grids in blueprint!");

                return(false);
            }


            bool LoadNearPosition = false;
            //For loading in the same location

            ParallelSpawner Spawner  = new ParallelSpawner(grids);
            var             position = grids[0].PositionAndOrientation.Value;

            if (keepOriginalLocation)
            {
                var sphere = FindBoundingSphere(grids);



                sphere.Center = position.Position;

                List <MyEntity> entities = new List <MyEntity>();
                MyGamePruningStructure.GetAllTopMostEntitiesInSphere(ref sphere, entities);

                foreach (var entity in entities)
                {
                    if (entity is MyCubeGrid)
                    {
                        chat.Respond("There are potentially other grids in the way. Loading near the original point.");

                        LoadNearPosition = true;
                    }
                }

                if (!LoadNearPosition)
                {
                    /* Remapping to prevent any key problems upon paste. */
                    MyEntities.RemapObjectBuilderCollection(grids);

                    Spawner.Start();

                    return(true);
                }
            }



            /*
             *  Everything else is loading for near player
             *
             *
             *
             */



            /* Where do we want to paste the grids? Lets find out. */
            var pos = FindPastePosition(grids, position.Position);

            if (pos == null)
            {
                Hangar.Debug("No free Space found!");
                chat.Respond("No free space available!");

                return(false);
            }

            var newPosition = pos.Value;

            /* Update GridsPosition if that doesnt work get out of here. */
            if (!UpdateGridsPosition(grids, newPosition))
            {
                chat.Respond("The File to be imported does not seem to be compatible with the server!");

                return(false);
            }


            MyEntities.RemapObjectBuilderCollection(grids);
            Spawner.Start();
            return(true);
        }
        private void WormholeTransferOutFile(string sendto, IMyCubeGrid grid, IMyJumpDrive WormholeDrive, Vector3D gatepoint, List <IMyJumpDrive> WormholeDrives)
        {
            if (!Config.JumpDriveSubid.Split(',').Any(s => s.Trim() == WormholeDrive.BlockDefinition.SubtypeId) && !Config.WorkWithAllJD)
            {
                return;
            }

            Request request = default;

            try
            {
                request = MyAPIGateway.Utilities.SerializeFromXML <Request>(WormholeDrive.CustomData);
            }
            catch { }

            string pickeddestination = default;

            if (request != null)
            {
                if (request.PluginRequest)
                {
                    if (request.Destination != null)
                    {
                        if (sendto.Split(',').Any(s => s.Trim() == request.Destination.Trim()))
                        {
                            pickeddestination = request.Destination.Trim();
                        }
                    }
                    Request reply = new Request
                    {
                        PluginRequest = false,
                        Destination   = null,
                        Destinations  = sendto.Split(',').Select(s => s.Trim()).ToArray()
                    };
                    WormholeDrive.CustomData = MyAPIGateway.Utilities.SerializeToXML <Request>(reply);
                }
            }
            else
            {
                Request reply = new Request
                {
                    PluginRequest = false,
                    Destination   = null,
                    Destinations  = sendto.Split(',').Select(s => s.Trim()).ToArray()
                };
                WormholeDrive.CustomData = MyAPIGateway.Utilities.SerializeToXML <Request>(reply);
            }

            if (Config.AutoSend && sendto.Split(',').Length == 1)
            {
                pickeddestination = sendto.Split(',')[0].Trim();
            }

            if (pickeddestination == null)
            {
                return;
            }

            if (!WormholeDrive.IsWorking || WormholeDrive.CurrentStoredPower != WormholeDrive.MaxStoredPower)
            {
                return;
            }

            var playerInCharge = MyAPIGateway.Players.GetPlayerControllingEntity(grid);

            if (playerInCharge == null || !Utilities.HasRightToMove(playerInCharge, grid as MyCubeGrid))
            {
                return;
            }

            WormholeDrive.CurrentStoredPower = 0;
            foreach (var DisablingWormholeDrive in WormholeDrives)
            {
                if (Config.JumpDriveSubid.Split(',').Any(s => s.Trim() == DisablingWormholeDrive.BlockDefinition.SubtypeId) || Config.WorkWithAllJD)
                {
                    DisablingWormholeDrive.Enabled = false;
                }
            }
            List <MyCubeGrid> grids = Utilities.FindGridList(grid.EntityId.ToString(), playerInCharge as MyCharacter, Config.IncludeConnectedGrids);

            if (grids == null)
            {
                return;
            }

            if (grids.Count == 0)
            {
                return;
            }

            MyVisualScriptLogicProvider.CreateLightning(gatepoint);

            //NEED TO DROP ENEMY GRIDS
            if (Config.WormholeGates.Any(s => s.Name.Trim() == pickeddestination.Split(':')[0]))
            {
                foreach (WormholeGate internalwormhole in Config.WormholeGates)
                {
                    if (internalwormhole.Name.Trim() == pickeddestination.Split(':')[0].Trim())
                    {
                        var box         = WormholeDrive.GetTopMostParent().WorldAABB;
                        var togatepoint = new Vector3D(internalwormhole.X, internalwormhole.Y, internalwormhole.Z);
                        var togate      = new BoundingSphereD(togatepoint, Config.RadiusGate);
                        Utilities.UpdateGridsPositionAndStopLive(WormholeDrive.GetTopMostParent(), Utilities.FindFreePos(togate, (float)(Vector3D.Distance(box.Center, box.Max) + 50)));
                        MyVisualScriptLogicProvider.CreateLightning(togatepoint);
                    }
                }
            }
            else
            {
                var destination = pickeddestination.Split(':');

                if (3 != destination.Length)
                {
                    throw new ArgumentException("failed parsing destination '" + destination + "'");
                }

                var transferFileInfo = new Utilities.TransferFileInfo
                {
                    destinationWormhole = destination[0],
                    steamUserId         = playerInCharge.SteamUserId,
                    playerName          = playerInCharge.DisplayName,
                    gridName            = grid.DisplayName,
                    time = DateTime.Now
                };

                Log.Info("creating filetransfer:" + transferFileInfo.ToString());
                var filename = transferFileInfo.createFileName();

                List <MyObjectBuilder_CubeGrid> objectBuilders = new List <MyObjectBuilder_CubeGrid>();
                foreach (MyCubeGrid mygrid in grids)
                {
                    if (!(mygrid.GetObjectBuilder(true) is MyObjectBuilder_CubeGrid objectBuilder))
                    {
                        throw new ArgumentException(mygrid + " has a ObjectBuilder thats not for a CubeGrid");
                    }
                    objectBuilders.Add(objectBuilder);
                }
                MyObjectBuilder_ShipBlueprintDefinition definition = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_ShipBlueprintDefinition>();

                definition.Id = new MyDefinitionId(new MyObjectBuilderType(typeof(MyObjectBuilder_ShipBlueprintDefinition)), filename);

                definition.CubeGrids = objectBuilders.Select(x => (MyObjectBuilder_CubeGrid)x.Clone()).ToArray();

                HashSet <ulong> sittingPlayerSteamIds = new HashSet <ulong>();
                foreach (MyObjectBuilder_CubeGrid cubeGrid in definition.CubeGrids)
                {
                    foreach (MyObjectBuilder_CubeBlock cubeBlock in cubeGrid.CubeBlocks)
                    {
                        cubeBlock.Owner   = 0L;
                        cubeBlock.BuiltBy = 0L;

                        if (!Config.ExportProjectorBlueprints)
                        {
                            if (cubeBlock is MyObjectBuilder_ProjectorBase projector)
                            {
                                projector.ProjectedGrids = null;
                            }
                        }
                        if (cubeBlock is MyObjectBuilder_Cockpit cockpit)
                        {
                            if (cockpit.Pilot != null)
                            {
                                var playerSteamId = cockpit.Pilot.PlayerSteamId;
                                sittingPlayerSteamIds.Add(playerSteamId);
                                ModCommunication.SendMessageTo(new JoinServerMessage(destination[1] + ":" + destination[2]), playerSteamId);
                            }
                        }
                    }
                }

                MyObjectBuilder_Definitions builderDefinition = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_Definitions>();
                builderDefinition.ShipBlueprints = new[] { definition };
                foreach (var playerSteamId in sittingPlayerSteamIds)
                {
                    KillCharacter(playerSteamId);
                }
                if (MyObjectBuilderSerializer.SerializeXML(Utilities.CreateBlueprintPath(Path.Combine(Config.Folder, admingatesfolder), filename), false, builderDefinition))
                {
                    // Saves the game if enabled in config.
                    if (Config.SaveOnExit)
                    {
                        grids.ForEach(b => b.Close());
                        // (re)Starts the task if it has never been started o´r is done
                        if ((saveOnExitTask is null) || saveOnExitTask.IsCompleted)
                        {
                            saveOnExitTask = Torch.Save();
                        }
                    }
                    else
                    {
                        grids.ForEach(b => b.Close());
                    }
                    DirectoryInfo gridDirsent = new DirectoryInfo(Config.Folder + "/" + admingatesconfirmsentfolder);
                    //creates just in case fir send
                    gridDirsent.Create();
                    File.Create(Utilities.CreateBlueprintPath(gridDirsent.FullName, filename));
                }
            }
        }
Esempio n. 13
0
        public static MyObjectBuilder_ShipBlueprintDefinition[] getBluePrint(string name, long newOwner, bool keepProjection, List <MyCubeGrid> grids)
        {
            List <MyObjectBuilder_CubeGrid> objectBuilders = new List <MyObjectBuilder_CubeGrid>();

            foreach (MyCubeGrid grid in grids)
            {
                /* What else should it be? LOL? */
                if (!(grid.GetObjectBuilder(true) is MyObjectBuilder_CubeGrid objectBuilder))
                {
                    throw new ArgumentException(grid + " has a ObjectBuilder thats not for a CubeGrid");
                }

                objectBuilders.Add(objectBuilder);
            }

            MyObjectBuilder_ShipBlueprintDefinition definition = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_ShipBlueprintDefinition>();

            definition.Id        = new MyDefinitionId(new MyObjectBuilderType(typeof(MyObjectBuilder_ShipBlueprintDefinition)), name);
            definition.CubeGrids = objectBuilders.Select(x => (MyObjectBuilder_CubeGrid)x.Clone()).ToArray();

            /* Reset ownership as it will be different on the new server anyway */
            foreach (MyObjectBuilder_CubeGrid cubeGrid in definition.CubeGrids)
            {
                cubeGrid.DisplayName = newOwner.ToString();

                foreach (MyObjectBuilder_CubeBlock cubeBlock in cubeGrid.CubeBlocks)
                {
                    long ownerID = AlliancePlugin.GetIdentityByNameOrId(newOwner.ToString()).IdentityId;
                    cubeBlock.Owner   = ownerID;
                    cubeBlock.BuiltBy = ownerID;


                    /* Remove Projections if not needed */
                    if (!keepProjection)
                    {
                        if (cubeBlock is MyObjectBuilder_ProjectorBase projector)
                        {
                            projector.ProjectedGrid  = null;
                            projector.ProjectedGrids = null;
                        }
                    }



                    /* Remove Pilot and Components (like Characters) from cockpits */
                    if (cubeBlock is MyObjectBuilder_Cockpit cockpit)
                    {
                        cockpit.Pilot = null;

                        if (cockpit.ComponentContainer != null)
                        {
                            var components = cockpit.ComponentContainer.Components;

                            if (components != null)
                            {
                                for (int i = components.Count - 1; i >= 0; i--)
                                {
                                    var component = components[i];

                                    if (component.TypeId == "MyHierarchyComponentBase")
                                    {
                                        components.RemoveAt(i);
                                        continue;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            MyObjectBuilder_Definitions builderDefinition = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_Definitions>();

            builderDefinition.ShipBlueprints = new MyObjectBuilder_ShipBlueprintDefinition[] { definition };

            return(builderDefinition.ShipBlueprints);
        }
Esempio n. 14
0
        public static bool LoadShipBlueprint(MyObjectBuilder_ShipBlueprintDefinition shipBlueprint,
                                             Vector3D playerPosition, bool keepOriginalLocation, long steamID, string Name, CommandContext context = null, bool force = false)
        {
            var grids = shipBlueprint.CubeGrids;

            if (grids == null || grids.Length == 0)
            {
                Log.Warn("No grids in blueprint!");

                if (context != null)
                {
                    context.Respond("No grids in blueprint!");
                }

                return(false);
            }

            foreach (var grid in grids)
            {
                foreach (MyObjectBuilder_CubeBlock block in grid.CubeBlocks)
                {
                    long ownerID = AlliancePlugin.GetIdentityByNameOrId(steamID.ToString()).IdentityId;
                    block.Owner   = ownerID;
                    block.BuiltBy = ownerID;
                }
            }

            List <MyObjectBuilder_EntityBase> objectBuilderList = new List <MyObjectBuilder_EntityBase>(grids.ToList());

            if (!keepOriginalLocation)
            {
                /* Where do we want to paste the grids? Lets find out. */
                var pos = FindPastePosition(grids, playerPosition);
                if (pos == null)
                {
                    Log.Warn("No free Space found!");

                    if (context != null)
                    {
                        context.Respond("No free space available!");
                    }

                    return(false);
                }

                var newPosition = pos.Value;

                /* Update GridsPosition if that doesnt work get out of here. */
                if (!UpdateGridsPosition(grids, newPosition))
                {
                    if (context != null)
                    {
                        context.Respond("The File to be imported does not seem to be compatible with the server!");
                    }

                    return(false);
                }
                Sandbox.Game.Entities.Character.MyCharacter player = MySession.Static.Players.GetPlayerByName(AlliancePlugin.GetIdentityByNameOrId(steamID.ToString()).DisplayName).Character;
                MyGps           gps           = CreateGps(pos.Value, Color.LightGreen, 60, Name);
                MyGpsCollection gpsCollection = (MyGpsCollection)MyAPIGateway.Session?.GPS;
                MyGps           gpsRef        = gps;
                long            entityId      = 0L;
                entityId = gps.EntityId;
                gpsCollection.SendAddGps(player.GetPlayerIdentityId(), ref gpsRef, entityId, true);
            }
            else if (!force)
            {
                var sphere = FindBoundingSphere(grids);

                var position = grids[0].PositionAndOrientation.Value;

                sphere.Center = position.Position;

                List <MyEntity> entities = new List <MyEntity>();
                MyGamePruningStructure.GetAllTopMostEntitiesInSphere(ref sphere, entities);

                foreach (var entity in entities)
                {
                    if (entity is MyCubeGrid)
                    {
                        if (context != null)
                        {
                            context.Respond("There are potentially other grids in the way. If you are certain is free you can set 'force' to true!");
                        }

                        return(false);
                    }
                }
            }
            /* Stop grids */
            foreach (var grid in grids)
            {
                grid.AngularVelocity = new SerializableVector3();
                grid.LinearVelocity  = new SerializableVector3();

                Random random = new Random();
            }
            /* Remapping to prevent any key problems upon paste. */
            MyEntities.RemapObjectBuilderCollection(objectBuilderList);

            bool hasMultipleGrids = objectBuilderList.Count > 1;

            if (!hasMultipleGrids)
            {
                foreach (var ob in objectBuilderList)
                {
                    MyEntities.CreateFromObjectBuilderParallel(ob, true);
                }
            }
            else
            {
                MyEntities.Load(objectBuilderList, out _);
            }

            return(true);
        }
Esempio n. 15
0
        private bool LoadShipBlueprint(MyObjectBuilder_ShipBlueprintDefinition shipBlueprint,
                                       Vector3D playerPosition, bool keepOriginalLocation, Chat chat, Hangar Plugin, bool force = false)
        {
            var grids = shipBlueprint.CubeGrids;

            if (grids == null || grids.Length == 0)
            {
                Hangar.Debug("No grids in blueprint!");
                chat.Respond("No grids in blueprint!");

                return(false);
            }

            try
            {
                MyIdentity IDentity = MySession.Static.Players.TryGetPlayerIdentity(new MyPlayer.PlayerId(SteamID));

                if (Plugin.GridBackup != null)
                {
                    Plugin.GridBackup.GetType().GetMethod("BackupGridsManuallyWithBuilders", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance, null, new Type[2] {
                        typeof(List <MyObjectBuilder_CubeGrid>), typeof(long)
                    }, null).Invoke(Plugin.GridBackup, new object[] { grids.ToList(), IDentity.IdentityId });
                    Log.Warn("Successfully BackedUp grid!");
                }
            }
            catch (Exception e)
            {
                Log.Fatal(e);
            }


            bool LoadNearPosition = false;
            //For loading in the same location

            ParallelSpawner Spawner  = new ParallelSpawner(grids);
            var             position = grids[0].PositionAndOrientation.Value;

            if (keepOriginalLocation)
            {
                var sphere = FindBoundingSphere(grids);



                sphere.Center = position.Position;

                List <MyEntity> entities = new List <MyEntity>();
                MyGamePruningStructure.GetAllTopMostEntitiesInSphere(ref sphere, entities);

                foreach (var entity in entities)
                {
                    if (entity is MyCubeGrid)
                    {
                        chat.Respond("There are potentially other grids in the way. Loading near the original point.");

                        LoadNearPosition = true;
                    }
                }

                if (!LoadNearPosition)
                {
                    /* Remapping to prevent any key problems upon paste. */
                    MyEntities.RemapObjectBuilderCollection(grids);

                    Spawner.Start();

                    return(true);
                }
            }



            /*
             *  Everything else is loading for near player
             *
             *
             *
             */



            /* Where do we want to paste the grids? Lets find out. */
            var pos = FindPastePosition(grids, position.Position);

            if (pos == null)
            {
                Hangar.Debug("No free Space found!");
                chat.Respond("No free space available!");

                return(false);
            }

            var newPosition = pos.Value;

            /* Update GridsPosition if that doesnt work get out of here. */
            if (!UpdateGridsPosition(grids, newPosition))
            {
                chat.Respond("The File to be imported does not seem to be compatible with the server!");

                return(false);
            }


            MyEntities.RemapObjectBuilderCollection(grids);
            Spawner.Start();
            return(true);
        }
Esempio n. 16
0
        private static GridImportResult LoadShipBlueprint(MyObjectBuilder_ShipBlueprintDefinition shipBlueprint, BoundingSphereD position, double cutout, bool keepOriginalLocation, long playerid, bool KeepOriginalOwner, bool PlayerRespawn, string ThisIp, bool force = false)
        {
            var grids = shipBlueprint.CubeGrids;

            if (grids == null || grids.Length == 0)
            {
                Log.Warn("No grids in blueprint!");
                return(GridImportResult.NO_GRIDS_IN_BLUEPRINT);
            }
            List <MyObjectBuilder_EntityBase> objectBuilderList = new List <MyObjectBuilder_EntityBase>(grids.ToList());

            if (!keepOriginalLocation)
            {
                /* Where do we want to paste the grids? Lets find out. */
                var pos = FindPastePosition(grids, position, cutout);
                if (pos == null)
                {
                    Log.Warn("No free Space found!");
                    return(GridImportResult.NO_FREE_SPACE_AVAILABLE);
                }

                var newPosition = pos.Value;

                /* Update GridsPosition if that doesnt work get out of here. */
                if (!UpdateGridsPosition(grids, newPosition))
                {
                    return(GridImportResult.NOT_COMPATIBLE);
                }
            }
            else if (!force)
            {
                var sphere = FindBoundingSphere(grids);

                var gridsPosition = grids[0].PositionAndOrientation.Value;

                sphere.Center = gridsPosition.Position;

                List <MyEntity> entities = new List <MyEntity>();
                MyGamePruningStructure.GetAllTopMostEntitiesInSphere(ref sphere, entities);

                foreach (var entity in entities)
                {
                    if (entity is MyCubeGrid)
                    {
                        return(GridImportResult.POTENTIAL_BLOCKED_SPACE);
                    }
                }
            }
            /* Stop grids */
            foreach (var grid in grids)
            {
                foreach (var block in grid.CubeBlocks)
                {
                    if (!KeepOriginalOwner)
                    {
                        block.BuiltBy = playerid;
                        block.Owner   = playerid;
                    }
                    if (block is MyObjectBuilder_Cockpit cockpit)
                    {
                        if (cockpit.Pilot != null)
                        {
                            var player = PlayerUtils.GetIdentityByNameOrId(cockpit.Pilot.PlayerSteamId.ToString());
                            if (PlayerUtils.GetIdentityByNameOrId(cockpit.Pilot.PlayerSteamId.ToString()) != null && PlayerRespawn)
                            {
                                cockpit.Pilot.OwningPlayerIdentityId = player.IdentityId;
                                if (player.Character != null)
                                {
                                    if (ThisIp != null && ThisIp != "")
                                    {
                                        ModCommunication.SendMessageTo(new JoinServerMessage(ThisIp), player.Character.ControlSteamId);
                                    }
                                    player.Character.EnableBag(false);
                                    Sandbox.Game.MyVisualScriptLogicProvider.SetPlayersHealth(player.IdentityId, 0);
                                    player.Character.Delete();
                                }
                                player.PerformFirstSpawn();
                                player.SavedCharacters.Clear();
                                player.SavedCharacters.Add(cockpit.Pilot.EntityId);
                                MyAPIGateway.Multiplayer.Players.SetControlledEntity(cockpit.Pilot.PlayerSteamId, cockpit.Pilot as VRage.ModAPI.IMyEntity);
                            }
                            else
                            {
                                cockpit.Pilot = null;
                            }
                        }
                    }
                }
                grid.AngularVelocity = new SerializableVector3();
                grid.LinearVelocity  = new SerializableVector3();
            }
            MyEntities.RemapObjectBuilderCollection(objectBuilderList);

            bool hasMultipleGrids = objectBuilderList.Count > 1;

            if (!hasMultipleGrids)
            {
                foreach (var ob in objectBuilderList)
                {
                    MyEntities.CreateFromObjectBuilderParallel(ob, true);
                }
            }
            else
            {
                MyEntities.Load(objectBuilderList, out _);
            }
            return(GridImportResult.OK);
        }
Esempio n. 17
0
        private static GridImportResult LoadShipBlueprint(MyObjectBuilder_ShipBlueprintDefinition shipBlueprint,
                                                          Vector3D playerPosition, bool keepOriginalLocation, bool force = false)
        {
            var grids = shipBlueprint.CubeGrids;

            if (grids == null || grids.Length == 0)
            {
                Log.Warn("No grids in blueprint!");
                return(GridImportResult.NO_GRIDS_IN_BLUEPRINT);
            }

            List <MyObjectBuilder_EntityBase> objectBuilderList = new List <MyObjectBuilder_EntityBase>(grids.ToList());

            if (!keepOriginalLocation)
            {
                /* Where do we want to paste the grids? Lets find out. */
                var pos = FindPastePosition(grids, playerPosition);
                if (pos == null)
                {
                    Log.Warn("No free Space found!");
                    return(GridImportResult.NO_FREE_SPACE_AVAILABLE);
                }

                var newPosition = pos.Value;

                /* Update GridsPosition if that doesnt work get out of here. */
                if (!UpdateGridsPosition(grids, newPosition))
                {
                    return(GridImportResult.NOT_COMPATIBLE);
                }
            }
            else if (!force)
            {
                var sphere = FindBoundingSphere(grids);

                var position = grids[0].PositionAndOrientation.Value;

                sphere.Center = position.Position;

                List <MyEntity> entities = new List <MyEntity>();
                MyGamePruningStructure.GetAllTopMostEntitiesInSphere(ref sphere, entities);

                foreach (var entity in entities)
                {
                    if (entity is MyCubeGrid)
                    {
                        return(GridImportResult.POTENTIAL_BLOCKED_SPACE);
                    }
                }
            }

            /* Stop grids */
            foreach (var grid in grids)
            {
                grid.AngularVelocity = new SerializableVector3();
                grid.LinearVelocity  = new SerializableVector3();
            }

            /* Remapping to prevent any key problems upon paste. */
            MyEntities.RemapObjectBuilderCollection(objectBuilderList);

            bool hasMultipleGrids = objectBuilderList.Count > 1;

            if (!hasMultipleGrids)
            {
                foreach (var ob in objectBuilderList)
                {
                    MyEntities.CreateFromObjectBuilderParallel(ob, true);
                }
            }
            else
            {
                MyEntities.Load(objectBuilderList, out _);
            }

            return(GridImportResult.OK);
        }