Пример #1
0
        public bool LoadGrid(int ID, out IEnumerable <MyObjectBuilder_CubeGrid> Grids, out GridStamp Stamp)
        {
            Grids = null;
            Stamp = null;
            if (ID - 1 >= SelectedPlayerFile.Grids.Count || ID < 1)
            {
                Chat?.Respond("Invalid Index! Grid doent exsist in that slot!");
                return(false);
            }


            Stamp = SelectedPlayerFile.GetGrid(ID);
            string GridPath = Path.Combine(PlayersFolderPath, Stamp.GridName + ".sbc");

            Log.Warn("Attempting to load grid @" + GridPath);
            if (!GridSerializer.LoadGrid(GridPath, out Grids))
            {
                return(false);
            }

            PluginDependencies.BackupGrid(Grids.ToList(), IdentityID);
            GridSerializer.TransferGridOwnership(Grids, IdentityID);

            return(true);
        }
Пример #2
0
        public void LoadGrid(int ID, bool LoadNearPlayer)
        {
            if (!PerformMainChecks(false))
            {
                return;
            }

            if (!PlayersHanger.LoadGrid(ID, out IEnumerable <MyObjectBuilder_CubeGrid> Grids, out GridStamp Stamp))
            {
                Log.Error($"Loading grid {ID} failed for {IdentityID}!");
                Chat.Respond("Loading grid failed! Report this to staff and check logs for more info!");
                return;
            }


            if (!PlayersHanger.CheckLimits(Stamp, Grids))
            {
                return;
            }

            if (!CheckEnemyDistance(Config.LoadType, Stamp.GridSavePosition))
            {
                return;
            }

            if (!RequireLoadCurrency(Stamp))
            {
                return;
            }

            PluginDependencies.BackupGrid(Grids.ToList(), IdentityID);
            Vector3D SpawnPos = DetermineSpawnPosition(Stamp.GridSavePosition, PlayerPosition, out bool KeepOriginalPosition, LoadNearPlayer);

            if (!CheckDistanceToLoadPoint(SpawnPos))
            {
                return;
            }


            ParallelSpawner Spawner = new ParallelSpawner(Grids, Chat, !KeepOriginalPosition, SpawnedGridsSuccessful);

            Log.Info("Attempting Grid Spawning @" + SpawnPos.ToString());
            if (Spawner.Start(KeepOriginalPosition, SpawnPos))
            {
                Chat?.Respond("Spawning Complete!");
                PlayersHanger.RemoveGridStamp(Stamp);
            }
            else
            {
                Chat?.Respond("An error occured while spawning the grid!");
            }
        }
Пример #3
0
        public bool LoadGrid(GridStamp Stamp, out IEnumerable <MyObjectBuilder_CubeGrid> Grids)
        {
            Grids = null;


            if (!Stamp.TryGetGrids(PlayersFolderPath, out Grids))
            {
                return(false);
            }


            PluginDependencies.BackupGrid(Grids.ToList(), Identity.IdentityId);
            GridSerializer.TransferGridOwnership(Grids, Identity.IdentityId, Stamp.TransferOwnerShipOnLoad);

            return(true);
        }
        public static bool SaveGridsAndClose(IEnumerable <MyCubeGrid> Grids, string Path, string GridName, long OwnerIdentity)
        {
            Log.Info(Grids.Count());
            Task <IEnumerable <MyObjectBuilder_CubeGrid> > GridTask = GameEvents.InvokeAsync <IEnumerable <MyCubeGrid>, IEnumerable <MyObjectBuilder_CubeGrid> >(GetObjectBuilders, Grids);

            if (!GridTask.Wait(5000))
            {
                Log.Info("Grid saving timed out!");
                return(false);
            }
            else
            {
                CloseAllGrids(Grids);
                //ClearAllAttachments(GridTask.Result);
                SaveGridToFile(Path, GridName, GridTask.Result);
                PluginDependencies.BackupGrid(GridTask.Result.ToList(), OwnerIdentity);
                return(true);
            }
        }
