Skip to content
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

Locker API #2026

Merged
merged 52 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
171 changes: 171 additions & 0 deletions Exiled.API/Features/Lockers/Chamber.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
// -----------------------------------------------------------------------
// <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>
{
internal static Dictionary<LockerChamber, Chamber> Chambers = new();

Check failure on line 24 in Exiled.API/Features/Lockers/Chamber.cs

View workflow job for this annotation

GitHub Actions / build

Check failure on line 24 in Exiled.API/Features/Lockers/Chamber.cs

View workflow job for this annotation

GitHub Actions / build


/// <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.
louis1706 marked this conversation as resolved.
Show resolved Hide resolved
/// </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.
Show resolved Hide resolved
/// </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.
Show resolved Hide resolved
/// </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.
Show resolved Hide resolved
/// </summary>
/// <remarks>
/// Will be used if <see cref="UseMultipleSpawnpoints"/> is <see langword="true"/>.
louis1706 marked this conversation as resolved.
Show resolved Hide resolved
/// </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.
Show resolved Hide resolved
/// </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.
Show resolved Hide resolved
/// </summary>
/// <remarks>
/// If true, spawnpoint system will use <see cref="Spawnpoints"/>. Otherwise, <see cref="Spawnpoint"/>.
louis1706 marked this conversation as resolved.
Show resolved Hide resolved
/// </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.
Show resolved Hide resolved
/// </summary>
/// <remarks>
/// Will be used if <see cref="UseMultipleSpawnpoints"/> is <see langword="false"/>.
louis1706 marked this conversation as resolved.
Show resolved Hide resolved
/// </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.
Show resolved Hide resolved
/// </summary>
public bool InitiallySpawn
{
get => Base._spawnOnFirstChamberOpening;
set => Base._spawnOnFirstChamberOpening = value;
}

/// <summary>
/// Gets or sets a time before player can again interact chamber.
Thundermaker300 marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
public float Cooldown
{
get => Base._targetCooldown;
set => Base._targetCooldown = value;
}

/// <summary>
/// Gets a value indicating whether or not player can interact with chamber now.
Thundermaker300 marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
public bool CanInteract => Base.CanInteract;

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

/// <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.
Show resolved Hide resolved
/// </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);
}
}
89 changes: 89 additions & 0 deletions Exiled.API/Features/Lockers/Locker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// -----------------------------------------------------------------------
// <copyright file="Locker.cs" company="Exiled Team">
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

using System;

Check failure on line 8 in Exiled.API/Features/Lockers/Locker.cs

View workflow job for this annotation

GitHub Actions / build


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;

public class Locker : TypeCastObject<Locker>, IWrapper<BaseLocker>

Check failure on line 22 in Exiled.API/Features/Lockers/Locker.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'Locker'

Check failure on line 22 in Exiled.API/Features/Lockers/Locker.cs

View workflow job for this annotation

GitHub Actions / build

{
internal static Dictionary<BaseLocker, Locker> BaseToExiledLockers = new();

Check failure on line 24 in Exiled.API/Features/Lockers/Locker.cs

View workflow job for this annotation

GitHub Actions / build

Check failure on line 24 in Exiled.API/Features/Lockers/Locker.cs

View workflow job for this annotation

GitHub Actions / build


public Locker(BaseLocker locker)

Check failure on line 26 in Exiled.API/Features/Lockers/Locker.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'Locker.Locker(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.
Show resolved Hide resolved
/// </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.
Show resolved Hide resolved
/// </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.
Show resolved Hide resolved
/// </summary>
public IReadOnlyCollection<Chamber> Chambers { get; }

/// <summary>
/// Gets the <see cref="Locker"/> by it's basegame analog.
louis1706 marked this conversation as resolved.
Show resolved Hide resolved
/// </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.
Show resolved Hide resolved
/// </summary>
/// <param name="predicate">Predicate to match.</param>
/// <returns>List of <see cref="Locker"/> which matches predicate.</returns>
louis1706 marked this conversation as resolved.
Show resolved Hide resolved
public static IEnumerable<Locker> Get(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>
/// <param name="player">Player who interacts.</param>
louis1706 marked this conversation as resolved.
Show resolved Hide resolved
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.
Show resolved Hide resolved

/// <summary>
/// Fills chamber.
louis1706 marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
/// <param name="chamber">Chamber to fill.</param>
public void FillChamber(Chamber chamber) => Base.FillChamber(chamber.Base);
}
}
28 changes: 28 additions & 0 deletions Exiled.API/Features/Lockers/PedestalLocker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// -----------------------------------------------------------------------
// <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;

