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

Some Scp914 QoL additions #2149

Merged
merged 7 commits into from
Oct 24, 2023
Merged
Changes from all commits
Commits
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
57 changes: 49 additions & 8 deletions Exiled.API/Features/Scp914.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@

namespace Exiled.API.Features
{
using global::Scp914;
using System.Collections.Generic;
using System.Linq;

using Exiled.API.Features.Pickups;
using Exiled.API.Features.Pools;
using global::Scp914;
using UnityEngine;

/// <summary>
Expand Down Expand Up @@ -64,6 +68,11 @@ public static Scp914Mode ConfigMode
/// </summary>
public static bool IsWorking => Scp914Controller._isUpgrading;

/// <summary>
/// Gets a value indicating all of the GameObjects currently present inside SCP-914's intake chamber.
/// </summary>
public static Collider[] InsideIntake => Physics.OverlapBox(IntakePosition, Scp914Controller.IntakeChamberSize);

/// <summary>
/// Gets the intake booth <see cref="UnityEngine.Transform"/>.
/// </summary>
Expand All @@ -74,20 +83,52 @@ public static Scp914Mode ConfigMode
/// </summary>
public static Transform OutputBooth => Scp914Controller.OutputChamber;

/// <summary>
/// Filters all GameObjects inside SCP-914's intake chamber into players and items.
/// </summary>
/// <param name="playersret">The <see cref="List{Player}"/> to return.</param>
/// <param name="pickupsret">The <see cref="List{Pickup}"/> to return.</param>
/// <returns>All GameObjects present inside SCP-914's intake chamber. And also return Player and Pickup casted.</returns>
public static IEnumerable<GameObject> Scp914InputObject(out IEnumerable<Player> playersret, out IEnumerable<Pickup> pickupsret)
louis1706 marked this conversation as resolved.
Show resolved Hide resolved
{
HashSet<GameObject> inside914 = HashSetPool<GameObject>.Pool.Get();
List<Player> players = ListPool<Player>.Pool.Get();
List<Pickup> pickups = ListPool<Pickup>.Pool.Get();

foreach (Collider collider in InsideIntake.ToList())
{
GameObject gameObject = collider.transform.root.gameObject;
if (inside914.Add(gameObject))
{
Pickup pickup;
if ((pickup = Pickup.Get(gameObject)) is not null && !pickup.IsLocked)
{
pickups.Add(pickup);
}
else if (Player.TryGet(gameObject, out Player player)
&& Physics.Linecast(player.Position, IntakePosition, Scp914Upgrader.SolidObjectMask))
{
players.Add(player);
}
}
}

playersret = ListPool<Player>.Pool.ToArrayReturn(players);
pickupsret = ListPool<Pickup>.Pool.ToArrayReturn(pickups);
return HashSetPool<GameObject>.Pool.ToArrayReturn(inside914);
}

/// <summary>
/// Plays the SCP-914's sound.
/// </summary>
/// <param name="soundId">The soundId to play.</param>
/// <remarks>There are two sounds only.
/// The values to identify them are <c>0</c>, which stands for the soundId played when SCP-914 is being activated,
/// and <c>1</c>, which stands for the soundId played when SCP-914's knob state is being changed.</remarks>
/// <param name="soundId">The <see cref="Scp914InteractCode"/> to play.</param>
public static void PlaySound(Scp914InteractCode soundId) => Scp914Controller.RpcPlaySound((byte)soundId);

/// <summary>
/// Starts SCP-914.
/// </summary>
/// <param name="player">Player who interacts with Scp914.</param>
/// <param name="code">Activated code.</param>
/// <param name="player"><see cref="Player"/> who interacts with Scp914.</param>
/// <param name="code"><see cref="Scp914InteractCode"/> Interact code.</param>
public static void Start(Player player = null, Scp914InteractCode code = Scp914InteractCode.Activate) => Scp914Controller.ServerInteract((player ?? Server.Host).ReferenceHub, (byte)code);
}
}
}
Loading