コード例 #1
0
        public static MyEntity Spawn(ref MyPhysicalInventoryItem item, Vector3 position, Vector3 speed)
        {
            var builder      = PrepareBuilder(ref item);
            var meteorEntity = MyEntities.CreateFromObjectBuilderNoinit(builder, false);

            MyEntities.CreateFromObjectBuilderParallel(builder, true, delegate() { SetSpawnSettings(meteorEntity, position, speed); }, meteorEntity);
            return(meteorEntity);
        }
コード例 #2
0
ファイル: EntityManager.cs プロジェクト: carlosmaid/Torch
        public void ImportGrid(string path, Vector3D position)
        {
            MyObjectBuilder_EntityBase gridOb;

            using (var f = File.OpenRead(path))
                MyObjectBuilderSerializer.DeserializeXML(f, out gridOb);

            var grid = MyEntities.CreateFromObjectBuilderParallel(gridOb);

            grid.PositionComp.SetPosition(position);
            MyEntities.Add(grid);
        }
コード例 #3
0
ファイル: GridModule.cs プロジェクト: dorimanx/Essentials
        public void Import(string gridName, string targetName = null)
        {
            Directory.CreateDirectory("ExportedGrids");
            if (targetName == null)
            {
                if (Context.Player == null)
                {
                    Context.Respond("Target entity must be specified.");
                    return;
                }

                targetName = Context.Player.Controller.ControlledEntity.Entity.DisplayName;
            }

            if (!Utilities.TryGetEntityByNameOrId(targetName, out var ent))
            {
                Context.Respond("Target entity not found.");
                return;
            }

            var path = string.Format(ExportPath, gridName);

            if (!File.Exists(path))
            {
                Context.Respond("File does not exist.");
                return;
            }

            if (MyObjectBuilderSerializer.DeserializeXML(path, out MyObjectBuilder_CubeGrid grid))
            {
                Context.Respond($"Importing grid from {path}");
                MyEntities.RemapObjectBuilder(grid);
                var pos = MyEntities.FindFreePlace(ent.GetPosition(), grid.CalculateBoundingSphere().Radius);
                if (pos == null)
                {
                    Context.Respond("No free place.");
                    return;
                }

                var x = grid.PositionAndOrientation ?? new MyPositionAndOrientation();
                x.Position = pos.Value;
                grid.PositionAndOrientation = x;
                MyEntities.CreateFromObjectBuilderParallel(grid, true);
            }
        }
コード例 #4
0
 public static void Spawn(this MyPhysicalInventoryItem thisItem, MyFixedPoint amount, MatrixD worldMatrix, MyEntity owner, Action <MyEntity> completionCallback)
 {
     if ((amount >= 0) && (thisItem.Content != null))
     {
         if (thisItem.Content is MyObjectBuilder_BlockItem)
         {
             if (typeof(MyObjectBuilder_CubeBlock).IsAssignableFrom((System.Type)thisItem.Content.GetObjectId().TypeId))
             {
                 MyCubeBlockDefinition     definition;
                 MyObjectBuilder_BlockItem content = thisItem.Content as MyObjectBuilder_BlockItem;
                 MyDefinitionManager.Static.TryGetCubeBlockDefinition(content.BlockDefId, out definition);
                 if (definition != null)
                 {
                     MyObjectBuilder_CubeGrid objectBuilder = MyObjectBuilderSerializer.CreateNewObject(typeof(MyObjectBuilder_CubeGrid)) as MyObjectBuilder_CubeGrid;
                     objectBuilder.GridSizeEnum           = definition.CubeSize;
                     objectBuilder.IsStatic               = false;
                     objectBuilder.PersistentFlags       |= MyPersistentEntityFlags2.InScene | MyPersistentEntityFlags2.Enabled;
                     objectBuilder.PositionAndOrientation = new MyPositionAndOrientation(worldMatrix);
                     MyObjectBuilder_CubeBlock item = MyObjectBuilderSerializer.CreateNewObject(content.BlockDefId) as MyObjectBuilder_CubeBlock;
                     if (item != null)
                     {
                         item.Min = (SerializableVector3I)(((definition.Size / 2) - definition.Size) + Vector3I.One);
                         objectBuilder.CubeBlocks.Add(item);
                         for (int i = 0; i < amount; i++)
                         {
                             objectBuilder.EntityId = MyEntityIdentifier.AllocateId(MyEntityIdentifier.ID_OBJECT_TYPE.ENTITY, MyEntityIdentifier.ID_ALLOCATION_METHOD.RANDOM);
                             item.EntityId          = MyEntityIdentifier.AllocateId(MyEntityIdentifier.ID_OBJECT_TYPE.ENTITY, MyEntityIdentifier.ID_ALLOCATION_METHOD.RANDOM);
                             Vector3D?relativeOffset = null;
                             MyEntities.CreateFromObjectBuilderParallel(objectBuilder, true, completionCallback, null, null, relativeOffset, false, false);
                         }
                     }
                 }
             }
         }
         else
         {
             MyPhysicalItemDefinition definition = null;
             if (MyDefinitionManager.Static.TryGetPhysicalItemDefinition(thisItem.Content.GetObjectId(), out definition))
             {
                 MyFloatingObjects.Spawn(new MyPhysicalInventoryItem(amount, thisItem.Content, 1f), worldMatrix, owner?.Physics, completionCallback);
             }
         }
     }
 }
