Skip to content

Commit

Permalink
Respawn API changes (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikihero authored Dec 9, 2024
1 parent 5a217d6 commit 63eade6
Show file tree
Hide file tree
Showing 3 changed files with 324 additions and 100 deletions.
5 changes: 5 additions & 0 deletions EXILED/Exiled.API/Enums/SpawnableFaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ namespace Exiled.API.Enums
/// </summary>
public enum SpawnableFaction
{
/// <summary>
/// Represents no wave.
/// </summary>
None,

/// <summary>
/// Normal NTF wave.
/// </summary>
Expand Down
57 changes: 54 additions & 3 deletions EXILED/Exiled.API/Extensions/RoleExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ namespace Exiled.API.Extensions
using System.Linq;

using Enums;
using Exiled.API.Features.Spawn;
using Features.Spawn;
using Footprinting;
using InventorySystem;
using InventorySystem.Configs;
using PlayerRoles;
using PlayerRoles.FirstPersonControl;
using Respawning;
using Respawning.Waves;
using UnityEngine;

Expand Down Expand Up @@ -233,12 +234,62 @@ public static Dictionary<AmmoType, ushort> GetStartingAmmo(this RoleTypeId roleT
/// </summary>
/// <param name="waveBase">A <see cref="SpawnableWaveBase"/> instance.</param>
/// <returns><see cref="SpawnableFaction"/> associated with the wave.</returns>
public static SpawnableFaction GetFaction(this SpawnableWaveBase waveBase) => waveBase switch
public static SpawnableFaction GetSpawnableFaction(this SpawnableWaveBase waveBase) => waveBase switch
{
NtfSpawnWave => SpawnableFaction.NtfWave,
NtfMiniWave => SpawnableFaction.NtfMiniWave,
ChaosSpawnWave => SpawnableFaction.ChaosWave,
_ => SpawnableFaction.ChaosMiniWave
ChaosMiniWave => SpawnableFaction.ChaosMiniWave,
_ => SpawnableFaction.None
};

/// <summary>
/// Gets the <see cref="Faction"/> associated with the provided <see cref="SpawnableFaction"/>.
/// </summary>
/// <param name="spawnableFaction">A member of the <see cref="SpawnableFaction"/> enum.</param>
/// <returns><see cref="Faction"/> associated with the provided <paramref name="spawnableFaction"/>.</returns>
public static Faction GetFaction(this SpawnableFaction spawnableFaction) => spawnableFaction switch
{
SpawnableFaction.ChaosWave or SpawnableFaction.ChaosMiniWave => Faction.FoundationEnemy,
SpawnableFaction.NtfWave or SpawnableFaction.NtfMiniWave => Faction.FoundationStaff,
_ => Faction.Unclassified,
};

/// <summary>
/// Gets the <see cref="Faction"/> associated with the provided <see cref="SpawnableTeamType"/>.
/// </summary>
/// <param name="spawnableTeamType">A member of the <see cref="SpawnableTeamType"/>enum.</param>
/// <returns><see cref="Faction"/> associated with the provided <paramref name="spawnableTeamType"/>.</returns>
public static Faction GetFaction(this SpawnableTeamType spawnableTeamType) => spawnableTeamType switch
{
SpawnableTeamType.ChaosInsurgency => Faction.FoundationEnemy,
SpawnableTeamType.NineTailedFox => Faction.FoundationStaff,
_ => Faction.Unclassified,
};

/// <summary>
/// Tries to get the <see cref="SpawnableFaction"/> associated with the provided <see cref="SpawnableTeamType"/> and <see cref="bool"/>.
/// </summary>
/// <param name="faction">A member of the <see cref="Faction"/>enum.</param>
/// <param name="spawnableFaction">The <see cref="SpawnableFaction"/> to return.</param>
/// <param name="mini">A <see cref="bool"/> determining whether to get a normal spawn wave or a mini one.</param>
/// <returns><see cref="Faction"/> associated with the provided <paramref name="faction"/> influenced by <paramref name="mini"/>.</returns>
public static bool TryGetSpawnableFaction(this Faction faction, out SpawnableFaction spawnableFaction, bool mini = false)
{
switch (faction)
{
case Faction.FoundationStaff:
spawnableFaction = mini ? SpawnableFaction.NtfMiniWave : SpawnableFaction.NtfWave;
break;
case Faction.FoundationEnemy:
spawnableFaction = mini ? SpawnableFaction.ChaosMiniWave : SpawnableFaction.ChaosWave;
break;
default:
spawnableFaction = SpawnableFaction.None;
return false;
}

return true;
}
}
}
Loading

0 comments on commit 63eade6

Please sign in to comment.