Skip to content

Commit

Permalink
LockerType enum
Browse files Browse the repository at this point in the history
* Code part of the code has been taken from MER (https://github.com/Michal78900/MapEditorReborn/blob/dev/MapEditorReborn/API/Extensions/LockerExtensions.cs) - Credits to Michal, i ask him i can use it, not answer yet but if the say no i will use another way.

* SupplyLocker now have a LockerType Property to know what type of Locker is

* LockerSpawnPoint can now chose what locker want to use
  • Loading branch information
SrLicht committed Aug 28, 2024
1 parent 4932bbe commit b9aa59e
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 6 deletions.
50 changes: 50 additions & 0 deletions EXILED/Exiled.API/Enums/LockerType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// -----------------------------------------------------------------------
// <copyright file="LockerType.cs" company="Exiled Team">
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.API.Enums
{
/// <summary>
/// Unique identifier for different types of <see cref="Features.SupplyLocker"/>s.
/// </summary>
public enum LockerType
{
/// <summary>
/// The pedestal used by SCPs.
/// </summary>
Pedestal,

/// <summary>
/// Large weapon locker.
/// </summary>
LargeGun,

/// <summary>
/// Locker for rifles, known as a rifle rack.
/// </summary>
RifleRack,

/// <summary>
/// Miscellaneous locker for various items.
/// </summary>
Misc,

/// <summary>
/// Locker that contains medkits.
/// </summary>
Medkit,

/// <summary>
/// Locker that contains adrenaline.
/// </summary>
Adrenaline,

/// <summary>
/// Unknow type of locker.
/// </summary>
Unknow
}
}
43 changes: 43 additions & 0 deletions EXILED/Exiled.API/Extensions/LockerExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// -----------------------------------------------------------------------
// <copyright file="LockerExtensions.cs" company="Exiled Team">
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.API.Extensions
{
using System;

using Exiled.API.Enums;
using MapGeneration.Distributors;

/// <summary>
/// A set of extensions for <see cref="Enums.LockerType"/>.
/// </summary>
public static class LockerExtensions
{
/// <summary>
/// Gets the <see cref="LockerType"/> from the given <see cref="Locker"/> object.
/// </summary>
/// <param name="locker">The <see cref="Locker"/> to check.</param>
/// <returns>The corresponding <see cref="LockerType"/>.</returns>
public static LockerType GetLockerType(this Locker locker) => locker.name.GetLockerTypeByName();

/// <summary>
/// Gets the <see cref="LockerType"/> by name.
/// </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
{
"Scp500PedestalStructure Variant" => LockerType.Pedestal,
"LargeGunLockerStructure" => LockerType.LargeGun,
"RifleRackStructure" => LockerType.RifleRack,
"MiscLocker" => LockerType.Misc,
"RegularMedkitStructure" => LockerType.Medkit,
"AdrenalineMedkitStructure" => LockerType.Adrenaline,
_ => LockerType.Unknow,
};
}
}
9 changes: 7 additions & 2 deletions EXILED/Exiled.API/Features/Spawn/LockerSpawnPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class LockerSpawnPoint : SpawnPoint
/// <summary>
/// Gets or sets the zone where the locker is located.
/// </summary>
public ZoneType Zone { get; set; }
public ZoneType Zone { get; set; } = ZoneType.Unspecified;

/// <summary>
/// Gets or sets a value indicating whether to use a random locker chamber's position for spawning.
Expand All @@ -34,6 +34,11 @@ public class LockerSpawnPoint : SpawnPoint
/// </summary>
public Vector3 Offset { get; set; } = Vector3.zero;

/// <summary>
/// Gets or sets the type of the <see cref="SupplyLocker"/>.
/// </summary>
public LockerType Type { get; set; } = LockerType.Unknow;

/// <inheritdoc/>
public override float Chance { get; set; }

Expand All @@ -51,7 +56,7 @@ public override Vector3 Position
{
get
{
SupplyLocker foundLocker = SupplyLocker.Random(Zone) ?? throw new NullReferenceException("No locker found in the specified zone.");
SupplyLocker foundLocker = SupplyLocker.Random(Zone, Type) ?? throw new NullReferenceException("No locker found in the specified zone.");

// If UseChamber is true, use a random chamber's position.
if (UseChamber)
Expand Down
27 changes: 23 additions & 4 deletions EXILED/Exiled.API/Features/SupplyLocker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ internal SupplyLocker(Locker locker)
{
Base = locker;
LockerToSupplyLocker.Add(locker, this);
Type = locker.GetLockerType();
}

/// <summary>
Expand All @@ -51,6 +52,12 @@ internal SupplyLocker(Locker locker)
/// </summary>
public Locker Base { get; }


/// <summary>
/// Gets the <see cref="LockerType"/> of the <see cref="SupplyLocker"/>.
/// </summary>
public LockerType Type { get; }

/// <summary>
/// Gets the <see cref="SupplyLocker"/> <see cref="UnityEngine.Transform"/>.
/// </summary>
Expand Down Expand Up @@ -130,11 +137,23 @@ public Vector3 RandomChamberPosition
public static IEnumerable<SupplyLocker> Get(Func<SupplyLocker, bool> predicate) => List.Where(predicate);

/// <summary>
/// Gets a random <see cref="SupplyLocker"/>.
/// Gets a random <see cref="SupplyLocker"/> based on the specified filters.
/// </summary>
/// <param name="zoneType">Filters by <see cref="ZoneType"/>.</param>
/// <returns><see cref="SupplyLocker"/> object.</returns>
public static SupplyLocker Random(ZoneType zoneType = ZoneType.Unspecified) => (zoneType is not ZoneType.Unspecified ? Get(r => r.Zone.HasFlag(zoneType)) : List).GetRandomValue();
/// <param name="zone">The <see cref="ZoneType"/> to filter by. If unspecified, all zones are considered.</param>
/// <param name="lockerType">The <see cref="LockerType"/> to filter by. If unspecified, all locker types are considered.</param>
/// <returns>A random <see cref="SupplyLocker"/> object, or null if no matching locker is found.</returns>
public static SupplyLocker? Random(ZoneType zone = ZoneType.Unspecified, LockerType lockerType = LockerType.Unknow)
{
IEnumerable<SupplyLocker> filteredLockers = List;

if (lockerType != LockerType.Unknow)
filteredLockers = filteredLockers.Where(l => l.Type == lockerType);

if (zone != ZoneType.Unspecified)
filteredLockers = filteredLockers.Where(l => l.Zone == zone);

return filteredLockers.GetRandomValue();
}

/// <summary>
/// Adds an item to a randomly selected locker chamber.
Expand Down

0 comments on commit b9aa59e

Please sign in to comment.