From 66eddee5802a6791ec3edd301ab9c191a1c71fd4 Mon Sep 17 00:00:00 2001 From: John Gross Date: Sat, 15 Apr 2017 18:40:07 -0700 Subject: [PATCH] Initial commit --- Concealment/Commands.cs | 45 +++++ Concealment/ConcealGroup.cs | 95 ++++++++++ Concealment/Concealment.csproj | 155 ++++++++++++++++ Concealment/Concealment.sln | 28 +++ Concealment/ConcealmentControl.xaml | 47 +++++ Concealment/ConcealmentControl.xaml.cs | 50 +++++ Concealment/ConcealmentPlugin.cs | 247 +++++++++++++++++++++++++ Concealment/Properties/AssemblyInfo.cs | 36 ++++ Concealment/Settings.cs | 68 +++++++ 9 files changed, 771 insertions(+) create mode 100644 Concealment/Commands.cs create mode 100644 Concealment/ConcealGroup.cs create mode 100644 Concealment/Concealment.csproj create mode 100644 Concealment/Concealment.sln create mode 100644 Concealment/ConcealmentControl.xaml create mode 100644 Concealment/ConcealmentControl.xaml.cs create mode 100644 Concealment/ConcealmentPlugin.cs create mode 100644 Concealment/Properties/AssemblyInfo.cs create mode 100644 Concealment/Settings.cs diff --git a/Concealment/Commands.cs b/Concealment/Commands.cs new file mode 100644 index 0000000..0162519 --- /dev/null +++ b/Concealment/Commands.cs @@ -0,0 +1,45 @@ +using Torch.Commands; +using Torch.Commands.Permissions; +using VRage.Game.ModAPI; +using VRageMath; + +namespace Concealment +{ + public class Commands : CommandModule + { + public ConcealmentPlugin Plugin => (ConcealmentPlugin)Context.Plugin; + + [Command("conceal", "Conceal grids x distance from players."), Permission(MyPromoteLevel.SpaceMaster)] + public void Conceal(double distance = 0) + { + if (distance == 0) + { + distance = Plugin.Settings.ConcealDistance; + } + var num = Plugin.ConcealDistantGrids(distance); + Context.Respond($"{num} grids concealed."); + } + + [Command("reveal", "Reveal all grids within the given distance"), Permission(MyPromoteLevel.SpaceMaster)] + public void Reveal(double distance = 1000) + { + var pos = Context.Player.Controller.ControlledEntity?.Entity.GetPosition(); + if (!pos.HasValue) + { + Context.Respond("You must be controlling an entity"); + return; + } + + var sphere = new BoundingSphereD(pos.Value, distance); + var num = Plugin.RevealGridsInSphere(sphere); + Context.Respond($"{num} grids revealed."); + } + + [Command("all", "Reveal all grids", null, "reveal"), Permission(MyPromoteLevel.SpaceMaster)] + public void RevealAll() + { + int num = Plugin.RevealAll(); + Context.Respond($"{num} grids revealed."); + } + } +} \ No newline at end of file diff --git a/Concealment/ConcealGroup.cs b/Concealment/ConcealGroup.cs new file mode 100644 index 0000000..8b7280f --- /dev/null +++ b/Concealment/ConcealGroup.cs @@ -0,0 +1,95 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using Sandbox.Game.Entities; +using Sandbox.Game.Entities.Blocks; +using Sandbox.Game.World; +using SpaceEngineers.Game.Entities.Blocks; +using VRage.Groups; +using VRageMath; + +namespace Concealment +{ + public class ConcealGroup + { + /// + /// Entity ID of the first grid in the group. + /// + public long Id { get; } + public DateTime ConcealTime { get; set; } + public BoundingBoxD WorldAABB { get; private set; } + public List Grids { get; } + public List MedicalRooms { get; } = new List(); + public List CryoChambers { get; } = new List(); + internal volatile int ProxyId = -1; + + public ConcealGroup(MyGroups.Group group) + { + Grids = group.Nodes.Select(n => n.NodeData).ToList(); + Id = Grids.First().EntityId; + } + + public string GridNames + { + get { return string.Join(", ", Grids.Select(g => g.DisplayName)); } + } + + public void UpdatePostConceal() + { + UpdateAABB(); + CacheSpawns(); + } + + private void UpdateAABB() + { + var startPos = Grids.First().PositionComp.GetPosition(); + var box = new BoundingBoxD(startPos, startPos); + + foreach (var aabb in Grids.Select(g => g.PositionComp.WorldAABB)) + box.Include(aabb); + + WorldAABB = box; + } + + private void CacheSpawns() + { + MedicalRooms.Clear(); + CryoChambers.Clear(); + + foreach (var block in Grids.SelectMany(x => x.GetFatBlocks())) + { + if (block is MyMedicalRoom medical) + MedicalRooms.Add(medical); + else if (block is MyCryoChamber cryo) + CryoChambers.Add(cryo); + } + } + + public bool IsMedicalRoomAvailable(long identityId) + { + foreach (var room in MedicalRooms) + { + if (room.HasPlayerAccess(identityId) && room.IsWorking) + return true; + } + + return false; + } + + public bool IsCryoOccupied(ulong steamId) + { + var currentIdField = typeof(MyCryoChamber).GetField("m_currentPlayerId", BindingFlags.NonPublic | BindingFlags.Instance); + + foreach (var chamber in CryoChambers) + { + var value = (MyPlayer.PlayerId?)currentIdField.GetValue(chamber); + if (value?.SteamId == steamId) + return true; + } + + return false; + } + } + +} diff --git a/Concealment/Concealment.csproj b/Concealment/Concealment.csproj new file mode 100644 index 0000000..68e5585 --- /dev/null +++ b/Concealment/Concealment.csproj @@ -0,0 +1,155 @@ + + + + + Debug + AnyCPU + {E5C0184B-7DC4-43D8-872E-2F71162748AA} + Library + Properties + Concealment + Concealment + v4.6.1 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x64\Debug\ + DEBUG;TRACE + full + x64 + prompt + MinimumRecommendedRules.ruleset + + + bin\x64\Release\ + TRACE + true + pdbonly + x64 + prompt + MinimumRecommendedRules.ruleset + + + + ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\HavokWrapper.dll + + + ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\NLog.dll + + + + + ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\Sandbox.Common.dll + + + ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\Sandbox.Game.dll + + + ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\Sandbox.Graphics.dll + + + ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\SpaceEngineers.Game.dll + + + ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\SpaceEngineers.ObjectBuilders.dll + + + ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\SpaceEngineers.ObjectBuilders.XmlSerializers.dll + + + ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\SteamSDK.dll + + + + + + + + + + + + False + ..\..\Torch\Torch.Server\bin\x64\Release\Torch.dll + + + False + ..\..\Torch\Torch.Server\bin\x64\Release\Torch.API.dll + + + ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.dll + + + ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Audio.dll + + + ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Dedicated.dll + + + ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Game.dll + + + ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Game.XmlSerializers.dll + + + ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Input.dll + + + ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Library.dll + + + ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Math.dll + + + ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Native.dll + + + ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.OpenVRWrapper.dll + + + ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Render.dll + + + ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Render11.dll + + + ..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Scripting.dll + + + + + + + + ConcealmentControl.xaml + + + + + + + + Designer + MSBuild:Compile + + + + \ No newline at end of file diff --git a/Concealment/Concealment.sln b/Concealment/Concealment.sln new file mode 100644 index 0000000..ca1ec15 --- /dev/null +++ b/Concealment/Concealment.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26403.3 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Concealment", "Concealment.csproj", "{E5C0184B-7DC4-43D8-872E-2F71162748AA}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E5C0184B-7DC4-43D8-872E-2F71162748AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E5C0184B-7DC4-43D8-872E-2F71162748AA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E5C0184B-7DC4-43D8-872E-2F71162748AA}.Debug|x64.ActiveCfg = Release|x64 + {E5C0184B-7DC4-43D8-872E-2F71162748AA}.Debug|x64.Build.0 = Release|x64 + {E5C0184B-7DC4-43D8-872E-2F71162748AA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E5C0184B-7DC4-43D8-872E-2F71162748AA}.Release|Any CPU.Build.0 = Release|Any CPU + {E5C0184B-7DC4-43D8-872E-2F71162748AA}.Release|x64.ActiveCfg = Release|x64 + {E5C0184B-7DC4-43D8-872E-2F71162748AA}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Concealment/ConcealmentControl.xaml b/Concealment/ConcealmentControl.xaml new file mode 100644 index 0000000..69fc0b4 --- /dev/null +++ b/Concealment/ConcealmentControl.xaml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + +