From 01d59ea05b172dc3bbcefcf6d6ab33966ce70d03 Mon Sep 17 00:00:00 2001 From: Yamato Date: Fri, 23 Feb 2024 00:37:51 +0100 Subject: [PATCH 01/13] Simplify Door/Lift API --- Exiled.API/Features/Doors/Door.cs | 163 +++--------------------------- Exiled.API/Features/Lift.cs | 2 +- Exiled.API/Features/Room.cs | 58 +++++++---- 3 files changed, 55 insertions(+), 168 deletions(-) diff --git a/Exiled.API/Features/Doors/Door.cs b/Exiled.API/Features/Doors/Door.cs index a3172e2900..bb2b4d49a2 100644 --- a/Exiled.API/Features/Doors/Door.cs +++ b/Exiled.API/Features/Doors/Door.cs @@ -17,6 +17,7 @@ namespace Exiled.API.Features.Doors using Exiled.API.Interfaces; using Interactables.Interobjects; using Interactables.Interobjects.DoorUtils; + using MapGeneration.Distributors; using MEC; using Mirror; using UnityEngine; @@ -208,12 +209,12 @@ public bool AllowsScp106 /// /// Gets a value indicating whether or not the door is locked. /// - public bool IsLocked => DoorLockType > 0; + public bool IsLocked => LockType > 0; /// /// Gets or sets the door lock type. /// - public DoorLockType DoorLockType + public DoorLockType LockType { get => (DoorLockType)Base.NetworkActiveLocks; set @@ -435,126 +436,6 @@ public static Door Random(ZoneType type = ZoneType.Unspecified, bool onlyUnbroke return doors[UnityEngine.Random.Range(0, doors.Count)]; } - /// - /// Permanently locks a corresponding to the given type. - /// - /// The door to affect. - /// The specified . - public static void Lock(DoorType type, DoorLockType lockType = DoorLockType.Regular079) => Get(type)?.Lock(lockType); - - /// - /// Temporary locks a corresponding to the given type. - /// - /// The door to affect. - /// The duration of the lockdown. - /// The specified . - public static void Lock(DoorType type, float duration, DoorLockType lockType = DoorLockType.Regular079) => Get(type)?.Lock(duration, lockType); - - /// - /// Unlocks a corresponding to the specified type. - /// - /// The . - public static void Unlock(DoorType type) => Get(type)?.Unlock(); - - /// - /// Locks a doors corresponding to the given type. - /// - /// The door to affect. - /// The duration of the lockdown. - /// The specified . - public static void LockAll(DoorType type, float duration, DoorLockType lockType = DoorLockType.Regular079) => Get(type)?.Lock(duration, lockType); - - /// - /// Permanently locks all doors in the facility. - /// - /// The specified . - public static void LockAll(DoorLockType lockType = DoorLockType.Regular079) => List.ForEach(door => door.Lock(lockType)); - - /// - /// Locks all doors in the facility. - /// - /// The duration of the lockdown. - /// The specified . - public static void LockAll(float duration, DoorLockType lockType = DoorLockType.Regular079) => List.ForEach(door => door.Lock(duration, lockType, true)); - - /// - /// Permanently locks all doors given the specified . - /// - /// The to affect. - /// The specified . - public static void LockAll(ZoneType type, DoorLockType lockType = DoorLockType.Regular079) => Get(type).ForEach(door => door.Lock(lockType, true)); - - /// - /// Permanently locks all doors given the specified zones. - /// - /// The zones to affect. - /// The specified . - public static void LockAll(IEnumerable types, DoorLockType lockType = DoorLockType.Regular079) => Get(types).ForEach(door => door.Lock(lockType, true)); - - /// - /// Temporary locks all doors given the specified . - /// - /// The to affect. - /// The duration of the lockdown. - /// The specified . - public static void LockAll(ZoneType type, float duration, DoorLockType lockType = DoorLockType.Regular079) => Get(type).ForEach(door => door.Lock(lockType, true)); - - /// - /// Temporary locks all doors given the specified zones. - /// - /// The zones to affect. - /// The duration of the lockdown. - /// The specified . - public static void LockAll(IEnumerable types, float duration, DoorLockType lockType = DoorLockType.Regular079) => types.ForEach(t => LockAll(t, duration, lockType)); - - /// - /// Permanently locks all doors corresponding to the given types. - /// - /// The doors to affect. - /// The specified . - public static void LockAll(IEnumerable types, DoorLockType lockType = DoorLockType.Regular079) => Get(types).ForEach(door => door.Lock(lockType, true)); - - /// - /// Temporary locks all doors corresponding to the given types. - /// - /// The doors to affect. - /// The duration of the lockdown. - /// The specified . - public static void LockAll(IEnumerable types, float duration, DoorLockType lockType = DoorLockType.Regular079) => types.ForEach(t => LockAll(t, duration, lockType)); - - /// - /// Unlocks all doors in the facility. - /// - public static void UnlockAll() => List.ForEach(door => door.Unlock()); - - /// - /// Unlocks all doors in the facility. - /// - /// The zones to affect. - public static void UnlockAll(ZoneType type) => UnlockAll(door => door.Zone.HasFlag(type)); - - /// - /// Unlocks all doors in the facility. - /// - /// The zones to affect. - public static void UnlockAll(params ZoneType[] types) => UnlockAll(door => types.Contains(door.Zone)); - - /// - /// Unlocks all doors in the facility. - /// - /// The zones to affect. - public static void UnlockAll(IEnumerable types) => UnlockAll(door => types.Contains(door.Zone)); - - /// - /// Unlocks all doors in the facility. - /// - /// The condition to satisfy. - public static void UnlockAll(Func predicate) - { - foreach (Door door in Get(predicate)) - door.Unlock(); - } - /// /// Makes the door play a beep sound. /// @@ -576,37 +457,25 @@ public void PlaySound(DoorBeepType beep) /// Change the door lock with the given lock type. /// /// The to use. - public void ChangeLock(DoorLockType lockType) - { - if (lockType is DoorLockType.None) - { - Base.NetworkActiveLocks = 0; - } - else - { - DoorLockType locks = DoorLockType; - if (locks.HasFlag(lockType)) - locks &= ~lockType; - else - locks |= lockType; - - Base.NetworkActiveLocks = (ushort)locks; - } - - DoorEvents.TriggerAction(Base, IsLocked ? DoorAction.Locked : DoorAction.Unlocked, null); - } + public void ChangeLock(DoorLockType lockType) => Base.ServerChangeLock((DoorLockReason)lockType, !LockType.HasFlag(lockType)); /// /// Permanently locks all active locks on the door, and then reverts back any changes after a specified length of time. /// /// The of the lockdown. - /// A value indicating whether the door should be closed. - public void Lock(DoorLockType lockType = DoorLockType.Regular079, bool shouldBeClosed = false) + /// A value indicating whether the door state should be modified. + public void Lock(DoorLockType lockType = DoorLockType.Regular079, bool shouldBeModified = false) { - if (shouldBeClosed) - IsOpen = false; - ChangeLock(lockType); + + if (shouldBeModified) + { + DoorLockMode mode = DoorLockUtils.GetMode((DoorLockReason)LockType); + if (mode is DoorLockMode.CanOpen) + IsOpen = true; + else if (mode is DoorLockMode.CanClose) + IsOpen = false; + } } /// @@ -644,7 +513,7 @@ public void Lock(float time, DoorLockType lockType = DoorLockType.Regular079, bo /// Returns the Door in a human-readable format. /// /// A string containing Door-related data. - public override string ToString() => $"{Type} ({Zone}) [{Room}] *{DoorLockType}* ={RequiredPermissions.RequiredPermissions}="; + public override string ToString() => $"{Type} ({Zone}) [{Room}] *{LockType}* ={RequiredPermissions.RequiredPermissions}="; /// /// Creates the door object associated with a specific . diff --git a/Exiled.API/Features/Lift.cs b/Exiled.API/Features/Lift.cs index 8ecfa0805a..5a7a538494 100644 --- a/Exiled.API/Features/Lift.cs +++ b/Exiled.API/Features/Lift.cs @@ -416,7 +416,7 @@ public void ChangeLock(DoorLockReason lockReason) { if (!forceLock) { - door.DoorLockType = 0; + door.LockType = 0; door.ChangeLock(DoorLockType.None); } diff --git a/Exiled.API/Features/Room.cs b/Exiled.API/Features/Room.cs index cb2daf3e7e..1232af4b2d 100644 --- a/Exiled.API/Features/Room.cs +++ b/Exiled.API/Features/Room.cs @@ -333,21 +333,22 @@ public static Room FindParentRoom(GameObject objectInRoom) public static Room Random(ZoneType zoneType = ZoneType.Unspecified) => (zoneType is not ZoneType.Unspecified ? Get(r => r.Zone.HasFlag(zoneType)) : List).Random(); /// - /// Flickers the room's lights off for a duration. + /// Flickers the room's lights off. /// - /// Duration in seconds, or -1 for an indefinite duration. - public void TurnOffLights(float duration = -1) + public void TurnOffLights() { - if (duration == -1) + foreach (RoomLightController light in RoomLightControllers) { - foreach (RoomLightController light in RoomLightControllers) - { - light.SetLights(false); - } - - return; + light.SetLights(false); } + } + /// + /// Flickers the room's lights off for a duration. + /// + /// Duration in seconds. + public void TurnOffLights(float duration) + { foreach (RoomLightController light in RoomLightControllers) { light.ServerFlickerLights(duration); @@ -357,26 +358,47 @@ public void TurnOffLights(float duration = -1) /// /// Locks all the doors in the room. /// - /// Duration in seconds, or -1 for permanent lockdown. /// DoorLockType of the lockdown. - public void LockDown(float duration, DoorLockType lockType = DoorLockType.Regular079) + public void LockDown(DoorLockType lockType = DoorLockType.Regular079) { foreach (Door door in Doors) { door.ChangeLock(lockType); door.IsOpen = false; } + } - if (duration < 0) - return; + /// + /// Locks all the doors in the room. + /// + /// Duration in seconds. + /// DoorLockType of the lockdown. + public void LockDown(float duration, DoorLockType lockType = DoorLockType.Regular079) + { + foreach (Door door in Doors) + { + door.ChangeLock(lockType); + door.IsOpen = false; + door.Unlock(duration, lockType); + } + } - Timing.CallDelayed(duration, UnlockAll); + /// + /// Locks all the doors and turns off all lights in the room. + /// + /// DoorLockType of the blackout. + /// + /// + public void Blackout(DoorLockType lockType = DoorLockType.Regular079) + { + LockDown(lockType); + TurnOffLights(); } /// /// Locks all the doors and turns off all lights in the room. /// - /// Duration in seconds, or -1 for permanent blackout. + /// Duration in seconds. /// DoorLockType of the blackout. /// /// @@ -389,10 +411,6 @@ public void Blackout(float duration, DoorLockType lockType = DoorLockType.Regula /// /// Unlocks all the doors in the room. /// - /// - /// - /// - /// public void UnlockAll() { foreach (Door door in Doors) From 6753bb2195dc3707be629cb86c5acab6f656ca3c Mon Sep 17 00:00:00 2001 From: Yamato Date: Fri, 23 Feb 2024 00:38:47 +0100 Subject: [PATCH 02/13] . --- Exiled.API/Features/Lift.cs | 100 ------------------------------------ 1 file changed, 100 deletions(-) diff --git a/Exiled.API/Features/Lift.cs b/Exiled.API/Features/Lift.cs index 5a7a538494..9e152fb03b 100644 --- a/Exiled.API/Features/Lift.cs +++ b/Exiled.API/Features/Lift.cs @@ -264,106 +264,6 @@ public override Quaternion Rotation /// A of which contains elements that satisfy the condition. public static IEnumerable Get(Func predicate) => List.Where(predicate); - /// - /// Permanently locks an elevator corresponding to the given type. - /// - /// The elevator to affect. - /// The specified . - public static void Lock(ElevatorType type, DoorLockReason lockReason = DoorLockReason.Isolation) => Get(type)?.Lock(lockReason); - - /// - /// Temporary locks an elevator corresponding to the given type. - /// - /// The elevator to affect. - /// The duration of the lockdown. - /// The specified . - public static void Lock(ElevatorType type, float duration, DoorLockReason lockReason = DoorLockReason.Isolation) => Get(type)?.Lock(duration, lockReason); - - /// - /// Unlocks a lift corresponding to the specified type. - /// - /// The . - public static void Unlock(ElevatorType type) => Get(type)?.Unlock(); - - /// - /// Permanently locks all elevators in the facility. - /// - /// The specified . - public static void LockAll(DoorLockReason lockReason = DoorLockReason.Isolation) => List.ForEach(lift => lift.Lock(lockReason)); - - /// - /// Temporary locks all elevators in the facility. - /// - /// The duration of the lockdown. - /// The specified . - public static void LockAll(float duration, DoorLockReason lockReason = DoorLockReason.Isolation) => List.ForEach(lift => lift.Lock(duration, lockReason)); - - /// - /// Permanently locks all elevators corresponding to the given types. - /// - /// The doors to affect. - /// The specified . - public static void LockAll(IEnumerable types, DoorLockReason lockReason = DoorLockReason.Isolation) => types.ForEach(t => Lock(t, lockReason)); - - /// - /// Temporary locks all elevators corresponding to the given types. - /// - /// The doors to affect. - /// The duration of the lockdown. - /// The specified . - public static void LockAll(IEnumerable types, float duration, DoorLockReason lockReason = DoorLockReason.Isolation) => types.ForEach(t => Lock(t, lockReason)); - - /// - /// Unlocks all lifts in the facility. - /// - public static void UnlockAll() => List.ForEach(lift => lift.Unlock()); - - /// - /// Unlocks all lifts in the facility. - /// - /// The zones to affect. - public static void UnlockAll(ZoneType type) => List.ForEach(lift => lift.Doors.Where(door => door.Zone == type).ForEach(door => door.Unlock())); - - /// - /// Unlocks all lifts in the facility. - /// - /// The zones to affect. - public static void UnlockAll(params ZoneType[] types) => List.ForEach(lift => lift.Doors.Where(door => types.Contains(door.Zone)).ForEach(door => door.Unlock())); - - /// - /// Unlocks all lifts in the facility. - /// - /// The zones to affect. - public static void UnlockAll(IEnumerable types) => List.ForEach(lift => lift.Doors.Where(door => types.Contains(door.Zone)).ForEach(door => door.Unlock())); - - /// - /// Unlocks all lifts in the facility. - /// - /// The types to affect. - public static void UnlockAll(params ElevatorType[] types) => Get(types).ForEach(lift => lift.Unlock()); - - /// - /// Unlocks all lifts in the facility. - /// - /// The types to affect. - public static void UnlockAll(IEnumerable types) => Get(types).ForEach(lift => lift.Unlock()); - - /// - /// Tries to melt a . - /// - /// The to melt. - /// if the player was melted successfully; otherwise, . - /// - public static bool TryMeltPlayer(Player player) - { - if (player.Position.y is >= 200 or <= -200) - return false; - - player.EnableEffect(EffectType.Decontaminating); - - return true; - } - /// /// Tries to start the lift. /// From 3588ade5fa5a9fb5233b66822c29ffc77a2b7843 Mon Sep 17 00:00:00 2001 From: Yamato Date: Fri, 23 Feb 2024 00:40:19 +0100 Subject: [PATCH 03/13] Random --- Exiled.API/Features/Doors/Door.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Exiled.API/Features/Doors/Door.cs b/Exiled.API/Features/Doors/Door.cs index bb2b4d49a2..8e889bc62f 100644 --- a/Exiled.API/Features/Doors/Door.cs +++ b/Exiled.API/Features/Doors/Door.cs @@ -428,12 +428,9 @@ public static Door GetClosest(Vector3 position, out float distance) /// object. public static Door Random(ZoneType type = ZoneType.Unspecified, bool onlyUnbroken = false) { - List doors = onlyUnbroken || type is not ZoneType.Unspecified ? Get(x => - (x.Room is null || x.Room.Zone.HasFlag(type) || type == ZoneType.Unspecified) && (x is Breakable { IsDestroyed: true } || !onlyUnbroken)). - ToList() : - DoorVariantToDoor.Values.ToList(); - - return doors[UnityEngine.Random.Range(0, doors.Count)]; + return onlyUnbroken || type is not ZoneType.Unspecified ? + Get(x => (x.Room is null || x.Room.Zone.HasFlag(type) || type == ZoneType.Unspecified) && (x is Breakable { IsDestroyed: true } || !onlyUnbroken)).Random() : + DoorVariantToDoor.Values.Random(); } /// From 7f79ecd4d4e2078db78187b6fe8c060919b97b88 Mon Sep 17 00:00:00 2001 From: Yamato Date: Fri, 23 Feb 2024 00:40:33 +0100 Subject: [PATCH 04/13] . --- Exiled.API/Features/Doors/Door.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Exiled.API/Features/Doors/Door.cs b/Exiled.API/Features/Doors/Door.cs index 8e889bc62f..532fa6d88a 100644 --- a/Exiled.API/Features/Doors/Door.cs +++ b/Exiled.API/Features/Doors/Door.cs @@ -426,12 +426,9 @@ public static Door GetClosest(Vector3 position, out float distance) /// Filters by . /// A value indicating whether it filters broken doors. /// object. - public static Door Random(ZoneType type = ZoneType.Unspecified, bool onlyUnbroken = false) - { - return onlyUnbroken || type is not ZoneType.Unspecified ? + public static Door Random(ZoneType type = ZoneType.Unspecified, bool onlyUnbroken = false) => onlyUnbroken || type is not ZoneType.Unspecified ? Get(x => (x.Room is null || x.Room.Zone.HasFlag(type) || type == ZoneType.Unspecified) && (x is Breakable { IsDestroyed: true } || !onlyUnbroken)).Random() : DoorVariantToDoor.Values.Random(); - } /// /// Makes the door play a beep sound. From d55481e3fb18dc20fac146e9510ebf27d34397af Mon Sep 17 00:00:00 2001 From: Yamato Date: Fri, 23 Feb 2024 00:51:25 +0100 Subject: [PATCH 05/13] Lift --- Exiled.API/Features/Doors/Door.cs | 14 +++++----- Exiled.API/Features/Lift.cs | 44 +++++++------------------------ 2 files changed, 17 insertions(+), 41 deletions(-) diff --git a/Exiled.API/Features/Doors/Door.cs b/Exiled.API/Features/Doors/Door.cs index 532fa6d88a..dcbb313d28 100644 --- a/Exiled.API/Features/Doors/Door.cs +++ b/Exiled.API/Features/Doors/Door.cs @@ -457,12 +457,12 @@ public void PlaySound(DoorBeepType beep) /// Permanently locks all active locks on the door, and then reverts back any changes after a specified length of time. /// /// The of the lockdown. - /// A value indicating whether the door state should be modified. - public void Lock(DoorLockType lockType = DoorLockType.Regular079, bool shouldBeModified = false) + /// A value indicating whether the door state should be modified. + public void Lock(DoorLockType lockType = DoorLockType.AdminCommand, bool updateTheDoorState = true) { ChangeLock(lockType); - if (shouldBeModified) + if (updateTheDoorState) { DoorLockMode mode = DoorLockUtils.GetMode((DoorLockReason)LockType); if (mode is DoorLockMode.CanOpen) @@ -477,10 +477,10 @@ public void Lock(DoorLockType lockType = DoorLockType.Regular079, bool shouldBeM /// /// The amount of time that must pass before unlocking the door. /// The of the lockdown. - /// A value indicating whether the door should be closed. - public void Lock(float time, DoorLockType lockType = DoorLockType.Regular079, bool shouldBeClosed = false) + /// A value indicating whether the door state should be modified. + public void Lock(float time, DoorLockType lockType = DoorLockType.AdminCommand, bool updateTheDoorState = true) { - Lock(lockType, shouldBeClosed); + Lock(lockType, updateTheDoorState); Unlock(time, lockType); } @@ -493,7 +493,7 @@ public void Lock(float time, DoorLockType lockType = DoorLockType.Regular079, bo /// Unlocks and clears all active locks on the door after a specified length of time. /// /// The amount of time that must pass before unlocking the door. - /// The of the lockdown. + /// The of the lockdown. public void Unlock(float time, DoorLockType flagsToUnlock) => DoorScheduledUnlocker.UnlockLater(Base, time, (DoorLockReason)flagsToUnlock); /// diff --git a/Exiled.API/Features/Lift.cs b/Exiled.API/Features/Lift.cs index 9e152fb03b..8c4af9e3c9 100644 --- a/Exiled.API/Features/Lift.cs +++ b/Exiled.API/Features/Lift.cs @@ -275,8 +275,8 @@ public override Quaternion Rotation /// /// Locks the lift. /// - /// The . - public void Lock(DoorLockReason lockReason = DoorLockReason.Isolation) + /// The . + public void Lock(DoorLockType lockReason = DoorLockType.Isolation) { Status = ElevatorSequence.DoorClosing; ChangeLock(lockReason); @@ -286,51 +286,27 @@ public void Lock(DoorLockReason lockReason = DoorLockReason.Isolation) /// Locks the lift. /// /// The duration of the lockdown. - /// The . - public void Lock(float duration, DoorLockReason lockReason = DoorLockReason.Isolation) - { - Status = ElevatorSequence.DoorClosing; - ChangeLock(lockReason); - } + /// The of the lockdown. + /// A value indicating whether the door state should be modified. + public void Lock(float duration, DoorLockType lockType = DoorLockType.AdminCommand, bool updateTheDoorState = true) => Doors.ForEach(x => x.Lock(duration, lockType, updateTheDoorState)); /// /// Unlocks the lift. /// - public void Unlock() => ChangeLock(DoorLockReason.None); + public void Unlock() => Doors.ForEach(x => x.ChangeLock(DoorLockType.None)); /// /// Unlocks the lift. /// /// The delay after which the lift should be unlocked. - public void Unlock(float delay) => Timing.CallDelayed(delay, () => ChangeLock(DoorLockReason.None)); + /// The of the lockdown. + public void Unlock(float delay, DoorLockType lockType = DoorLockType.AdminCommand) => Doors.ForEach(x => x.Unlock(delay, lockType)); /// /// Changes lock of the lift. /// - /// The . - public void ChangeLock(DoorLockReason lockReason) - { - bool forceLock = lockReason != DoorLockReason.None; - - foreach (Doors.ElevatorDoor door in Doors) - { - if (!forceLock) - { - door.LockType = 0; - - door.ChangeLock(DoorLockType.None); - } - else - { - door.ChangeLock((DoorLockType)lockReason); - - if (CurrentLevel != 1) - TrySetDestination(Group, 1, true); - } - - Base.RefreshLocks(Group, door.Base); - } - } + /// The . + public void ChangeLock(DoorLockType lockReason) => Doors.ForEach(x => x.ChangeLock(lockReason)); /// /// Returns whether or not the provided position is inside the lift. From 7f5ec24ae9a44ae64df1912338c4f4d67de96b89 Mon Sep 17 00:00:00 2001 From: Yamato Date: Fri, 23 Feb 2024 01:00:44 +0100 Subject: [PATCH 06/13] Fix error --- Exiled.API/Enums/DoorLockType.cs | 1 - .../API/Features/CustomGamemodes/GameState.cs | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Exiled.API/Enums/DoorLockType.cs b/Exiled.API/Enums/DoorLockType.cs index f3bacad7a0..331fa33760 100644 --- a/Exiled.API/Enums/DoorLockType.cs +++ b/Exiled.API/Enums/DoorLockType.cs @@ -14,7 +14,6 @@ namespace Exiled.API.Enums /// /// All possible door locks. /// - /// /// [Flags] public enum DoorLockType diff --git a/Exiled.CustomModules/API/Features/CustomGamemodes/GameState.cs b/Exiled.CustomModules/API/Features/CustomGamemodes/GameState.cs index 0b402d3f30..71a230cda1 100644 --- a/Exiled.CustomModules/API/Features/CustomGamemodes/GameState.cs +++ b/Exiled.CustomModules/API/Features/CustomGamemodes/GameState.cs @@ -201,9 +201,9 @@ protected override void OnBeginPlay() { base.OnBeginPlay(); - Door.LockAll(Settings.LockedZones); - Door.LockAll(Settings.LockedDoors); - Lift.LockAll(Settings.LockedElevators); + Door.Get(Settings.LockedZones).ForEach(x => x.Lock()); + Door.Get(Settings.LockedDoors).ForEach(x => x.Lock()); + Lift.Get(Settings.LockedElevators).ForEach(x => x.Lock()); } /// @@ -211,8 +211,8 @@ protected override void OnEndPlay() { base.OnEndPlay(); - Door.UnlockAll(); - Lift.UnlockAll(); + Door.List.ForEach(x => x.Unlock()); + Lift.List.ForEach(x => x.Unlock()); } /// From ccb3255734a62068e46331ee37d0fd292d33659c Mon Sep 17 00:00:00 2001 From: Yamato Date: Fri, 23 Feb 2024 12:41:00 +0100 Subject: [PATCH 07/13] IsClose --- Exiled.API/Features/Doors/Door.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Exiled.API/Features/Doors/Door.cs b/Exiled.API/Features/Doors/Door.cs index dcbb313d28..756df0d8f7 100644 --- a/Exiled.API/Features/Doors/Door.cs +++ b/Exiled.API/Features/Doors/Door.cs @@ -129,6 +129,15 @@ public bool IsOpen set => Base.NetworkTargetState = value; } + /// + /// Gets or sets a value indicating whether the door is close. + /// + public bool IsClose + { + get => !IsOpen; + set => IsOpen = !value; + } + /// /// Gets a value indicating whether or not this door is a gate. /// From e155b8000fee8d2b8b15955bba91768d7177e4b8 Mon Sep 17 00:00:00 2001 From: Yamato Date: Fri, 23 Feb 2024 12:41:10 +0100 Subject: [PATCH 08/13] List & not needed Get --- Exiled.API/Features/Lift.cs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/Exiled.API/Features/Lift.cs b/Exiled.API/Features/Lift.cs index 8c4af9e3c9..6b2667fb4d 100644 --- a/Exiled.API/Features/Lift.cs +++ b/Exiled.API/Features/Lift.cs @@ -25,7 +25,8 @@ namespace Exiled.API.Features using static Interactables.Interobjects.ElevatorChamber; using static Interactables.Interobjects.ElevatorManager; - using Elevator = Interactables.Interobjects.ElevatorDoor; + using BaseElevatorDoor = Interactables.Interobjects.ElevatorDoor; + using ElevatorDoor = Doors.ElevatorDoor; /// /// The in-game lift. @@ -40,7 +41,7 @@ public class Lift : GameEntity, IWrapper, IWorldSpace /// /// Internal list that contains all ElevatorDoor for current group. /// - private readonly List internalDoorsList = ListPool.Pool.Get(); + private readonly List internalDoorsList = ListPool.Pool.Get(); /// /// Initializes a new instance of the class. @@ -52,13 +53,13 @@ internal Lift(ElevatorChamber elevator) Base = elevator; ElevatorChamberToLift.Add(elevator, this); - internalDoorsList.AddRange(Interactables.Interobjects.ElevatorDoor.AllElevatorDoors[Group]); + internalDoorsList.AddRange(BaseElevatorDoor.AllElevatorDoors[Group].Select(x => Door.Get(x).As())); } /// /// Finalizes an instance of the class. /// - ~Lift() => ListPool.Pool.Return(internalDoorsList); + ~Lift() => ListPool.Pool.Return(internalDoorsList); /// /// Gets a of which contains all the instances. @@ -74,7 +75,7 @@ internal Lift(ElevatorChamber elevator) /// /// Gets a value of the internal doors list. /// - public IReadOnlyCollection Doors => internalDoorsList.Select(x => Door.Get(x).As()).ToList(); + public IReadOnlyList Doors => internalDoorsList; /// /// Gets a of in the . @@ -176,7 +177,7 @@ public float AnimationTime /// /// Gets the . /// - public Doors.ElevatorDoor CurrentDestination => Door.Get(Base.CurrentDestination).As(); + public ElevatorDoor CurrentDestination => Door.Get(Base.CurrentDestination).As(); /// /// Gets or sets the lift's position. @@ -201,13 +202,6 @@ public override Quaternion Rotation /// public ElevatorChamber Base { get; } - /// - /// Gets a of which contains all the instances from the specified . - /// - /// The specified . - /// A or if not found. - public static IEnumerable Get(ElevatorSequence status) => Get(lift => lift.Status == status); - /// /// Gets the belonging to the , if any. /// From a2a250c507283ee17e9d234c6957e03b7ad1f0ed Mon Sep 17 00:00:00 2001 From: Yamato <66829532+louis1706@users.noreply.github.com> Date: Sat, 6 Apr 2024 19:43:36 +0200 Subject: [PATCH 09/13] Update Exiled.API/Features/Doors/Door.cs --- Exiled.API/Features/Doors/Door.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Exiled.API/Features/Doors/Door.cs b/Exiled.API/Features/Doors/Door.cs index fe46c565cc..8224399773 100644 --- a/Exiled.API/Features/Doors/Door.cs +++ b/Exiled.API/Features/Doors/Door.cs @@ -132,7 +132,7 @@ public bool IsOpen /// /// Gets or sets a value indicating whether the door is close. /// - public bool IsClose + public bool IsClosed { get => !IsOpen; set => IsOpen = !value; From 2188463d3604e205e4da77038c307f2f51187a2f Mon Sep 17 00:00:00 2001 From: Yamato Date: Sun, 12 May 2024 19:06:48 +0200 Subject: [PATCH 10/13] DoorLockType --- Exiled.API/Features/Doors/Door.cs | 120 ++++++++++++++++++++++++++++++ Exiled.API/Features/Lift.cs | 102 ++++++++++++++++++++----- 2 files changed, 204 insertions(+), 18 deletions(-) diff --git a/Exiled.API/Features/Doors/Door.cs b/Exiled.API/Features/Doors/Door.cs index 25f8cde196..3bdc3b0b3d 100644 --- a/Exiled.API/Features/Doors/Door.cs +++ b/Exiled.API/Features/Doors/Door.cs @@ -439,6 +439,126 @@ public static Door Random(ZoneType type = ZoneType.Unspecified, bool onlyUnbroke Get(x => (x.Room is null || x.Room.Zone.HasFlag(type) || type == ZoneType.Unspecified) && (x is Breakable { IsDestroyed: true } || !onlyUnbroken)).Random() : DoorVariantToDoor.Values.Random(); + /// + /// Permanently locks a corresponding to the given type. + /// + /// The door to affect. + /// The specified . + public static void Lock(DoorType type, DoorLockType lockType = DoorLockType.Regular079) => Get(type)?.Lock(lockType); + + /// + /// Temporary locks a corresponding to the given type. + /// + /// The door to affect. + /// The duration of the lockdown. + /// The specified . + public static void Lock(DoorType type, float duration, DoorLockType lockType = DoorLockType.Regular079) => Get(type)?.Lock(duration, lockType); + + /// + /// Unlocks a corresponding to the specified type. + /// + /// The . + public static void Unlock(DoorType type) => Get(type)?.Unlock(); + + /// + /// Locks a doors corresponding to the given type. + /// + /// The door to affect. + /// The duration of the lockdown. + /// The specified . + public static void LockAll(DoorType type, float duration, DoorLockType lockType = DoorLockType.Regular079) => Get(type)?.Lock(duration, lockType); + + /// + /// Permanently locks all doors in the facility. + /// + /// The specified . + public static void LockAll(DoorLockType lockType = DoorLockType.Regular079) => List.ForEach(door => door.Lock(lockType)); + + /// + /// Locks all doors in the facility. + /// + /// The duration of the lockdown. + /// The specified . + public static void LockAll(float duration, DoorLockType lockType = DoorLockType.Regular079) => List.ForEach(door => door.Lock(duration, lockType, true)); + + /// + /// Permanently locks all doors given the specified . + /// + /// The to affect. + /// The specified . + public static void LockAll(ZoneType type, DoorLockType lockType = DoorLockType.Regular079) => Get(type).ForEach(door => door.Lock(lockType, true)); + + /// + /// Permanently locks all doors given the specified zones. + /// + /// The zones to affect. + /// The specified . + public static void LockAll(IEnumerable types, DoorLockType lockType = DoorLockType.Regular079) => Get(types).ForEach(door => door.Lock(lockType, true)); + + /// + /// Temporary locks all doors given the specified . + /// + /// The to affect. + /// The duration of the lockdown. + /// The specified . + public static void LockAll(ZoneType type, float duration, DoorLockType lockType = DoorLockType.Regular079) => Get(type).ForEach(door => door.Lock(lockType, true)); + + /// + /// Temporary locks all doors given the specified zones. + /// + /// The zones to affect. + /// The duration of the lockdown. + /// The specified . + public static void LockAll(IEnumerable types, float duration, DoorLockType lockType = DoorLockType.Regular079) => types.ForEach(t => LockAll(t, duration, lockType)); + + /// + /// Permanently locks all doors corresponding to the given types. + /// + /// The doors to affect. + /// The specified . + public static void LockAll(IEnumerable types, DoorLockType lockType = DoorLockType.Regular079) => Get(types).ForEach(door => door.Lock(lockType, true)); + + /// + /// Temporary locks all doors corresponding to the given types. + /// + /// The doors to affect. + /// The duration of the lockdown. + /// The specified . + public static void LockAll(IEnumerable types, float duration, DoorLockType lockType = DoorLockType.Regular079) => types.ForEach(t => LockAll(t, duration, lockType)); + + /// + /// Unlocks all doors in the facility. + /// + public static void UnlockAll() => List.ForEach(door => door.Unlock()); + + /// + /// Unlocks all doors in the facility. + /// + /// The zones to affect. + public static void UnlockAll(ZoneType type) => UnlockAll(door => door.Zone.HasFlag(type)); + + /// + /// Unlocks all doors in the facility. + /// + /// The zones to affect. + public static void UnlockAll(params ZoneType[] types) => UnlockAll(door => types.Contains(door.Zone)); + + /// + /// Unlocks all doors in the facility. + /// + /// The zones to affect. + public static void UnlockAll(IEnumerable types) => UnlockAll(door => types.Contains(door.Zone)); + + /// + /// Unlocks all doors in the facility. + /// + /// The condition to satisfy. + public static void UnlockAll(Func predicate) + { + foreach (Door door in Get(predicate)) + door.Unlock(); + } + /// /// Interacts with the Door. /// diff --git a/Exiled.API/Features/Lift.cs b/Exiled.API/Features/Lift.cs index bd96aaddb0..b6c61864fa 100644 --- a/Exiled.API/Features/Lift.cs +++ b/Exiled.API/Features/Lift.cs @@ -174,24 +174,6 @@ public float AnimationTime /// public ElevatorDoor CurrentDestination => Door.Get(Base.CurrentDestination).As(); - /// - /// Gets or sets the lift's position. - /// - public override Vector3 Position - { - get => Transform.position; - set => Transform.position = value; - } - - /// - /// Gets or sets the lift's rotation. - /// - public override Quaternion Rotation - { - get => Transform.rotation; - set => Transform.rotation = value; - } - /// /// Gets the base . /// @@ -253,6 +235,90 @@ public override Quaternion Rotation /// A of which contains elements that satisfy the condition. public static IEnumerable Get(Func predicate) => List.Where(predicate); + /// + /// Permanently locks an elevator corresponding to the given type. + /// + /// The elevator to affect. + /// The specified . + public static void Lock(ElevatorType type, DoorLockType lockReason = DoorLockType.Isolation) => Get(type)?.Lock(lockReason); + + /// + /// Temporary locks an elevator corresponding to the given type. + /// + /// The elevator to affect. + /// The duration of the lockdown. + /// The specified . + public static void Lock(ElevatorType type, float duration, DoorLockType lockReason = DoorLockType.Isolation) => Get(type)?.Lock(duration, lockReason); + + /// + /// Unlocks a lift corresponding to the specified type. + /// + /// The . + public static void Unlock(ElevatorType type) => Get(type)?.Unlock(); + + /// + /// Permanently locks all elevators in the facility. + /// + /// The specified . + public static void LockAll(DoorLockType lockReason = DoorLockType.Isolation) => List.ForEach(lift => lift.Lock(lockReason)); + + /// + /// Temporary locks all elevators in the facility. + /// + /// The duration of the lockdown. + /// The specified . + public static void LockAll(float duration, DoorLockType lockReason = DoorLockType.Isolation) => List.ForEach(lift => lift.Lock(duration, lockReason)); + + /// + /// Permanently locks all elevators corresponding to the given types. + /// + /// The doors to affect. + /// The specified . + public static void LockAll(IEnumerable types, DoorLockType lockReason = DoorLockType.Isolation) => types.ForEach(t => Lock(t, lockReason)); + + /// + /// Temporary locks all elevators corresponding to the given types. + /// + /// The doors to affect. + /// The duration of the lockdown. + /// The specified . + public static void LockAll(IEnumerable types, float duration, DoorLockType lockReason = DoorLockType.Isolation) => types.ForEach(t => Lock(t, duration, lockReason)); + + /// + /// Unlocks all lifts in the facility. + /// + public static void UnlockAll() => List.ForEach(lift => lift.Unlock()); + + /// + /// Unlocks all lifts in the facility. + /// + /// The zones to affect. + public static void UnlockAll(ZoneType type) => List.ForEach(lift => lift.Doors.Where(door => door.Zone == type).ForEach(door => door.Unlock())); + + /// + /// Unlocks all lifts in the facility. + /// + /// The zones to affect. + public static void UnlockAll(params ZoneType[] types) => List.ForEach(lift => lift.Doors.Where(door => types.Contains(door.Zone)).ForEach(door => door.Unlock())); + + /// + /// Unlocks all lifts in the facility. + /// + /// The zones to affect. + public static void UnlockAll(IEnumerable types) => List.ForEach(lift => lift.Doors.Where(door => types.Contains(door.Zone)).ForEach(door => door.Unlock())); + + /// + /// Unlocks all lifts in the facility. + /// + /// The types to affect. + public static void UnlockAll(params ElevatorType[] types) => Get(types).ForEach(lift => lift.Unlock()); + + /// + /// Unlocks all lifts in the facility. + /// + /// The types to affect. + public static void UnlockAll(IEnumerable types) => Get(types).ForEach(lift => lift.Unlock()); + /// /// Tries to start the lift. /// From d603fe4f41ed53f76e159b2f921993e28b486fef Mon Sep 17 00:00:00 2001 From: Yamato Date: Sun, 12 May 2024 19:13:14 +0200 Subject: [PATCH 11/13] Revert --- .../API/Features/CustomGamemodes/GameState.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Exiled.CustomModules/API/Features/CustomGamemodes/GameState.cs b/Exiled.CustomModules/API/Features/CustomGamemodes/GameState.cs index 71a230cda1..0b402d3f30 100644 --- a/Exiled.CustomModules/API/Features/CustomGamemodes/GameState.cs +++ b/Exiled.CustomModules/API/Features/CustomGamemodes/GameState.cs @@ -201,9 +201,9 @@ protected override void OnBeginPlay() { base.OnBeginPlay(); - Door.Get(Settings.LockedZones).ForEach(x => x.Lock()); - Door.Get(Settings.LockedDoors).ForEach(x => x.Lock()); - Lift.Get(Settings.LockedElevators).ForEach(x => x.Lock()); + Door.LockAll(Settings.LockedZones); + Door.LockAll(Settings.LockedDoors); + Lift.LockAll(Settings.LockedElevators); } /// @@ -211,8 +211,8 @@ protected override void OnEndPlay() { base.OnEndPlay(); - Door.List.ForEach(x => x.Unlock()); - Lift.List.ForEach(x => x.Unlock()); + Door.UnlockAll(); + Lift.UnlockAll(); } /// From cd2f82290845738d03715feed7c1f0566277e112 Mon Sep 17 00:00:00 2001 From: Yamato Date: Sun, 12 May 2024 19:20:11 +0200 Subject: [PATCH 12/13] Unlock --- Exiled.API/Features/Doors/Door.cs | 8 ++++---- Exiled.API/Features/Lift.cs | 2 +- Exiled.API/Features/Room.cs | 4 ++++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Exiled.API/Features/Doors/Door.cs b/Exiled.API/Features/Doors/Door.cs index 3bdc3b0b3d..aece59473f 100644 --- a/Exiled.API/Features/Doors/Door.cs +++ b/Exiled.API/Features/Doors/Door.cs @@ -501,7 +501,7 @@ public static Door Random(ZoneType type = ZoneType.Unspecified, bool onlyUnbroke /// The to affect. /// The duration of the lockdown. /// The specified . - public static void LockAll(ZoneType type, float duration, DoorLockType lockType = DoorLockType.Regular079) => Get(type).ForEach(door => door.Lock(lockType, true)); + public static void LockAll(ZoneType type, float duration, DoorLockType lockType = DoorLockType.Regular079) => Get(type).ForEach(door => door.Lock(duration, lockType, true)); /// /// Temporary locks all doors given the specified zones. @@ -585,13 +585,13 @@ public void PlaySound(DoorBeepType beep) /// /// Change the door lock with the given lock type. /// - /// The to use. + /// The to use. public void ChangeLock(DoorLockType lockType) => Base.ServerChangeLock((DoorLockReason)lockType, !LockType.HasFlag(lockType)); /// /// Permanently locks all active locks on the door, and then reverts back any changes after a specified length of time. /// - /// The of the lockdown. + /// The of the lockdown. /// A value indicating whether the door state should be modified. public void Lock(DoorLockType lockType = DoorLockType.AdminCommand, bool updateTheDoorState = true) { @@ -611,7 +611,7 @@ public void Lock(DoorLockType lockType = DoorLockType.AdminCommand, bool updateT /// Temporary locks all active locks on the door, and then reverts back any changes after a specified length of time. /// /// The amount of time that must pass before unlocking the door. - /// The of the lockdown. + /// The of the lockdown. /// A value indicating whether the door state should be modified. public void Lock(float time, DoorLockType lockType = DoorLockType.AdminCommand, bool updateTheDoorState = true) { diff --git a/Exiled.API/Features/Lift.cs b/Exiled.API/Features/Lift.cs index b6c61864fa..5896cb41e9 100644 --- a/Exiled.API/Features/Lift.cs +++ b/Exiled.API/Features/Lift.cs @@ -348,7 +348,7 @@ public void Lock(DoorLockType lockReason = DoorLockType.Isolation) /// /// Unlocks the lift. /// - public void Unlock() => Doors.ForEach(x => x.ChangeLock(DoorLockType.None)); + public void Unlock() => Doors.ForEach(x => x.Unlock()); /// /// Unlocks the lift. diff --git a/Exiled.API/Features/Room.cs b/Exiled.API/Features/Room.cs index ce0cc54024..f168140208 100644 --- a/Exiled.API/Features/Room.cs +++ b/Exiled.API/Features/Room.cs @@ -401,6 +401,10 @@ public void Blackout(float duration, DoorLockType lockType = DoorLockType.Regula /// /// Unlocks all the doors in the room. /// + /// + /// + /// + /// public void UnlockAll() { foreach (Door door in Doors) From 98ffdb99be63202e2b2c593c9776b80566750ad7 Mon Sep 17 00:00:00 2001 From: Yamato Date: Sun, 12 May 2024 19:53:06 +0200 Subject: [PATCH 13/13] was hard to read actually --- Exiled.API/Features/Doors/Door.cs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/Exiled.API/Features/Doors/Door.cs b/Exiled.API/Features/Doors/Door.cs index aece59473f..03b94992d9 100644 --- a/Exiled.API/Features/Doors/Door.cs +++ b/Exiled.API/Features/Doors/Door.cs @@ -435,9 +435,13 @@ public static Door GetClosest(Vector3 position, out float distance) /// Filters by . /// A value indicating whether it filters broken doors. /// object. - public static Door Random(ZoneType type = ZoneType.Unspecified, bool onlyUnbroken = false) => onlyUnbroken || type is not ZoneType.Unspecified ? - Get(x => (x.Room is null || x.Room.Zone.HasFlag(type) || type == ZoneType.Unspecified) && (x is Breakable { IsDestroyed: true } || !onlyUnbroken)).Random() : - DoorVariantToDoor.Values.Random(); + public static Door Random(ZoneType type = ZoneType.Unspecified, bool onlyUnbroken = false) + { + if (onlyUnbroken || type != ZoneType.Unspecified) + return Get(x => (x.Room == null || x.Room.Zone.HasFlag(type) || type == ZoneType.Unspecified) && (!onlyUnbroken || !(x is Breakable { IsDestroyed: true }))).Random(); + + return DoorVariantToDoor.Values.Random(); + } /// /// Permanently locks a corresponding to the given type. @@ -598,13 +602,13 @@ public void Lock(DoorLockType lockType = DoorLockType.AdminCommand, bool updateT ChangeLock(lockType); if (updateTheDoorState) - { - DoorLockMode mode = DoorLockUtils.GetMode((DoorLockReason)LockType); - if (mode is DoorLockMode.CanOpen) - IsOpen = true; - else if (mode is DoorLockMode.CanClose) - IsOpen = false; - } + return; + + DoorLockMode mode = DoorLockUtils.GetMode((DoorLockReason)LockType); + if (mode is DoorLockMode.CanOpen) + IsOpen = true; + else if (mode is DoorLockMode.CanClose) + IsOpen = false; } ///