Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        public bool LoadGrid(string GridName, MyCharacter Player, long TargetPlayerID, bool keepOriginalLocation, Chat chat, Hangar Plugin, bool force = false)
        {
            string path = Path.Combine(FolderPath, GridName + ".sbc");

            if (!File.Exists(path))
            {
                chat.Respond("Grid doesnt exist! Admin should check logs for more information.");
                Log.Fatal("Grid doesnt exsist @" + path);
                return(false);
            }


            if (MyObjectBuilderSerializer.DeserializeXML(path, out MyObjectBuilder_Definitions myObjectBuilder_Definitions))
            {
                var shipBlueprints = myObjectBuilder_Definitions.ShipBlueprints;


                if (shipBlueprints == null)
                {
                    Hangar.Debug("No ShipBlueprints in File '" + path + "'");
                    chat.Respond("There arent any Grids in your file to import!");
                    return(false);
                }

                if (!HangarChecker.BlockLimitChecker(shipBlueprints))
                {
                    Hangar.Debug("Block Limiter Checker Failed");
                    return(false);
                }



                if (Config.OnLoadTransfer)
                {
                    Log.Warn("Target player: " + TargetPlayerID);

                    //Will transfer pcu to new player
                    foreach (MyObjectBuilder_ShipBlueprintDefinition definition in shipBlueprints)
                    {
                        foreach (MyObjectBuilder_CubeGrid CubeGridDef in definition.CubeGrids)
                        {
                            foreach (MyObjectBuilder_CubeBlock block in CubeGridDef.CubeBlocks)
                            {
                                block.Owner   = TargetPlayerID;
                                block.BuiltBy = TargetPlayerID;
                            }
                        }
                    }
                }



                if (keepOriginalLocation)
                {
                    foreach (var shipBlueprint in shipBlueprints)
                    {
                        if (!LoadShipBlueprint(shipBlueprint, Player.PositionComp.GetPosition(), true, chat, Plugin))
                        {
                            Hangar.Debug("Error Loading ShipBlueprints from File '" + path + "'");
                            return(false);
                        }
                    }
                    File.Delete(path);
                    return(true);
                }
                else
                {
                    Hangar.Debug("Attempting to align grid to gravity!");
                    AlignToGravity GravityAligner = new AlignToGravity(shipBlueprints, Player.PositionComp.GetPosition(), chat);

                    if (GravityAligner.Start())
                    {
                        File.Delete(path);
                        return(true);
                    }
                }
            }

            return(false);
        }