Skip to content

Commit

Permalink
feat: LockerType extension (#384)
Browse files Browse the repository at this point in the history
* feat: LockerType extension

* fix: fix of fix

* fix: init fix for play gun sound

* Revert "fix: init fix for play gun sound"

This reverts commit f4d5541.
  • Loading branch information
VALERA771 authored Jan 10, 2025
1 parent 6ae3594 commit b33f211
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 4 deletions.
63 changes: 63 additions & 0 deletions EXILED/Exiled.API/Enums/LockerType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Exiled.API.Enums
{
using System;

/// <summary>
/// Unique identifier for different types of <see cref="Features.Lockers.Locker"/>s.
/// </summary>
Expand All @@ -15,6 +17,7 @@ public enum LockerType
/// <summary>
/// The pedestal used by SCP items.
/// </summary>
[Obsolete("This value is not used.")]
Pedestal,

/// <summary>
Expand Down Expand Up @@ -46,5 +49,65 @@ public enum LockerType
/// Unknow type of locker.
/// </summary>
Unknow,

/// <summary>
/// MircoHid pedestal.
/// </summary>
MicroHid,

/// <summary>
/// Experimental weapon locker.
/// </summary>
ExperimentalWeapon,

/// <summary>
/// SCP-500 pedestal.
/// </summary>
Scp500Pedestal,

/// <summary>
/// SCP-207? (Anti SCP-207) pedestal.
/// </summary>
AntiScp207Pedestal,

/// <summary>
/// SCP-207 pedestal.
/// </summary>
Scp207Pedestal,

/// <summary>
/// SCP-268 pedestal.
/// </summary>
Scp268Pedestal,

/// <summary>
/// SCP-1344 pedestal.
/// </summary>
Scp1344Pedestal,

/// <summary>
/// SCP-018 pedestal.
/// </summary>
Scp018Pedestal,

/// <summary>
/// SCP-1576 pedestal.
/// </summary>
Scp1576Pedestal,

/// <summary>
/// SCP-244 pedestal.
/// </summary>
Scp244Pedestal,

/// <summary>
/// SCP-2176 pedestal.
/// </summary>
Scp2176Pedestal,

/// <summary>
/// SCP-1853 pedestal.
/// </summary>
Scp1853Pedestal,
}
}
15 changes: 13 additions & 2 deletions EXILED/Exiled.API/Extensions/LockerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,25 @@ public static class LockerExtensions
/// </summary>
/// <param name="name">The name to check.</param>
/// <returns>The corresponding <see cref="LockerType"/>.</returns>
public static LockerType GetLockerTypeByName(this string name) => name.Replace("(Clone)", string.Empty) switch
public static LockerType GetLockerTypeByName(this string name) => name.Split('(')[0].Trim() switch
{
"Scp500PedestalStructure Variant" => LockerType.Pedestal,
"Scp500PedestalStructure Variant" => LockerType.Scp500Pedestal,
"AntiScp207PedestalStructure Variant" => LockerType.AntiScp207Pedestal,
"Scp207PedestalStructure Variant" => LockerType.Scp207Pedestal,
"Experimental Weapon Locker" => LockerType.ExperimentalWeapon,
"Scp1344PedestalStructure Variant" => LockerType.Scp1344Pedestal,
"Scp1576PedestalStructure Variant" => LockerType.Scp1576Pedestal,
"Scp2176PedestalStructure Variant" => LockerType.Scp2176Pedestal,
"Scp1853PedestalStructure Variant" => LockerType.Scp1853Pedestal,
"Scp268PedestalStructure Variant" => LockerType.Scp268Pedestal,
"Scp244PedestalStructure Variant" => LockerType.Scp244Pedestal,
"Scp018PedestalStructure Variant" => LockerType.Scp018Pedestal,
"LargeGunLockerStructure" => LockerType.LargeGun,
"RifleRackStructure" => LockerType.RifleRack,
"MiscLocker" => LockerType.Misc,
"RegularMedkitStructure" => LockerType.Medkit,
"AdrenalineMedkitStructure" => LockerType.Adrenaline,
"MicroHIDpedestal" => LockerType.MicroHid,
_ => LockerType.Unknow,
};
}
Expand Down
11 changes: 9 additions & 2 deletions EXILED/Exiled.API/Features/Lockers/Locker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public Vector3 RandomChamberPosition
Chamber randomChamber = Chambers.GetRandomValue();

// Determine if the chamber uses multiple spawn points and has at least one available spawn point.
if (randomChamber.UseMultipleSpawnpoints && randomChamber.Spawnpoints.Count() > 0)
if (randomChamber.UseMultipleSpawnpoints && randomChamber.Spawnpoints.Any())
{
// Return the position of a random spawn point within the chamber.
return randomChamber.Spawnpoints.GetRandomValue().position;
Expand All @@ -136,11 +136,18 @@ public Vector3 RandomChamberPosition
/// <returns>The <see cref="Locker"/> with the given <see cref="ZoneType"/> or <see langword="null"/> if not found.</returns>
public static IEnumerable<Locker> Get(ZoneType zoneType) => Get(room => room.Zone.HasFlag(zoneType));

/// <summary>
/// Gets an <see cref="IEnumerable{T}"/> of <see cref="Locker"/> given the specified <see cref="LockerType"/>.
/// </summary>
/// <param name="lockerType">The <see cref="LockerType"/> to search for.</param>
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="Locker"/> which contains elements that satisfy the condition.</returns>
public static IEnumerable<Locker> Get(LockerType lockerType) => Get(x => x.Type == lockerType);

/// <summary>
/// Gets a <see cref="IEnumerable{T}"/> of <see cref="Locker"/> filtered based on a predicate.
/// </summary>
/// <param name="predicate">The condition to satify.</param>
/// <returns>A <see cref="IEnumerable{T}"/> of <see cref="Locker"/> which contains elements that satify the condition.</returns>
/// <returns>A <see cref="IEnumerable{T}"/> of <see cref="Locker"/> which contains elements that satisfy the condition.</returns>
public static IEnumerable<Locker> Get(Func<Locker, bool> predicate) => List.Where(predicate);

/// <summary>
Expand Down

0 comments on commit b33f211

Please sign in to comment.