Пример #5
0
        public static async Task <bool> SaveGridsAndClose(IEnumerable <MyCubeGrid> Grids, string Path, string GridName, long OwnerIdentity)
        {
            Thread CurrentThread = Thread.CurrentThread;

            if (CurrentThread == MyUtils.MainThread)
            {
                //Log.Warn("Running on game thread!");

                IEnumerable <MyObjectBuilder_CubeGrid> grids = GetObjectBuilders(Grids);
                Grids.Close();


                await Task.Run(() => {
                    SaveGridToFile(Path, GridName, grids);
                    PluginDependencies.BackupGrid(grids.ToList(), OwnerIdentity);
                });

                return(true);
            }
            else
            {
                //Log.Warn("Not running on game thread!");

                //Log.Info(Grids.Count());
                Task <IEnumerable <MyObjectBuilder_CubeGrid> > GridTask = GameEvents.InvokeAsync <IEnumerable <MyCubeGrid>, IEnumerable <MyObjectBuilder_CubeGrid> >(GetObjectBuilders, Grids);
                if (!GridTask.Wait(5000))
                {
                    Log.Info("Grid saving timed out!");
                    return(false);
                }
                else
                {
                    Grids.Close();
                    //ClearAllAttachments(GridTask.Result);
                    SaveGridToFile(Path, GridName, GridTask.Result);
                    PluginDependencies.BackupGrid(GridTask.Result.ToList(), OwnerIdentity);
                    return(true);
                }
            }
        }
Пример #6
0
        public void LoadGrid(string input, bool LoadNearPlayer)
        {
            if (!PerformMainChecks(false))
            {
                return;
            }


            if (!PlayersHanger.ParseInput(input, out int ID))
            {
                Chat.Respond($"Grid {input} could not be found!");
                return;
            }



            if (!PlayersHanger.TryGetGridStamp(ID, out GridStamp Stamp))
            {
                return;
            }



            //Check to see if the grid is for sale. We need to let the player know if it is
            if (!CheckGridForSale(Stamp, ID))
            {
                return;
            }



            if (!PlayersHanger.LoadGrid(Stamp, out IEnumerable <MyObjectBuilder_CubeGrid> Grids))
            {
                Log.Error($"Loading grid {ID} failed for {IdentityID}!");
                Chat.Respond("Loading grid failed! Report this to staff and check logs for more info!");
                return;
            }

            if (!PlayersHanger.CheckLimits(Stamp, Grids))
            {
                return;
            }

            if (!CheckEnemyDistance(Config.LoadType, Stamp.GridSavePosition) && !Config.AllowLoadNearEnemy)
            {
                return;
            }

            if (!RequireLoadCurrency(Stamp))
            {
                return;
            }

            PluginDependencies.BackupGrid(Grids.ToList(), IdentityID);
            Vector3D SpawnPos = DetermineSpawnPosition(Stamp.GridSavePosition, PlayerPosition, out bool KeepOriginalPosition, LoadNearPlayer);

            if (!CheckDistanceToLoadPoint(SpawnPos))
            {
                return;
            }

            if (PluginDependencies.NexusInstalled && Config.NexusAPI &&
                NexusSupport.RelayLoadIfNecessary(SpawnPos, ID, LoadNearPlayer, Chat, SteamID, IdentityID, PlayerPosition))
            {
                return;
            }

            ParallelSpawner Spawner = new ParallelSpawner(Grids, Chat, SpawnedGridsSuccessful);

            Log.Info("Attempting Grid Spawning @" + SpawnPos.ToString());
            if (Spawner.Start(SpawnPos, KeepOriginalPosition))
            {
                Chat?.Respond("Spawning Complete!");
                PlayersHanger.RemoveGridStamp(ID);
            }
            else
            {
                Chat?.Respond("An error occured while spawning the grid!");
            }
        }