Skip to content

Commit

Permalink
Merge branch 'apis-rework' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
louis1706 authored Feb 10, 2024
2 parents 699503d + 4a0ccb8 commit 1365ca2
Show file tree
Hide file tree
Showing 28 changed files with 164 additions and 175 deletions.
2 changes: 1 addition & 1 deletion Exiled.API/Enums/EffectType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public enum EffectType
/// <summary>
/// This EffectType do not exist it's only use when not found or error.
/// </summary>
None = -1, // TODO: remove = -1
None,

/// <summary>
/// The player isn't able to open their inventory or reload a weapon.
Expand Down
23 changes: 16 additions & 7 deletions Exiled.API/Enums/EscapeScenario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,48 @@

namespace Exiled.API.Enums
{
using Exiled.API.Features.Core.Generic;

using static Escape;

/// <summary>
/// A set of different Escape Scenario Type.
/// </summary>
public enum EscapeScenario
public sealed class EscapeScenario : EnumClass<EscapeScenarioType, EscapeScenario>
{
/// <summary>
/// No Escape Scenario.
/// </summary>
None,
public static readonly EscapeScenario None = new(EscapeScenarioType.None);

/// <summary>
/// ClassD Escape Scenario.
/// </summary>
ClassD,
public static readonly EscapeScenario ClassD = new(EscapeScenarioType.ClassD);

/// <summary>
/// Cuffed ClassD Escape.
/// </summary>
CuffedClassD,
public static readonly EscapeScenario CuffedClassD = new(EscapeScenarioType.CuffedClassD);

/// <summary>
/// Scientist Escape.
/// </summary>
Scientist,
public static readonly EscapeScenario Scientist = new(EscapeScenarioType.Scientist);

/// <summary>
/// Cuffed Scientist Escape.
/// </summary>
CuffedScientist,
public static readonly EscapeScenario CuffedScientist = new(EscapeScenarioType.CuffedScientist);

/// <summary>
/// Unspecified Escape.
/// </summary>
CustomEscape,
public static readonly EscapeScenario CustomEscape = new((EscapeScenarioType)5);

private EscapeScenario(EscapeScenarioType value)
: base(value)
{
}
}
}
35 changes: 24 additions & 11 deletions Exiled.API/Enums/SpawnReason.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,67 @@

namespace Exiled.API.Enums
{
using Exiled.API.Features.Core.Generic;
using PlayerRoles;

/// <summary>
/// Possible spawn reasons.
/// </summary>
public enum SpawnReason : byte // TOTO: Remove this file and use Basegame
public sealed class SpawnReason : EnumClass<RoleChangeReason, SpawnReason>
{
/// <summary>
/// No reason specified.
/// </summary>
None,
public static readonly SpawnReason None = new(RoleChangeReason.None);

/// <summary>
/// The round has just started.
/// </summary>
RoundStart,
public static readonly SpawnReason RoundStart = new(RoleChangeReason.RoundStart);

/// <summary>
/// The player joined and the round recently started.
/// </summary>
LateJoin,
public static readonly SpawnReason LateJoin = new(RoleChangeReason.LateJoin);

/// <summary>
/// The player was dead and is respawning.
/// </summary>
Respawn,
public static readonly SpawnReason Respawn = new(RoleChangeReason.Respawn);

/// <summary>
/// The player has died.
/// </summary>
Died,
public static readonly SpawnReason Died = new(RoleChangeReason.Died);

/// <summary>
/// The player has escaped.
/// </summary>
Escaped,
public static readonly SpawnReason Escaped = new(RoleChangeReason.Escaped);

/// <summary>
/// The player was revived by SCP-049.
/// </summary>
Revived,
public static readonly SpawnReason Revived = new(RoleChangeReason.Revived);

/// <summary>
/// The player's role was changed by an admin command or plugin.
/// The player's role was changed by an admin command.
/// </summary>
ForceClass,
public static readonly SpawnReason RemoteAdmin = new(RoleChangeReason.RemoteAdmin);

/// <summary>
/// The user will be destroyed.
/// </summary>
Destroyed,
public static readonly SpawnReason Destroyed = new(RoleChangeReason.Destroyed);

/// <summary>
/// The player's role was changed by an exiled plugin.
/// </summary>
public static readonly SpawnReason ForceClass = new((RoleChangeReason)9);

private SpawnReason(RoleChangeReason value)
: base(value)
{
}
}
}
6 changes: 1 addition & 5 deletions Exiled.API/Extensions/DamageTypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,7 @@ public static class DamageTypeExtensions
/// </summary>
/// <param name="type">The damage type to be checked.</param>
/// <returns>Returns whether or not the <see cref="DamageType"/> is caused by status effect.</returns>
public static bool IsStatusEffect(this DamageType type) => type switch
{
DamageType.Asphyxiation or DamageType.Poison or DamageType.Bleeding or DamageType.Scp207 or DamageType.Hypothermia or DamageType.Strangled => true,
_ => false,
};
public static bool IsStatusEffect(this DamageType type) => type is DamageType.Asphyxiation or DamageType.Poison or DamageType.Bleeding or DamageType.Scp207 or DamageType.Hypothermia or DamageType.Strangled;