コード例 #5
0
        public static void Spawn(MyPhysicalInventoryItem item, BoundingSphereD sphere, MyPhysicsComponentBase motionInheritedFrom, MyVoxelMaterialDefinition voxelMaterial, Action <MyEntity> OnDone)
        {
            Vector3D?relativeOffset = null;

            MyEntities.CreateFromObjectBuilderParallel(PrepareBuilder(ref item), false, delegate(MyEntity entity) {
                if (voxelMaterial.DamagedMaterial != MyStringHash.NullOrEmpty)
                {
                    voxelMaterial = MyDefinitionManager.Static.GetVoxelMaterialDefinition(voxelMaterial.DamagedMaterial.ToString());
                }
                ((MyFloatingObject)entity).VoxelMaterial = voxelMaterial;
                float radius = entity.PositionComp.LocalVolume.Radius;
                double num2  = Math.Max((double)(sphere.Radius - radius), (double)0.0);
                sphere       = new BoundingSphereD(sphere.Center, num2);
                Vector3D randomBorderPosition = MyUtils.GetRandomBorderPosition(ref sphere);
                AddToPos(entity, randomBorderPosition, motionInheritedFrom);
                if (MyVisualScriptLogicProvider.ItemSpawned != null)
                {
                    MyVisualScriptLogicProvider.ItemSpawned(item.Content.TypeId.ToString(), item.Content.SubtypeName, entity.EntityId, item.Amount.ToIntSafe(), randomBorderPosition);
                }
                OnDone(entity);
            }, null, null, relativeOffset, false, false);
        }
コード例 #6
0
 public static void Spawn(MyPhysicalInventoryItem item, MatrixD worldMatrix, MyPhysicsComponentBase motionInheritedFrom, Action <MyEntity> completionCallback)
 {
     if (MyEntities.IsInsideWorld(worldMatrix.Translation))
     {
         MyObjectBuilder_FloatingObject objectBuilder = PrepareBuilder(ref item);
         objectBuilder.PositionAndOrientation = new MyPositionAndOrientation(worldMatrix);
         Vector3D?relativeOffset = null;
         MyEntities.CreateFromObjectBuilderParallel(objectBuilder, true, delegate(MyEntity entity) {
             if ((entity != null) && (entity.Physics != null))
             {
                 entity.Physics.ForceActivate();
                 ApplyPhysics(entity, motionInheritedFrom);
                 if (MyVisualScriptLogicProvider.ItemSpawned != null)
                 {
                     MyVisualScriptLogicProvider.ItemSpawned(item.Content.TypeId.ToString(), item.Content.SubtypeName, entity.EntityId, item.Amount.ToIntSafe(), worldMatrix.Translation);
                 }
                 if (completionCallback != null)
                 {
                     completionCallback(entity);
                 }
             }
         }, null, null, relativeOffset, false, false);
     }
 }
