-
Notifications
You must be signed in to change notification settings - Fork 168
Locker API #2026
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Locker API #2026
Changes from 15 commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
0c56101
init
VALERA771 4ff0690
Merge remote-tracking branch 'origin/locker-api' into locker-api
VALERA771 45e36fd
Merge branch 'dev' into locker-api
VALERA771 5c4e17e
another one
VALERA771 401667e
patch
VALERA771 0c120bb
fix build erros
VALERA771 4a163b8
Merge branch 'dev' into locker-api
VALERA771 cfc1590
i think fix
VALERA771 81318c3
kill me pls
VALERA771 2cb0180
Apply suggestions from code review
Thundermaker300 be35bbf
Merge branch 'dev' into locker-api
Thundermaker300 1c47cba
Merge branch 'dev' into locker-api
VALERA771 21839d8
Merge branch 'dev' into locker-api
VALERA771 21239fa
i hope no breaking changes
VALERA771 d520772
Merge branch 'dev' into locker-api
louis1706 d4bb7e6
Merge branch 'dev' into locker-api
louis1706 bdc0071
Merge branch 'dev' into locker-api
VALERA771 8da6c3b
some fixes
VALERA771 8c3f54d
Merge branch 'dev' into locker-api
VALERA771 cf9287d
Merge branch 'dev' into locker-api
VALERA771 80e3c04
patch fix
VALERA771 39894e8
Merge branch 'dev' into locker-api
VALERA771 ac0ffe4
Merge branch 'dev' into locker-api
louis1706 b2151e8
bc
VALERA771 156dc92
abc
VALERA771 37e1ce7
new
VALERA771 c98a7cd
Merge branch 'apis-rework' into locker-api
VALERA771 ac0dbc7
Delete Exiled.CustomItems directory
VALERA771 f57f1d7
Merge branch 'apis-rework' into locker-api
VALERA771 d8d4c02
fix
VALERA771 f54b428
Fix Build Error
louis1706 97d32f2
Merge branch 'apis-rework' into locker-api
louis1706 d262345
Merge branch 'apis-rework' into locker-api
louis1706 fece024
Merge branch 'apis-rework' into locker-api
louis1706 0023786
Chamber as GameEntity
louis1706 2be2efa
Merge branch 'locker-api' of https://github.com/VALERA771/EXILED into…
louis1706 08b25fd
Fix Error
louis1706 289deef
Merge branch 'apis-rework' into locker-api
louis1706 72b5e1c
No need of transpiler
louis1706 3b648ff
Merge branch 'apis-rework' into locker-api
louis1706 1c0bc43
Merge branch 'apis-rework' into locker-api
louis1706 1695679
Merge branch 'apis-rework' into locker-api
louis1706 304fd63
Merge branch 'apis-rework' into locker-api
louis1706 12e3cb6
Merge branch 'apis-rework' into locker-api
louis1706 2a712dc
Fixed
louis1706 a31e12d
Merge branch 'apis-rework' into locker-api
louis1706 498795e
Merge branch 'apis-rework' into locker-api
louis1706 216741a
Merge branch 'apis-rework' into locker-api
louis1706 cde1d01
Merge branch 'apis-rework' into locker-api
louis1706 0461e8f
Merge branch 'apis-rework' into locker-api
louis1706 8ad9de5
Apply suggestions from Nao code review
louis1706 569174e
Merge branch 'apis-rework' into locker-api
louis1706 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | ||
| /// </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. | ||
|
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. | ||
|
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. | ||
|
louis1706 marked this conversation as resolved.
Outdated
|
||
| /// </summary> | ||
| /// <remarks> | ||
| /// Will be used if <see cref="UseMultipleSpawnpoints"/> is <see langword="true"/>. | ||
|
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. | ||
|
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. | ||
|
louis1706 marked this conversation as resolved.
Outdated
|
||
| /// </summary> | ||
| /// <remarks> | ||
| /// If true, spawnpoint system will use <see cref="Spawnpoints"/>. Otherwise, <see cref="Spawnpoint"/>. | ||
|
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. | ||
|
louis1706 marked this conversation as resolved.
Outdated
|
||
| /// </summary> | ||
| /// <remarks> | ||
| /// Will be used if <see cref="UseMultipleSpawnpoints"/> is <see langword="false"/>. | ||
|
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. | ||
|
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. | ||
|
louis1706 marked this conversation as resolved.
Outdated
|
||
| /// </summary> | ||
| public bool CanInteract => Base.CanInteract; | ||
|
|
||
| /// <summary> | ||
| /// Gets the locker where this chamber is located. | ||
|
louis1706 marked this conversation as resolved.
Outdated
|
||
| /// </summary> | ||
| public Locker Locker => Locker.Get(x => x.Chambers.Contains(this)).FirstOrDefault(); | ||
|
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"/>. | ||
|
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); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"/>. | ||
|
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. | ||
|
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. | ||
|
louis1706 marked this conversation as resolved.
Outdated
|
||
| /// </summary> | ||
| public IReadOnlyCollection<Chamber> Chambers { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the <see cref="Locker"/> by it's basegame analog. | ||
|
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. | ||
|
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> | ||
|
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> | ||
|
louis1706 marked this conversation as resolved.
Outdated
|
||
| /// <param name="player">Player who interacts.</param> | ||
|
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))); | ||
|
VALERA771 marked this conversation as resolved.
Outdated
|
||
|
|
||
| /// <summary> | ||
| /// Fills chamber. | ||
|
louis1706 marked this conversation as resolved.
Outdated
|
||
| /// </summary> | ||
| /// <param name="chamber">Chamber to fill.</param> | ||
| public void FillChamber(Chamber chamber) => Base.FillChamber(chamber.Base); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.