From 6b3d30a7ae21ecaa2e744426975002fe14c62a5e Mon Sep 17 00:00:00 2001 From: Yuri Date: Mon, 18 Oct 2021 15:21:27 +0300 Subject: [PATCH] GridModule. Fixes Add more checks to convert to static command. now it's will convert only the mian grid and not the subgrids! * it's will skip NPC ships. * Add temp GPS coordinates on request. https://github.com/TorchAPI/Essentials/issues/196 --- Essentials/Commands/GridModule.cs | 46 +++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/Essentials/Commands/GridModule.cs b/Essentials/Commands/GridModule.cs index 932576a..6d2cf39 100644 --- a/Essentials/Commands/GridModule.cs +++ b/Essentials/Commands/GridModule.cs @@ -16,6 +16,11 @@ using VRage.ObjectBuilders; using System.Collections.Concurrent; using VRage.Groups; +using Sandbox.Game.World; +using System.Collections.Generic; +using VRage.Network; +using Sandbox.Engine.Multiplayer; +using System; namespace Essentials { @@ -26,7 +31,7 @@ public class GridModule : CommandModule [Permission(MyPromoteLevel.SpaceMaster)] public void SetOwner(string gridName, string playerName) { - var firstArg = Context.Args.FirstOrDefault(); + _ = Context.Args.FirstOrDefault(); Utilities.TryGetEntityByNameOrId(gridName, out IMyEntity entity); if (!(entity is IMyCubeGrid grid)) @@ -35,9 +40,8 @@ public void SetOwner(string gridName, string playerName) return; } - var secondArg = Context.Args.ElementAtOrDefault(1); - long identityId; - if (!long.TryParse(playerName, out identityId)) + _ = Context.Args.ElementAtOrDefault(1); + if (!long.TryParse(playerName, out long identityId)) { var player = Context.Torch.CurrentSession?.Managers?.GetManager().GetPlayerByName(playerName); if (player == null) @@ -139,8 +143,29 @@ public void Eject(string gridName = null) [Permission(MyPromoteLevel.SpaceMaster)] public void StaticLarge() { - foreach (var grid in MyEntities.GetEntities().OfType().Where(g => g.GridSizeEnum == MyCubeSize.Large).Where(x => x.Projector == null)) - grid.OnConvertedToStationRequest(); //Keen why do you do this to me? + foreach (var grid in MyEntities.GetEntities().OfType().Where(g => g.Projector == null && g.GridSizeEnum == MyCubeSize.Large)) + { + if (grid.BigOwners.Count > 0 && !MySession.Static.Players.IdentityIsNpc(grid.BigOwners.FirstOrDefault())) + { + var grids = MyCubeGridGroups.Static.GetGroups(GridLinkTypeEnum.Logical).GetGroupNodes(grid); + grids.SortNoAlloc((x, y) => x.BlocksCount.CompareTo(y.BlocksCount)); + grids.Reverse(); + grids.SortNoAlloc((x, y) => x.GridSizeEnum.CompareTo(y.GridSizeEnum)); + + // stop the grids. + foreach (var gridtostop in grids) + gridtostop.Physics?.ClearSpeed(); + + // tell to server + grids.First().ConvertToStatic(); + + // tell to client + MyMultiplayer.RaiseEvent(grids.First(), (MyCubeGrid x) => new Action(x.ConvertToStatic), default); + MyMultiplayer.RaiseEvent(grids.First(), (MyCubeGrid x) => new Action(x.ConvertToStatic), MyEventContext.Current.Sender); + } + else + grid.OnConvertedToStationRequest(); //Keen why do you do this to me? + } } [Command("stopall", "Stops all moving grids.")] @@ -162,23 +187,20 @@ public void List() foreach (var entity in MyEntities.GetEntities()) { - var grid = entity as MyCubeGrid; - if (grid == null || grid.Projector != null) + if (!(entity is MyCubeGrid grid) || grid.Projector != null) continue; if (grid.BigOwners.Contains(id)) { - sb.AppendLine($"{grid.DisplayName} - {grid.GridSizeEnum} - {grid.BlocksCount} blocks - Position {(EssentialsPlugin.Instance.Config.UtilityShowPosition ? grid.PositionComp.GetPosition().ToString() : "Unknown")}"); if (EssentialsPlugin.Instance.Config.MarkerShowPosition) { - var gridGPS = MyAPIGateway.Session?.GPS.Create(grid.DisplayName, ($"{grid.DisplayName} - {grid.GridSizeEnum} - {grid.BlocksCount} blocks"), grid.PositionComp.GetPosition(), true); - + // Add temp GPS coordinates on request. + var gridGPS = MyAPIGateway.Session?.GPS.Create(grid.DisplayName, ($"{grid.DisplayName} - {grid.GridSizeEnum} - {grid.BlocksCount} blocks"), grid.PositionComp.GetPosition(), true, true); MyAPIGateway.Session?.GPS.AddGps(Context.Player.IdentityId, gridGPS); } } } - ModCommunication.SendMessageTo(new DialogMessage("Grids List", $"Ships/Stations owned by {Context.Player.DisplayName}", sb.ToString()), Context.Player.SteamUserId); }