public class PedestalLocker : Locker, IWrapper<PedestalScpLocker>

Check failure on line 13 in Exiled.API/Features/Lockers/PedestalLocker.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'PedestalLocker'
{
/// <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; }
}
}
7 changes: 4 additions & 3 deletions Exiled.API/Features/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// </copyright>
// -----------------------------------------------------------------------

using Exiled.API.Features.Lockers;

Check failure on line 8 in Exiled.API/Features/Map.cs

View workflow job for this annotation

GitHub Actions / build


namespace Exiled.API.Features
{
using System;
Expand All @@ -25,7 +27,6 @@
using Items;
using LightContainmentZoneDecontamination;
using MapGeneration;
using MapGeneration.Distributors;
using Mirror;
using PlayerRoles;
using PlayerRoles.PlayableScps.Scp173;
Expand Down Expand Up @@ -116,9 +117,9 @@
public static ReadOnlyCollection<PocketDimensionTeleport> PocketDimensionTeleports => ReadOnlyTeleportsValue;

/// <summary>
/// Gets all <see cref="Locker"/> objects.
/// Gets all <see cref="Lockers.Locker"/> objects.
/// </summary>
public static ReadOnlyCollection<Locker> Lockers => ReadOnlyLockersValue;
public static ReadOnlyCollection<Lockers.Locker> Lockers => ReadOnlyLockersValue;

/// <summary>
/// Gets all <see cref="AdminToy"/> objects.
Expand Down
12 changes: 6 additions & 6 deletions Exiled.API/Features/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3005,11 +3005,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 @@ -3044,7 +3044,7 @@ public void Teleport(object obj, Vector3 offset)
/// <param name="type">Object for teleport.</param>
public void RandomTeleport(Type type)
{
LockerChamber[] chambers;
Lockers.Chamber[] chambers;

object randomObject = type.Name switch
{
Expand All @@ -3059,7 +3059,7 @@ public void RandomTeleport(Type type)
nameof(Generator) => Generator.List.ElementAt(Random.Range(0, Generator.Scp079GeneratorToGenerator.Count)),
nameof(Window) => Window.List.ElementAt(Random.Range(0, Window.BreakableWindowToWindow.Count)),
nameof(Scp914) => Scp914.Scp914Controller,
nameof(LockerChamber) => (chambers = Map.GetRandomLocker().Chambers)[Random.Range(0, chambers.Length)],
nameof(Lockers.Chamber) => (chambers = Map.GetRandomLocker().Chambers.ToArray())[Random.Range(0, chambers.Length)],
_ => null,
};

Expand Down
12 changes: 9 additions & 3 deletions Exiled.CustomItems/API/Features/CustomItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// </copyright>
// -----------------------------------------------------------------------

using Exiled.API.Features.Lockers;

namespace Exiled.CustomItems.API.Features
{
using System;
Expand Down Expand Up @@ -681,7 +683,7 @@ public virtual uint Spawn(IEnumerable<SpawnPoint> spawnPoints, uint limit)
continue;
}

Locker locker =
Exiled.API.Features.Lockers.Locker locker =
Map.Lockers[
Loader.Random.Next(Map.Lockers.Count)];

Expand All @@ -703,15 +705,19 @@ public virtual uint Spawn(IEnumerable<SpawnPoint> spawnPoints, uint limit)
continue;
}

LockerChamber chamber = locker.Chambers[Loader.Random.Next(Mathf.Max(0, locker.Chambers.Length - 1))];
Chamber chamber = locker.Chambers.ElementAt(Loader.Random.Next(Mathf.Max(0, locker.Chambers.Count - 1)));

if (chamber is null)
{
Log.Debug($"{nameof(Spawn)}: chamber is null");
continue;
}

Vector3 position = chamber._spawnpoint.transform.position;
Vector3 position = chamber.Spawnpoint.transform.position;

if (chamber.UseMultipleSpawnpoints)
position = chamber.Spawnpoints.ElementAt(Loader.Random.Next(Mathf.Max(0, chamber.Spawnpoints.Count() - 1))).transform.position;

Spawn(position, null);
Log.Debug($"Spawned {Name} at {position} ({spawnPoint.Name})");

Expand Down
Loading
Loading