Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
185 changes: 185 additions & 0 deletions Exiled.API/Features/Lockers/Chamber.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
// -----------------------------------------------------------------------
// <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.Diagnostics;
using System.Linq;

using Exiled.API.Enums;
using Exiled.API.Features.Core;
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 : GameEntity, 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>
/// <param name="locker"><see cref="Lockers.Locker"/> where this chamber is located.</param>
public Chamber(LockerChamber chamber, Locker locker)
: base(chamber.gameObject)
{
Base = chamber;
Locker = locker;

Chambers.Add(chamber, this);
}

/// <summary>
/// Gets all chambers.
/// </summary>
public static new IReadOnlyCollection<Chamber> List => Chambers.Values;

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

/// <summary>
/// Gets or sets all pickups that should be spawned when the door is initially opened.
/// </summary>
public IEnumerable<Pickup> ToBeSpawned
{
get => Base._toBeSpawned.Select(Pickup.Get);
set
{
Base._toBeSpawned.Clear();

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

/// <summary>
/// Gets or sets all pickups in the chamber.
/// </summary>
public IEnumerable<Pickup> AllPickups
{
get => Base._content.Select(Pickup.Get);
set
{
Base._content.Clear();

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

/// <summary>
/// Gets or sets all spawn points.
/// </summary>
/// <remarks>
/// Used if <see cref="UseMultipleSpawnpoints"/> is set to <see langword="true"/>.
/// </remarks>
public IEnumerable<Transform> Spawnpoints
{
get => Base._spawnpoints;
set => Base._spawnpoints = value.ToArray();
}

/// <summary>
/// Gets or sets all the acceptable items which can be spawned in this chamber.
/// </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 multiple spawn points should be used.
/// </summary>
/// <remarks>
/// If <see langword="true"/>, <see cref="Spawnpoints"/> will be used over <see cref="Spawnpoint"/>.
/// </remarks>
public bool UseMultipleSpawnpoints
{
get => Base._useMultipleSpawnpoints;
set => Base._useMultipleSpawnpoints = value;
}

/// <summary>
/// Gets or sets a spawn point for the items in the chamber.
/// </summary>
/// <remarks>
/// Used if <see cref="UseMultipleSpawnpoints"/> is set to <see langword="false"/>.
/// </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 initialized.
/// </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 the <see cref="Stopwatch"/> of current cooldown.
/// </summary>
/// <remarks>Used in <see cref="CanInteract"/> check.</remarks>
public Stopwatch CurrentCooldown => Base._stopwatch;

/// <summary>
/// Gets a value indicating whether the chamber is interactable.
/// </summary>
public bool CanInteract => Base.CanInteract;

/// <summary>
/// Gets the locker where this chamber is located at.
/// </summary>
public Locker Locker { get; }

/// <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 its <see cref="LockerChamber"/>.
/// </summary>
/// <param name="chamber"><see cref="LockerChamber"/>.</param>
/// <returns><see cref="Chamber"/>.</returns>
internal static Chamber Get(LockerChamber chamber) => Chambers.TryGetValue(chamber, out Chamber chmb) ? chmb : new(chamber, Locker.Get(x => x.Chambers.Any(x => x.Base == chamber)).FirstOrDefault());
}
}
112 changes: 112 additions & 0 deletions Exiled.API/Features/Lockers/Locker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// -----------------------------------------------------------------------
// <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.Extensions;
using Exiled.API.Features.Core;
using Exiled.API.Interfaces;
using MapGeneration.Distributors;

using BaseLocker = MapGeneration.Distributors.Locker;

/// <summary>
/// Represents a basic locker.
/// </summary>
public class Locker : GameEntity, 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.gameObject)
{
Base = locker;
Chambers = locker.Chambers.Select(x => new Chamber(x, this)).ToList();

BaseToExiledLockers.Add(locker, this);
}

/// <summary>
/// Gets the all <see cref="Locker"/> instances.
/// </summary>
public static new IReadOnlyCollection<Locker> List => BaseToExiledLockers.Values;

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

/// <summary>
/// Gets or sets all <see cref="LockerLoot"/> instances in this locker.
/// </summary>
public IEnumerable<LockerLoot> Loot
{
get => Base.Loot;
set => Base.Loot = value.ToArray();
}

/// <summary>
/// Gets the all <see cref="Chambers"/> in this locker.
/// </summary>
public IReadOnlyCollection<Chamber> Chambers { get; }

/// <summary>
/// Gets or sets an id for manipulating opened chambers.
/// </summary>
public ushort OpenedChambers
{
get => Base.OpenedChambers;
set => Base.NetworkOpenedChambers = value;
}

/// <summary>
/// Gets the <see cref="Locker"/> given the <see cref="BaseLocker"/> instance.
/// </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 Locker lk)
? lk
: locker switch
{
PedestalScpLocker psl => new PedestalLocker(psl),
_ => new Locker(locker)
};

/// <summary>
/// Gets the all <see cref="Locker"/> instances matching the predicate.
/// </summary>
/// <param name="predicate">Predicate to match.</param>
/// <returns>All <see cref="Locker"/> instances matching the predicate.</returns>
public static IEnumerable<Locker> Get(System.Func<Locker, bool> predicate) => List.Where(predicate);

/// <summary>
/// Interacts with a specific chamber.
/// </summary>
/// <param name="chamber">If <see langword="null"/>, the interaction will be randomized.</param>
/// <param name="player">The player who interacts.</param>
public void Interact(Chamber chamber = null, Player player = null)
{
chamber ??= Chambers.Random();

Base.ServerInteract(player?.ReferenceHub, (byte)Chambers.ToList().IndexOf(chamber));
}

/// <summary>
/// Fills the chamber.
/// </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; }
}
}
Loading