コード例 #7
0
        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)
            {
                return;
            }

            if (!gridDir.GetFiles().Any(s => s.Name.Split('_')[0] == name))
            {
                return;
            }

            foreach (var file in gridDir.GetFiles())
            {
                if (file == null)
                {
                    continue;
                }

                var filedataarray = file.Name.Split('_');
                if (filedataarray[0] != name)
                {
                    continue;
                }

                Log.Info("yay we are going to load file: " + file.Name);

                var player = Utilities.GetIdentityByNameOrId(filedataarray[1]);
                if (player == null)
                {
                    continue;
                }

                var playerid = 0L;
                playerid = player.IdentityId;

                if (!File.Exists(file.FullName))
                {
                    continue;
                }

                if (!MyObjectBuilderSerializer.DeserializeXML(file.FullName, out MyObjectBuilder_Definitions myObjectBuilder_Definitions))
                {
                    continue;
                }

                var shipBlueprints = myObjectBuilder_Definitions.ShipBlueprints;

                if (shipBlueprints == null)
                {
                    continue;
                }

                foreach (var shipBlueprint in shipBlueprints)
                {
                    var grids = shipBlueprint.CubeGrids;
                    if (grids == null || grids.Length == 0)
                    {
                        continue;
                    }

                    var pos = Utilities.FindFreePos(gate, Utilities.FindGridsRadius(grids));
                    if (pos == null)
                    {
                        Log.Warn("Unable to load grid no free space found at Wormhole: " + name);
                        continue;
                    }

                    if (Utilities.UpdateGridsPositionAndStop(grids, pos))
                    {
                        foreach (var mygrid in grids)
                        {
                            foreach (MyObjectBuilder_CubeBlock block in mygrid.CubeBlocks)
                            {
                                block.BuiltBy = playerid;
                                block.Owner   = playerid;

                                if (!(block is MyObjectBuilder_Cockpit cockpit) || cockpit.Pilot == null)
                                {
                                    continue;
                                }

                                var seatedplayerid = MyAPIGateway.Multiplayer.Players.TryGetIdentityId(cockpit.Pilot.PlayerSteamId);
                                if (seatedplayerid == -1)
                                {
                                    cockpit.Pilot = null;
                                    continue;
                                }

                                var myplayer = MySession.Static.Players.TryGetIdentity(seatedplayerid);
                                if (seatedplayerid == -1 || !Config.PlayerRespawn)
                                {
                                    cockpit.Pilot = null;
                                    continue;
                                }
                                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);
                                    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);
                            }
                        }
                    }

                    List <MyObjectBuilder_EntityBase> objectBuilderList = new List <MyObjectBuilder_EntityBase>(grids.ToList());
                    MyEntities.RemapObjectBuilderCollection(objectBuilderList);
                    if (objectBuilderList.Count > 1)
                    {
                        if (MyEntities.Load(objectBuilderList, out _))
                        {
                            file.Delete();
                        }
                        else
                        {
                            foreach (var ob in objectBuilderList)
                            {
                                if (MyEntities.CreateFromObjectBuilderParallel(ob, true) != null)
                                {
                                    file.Delete();
                                }
                            }
                        }
                    }

                    MyVisualScriptLogicProvider.CreateLightning(gatepoint);
                }
            }
        }
コード例 #8
0
        private CheckResult FixGroup(MyGroups<MyCubeGrid, MyGridPhysicalGroupData>.Group group, MyIdentity executingPlayer) {

            string playerName = "Server";

            if (executingPlayer != null)
                playerName = executingPlayer.DisplayName;

            List<MyObjectBuilder_EntityBase> objectBuilderList = new List<MyObjectBuilder_EntityBase>();
            List<MyCubeGrid> gridsList = new List<MyCubeGrid>();

            foreach (MyGroups<MyCubeGrid, MyGridPhysicalGroupData>.Node groupNodes in group.Nodes) {

                MyCubeGrid grid = groupNodes.NodeData;
                gridsList.Add(grid);

                grid.Physics.LinearVelocity = Vector3.Zero;

                MyObjectBuilder_EntityBase ob = grid.GetObjectBuilder(true);

                if (!objectBuilderList.Contains(ob)) {

                    if (ob is MyObjectBuilder_CubeGrid gridBuilder) {

                        foreach (MyObjectBuilder_CubeBlock cubeBlock in gridBuilder.CubeBlocks) {

                            if (Config.RemoveBlueprintsFromProjectors)
                                if (cubeBlock is MyObjectBuilder_ProjectorBase projector)
                                    projector.ProjectedGrids = null;

                            if (cubeBlock is MyObjectBuilder_OxygenTank o2Tank)
                                o2Tank.AutoRefill = false;
                        }
                    }

                    objectBuilderList.Add(ob);
                }
            }

            foreach (MyCubeGrid grid in gridsList) {

                var entity = grid as IMyEntity;

                Log.Warn("Player " + playerName + " used ShipFixerPlugin on Grid " + grid.DisplayName + " for cut & paste!");

                entity.Close();
            }

            MyAPIGateway.Entities.RemapObjectBuilderCollection(objectBuilderList);

            bool hasMultipleGrids = objectBuilderList.Count > 1;

            if (!hasMultipleGrids) {

                foreach (var ob in objectBuilderList)
                    MyEntities.CreateFromObjectBuilderParallel(ob, true);

            } else {

                MyEntities.Load(objectBuilderList, out _);
            }

            return CheckResult.SHIP_FIXED;
        }
