public void Inboundwormhole(string infile, double xgate, double ygate, double zgate) { DirectoryInfo gridDir = new DirectoryInfo(infile); if (gridDir.Exists) { foreach (var file in gridDir.GetFiles()) { if (file != null) { var player = PlayerUtils.GetIdentityByNameOrId(file.Name.Split('_')[0]); if (player != null || Config.KeepOriginalOwner) { var playerid = -1L; if (player != null) { playerid = player.IdentityId; } if (GridManager.LoadGrid(file.FullName, new BoundingSphereD(new Vector3D(xgate, ygate, zgate), Config.OutOutsideRadiusGate), Config.OutInsideRadiusGate, false, playerid, Config.KeepOriginalOwner, Config.PlayerRespawn, Config.ThisIp, false) == GridImportResult.OK) { Sandbox.Game.MyVisualScriptLogicProvider.CreateLightning(new Vector3D(xgate, ygate, zgate)); file.Delete(); } } } } } }
public void Restore(string playernameOrSteamId, string gridNameOrEntityId, int backupNumber = 1, bool keepOriginalPosition = false, bool force = false) { MyIdentity player = PlayerUtils.GetIdentityByNameOrId(playernameOrSteamId); if (player == null) { Context.Respond("Player not found!"); return; } List <long> playerIdentityList = new List <long>(); playerIdentityList.Add(player.IdentityId); var relevantGrids = Utilities.FindRelevantGrids(Plugin, playerIdentityList); Utilities.FindPathToRestore(Plugin, relevantGrids, gridNameOrEntityId, backupNumber, out string path, out bool gridFound, out bool outOfBounds); if (outOfBounds) { Context.Respond("Backup not found! Check if the number is in range!"); return; } if (!gridFound) { Context.Respond("Grid not found!"); return; } ImportPath(path, keepOriginalPosition, force); }
public void List(string playernameOrSteamId, string gridNameOrEntityId = null) { MyIdentity player = PlayerUtils.GetIdentityByNameOrId(playernameOrSteamId); if (player == null) { Context.Respond("Player not found!"); return; } StringBuilder sb = new StringBuilder(); int i = 1; string gridname = null; if (gridNameOrEntityId == null) { Utilities.AddListEntriesToSb(Plugin, sb, player.IdentityId, i, false, out _); } else { List <long> playerIdentityList = new List <long>(); playerIdentityList.Add(player.IdentityId); var relevantGrids = Utilities.FindRelevantGrids(Plugin, playerIdentityList); Utilities.AddListEntriesToSb(relevantGrids, sb, gridNameOrEntityId, out gridname); if (gridname == null) { Context.Respond("Grid not found!"); return; } } if (Context.Player == null) { Context.Respond($"Backed up Grids for Player {player.DisplayName} #{player.IdentityId}"); if (gridname != null) { Context.Respond($"Grid {gridname}"); } Context.Respond(sb.ToString()); } else { if (gridname != null) { ModCommunication.SendMessageTo(new DialogMessage("Backed up Grids", $"Grid {gridname}", sb.ToString()), Context.Player.SteamUserId); } else { ModCommunication.SendMessageTo(new DialogMessage("Backed up Grids", $"Player {player.DisplayName} #{player.IdentityId}", sb.ToString()), Context.Player.SteamUserId); } } }
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 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); }
public void Wormholetransferin(string name, double xgate, double ygate, double zgate) { Vector3D gatepoint = new Vector3D(xgate, ygate, zgate); BoundingSphereD gate = new BoundingSphereD(gatepoint, Config.RadiusGate); DirectoryInfo gridDir = new DirectoryInfo(Config.Folder + "/" + admingatesfolder); if (gridDir.Exists) { if (gridDir.GetFiles().Any(s => s.Name.Split('_')[0] == name)) { foreach (var file in gridDir.GetFiles()) { if (file != null) { var filedataarray = file.Name.Split('_'); if (filedataarray[0] == name) { Log.Warn("yay we are going to load file: " + file.Name); var player = PlayerUtils.GetIdentityByNameOrId(filedataarray[1]); if (player != null || Config.KeepOriginalOwner) { var playerid = 0L; if (player != null) { playerid = player.IdentityId; } if (File.Exists(file.FullName)) { Log.Warn("test 1"); if (MyObjectBuilderSerializer.DeserializeXML(file.FullName, out MyObjectBuilder_Definitions myObjectBuilder_Definitions)) { var shipBlueprints = myObjectBuilder_Definitions.ShipBlueprints; if (shipBlueprints != null) { Log.Warn("test 2"); foreach (var shipBlueprint in shipBlueprints) { var grids = shipBlueprint.CubeGrids; if (grids != null && grids.Length > 0) { var pos = Utilities.FindFreePos(gate, Utilities.FindGridsRadius(grids)); if (pos != null) { if (Utilities.UpdateGridsPositionAndStop(grids, pos)) { Log.Warn("test 3"); foreach (var mygrid in grids) { foreach (MyObjectBuilder_CubeBlock block in mygrid.CubeBlocks) { if (!Config.KeepOriginalOwner) { block.BuiltBy = playerid; block.Owner = playerid; } if (block is MyObjectBuilder_Cockpit cockpit) { if (cockpit.Pilot != null) { var seatedplayerid = MyAPIGateway.Multiplayer.Players.TryGetIdentityId(cockpit.Pilot.PlayerSteamId); if (seatedplayerid != -1) { Log.Warn("test 4"); var myplayer = MySession.Static.Players.TryGetIdentity(seatedplayerid); if (seatedplayerid != -1 && Config.PlayerRespawn) { cockpit.Pilot.OwningPlayerIdentityId = seatedplayerid; if (myplayer.Character != null) { if (Config.ThisIp != null && Config.ThisIp != "") { ModCommunication.SendMessageTo(new JoinServerMessage(Config.ThisIp), cockpit.Pilot.PlayerSteamId); } myplayer.Character.EnableBag(false); Sandbox.Game.MyVisualScriptLogicProvider.SetPlayersHealth(seatedplayerid, 0); myplayer.Character.Close(); } myplayer.PerformFirstSpawn(); myplayer.SavedCharacters.Clear(); myplayer.SavedCharacters.Add(cockpit.Pilot.EntityId); MyAPIGateway.Multiplayer.Players.SetControlledEntity(cockpit.Pilot.PlayerSteamId, cockpit.Pilot as VRage.ModAPI.IMyEntity); } else { cockpit.Pilot = null; } } else { cockpit.Pilot = null; } } } } } Log.Warn("test 5"); List <MyObjectBuilder_EntityBase> objectBuilderList = new List <MyObjectBuilder_EntityBase>(grids.ToList()); Log.Warn("test 6"); MyEntities.RemapObjectBuilderCollection(objectBuilderList); Log.Warn("test 7"); if (!(objectBuilderList.Count > 1)) { foreach (var ob in objectBuilderList) { MyEntities.CreateFromObjectBuilderParallel(ob, true); } } else { MyStringId?temp; MyEntities.Load(objectBuilderList, out temp); Log.Warn(temp.ToString()); } Sandbox.Game.MyVisualScriptLogicProvider.CreateLightning(gatepoint); file.Delete(); } } else { Log.Warn("Unable to load grid no free space found at Wormhole: " + name); } } } } } } } } } } } } }
public void Wormholetransferout(string name, string sendto, double xgate, double ygate, double zgate) { Vector3D gatepoint = new Vector3D(xgate, ygate, zgate); BoundingSphereD gate = new BoundingSphereD(gatepoint, Config.RadiusGate); foreach (var entity in MyAPIGateway.Entities.GetTopMostEntitiesInSphere(ref gate)) { var grid = (entity as IMyCubeGrid); if (grid != null) { var WormholeDrives = new List <IMyJumpDrive>(); Log.Warn("test a"); var gts = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(grid); gts.GetBlocksOfType(WormholeDrives); if (WormholeDrives.Count > 0) { foreach (var WormholeDrive in WormholeDrives) { if (Config.JumpDriveSubid.Split(',').Any(s => s.Trim() == WormholeDrive.BlockDefinition.SubtypeId) || Config.WorkWithAllJD) { Request request = null; try { request = MyAPIGateway.Utilities.SerializeFromXML <Request>(WormholeDrive.CustomData); } catch { } string pickeddestination = null; 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) { if (WormholeDrive.IsWorking && WormholeDrive.CurrentStoredPower == WormholeDrive.MaxStoredPower) { var playerInCharge = MyAPIGateway.Players.GetPlayerControllingEntity(entity); if (playerInCharge != null && HasRightToMove(playerInCharge, entity as MyCubeGrid)) { 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 = GridFinder.FindGridList(grid.EntityId.ToString(), playerInCharge as MyCharacter, Config.IncludeConnectedGrids); if (grids == null) { return; } if (grids.Count == 0) { return; } Sandbox.Game.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))); Sandbox.Game.MyVisualScriptLogicProvider.CreateLightning(togatepoint); } } } else { var destination = pickeddestination.Split(':'); var filename = destination[0] + "_" + playerInCharge.SteamUserId.ToString() + "_" + LegalCharOnly(playerInCharge.DisplayName) + "_" + LegalCharOnly(grid.DisplayName) + "_" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss"); List <MyObjectBuilder_CubeGrid> objectBuilders = new List <MyObjectBuilder_CubeGrid>(); foreach (MyCubeGrid mygrid in grids) { if (!(grid.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) { if (!Config.KeepOriginalOwner) { 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 = PlayerUtils.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 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.Close(); } if (MyObjectBuilderSerializer.SerializeXML(CreatePath(Config.Folder + "/" + admingatesfolder, filename), false, builderDefinition)) { foreach (var delgrid in grids) { delgrid.Close(); } } } } } } } } } } } }