Skip to content

Commit

Permalink
MORE
Browse files Browse the repository at this point in the history
* Added GetRandomSpawnPoint() in Chamber

* Added AddItemToSpawn((ItemType itemType, int quantity = 1, bool spawnIfIsOpen = false)) in Chamber

* Added IsOpen in chamber.
  • Loading branch information
SrLicht committed Aug 28, 2024
1 parent 2fddd75 commit 03fc68d
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions EXILED/Exiled.API/Features/Lockers/Chamber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Exiled.API.Features.Lockers
using System.Linq;

using Exiled.API.Enums;
using Exiled.API.Extensions;
using Exiled.API.Features.Pickups;
using Exiled.API.Interfaces;
using MapGeneration.Distributors;
Expand Down Expand Up @@ -145,6 +146,11 @@ public float Cooldown
set => Base._targetCooldown = value;
}

/// <summary>
/// Gets a value indicating whether the chamber is currently open.
/// </summary>
public bool IsOpen => Base.IsOpen;

/// <summary>
/// Gets the <see cref="Stopwatch"/> of current cooldown.
/// </summary>
Expand All @@ -163,6 +169,51 @@ public float Cooldown
/// <param name="amount">Amount of items that should be spawned.</param>
public void SpawnItem(ItemType type, int amount) => Base.SpawnItem(type, amount);

/// <summary>
/// Adds an item of the specified type to the chamber's spawn list.
/// If the chamber is open and <paramref name="spawnIfIsOpen"/> is set to <see langword="true"/>,
/// the item is spawned immediately at a random spawn point within the chamber.
/// </summary>
/// <param name="itemType">The type of item to add to the spawn list.</param>
/// <param name="quantity">The number of items to add. Defaults to 1.</param>
/// <param name="spawnIfIsOpen">
/// If <see langword="true"/> and the chamber is open, the item is immediately spawned at a random spawn point.
/// Otherwise, the item is added to the spawn list and will spawn when the chamber is opened.
/// </param>
public void AddItemToSpawn(ItemType itemType, int quantity = 1, bool spawnIfIsOpen = false)
{
for (int i = 0; i < quantity; i++)
{
Pickup pickup = Pickup.Create(itemType);

if (spawnIfIsOpen && IsOpen)
{
pickup.Position = GetRandomSpawnPoint();
pickup.Spawn();
continue;
}

Base._toBeSpawned.Add(pickup.Base);
}
}

/// <summary>
/// Gets a random spawn point within the chamber.
/// If multiple spawn points are available and <see cref="UseMultipleSpawnpoints"/> is <see langword="true"/>,
/// a random spawn point is selected from the available points.
/// Otherwise, the default spawn point is used.
/// </summary>
/// <returns>A <see cref="Vector3"/> representing the position of the selected spawn point.</returns>
public Vector3 GetRandomSpawnPoint()
{
if (UseMultipleSpawnpoints && Spawnpoints.Any())
{
return Spawnpoints.GetRandomValue().position;
}

return Spawnpoint.position;
}

/// <summary>
/// Gets the chamber by its <see cref="LockerChamber"/>.
/// </summary>
Expand Down

0 comments on commit 03fc68d

Please sign in to comment.