public void Execute() { GridMethods.Copy(this.source, this.destination, this.sourceX, this.sourceY, this.destX, this.destY, this.width, this.height); }
public void Undo() { GridMethods.Copy(this.oldContents, this.destination, this.destX, this.destY); }
public void Undo() { GridMethods.Copy(this.oldContents, this.target, this.x, this.y); }
public void Execute() { this.oldContents = new Grid <T>(this.width, this.height); GridMethods.Copy(this.target, this.oldContents, this.x, this.y, 0, 0, this.width, this.height); GridMethods.Fill(this.target, this.x, this.y, this.width, this.height, this.fillValue); }
public void SaveAll() { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); int GridCounter = 0; int TotalGridCounter = 0; Dictionary <long, List <Result> > ToSaveGrids = new Dictionary <long, List <Result> >(); Parallel.ForEach(MyCubeGridGroups.Static.Physical.Groups, group => { List <MyCubeGrid> gridList = new List <MyCubeGrid>(); var BiggestGrid = group.Nodes.First().NodeData; Result result = new Result(); foreach (MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Node groupNodes in group.Nodes) { MyCubeGrid grid = groupNodes.NodeData; if (grid.Physics == null) { continue; } if (grid.BlocksCount > BiggestGrid.BlocksCount) { BiggestGrid = grid; } TotalGridCounter += 1; gridList.Add(grid); } if (gridList.Count == 0) { return; } result.grids = gridList; result.biggestGrid = BiggestGrid; if (ToSaveGrids.ContainsKey(BiggestGrid.BigOwners[0])) { //Dictionary already contains grid! ToSaveGrids[BiggestGrid.BigOwners[0]].Add(result); } else { List <Result> AllGrids = new List <Result>(); AllGrids.Add(result); ToSaveGrids.Add(BiggestGrid.BigOwners[0], AllGrids); } }); //Attempt save! foreach (var item in ToSaveGrids) { ulong id = 0; try { id = MySession.Static.Players.TryGetSteamId(item.Key); } catch { Hangar.Debug("Identitiy doesnt have a SteamID! Shipping!"); continue; } if (id == 0) { //Sanity check continue; } GridMethods methods = new GridMethods(id, Plugin.Config.FolderDirectory); //string path = GridMethods.CreatePathForPlayer(Config.FolderDirectory, id); if (!methods.LoadInfoFile(out PlayerInfo Data)) { continue; } foreach (Result R in item.Value) { //Fix invalid characters Utils.FormatGridName(Data, R); if (methods.SaveGrids(R.grids, R.GridName, Plugin)) { //Load player file and update! //Fill out grid info and store in file HangarChecks.GetBPDetails(R, Plugin.Config, out GridStamp Grid); Grid.GridName = R.GridName; Data.Grids.Add(Grid); GridCounter += 1; Hangar.Debug(R.biggestGrid.DisplayName + " was sent to Hangar due to inside planet!"); } else { Hangar.Debug(R.biggestGrid.DisplayName + " FAILED to Hangar due to inside planet!"); } } //Save file methods.SaveInfoFile(Data); } stopwatch.Stop(); TimeSpan ts = stopwatch.Elapsed; Hangar.Debug("SaveAll: Found [" + GridCounter + "] grids out of [" + TotalGridCounter + "] total grids under planet! Action took: " + ts.ToString()); }
private void AutoHangarWorker(Hangar Plugin) { //Significant performance increase if (MySession.Static.Ready) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); List <MyCubeGrid> ExportedGrids = new List <MyCubeGrid>(); List <MyIdentity> ExportPlayerIdentities = new List <MyIdentity>(); Hangar.Debug("AutoHangar: Getting Players!"); var PlayerIdentities = MySession.Static.Players.GetAllIdentities().OfType <MyIdentity>(); foreach (MyIdentity player in PlayerIdentities) { if (player == null) { continue; } DateTime LastLogin; LastLogin = player.LastLoginTime; ulong SteamID = MySession.Static.Players.TryGetSteamId(player.IdentityId); if (LastLogin.AddDays(Plugin.Config.AutoHangarDayAmount) < DateTime.Now) { //AutoHangarBlacklist if (!Plugin.Config.AutoHangarPlayerBlacklist.Any(x => x.SteamID == SteamID)) { ExportPlayerIdentities.Add(player); } } } Hangar.Debug("AutoHangar: Total players to check-" + ExportPlayerIdentities.Count()); int GridCounter = 0; //This gets all the grids foreach (MyIdentity player in ExportPlayerIdentities) { ulong id = 0; try { id = MySession.Static.Players.TryGetSteamId(player.IdentityId); } catch { Hangar.Debug("Identitiy doesnt have a SteamID! Shipping!"); continue; } if (id == 0) { //Sanity check continue; } GridMethods methods = new GridMethods(id, Plugin.Config.FolderDirectory); //string path = GridMethods.CreatePathForPlayer(Config.FolderDirectory, id); if (!methods.LoadInfoFile(out PlayerInfo Data)) { return; } ConcurrentBag <List <MyCubeGrid> > gridGroups = GridFinder.FindGridList(player.IdentityId, false); if (gridGroups.Count == 0) { continue; } long LargestGridID = 0; if (Plugin.Config.KeepPlayersLargestGrid) { //First need to find their largets grid int BlocksCount = 0; foreach (List <MyCubeGrid> grids in gridGroups) { int GridBlockCounts = 0; int LargestSingleGridCount = 0; MyCubeGrid LargetsGrid = grids[0]; foreach (MyCubeGrid grid in grids) { if (grid.BlocksCount > LargestSingleGridCount) { LargestSingleGridCount = grid.BlocksCount; LargetsGrid = grid; } } GridBlockCounts = LargetsGrid.BlocksCount; if (GridBlockCounts > BlocksCount) { BlocksCount = GridBlockCounts; LargestGridID = LargetsGrid.EntityId; } } } foreach (List <MyCubeGrid> grids in gridGroups) { if (grids.Count == 0) { continue; } if (grids[0].IsRespawnGrid && Plugin.Config.DeleteRespawnPods) { grids[0].Close(); continue; } Result result = new Result(); result.grids = grids; var BiggestGrid = grids[0]; foreach (MyCubeGrid grid in grids) { if (grid.BlocksCount > BiggestGrid.BlocksCount) { BiggestGrid = grid; } } if (Plugin.Config.KeepPlayersLargestGrid) { if (BiggestGrid.EntityId == LargestGridID) { //Skip players largest grid continue; } } //Grid Size Checks if (BiggestGrid.GridSizeEnum == MyCubeSize.Large) { if (BiggestGrid.IsStatic && !Plugin.Config.AutoHangarStaticGrids) { continue; } else if (!BiggestGrid.IsStatic && !Plugin.Config.AutoHangarLargeGrids) { continue; } } else if (BiggestGrid.GridSizeEnum == MyCubeSize.Small && !Plugin.Config.AutoHangarSmallGrids) { continue; } result.biggestGrid = BiggestGrid; result.GetGrids = true; //Check for existing grid names Utils.FormatGridName(Data, result); if (methods.SaveGrids(result.grids, result.GridName, Plugin)) { //Load player file and update! //Fill out grid info and store in file HangarChecks.GetBPDetails(result, Plugin.Config, out GridStamp Grid); Grid.GridName = result.GridName; Data.Grids.Add(Grid); GridCounter++; Hangar.Debug(result.biggestGrid.DisplayName + " was sent to Hangar due to inactivity!"); } else { Hangar.Debug(result.biggestGrid.DisplayName + " FAILED to Hangar due to inactivity!"); } } //Save players file! methods.SaveInfoFile(Data); } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Hangar.Debug("AutoHangar: Finished Hangaring -" + GridCounter + " grids! Action took: " + ts.ToString()); } }
private void UnderPlanetWorker(Hangar Plugin) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); int GridCounter = 0; int TotalGridCounter = 0; Dictionary <long, List <Result> > ToSaveGrids = new Dictionary <long, List <Result> >(); Parallel.ForEach(MyCubeGridGroups.Static.Physical.Groups, group => { try { List <MyCubeGrid> gridList = new List <MyCubeGrid>(); var BiggestGrid = group.Nodes.First().NodeData; Result result = new Result(); foreach (MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Node groupNodes in group.Nodes) { MyCubeGrid grid = groupNodes.NodeData; if (grid.Physics == null) { continue; } if (grid.BlocksCount > BiggestGrid.BlocksCount) { BiggestGrid = grid; } TotalGridCounter += 1; gridList.Add(grid); } if (gridList.Count == 0) { return; } result.grids = gridList; result.biggestGrid = BiggestGrid; result.GridName = BiggestGrid.DisplayName; Vector3D Position = BiggestGrid.PositionComp.GetPosition(); if (!Vector3D.IsZero(MyGravityProviderSystem.CalculateNaturalGravityInPoint(Position))) { MyPlanet planet = MyGamePruningStructure.GetClosestPlanet(Position); //Main.Debug("Planet Min Radius: " + planet.MinimumRadius); double distance = Vector3D.Distance(Position, planet.PositionComp.GetPosition()); //Main.Debug("Your distance from center: " + distance); if (distance < planet.MinimumRadius * .7) { //Will save grid! if (ToSaveGrids.ContainsKey(BiggestGrid.BigOwners[0])) { //Dictionary already contains grid! ToSaveGrids[BiggestGrid.BigOwners[0]].Add(result); } else { List <Result> AllGrids = new List <Result>(); AllGrids.Add(result); ToSaveGrids.Add(BiggestGrid.BigOwners[0], AllGrids); } return; } else { return; } } else { return; } } catch (Exception ex) { Hangar.Debug("Help", ex); } }); //Attempt save! foreach (var item in ToSaveGrids) { ulong id = 0; try { id = MySession.Static.Players.TryGetSteamId(item.Key); } catch { Hangar.Debug("Identitiy doesnt have a SteamID! Shipping!"); continue; } if (id == 0) { //Sanity check continue; } GridMethods methods = new GridMethods(id, Plugin.Config.FolderDirectory); //string path = GridMethods.CreatePathForPlayer(Config.FolderDirectory, id); if (!methods.LoadInfoFile(out PlayerInfo Data)) { continue; } foreach (Result R in item.Value) { //Fix invalid characters Utils.FormatGridName(Data, R); if (methods.SaveGrids(R.grids, R.GridName, Plugin)) { //Load player file and update! //Fill out grid info and store in file HangarChecks.GetBPDetails(R, Plugin.Config, out GridStamp Grid); Grid.ForceSpawnNearPlayer = true; Grid.GridName = R.GridName; Data.Grids.Add(Grid); GridCounter += 1; Hangar.Debug(R.biggestGrid.DisplayName + " was sent to Hangar due to inside planet!"); } else { Hangar.Debug(R.biggestGrid.DisplayName + " FAILED to Hangar due to inside planet!"); } } //Save file methods.SaveInfoFile(Data); } stopwatch.Stop(); TimeSpan ts = stopwatch.Elapsed; Hangar.Debug("PlanetHangar: Found [" + GridCounter + "] grids out of [" + TotalGridCounter + "] total grids under planet! Action took: " + ts.ToString()); }