Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
0c56101
init
VALERA771 Aug 31, 2023
4ff0690
Merge remote-tracking branch 'origin/locker-api' into locker-api
VALERA771 Aug 31, 2023
45e36fd
Merge branch 'dev' into locker-api
VALERA771 Aug 31, 2023
5c4e17e
another one
VALERA771 Aug 31, 2023
401667e
patch
VALERA771 Aug 31, 2023
0c120bb
fix build erros
VALERA771 Aug 31, 2023
4a163b8
Merge branch 'dev' into locker-api
VALERA771 Aug 31, 2023
cfc1590
i think fix
VALERA771 Aug 31, 2023
81318c3
kill me pls
VALERA771 Aug 31, 2023
2cb0180
Apply suggestions from code review
Thundermaker300 Sep 1, 2023
be35bbf
Merge branch 'dev' into locker-api
Thundermaker300 Sep 1, 2023
1c47cba
Merge branch 'dev' into locker-api
VALERA771 Sep 3, 2023
21839d8
Merge branch 'dev' into locker-api
VALERA771 Sep 3, 2023
21239fa
i hope no breaking changes
VALERA771 Sep 3, 2023
d520772
Merge branch 'dev' into locker-api
louis1706 Sep 5, 2023
d4bb7e6
Merge branch 'dev' into locker-api
louis1706 Oct 11, 2023
bdc0071
Merge branch 'dev' into locker-api
VALERA771 Nov 8, 2023
8da6c3b
some fixes
VALERA771 Nov 8, 2023
8c3f54d
Merge branch 'dev' into locker-api
VALERA771 Nov 11, 2023
cf9287d
Merge branch 'dev' into locker-api
VALERA771 Nov 13, 2023
80e3c04
patch fix
VALERA771 Dec 8, 2023
39894e8
Merge branch 'dev' into locker-api
VALERA771 Dec 8, 2023
ac0ffe4
Merge branch 'dev' into locker-api
louis1706 Jan 7, 2024
b2151e8
bc
VALERA771 Jan 13, 2024
156dc92
abc
VALERA771 Jan 13, 2024
37e1ce7
new
VALERA771 Jan 13, 2024
c98a7cd
Merge branch 'apis-rework' into locker-api
VALERA771 Jan 14, 2024
ac0dbc7
Delete Exiled.CustomItems directory
VALERA771 Feb 3, 2024
f57f1d7
Merge branch 'apis-rework' into locker-api
VALERA771 Feb 3, 2024
d8d4c02
fix
VALERA771 Feb 3, 2024
f54b428
Fix Build Error
louis1706 Feb 4, 2024
97d32f2
Merge branch 'apis-rework' into locker-api
louis1706 Feb 4, 2024
d262345
Merge branch 'apis-rework' into locker-api
louis1706 Feb 8, 2024
fece024
Merge branch 'apis-rework' into locker-api
louis1706 Feb 10, 2024
0023786
Chamber as GameEntity
louis1706 Feb 10, 2024
2be2efa
Merge branch 'locker-api' of https://github.com/VALERA771/EXILED into…
louis1706 Feb 10, 2024
08b25fd
Fix Error
louis1706 Feb 10, 2024
289deef
Merge branch 'apis-rework' into locker-api
louis1706 Feb 10, 2024
72b5e1c
No need of transpiler
louis1706 Feb 10, 2024
3b648ff
Merge branch 'apis-rework' into locker-api
louis1706 Feb 11, 2024
1c0bc43
Merge branch 'apis-rework' into locker-api
louis1706 Apr 4, 2024
1695679
Merge branch 'apis-rework' into locker-api
louis1706 Apr 6, 2024
304fd63
Merge branch 'apis-rework' into locker-api
louis1706 Apr 10, 2024
12e3cb6
Merge branch 'apis-rework' into locker-api
louis1706 May 10, 2024
2a712dc
Fixed
louis1706 May 11, 2024
a31e12d
Merge branch 'apis-rework' into locker-api
louis1706 May 11, 2024
498795e
Merge branch 'apis-rework' into locker-api
louis1706 May 12, 2024
216741a
Merge branch 'apis-rework' into locker-api
louis1706 May 13, 2024
cde1d01
Merge branch 'apis-rework' into locker-api
louis1706 May 13, 2024
0461e8f
Merge branch 'apis-rework' into locker-api
louis1706 May 14, 2024
8ad9de5
Apply suggestions from Nao code review
louis1706 May 15, 2024
569174e
Merge branch 'apis-rework' into locker-api
louis1706 May 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
174 changes: 174 additions & 0 deletions Exiled.API/Features/Lockers/Chamber.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
// -----------------------------------------------------------------------
// <copyright file="Chamber.cs" company="Exiled Team">
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.API.Features.Lockers
{
using System.Collections.Generic;
using System.Linq;

using Exiled.API.Enums;
using Exiled.API.Features.Pickups;
using Exiled.API.Interfaces;
using MapGeneration.Distributors;
using UnityEngine;

/// <summary>
/// A wrapper for <see cref="LockerChamber"/>.
/// </summary>
public class Chamber : IWrapper<LockerChamber>
{
/// <summary>
/// <see cref="Dictionary{TKey,TValue}"/> with <see cref="LockerChamber"/> and <see cref="Chamber"/>.
/// </summary>
internal static readonly Dictionary<LockerChamber, Chamber> Chambers = new();

/// <summary>
/// Initializes a new instance of the <see cref="Chamber"/> class.
/// </summary>
/// <param name="chamber"><see cref="LockerChamber"/> instance.</param>
public Chamber(LockerChamber chamber)
{
Base = chamber;

Chambers.Add(chamber, this);
}

/// <summary>
/// Gets the list with all chambers.
Comment thread
louis1706 marked this conversation as resolved.
Outdated
/// </summary>
public static IReadOnlyCollection<Chamber> List => Chambers.Values;

/// <inheritdoc/>
public LockerChamber Base { get; }

/// <summary>
/// Gets or sets a list with all pickups that should be spawned when door will be opened first time.
Comment thread
louis1706 marked this conversation as resolved.
Outdated
/// </summary>
public IEnumerable<Pickup> ToBeSpawned
{
get => Base._toBeSpawned.Select(Pickup.Get);
set
{
Base._toBeSpawned.Clear();

foreach (var pickup in value)
Base._toBeSpawned.Add(pickup.Base);
}
}

/// <summary>
/// Gets or sets the list with all pickups in chamber.
Comment thread
louis1706 marked this conversation as resolved.
Outdated
/// </summary>
public IEnumerable<Pickup> AllPickups
{
get => Base._content.Select(Pickup.Get);
set
{
Base._content.Clear();

foreach (var pickup in value)
Base._content.Add(pickup.Base);
}
}

/// <summary>
/// Gets or sets the list with all spawnpoints.
Comment thread
louis1706 marked this conversation as resolved.
Outdated
/// </summary>
/// <remarks>
/// Will be used if <see cref="UseMultipleSpawnpoints"/> is <see langword="true"/>.
Comment thread
louis1706 marked this conversation as resolved.
Outdated
/// </remarks>
public IEnumerable<Transform> Spawnpoints
{
get => Base._spawnpoints;
set => Base._spawnpoints = value.ToArray();
}

/// <summary>
/// Gets or sets the list with <see cref="ItemType"/> which can be spawned in this chamber.
Comment thread
louis1706 marked this conversation as resolved.
Outdated
/// </summary>
public IEnumerable<ItemType> AcceptableTypes
{
get => Base.AcceptableItems;
set => Base.AcceptableItems = value.ToArray();
}

/// <summary>
/// Gets or sets required permissions to open this chamber.
/// </summary>
public KeycardPermissions RequiredPermissions
{
get => (KeycardPermissions)Base.RequiredPermissions;
set => Base.RequiredPermissions = (Interactables.Interobjects.DoorUtils.KeycardPermissions)value;
}

/// <summary>
/// Gets or sets a value indicating whether or not multiple spawnpoint system should be used.
Comment thread
louis1706 marked this conversation as resolved.
Outdated
/// </summary>
/// <remarks>
/// If true, spawnpoint system will use <see cref="Spawnpoints"/>. Otherwise, <see cref="Spawnpoint"/>.
Comment thread
louis1706 marked this conversation as resolved.
Outdated
/// </remarks>
public bool UseMultipleSpawnpoints
{
get => Base._useMultipleSpawnpoints;
set => Base._useMultipleSpawnpoints = value;
}

/// <summary>
/// Gets or sets a spawnpoint for items in locker chamber.
Comment thread
louis1706 marked this conversation as resolved.
Outdated
/// </summary>
/// <remarks>
/// Will be used if <see cref="UseMultipleSpawnpoints"/> is <see langword="false"/>.
Comment thread
louis1706 marked this conversation as resolved.
Outdated
/// </remarks>
public Transform Spawnpoint
{
get => Base._spawnpoint;
set => Base._spawnpoint = value;
}

/// <summary>
/// Gets or sets a value indicating whether or not items should be spawned as soon as they are initialised.
Comment thread
louis1706 marked this conversation as resolved.
Outdated
/// </summary>
public bool InitiallySpawn
{
get => Base._spawnOnFirstChamberOpening;
set => Base._spawnOnFirstChamberOpening = value;
}

/// <summary>
/// Gets or sets the amount of time before a player can interact with the chamber again.
/// </summary>
public float Cooldown
{
get => Base._targetCooldown;
set => Base._targetCooldown = value;
}

/// <summary>
/// Gets a value indicating whether or not the chamber can currently be interacted with.
Comment thread
louis1706 marked this conversation as resolved.
Outdated
/// </summary>
public bool CanInteract => Base.CanInteract;

/// <summary>
/// Gets the locker where this chamber is located.
Comment thread
louis1706 marked this conversation as resolved.
Outdated
/// </summary>
public Locker Locker => Locker.Get(x => x.Chambers.Contains(this)).FirstOrDefault();
Comment thread
VALERA771 marked this conversation as resolved.
Outdated

/// <summary>
/// Spawns a specified item from <see cref="AcceptableTypes"/>.
/// </summary>
/// <param name="type"><see cref="ItemType"/> from <see cref="AcceptableTypes"/>.</param>
/// <param name="amount">Amount of items that should be spawned.</param>
public void SpawnItem(ItemType type, int amount) => Base.SpawnItem(type, amount);

/// <summary>
/// Gets the chamber by it's <see cref="LockerChamber"/>.
Comment thread
louis1706 marked this conversation as resolved.
Outdated
/// </summary>
/// <param name="chamber"><see cref="LockerChamber"/>.</param>
/// <returns><see cref="Chamber"/>.</returns>
internal static Chamber Get(LockerChamber chamber) => Chambers.TryGetValue(chamber, out var chmb) ? chmb : new(chamber);
}
}
97 changes: 97 additions & 0 deletions Exiled.API/Features/Lockers/Locker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// -----------------------------------------------------------------------
// <copyright file="Locker.cs" company="Exiled Team">
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.API.Features.Lockers
{
using System.Collections.Generic;
using System.Linq;

using Exiled.API.Features.Core;
using Exiled.API.Interfaces;
using MapGeneration.Distributors;
using UnityEngine;

using BaseLocker = MapGeneration.Distributors.Locker;

/// <summary>
/// Represents a basic locker.
/// </summary>
public class Locker : TypeCastObject<Locker>, IWrapper<BaseLocker>
{
/// <summary>
/// <see cref="Dictionary{TKey,TValue}"/> with <see cref="BaseLocker"/> and <see cref="Locker"/>.
/// </summary>
internal static readonly Dictionary<BaseLocker, Locker> BaseToExiledLockers = new();

/// <summary>
/// Initializes a new instance of the <see cref="Locker"/> class.
/// </summary>
/// <param name="locker">The <see cref="BaseLocker"/> instance.</param>
public Locker(BaseLocker locker)
{
Base = locker;
Chambers = locker.Chambers.Select(x => new Chamber(x)).ToList();

BaseToExiledLockers.Add(locker, this);
}

/// <summary>
/// Gets the list with all <see cref="Locker"/>.
Comment thread
louis1706 marked this conversation as resolved.
Outdated
/// </summary>
public static IReadOnlyCollection<Locker> List => BaseToExiledLockers.Values;

/// <inheritdoc/>
public BaseLocker Base { get; }

/// <summary>
/// Gets or sets list of all <see cref="LockerLoot"/> in this locker.
Comment thread
louis1706 marked this conversation as resolved.
Outdated
/// </summary>
public IEnumerable<LockerLoot> Loot
{
get => Base.Loot;
set => Base.Loot = value.ToArray();
}

/// <summary>
/// Gets the list with all <see cref="Chambers"/> in this locker.
Comment thread
louis1706 marked this conversation as resolved.
Outdated
/// </summary>
public IReadOnlyCollection<Chamber> Chambers { get; }

/// <summary>
/// Gets the <see cref="Locker"/> by it's basegame analog.
Comment thread
louis1706 marked this conversation as resolved.
Outdated
/// </summary>
/// <param name="locker"><see cref="BaseLocker"/> instance.</param>
/// <returns><see cref="Locker"/> instance.</returns>
public static Locker Get(BaseLocker locker) => BaseToExiledLockers.TryGetValue(locker, out var lk)
? lk
: locker switch
{
PedestalScpLocker psl => new PedestalLocker(psl),
_ => new Locker(locker)
};

/// <summary>
/// Gets the list of <see cref="Locker"/> which matches predicate.
Comment thread
louis1706 marked this conversation as resolved.
Outdated
/// </summary>
/// <param name="predicate">Predicate to match.</param>
/// <returns>List of <see cref="Locker"/> which matches predicate.</returns>
Comment thread
louis1706 marked this conversation as resolved.
Outdated
public static IEnumerable<Locker> Get(System.Func<Locker, bool> predicate) => List.Where(predicate);

/// <summary>
/// Interacts with a specific chamber.
/// </summary>
/// <param name="chamber">Chamber. If <see langword="null"/>, will interact with random.</param>
Comment thread
louis1706 marked this conversation as resolved.
Outdated
/// <param name="player">Player who interacts.</param>
Comment thread
louis1706 marked this conversation as resolved.
Outdated
public void Interact(Chamber chamber = null, Player player = null) => Base.ServerInteract(player?.ReferenceHub, (byte)(chamber == null ? Random.Range(0, Chambers.Count + 1) : Chambers.ToList().IndexOf(chamber)));
Comment thread
VALERA771 marked this conversation as resolved.
Outdated

/// <summary>
/// Fills chamber.
Comment thread
louis1706 marked this conversation as resolved.
Outdated
/// </summary>
/// <param name="chamber">Chamber to fill.</param>
public void FillChamber(Chamber chamber) => Base.FillChamber(chamber.Base);
}
}
31 changes: 31 additions & 0 deletions Exiled.API/Features/Lockers/PedestalLocker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// -----------------------------------------------------------------------
// <copyright file="PedestalLocker.cs" company="Exiled Team">
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.API.Features.Lockers
{
using Exiled.API.Interfaces;
using MapGeneration.Distributors;

/// <summary>
/// Represents a pedestal.
/// </summary>
public class PedestalLocker : Locker, IWrapper<PedestalScpLocker>
{
/// <summary>
/// Initializes a new instance of the <see cref="PedestalLocker"/> class.
/// </summary>
/// <param name="locker"><see cref="PedestalScpLocker"/> instance.</param>
public PedestalLocker(PedestalScpLocker locker)
: base(locker)
{
Base = locker;
}

/// <inheritdoc/>
public new PedestalScpLocker Base { get; }
}
}
15 changes: 13 additions & 2 deletions Exiled.API/Features/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public static class Map
/// <summary>
/// A list of <see cref="Locker"/>s on the map.
/// </summary>
internal static readonly List<Locker> LockersValue = new(35);
// ReSharper disable once CollectionNeverUpdated.Global
internal static readonly List<Locker> LockersValue = new(35); // TODO: Remove