/// <summary>
/// Gets the <see cref="DamageType"/> of an <see cref="DamageHandlerBase"/>s.
Expand Down
26 changes: 21 additions & 5 deletions Exiled.API/Extensions/MirrorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,14 @@ namespace Exiled.API.Extensions

using Features;
using Features.Core.Generic.Pools;

using InventorySystem.Items.Firearms;

using Mirror;

using PlayerRoles;
using PlayerRoles.FirstPersonControl;
using PlayerRoles.PlayableScps.Scp049.Zombies;
using PlayerRoles.Subroutines;
using RelativePositioning;

using Respawning;

using UnityEngine;

/// <summary>
Expand Down Expand Up @@ -449,6 +445,26 @@ public static void EditNetworkObject(NetworkIdentity identity, Action<NetworkIde
}
}

/// <summary>
/// Sends a <see cref="SubroutineMessage"/>.
/// </summary>
/// <param name="subroutineBase">Base <see cref="SubroutineBase"/> instance.</param>
/// <param name="applyingChanges">Action that will apply needed changes to a <paramref name="subroutineBase"/>.</param>
/// <param name="toAll">Should message be sent to everybody or to <see cref="SubroutineBase.Role"/> only.</param>
/// <typeparam name="T">A type of <see cref="SubroutineBase"/>.</typeparam>
public static void SendRpc<T>(this T subroutineBase, Action<T> applyingChanges, bool toAll = true)
where T : SubroutineBase
{
applyingChanges(subroutineBase);

SubroutineMessage msg = new(subroutineBase, true);

if (toAll)
NetworkServer.SendToAll(msg);
else
subroutineBase.Role._lastOwner.connectionToClient.Send(msg);
}

