From 4794c1bf2082c6f94cf663cecfc8b58b738a83ec Mon Sep 17 00:00:00 2001 From: Aristeas <94058548+ari-steas@users.noreply.github.com> Date: Thu, 5 Dec 2024 20:29:36 -0600 Subject: [PATCH] Create DoorDestroyer --- .../Data/Scripts/DoorDestroyer/Main.cs | 47 +++++++++++++++++++ .../DoorDestroyer.csproj.DotSettings | 3 ++ 2 files changed, 50 insertions(+) create mode 100644 DoorDestroyer/Data/Scripts/DoorDestroyer/Main.cs create mode 100644 DoorDestroyer/DoorDestroyer.csproj.DotSettings diff --git a/DoorDestroyer/Data/Scripts/DoorDestroyer/Main.cs b/DoorDestroyer/Data/Scripts/DoorDestroyer/Main.cs new file mode 100644 index 0000000..d3591df --- /dev/null +++ b/DoorDestroyer/Data/Scripts/DoorDestroyer/Main.cs @@ -0,0 +1,47 @@ +using Sandbox.Common.ObjectBuilders; +using Sandbox.ModAPI; +using VRage.Game.Components; +using VRage.Game.Entity; +using VRage.Game.ModAPI; +using VRage.ModAPI; +using VRage.ObjectBuilders; + +// ReSharper disable UnusedType.Global +namespace TSTSSES.DoorDestroyer +{ + [MyEntityComponentDescriptor(typeof(MyObjectBuilder_Door), false)] + internal class DoorDestroyer : GenericDoorDestroyer { } + + [MyEntityComponentDescriptor(typeof(MyObjectBuilder_AirtightSlideDoor), false)] + internal class SlideGenericDoorDestroyer : GenericDoorDestroyer { } + + [MyEntityComponentDescriptor(typeof(MyObjectBuilder_AirtightHangarDoor), false)] + internal class HangarGenericDoorDestroyer : GenericDoorDestroyer { } + + [MyEntityComponentDescriptor(typeof(MyObjectBuilder_AdvancedDoor), false)] + internal class AdvancedGenericDoorDestroyer : GenericDoorDestroyer { } + + internal class GenericDoorDestroyer : MyGameLogicComponent where T : IMyCubeBlock + { + private T _door; + + public override void Init(MyObjectBuilder_EntityBase objectBuilder) + { + base.Init(objectBuilder); + NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME; + } + + public override void UpdateOnceBeforeFrame() + { + base.UpdateOnceBeforeFrame(); + + _door = (T) Entity; + if(_door?.CubeGrid?.Physics == null || !(_door is MyEntity)) + return; + + foreach (var part in (_door as MyEntity).Subparts.Values) + if (part.Physics != null) + part.Physics.Enabled = false; + } + } +} diff --git a/DoorDestroyer/DoorDestroyer.csproj.DotSettings b/DoorDestroyer/DoorDestroyer.csproj.DotSettings new file mode 100644 index 0000000..3db4d58 --- /dev/null +++ b/DoorDestroyer/DoorDestroyer.csproj.DotSettings @@ -0,0 +1,3 @@ + + True + True \ No newline at end of file