/// <summary>
/// A list of <see cref="PocketDimensionTeleport"/>s on the map.
Expand Down Expand Up @@ -114,8 +115,9 @@ public static Scp939AmnesticCloudInstance AmnesticCloudPrefab
public static ReadOnlyCollection<PocketDimensionTeleport> PocketDimensionTeleports { get; } = TeleportsValue.AsReadOnly();

/// <summary>
/// Gets all <see cref="Locker"/> objects.
/// Gets all <see cref="Lockers.Locker"/> objects.
/// </summary>
[Obsolete("Use Locker::List instead.")]
public static ReadOnlyCollection<Locker> Lockers { get; } = LockersValue.AsReadOnly();

/// <summary>
Expand Down Expand Up @@ -221,8 +223,15 @@ public static void TurnOffAllLights(float duration, IEnumerable<ZoneType> zoneTy
/// Gets a random <see cref="Locker"/>.
/// </summary>
/// <returns><see cref="Locker"/> object.</returns>
[Obsolete("Use GetRandomExiledLocker() instead.")]
public static Locker GetRandomLocker() => Lockers.GetRandomValue();

/// <summary>
/// Gets a random <see cref="Features.Lockers.Locker"/>.
/// </summary>
/// <returns><see cref="Features.Lockers.Locker"/> object.</returns>
public static Lockers.Locker GetRandomExiledLocker() => Features.Lockers.Locker.List.GetRandomValue();
Comment thread
VALERA771 marked this conversation as resolved.
Outdated

/// <summary>
/// Gets a random <see cref="Pickup"/>.
/// </summary>
Expand Down Expand Up @@ -375,6 +384,8 @@ internal static void ClearCache()
Firearm.ItemTypeToFirearmInstance.Clear();
Firearm.BaseCodesValue.Clear();
Firearm.AvailableAttachmentsValue.Clear();
Features.Lockers.Locker.BaseToExiledLockers.Clear();
Features.Lockers.Chamber.Chambers.Clear();
}
}
}
13 changes: 7 additions & 6 deletions Exiled.API/Features/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace Exiled.API.Features
using Exiled.API.Features.Doors;
using Exiled.API.Features.Hazards;
using Exiled.API.Features.Items;
using Exiled.API.Features.Lockers;
using Exiled.API.Features.Pickups;
using Exiled.API.Features.Pools;
using Exiled.API.Features.Roles;
Expand Down Expand Up @@ -2992,11 +2993,11 @@ public void Teleport(object obj, Vector3 offset)
else
Log.Warn($"{nameof(Teleport)}: {Assembly.GetCallingAssembly().GetName().Name}: Invalid role teleport (role is missing Owner).");
break;
case Locker locker:
Teleport(locker.transform.position + Vector3.up + offset);
case Lockers.Locker locker:
Teleport(locker.Base.transform.position + Vector3.up + offset);
break;
case LockerChamber chamber:
Teleport(chamber._spawnpoint.position + Vector3.up + offset);
case Lockers.Chamber chamber:
Teleport(chamber.UseMultipleSpawnpoints ? chamber.Spawnpoints.ElementAt(Random.Range(0, chamber.Spawnpoints.Count() - 1)).transform.position : chamber.Spawnpoint.transform.position + Vector3.up + offset);
break;
case ElevatorChamber elevator:
Teleport(elevator.transform.position + Vector3.up + offset);
Expand Down Expand Up @@ -3040,11 +3041,11 @@ public void RandomTeleport(Type type)
nameof(Player) => Dictionary.Values.GetRandomValue(),
nameof(Pickup) => Pickup.BaseToPickup.GetRandomValue().Value,
nameof(Ragdoll) => Ragdoll.List.GetRandomValue(),
nameof(Locker) => Map.GetRandomLocker(),
nameof(MapGeneration.Distributors.Locker) or nameof(Lockers.Locker) => Map.GetRandomExiledLocker(),
nameof(Generator) => Generator.List.GetRandomValue(),
nameof(Window) => Window.List.GetRandomValue(),
nameof(Scp914) => Scp914.Scp914Controller,
nameof(LockerChamber) => Map.GetRandomLocker().Chambers.GetRandomValue(),
nameof(LockerChamber) or nameof(Chamber) => Map.GetRandomExiledLocker().Chambers.GetRandomValue(),
_ => null,
};

Expand Down
Loading