From 03fc68d1476dea4998b2e9e340edf61350ef2c65 Mon Sep 17 00:00:00 2001 From: SrLicht Date: Wed, 28 Aug 2024 15:36:44 -0300 Subject: [PATCH] MORE * Added GetRandomSpawnPoint() in Chamber * Added AddItemToSpawn((ItemType itemType, int quantity = 1, bool spawnIfIsOpen = false)) in Chamber * Added IsOpen in chamber. --- EXILED/Exiled.API/Features/Lockers/Chamber.cs | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/EXILED/Exiled.API/Features/Lockers/Chamber.cs b/EXILED/Exiled.API/Features/Lockers/Chamber.cs index c6bae8c8cb..25f9385b89 100644 --- a/EXILED/Exiled.API/Features/Lockers/Chamber.cs +++ b/EXILED/Exiled.API/Features/Lockers/Chamber.cs @@ -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; @@ -145,6 +146,11 @@ public float Cooldown set => Base._targetCooldown = value; } + /// + /// Gets a value indicating whether the chamber is currently open. + /// + public bool IsOpen => Base.IsOpen; + /// /// Gets the of current cooldown. /// @@ -163,6 +169,51 @@ public float Cooldown /// Amount of items that should be spawned. public void SpawnItem(ItemType type, int amount) => Base.SpawnItem(type, amount); + /// + /// Adds an item of the specified type to the chamber's spawn list. + /// If the chamber is open and is set to , + /// the item is spawned immediately at a random spawn point within the chamber. + /// + /// The type of item to add to the spawn list. + /// The number of items to add. Defaults to 1. + /// + /// If 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. + /// + 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); + } + } + + /// + /// Gets a random spawn point within the chamber. + /// If multiple spawn points are available and is , + /// a random spawn point is selected from the available points. + /// Otherwise, the default spawn point is used. + /// + /// A representing the position of the selected spawn point. + public Vector3 GetRandomSpawnPoint() + { + if (UseMultipleSpawnpoints && Spawnpoints.Any()) + { + return Spawnpoints.GetRandomValue().position; + } + + return Spawnpoint.position; + } + /// /// Gets the chamber by its . ///