diff --git a/Features/Enums/BlockType.cs b/Features/Enums/BlockType.cs index ff0a3e6..dc98142 100644 --- a/Features/Enums/BlockType.cs +++ b/Features/Enums/BlockType.cs @@ -44,8 +44,8 @@ public enum BlockType /// Represents a locker. /// Locker = 7, - Text = 8, Interactable = 9, Waypoint = 10, + Door = 30, // when merging replace with normal serial number } diff --git a/Features/Objects/SchematicObject.cs b/Features/Objects/SchematicObject.cs index 8f09cf9..f516718 100644 --- a/Features/Objects/SchematicObject.cs +++ b/Features/Objects/SchematicObject.cs @@ -167,6 +167,12 @@ private void CreateRecursiveFromID(int id, List blocks, Tran GameObject gameObject = block.Create(this, parentTransform); NetworkServer.Spawn(gameObject); + + // We return the parent for the door so that when deleting the schematic, the door is deleted + if (block.BlockType == BlockType.Door) + { + gameObject.transform.SetParent(parentTransform); + } ObjectFromId.Add(block.ObjectId, gameObject.transform); diff --git a/Features/Serializable/Schematics/SchematicBlockData.cs b/Features/Serializable/Schematics/SchematicBlockData.cs index 5e2ae64..157a2f8 100644 --- a/Features/Serializable/Schematics/SchematicBlockData.cs +++ b/Features/Serializable/Schematics/SchematicBlockData.cs @@ -1,4 +1,6 @@ using AdminToys; +using GameCore; +using Interactables.Interobjects.DoorUtils; using InventorySystem.Items.Firearms.Attachments; using LabApi.Features.Wrappers; using ProjectMER.Events.Handlers.Internal; @@ -44,6 +46,7 @@ public GameObject Create(SchematicObject schematicObject, Transform parentTransf BlockType.Workstation => CreateWorkstation(), BlockType.Text => CreateText(), BlockType.Interactable => CreateInteractable(), + BlockType.Door => CreateDoor(), BlockType.Waypoint => CreateWaypoint(), _ => CreateEmpty(true) }; @@ -61,6 +64,13 @@ public GameObject Create(SchematicObject schematicObject, Transform parentTransf _ => Scale, }; + // if you don't remove the parent before NetworkServer.Spawn then there won't be a door + if (BlockType == BlockType.Door) + { + transform.SetParent(null); + } + + if (gameObject.TryGetComponent(out AdminToyBase adminToyBase)) { if (Properties != null && Properties.TryGetValue("Static", out object isStatic) && Convert.ToBoolean(isStatic)) @@ -158,6 +168,27 @@ private GameObject CreateWorkstation() return workstation.gameObject; } + private GameObject CreateDoor() + { + DoorVariant prefab = (DoorType)Convert.ToInt32(Properties["DoorType"]) switch + { + DoorType.Hcz or DoorType.HeavyContainmentDoor => PrefabManager.DoorHcz, + DoorType.Bulkdoor or DoorType.HeavyBulkDoor => PrefabManager.DoorHeavyBulk, + DoorType.Lcz or DoorType.LightContainmentDoor => PrefabManager.DoorLcz, + DoorType.Ez or DoorType.EntranceDoor => PrefabManager.DoorEz, + DoorType.Gate => PrefabManager.DoorGate, + _ => PrefabManager.DoorEz + }; + + DoorVariant doorVariant = GameObject.Instantiate(prefab); + doorVariant.NetworkTargetState = Convert.ToBoolean(Properties["IsOpen"]); + doorVariant.ServerChangeLock(DoorLockReason.SpecialDoorFeature, Convert.ToBoolean(Properties["IsLocked"])); + doorVariant.RequiredPermissions = new DoorPermissionsPolicy( + (DoorPermissionFlags)Convert.ToUInt16(Properties["RequiredPermissions"]), + Convert.ToBoolean(Properties["RequireAll"])); + return doorVariant.gameObject; + } + private GameObject CreateText() { TextToy text = GameObject.Instantiate(PrefabManager.Text);