コード例 #9
0
        private void WormholeTransferInFile(FileInfo fileInfo, Utilities.TransferFileInfo fileTransferInfo, Vector3D gatePosition, BoundingSphereD gate)
        {
            Log.Info("processing filetransfer:" + fileTransferInfo.createLogString());

            var playerid = MySession.Static.Players.TryGetIdentityId(fileTransferInfo.steamUserId); // defaults to 0

            if (playerid <= 0)
            {
                Log.Error("couldn't find player with steam id: " + fileTransferInfo.steamUserId);
                return;
            }

            if (!MyObjectBuilderSerializer.DeserializeXML(fileInfo.FullName, out MyObjectBuilder_Definitions myObjectBuilder_Definitions))
            {
                Log.Error("error deserializing xml: " + fileInfo.FullName);
                return;
            }

            var shipBlueprints = myObjectBuilder_Definitions.ShipBlueprints;

            if (shipBlueprints == null)
            {
                Log.Error("can't find any blueprints in xml: " + fileInfo.FullName);
                return;
            }

            foreach (var shipBlueprint in shipBlueprints)
            {
                var grids = shipBlueprint.CubeGrids;
                if (grids == null || grids.Length == 0)
                {
                    continue;
                }

                var pos = Utilities.FindFreePos(gate, Utilities.FindGridsRadius(grids));
                if (pos == null)
                {
                    Log.Warn("no free space available for grid '" + shipBlueprint.DisplayName + "' at wormhole '" + fileTransferInfo.destinationWormhole + "'");
                    continue;
                }

                if (Utilities.UpdateGridsPositionAndStop(grids, pos))
                {
                    foreach (var mygrid in grids)
                    {
                        // takeover ownership
                        foreach (MyObjectBuilder_CubeBlock block in mygrid.CubeBlocks)
                        {
                            block.BuiltBy = playerid;
                            block.Owner   = playerid;
                        }

                        foreach (MyObjectBuilder_Cockpit cockpit in mygrid.CubeBlocks.Where(block => block is MyObjectBuilder_Cockpit))
                        {
                            if (cockpit.Pilot == null || !Config.PlayerRespawn)
                            {
                                cockpit.Pilot = null;
                                continue;
                            }

                            var pilotSteamId    = cockpit.Pilot.PlayerSteamId;
                            var pilotIdentityId = MyAPIGateway.Multiplayer.Players.TryGetIdentityId(pilotSteamId);
                            if (pilotIdentityId == -1)
                            {
                                Log.Info("cannot find player, removing character from cockpit, steamid: " + pilotSteamId);
                                cockpit.Pilot = null;
                                continue;
                            }
                            cockpit.Pilot.OwningPlayerIdentityId = pilotIdentityId;

                            var pilotIdentity = MySession.Static.Players.TryGetIdentity(pilotIdentityId);
                            if (pilotIdentity.Character != null)
                            {
                                // if there is a character, kill it
                                if (Config.ThisIp != null && Config.ThisIp != "")
                                {
                                    ModCommunication.SendMessageTo(new JoinServerMessage(Config.ThisIp), pilotSteamId);
                                }
                                KillCharacter(pilotSteamId);
                            }
                            pilotIdentity.PerformFirstSpawn();
                            pilotIdentity.SavedCharacters.Clear();
                            pilotIdentity.SavedCharacters.Add(cockpit.Pilot.EntityId);
                            MyAPIGateway.Multiplayer.Players.SetControlledEntity(pilotSteamId, cockpit.Pilot as VRage.ModAPI.IMyEntity);
                        }
                    }
                }

                List <MyObjectBuilder_EntityBase> objectBuilderList = new List <MyObjectBuilder_EntityBase>(grids.ToList());
                MyEntities.RemapObjectBuilderCollection(objectBuilderList);
                if (objectBuilderList.Count > 1)
                {
                    if (MyEntities.Load(objectBuilderList, out _))
                    {
                        fileInfo.Delete();
                    }
                }
                else
                {
                    foreach (var ob in objectBuilderList)
                    {
                        if (MyEntities.CreateFromObjectBuilderParallel(ob, true) != null)
                        {
                            fileInfo.Delete();
                        }
                    }
                }

                MyVisualScriptLogicProvider.CreateLightning(gatePosition);
            }
        }
コード例 #10
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);
        }
コード例 #11
0
ファイル: GridManager.cs プロジェクト: Izion/Wormhole-Master
        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);
        }
コード例 #12
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);
        }