// Get components index in identity.(private)
private static int GetComponentIndex(NetworkIdentity identity, Type type)
{
Expand Down
14 changes: 14 additions & 0 deletions Exiled.API/Features/Core/GameEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,20 @@ public virtual Quaternion Rotation
/// <returns>The filtered collection of <see cref="GameEntity" /> objects.</returns>
public static IEnumerable<GameEntity> GetFarthestEntities(Vector3 vector, float distance) => List.Where(p => p.GameObject.transform && (vector - p.GameObject.transform.position).sqrMagnitude >= distance * distance);

/// <summary>
/// Returns the local space position, based on a world space position.
/// </summary>
/// <param name="position">World position.</param>
/// <returns>Local position, based on the GameEntity.</returns>
public Vector3 LocalPosition(Vector3 position) => Transform.InverseTransformPoint(position);

/// <summary>
/// Returns the World position, based on a local space position.
/// </summary>
/// <param name="offset">Local position.</param>
/// <returns>World position, based on the GameEntity.</returns>
public Vector3 WorldPosition(Vector3 offset) => Transform.TransformPoint(offset);

/// <inheritdoc/>
public T AddComponent<T>(string name = "")
where T : EActor
Expand Down
37 changes: 18 additions & 19 deletions Exiled.API/Features/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,24 @@ public bool BadgeHidden
/// </summary>
public bool IsInventoryFull => Items.Count >= Inventory.MaxSlots;

/// <summary>
/// Gets a value indicating whether the player is a target of SCP-096.
/// </summary>
/// <remarks>
/// This property checks if the player is present in the list of targets maintained by SCP-096.
/// </remarks>
/// <returns>True if the player is a target of SCP-096; otherwise, false.</returns>
public bool IsScp096Target => Player.List.Any(x => x.Role is Roles.Scp096Role scp096Role && scp096Role.Targets.Contains(x));

/// <summary>
/// Gets a value indicating whether the player is an observer of SCP-173.
/// </summary>
/// <remarks>
/// This property checks if the player is present in the list of observers maintained by SCP-173.
/// </remarks>
/// <returns>True if the player is an observer of SCP-173; otherwise, false.</returns>
public bool IsScp173Observer => Player.List.Any(x => x.Role is Roles.Scp173Role scp173Role && scp173Role.ObservingPlayers.Contains(x));

/// <summary>
/// Gets a value indicating whether or not the player has agreed to microphone recording.
/// </summary>
Expand Down Expand Up @@ -1499,16 +1517,6 @@ public static Player Get(string args)
/// <returns>An <see cref="IEnumerable{Player}"/> representing the processed players.</returns>
public static IEnumerable<Player> GetProcessedData(ArraySegment<string> args, int startIndex = 0) => GetProcessedData(args, startIndex, out string[] _);

/// <summary>
/// Adds a player's UserId to the list of reserved slots.
/// </summary>
/// <remarks>This method does not permanently give a user a reserved slot. The slot will be removed if the reserved slots are reloaded.</remarks>
/// <param name="userId">The UserId of the player to add.</param>
/// <returns><see langword="true"/> if the slot was successfully added, or <see langword="false"/> if the provided UserId already has a reserved slot.</returns>
/// <seealso cref="GiveReservedSlot()"/>
// TODO: Remove this method
public static bool AddReservedSlot(string userId) => ReservedSlot.Users.Add(userId);

/// <summary>
/// Adds a player's UserId to the list of reserved slots.
/// </summary>
Expand Down Expand Up @@ -1561,15 +1569,6 @@ public static bool AddToWhitelist(string userId, bool isPermanent)
/// </summary>
public static void ReloadWhitelist() => WhiteList.Reload();

/// <summary>
/// Adds the player's UserId to the list of reserved slots.
/// </summary>
/// <remarks>This method does not permanently give a user a reserved slot. The slot will be removed if the reserved slots are reloaded.</remarks>
/// <returns><see langword="true"/> if the slot was successfully added, or <see langword="false"/> if the player already has a reserved slot.</returns>
/// <seealso cref="AddReservedSlot(string)"/>
// TODO: Remove this method
public bool GiveReservedSlot() => AddReservedSlot(UserId);

/// <summary>
/// Adds a player's UserId to the list of reserved slots.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion Exiled.API/Features/Recontainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,6 @@ public static bool IsContainmentSequenceSuccessful
/// <summary>
/// Breaks the glass protecting the activator button.
/// </summary>
public static void BreakGlass() => ActivatorWindow.BreakWindow();
public static void Break() => ActivatorWindow.Break();
}
}
8 changes: 4 additions & 4 deletions Exiled.API/Features/Roles/Role.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,14 @@ public static RoleTypeId Random(bool includeNonPlayableRoles = false, IEnumerabl
/// </summary>
/// <param name="newRole">The new <see cref="RoleTypeId"/> to be set.</param>
/// <param name="reason">The <see cref="Enums.SpawnReason"/> defining why the player's role was changed.</param>
public virtual void Set(RoleTypeId newRole, SpawnReason reason = Enums.SpawnReason.ForceClass) => Set(newRole, reason, RoleSpawnFlags.All);
public virtual void Set(RoleTypeId newRole, SpawnReason reason = null) => Set(newRole, reason ?? Enums.SpawnReason.ForceClass, RoleSpawnFlags.All);

/// <summary>
/// <summary>S
/// Sets the player's <see cref="RoleTypeId"/>.
/// </summary>
/// <param name="newRole">The new <see cref="RoleTypeId"/> to be set.</param>
/// <param name="spawnFlags">The <see cref="RoleSpawnFlags"/> defining player spawn logic.</param>
public virtual void Set(RoleTypeId newRole, RoleSpawnFlags spawnFlags) => Owner.RoleManager.ServerSetRole(newRole, (RoleChangeReason)Enums.SpawnReason.ForceClass, spawnFlags);
public virtual void Set(RoleTypeId newRole, RoleSpawnFlags spawnFlags) => Owner.RoleManager.ServerSetRole(newRole, Enums.SpawnReason.ForceClass, spawnFlags);

/// <summary>
/// Sets the player's <see cref="RoleTypeId"/>.
Expand All @@ -245,7 +245,7 @@ public static RoleTypeId Random(bool includeNonPlayableRoles = false, IEnumerabl
/// <param name="reason">The <see cref="Enums.SpawnReason"/> defining why the player's role was changed.</param>
/// <param name="spawnFlags">The <see cref="RoleSpawnFlags"/> defining player spawn logic.</param>
public virtual void Set(RoleTypeId newRole, SpawnReason reason, RoleSpawnFlags spawnFlags) =>
Owner.RoleManager.ServerSetRole(newRole, (RoleChangeReason)reason, spawnFlags);
Owner.RoleManager.ServerSetRole(newRole, reason, spawnFlags);

/// <summary>
/// Creates a role from <see cref="RoleTypeId"/> and <see cref="Player"/>.
Expand Down
8 changes: 5 additions & 3 deletions Exiled.API/Features/Roles/Scp106Role.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,22 +297,24 @@ public bool UsePortal(Vector3 position, float cost = 0f)
/// Send a player to the pocket dimension.
/// </summary>
/// <param name="player">The <see cref="Player"/>to send.</param>
public void CapturePlayer(Player player) // Convert to bool.
/// <returns>If the player has been capture in PocketDimension.</returns>
public bool CapturePlayer(Player player)
{
if (player is null)
return;
return false;
Attack._targetHub = player.ReferenceHub;
DamageHandlerBase handler = new ScpDamageHandler(Attack.Owner, AttackDamage, DeathTranslations.PocketDecay);

if (!Attack._targetHub.playerStats.DealDamage(handler))
return;
return false;

Attack.SendCooldown(Attack._hitCooldown);
Vigor += VigorCaptureReward;
Attack.ReduceSinkholeCooldown();
Hitmarker.SendHitmarkerDirectly(Attack.Owner, 1f);

player.EnableEffect(EffectType.PocketCorroding);
return true;
}

/// <summary>
Expand Down
12 changes: 12 additions & 0 deletions Exiled.API/Features/Roles/Scp3114Role.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace Exiled.API.Features.Roles
{
using System.Collections.Generic;

using Exiled.API.Enums;
using Exiled.API.Extensions;
using PlayerRoles;
using PlayerRoles.PlayableScps;
using PlayerRoles.PlayableScps.HumeShield;
Expand Down Expand Up @@ -235,5 +237,15 @@ public void PlaySound(Scp3114VoiceLines.VoiceLinesName voiceLine = Scp3114VoiceL
/// <param name="alreadySpawned">The List of Roles already spawned.</param>
/// <returns>The Spawn Chance.</returns>
public float GetSpawnChance(List<RoleTypeId> alreadySpawned) => Base is ISpawnableScp spawnableScp ? spawnableScp.GetSpawnChance(alreadySpawned) : 0;

/// <summary>
/// Stops dancing.
/// </summary>
public void StopDancing() => Dance.SendRpc(x => x.IsDancing = false);

/// <summary>
/// Starts dancing.
/// </summary>
public void StartDanging() => Dance.SendRpc(x => x.IsDancing = true);
}
}
14 changes: 0 additions & 14 deletions Exiled.API/Features/Room.cs
Original file line number Diff line number Diff line change
Expand Up @@ -332,20 +332,6 @@ public static Room FindParentRoom(GameObject objectInRoom)
/// <returns><see cref="Room"/> object.</returns>
public static Room Random(ZoneType zoneType = ZoneType.Unspecified) => (zoneType is not ZoneType.Unspecified ? Get(r => r.Zone.HasFlag(zoneType)) : List).Random();

/// <summary>
/// Returns the local space position, based on a world space position.
/// </summary>
/// <param name="position">World position.</param>
/// <returns>Local position, based on the room.</returns>
public Vector3 LocalPosition(Vector3 position) => Transform.InverseTransformPoint(position);

/// <summary>
/// Returns the World position, based on a local space position.
/// </summary>
/// <param name="offset">Local position.</param>
/// <returns>World position, based on the room.</returns>
public Vector3 WorldPosition(Vector3 offset) => Transform.TransformPoint(offset);

/// <summary>
/// Flickers the room's lights off for a duration.
/// </summary>
Expand Down
Loading

0 comments on commit 1365ca2

Please sign in to comment.