Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
RespawnTimer Support
Browse files Browse the repository at this point in the history
- Added RespawnTimer Support
  • Loading branch information
Marco15453 committed Jun 30, 2023
1 parent af7da13 commit 9519aad
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
3 changes: 3 additions & 0 deletions Configs/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public class Config : IConfig
[Description("Should debug messages be shown in a server console.")]
public bool Debug { get; set; } = false;

[Description("How many seconds before a spawnwave occurs should it calculate the spawn chance")]
public int SpawnWaveCalculation { get; set; } = 10;

[Description("Options for UIU spawn:")]
public SpawnManager SpawnManager { get; private set; } = new SpawnManager();

Expand Down
40 changes: 30 additions & 10 deletions EventHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using MEC;
using PlayerRoles;
using Respawning;
using System;
using System.Collections.Generic;

namespace UIURescueSquad
Expand All @@ -17,23 +18,43 @@ internal sealed class EventHandlers

private int Respawns = 0;
private int UIURespawns = 0;
public bool UIUSpawns = false;
private CoroutineHandle calcuationCoroutine;

public void OnRoundStarted()
{
plugin.IsSpawnable = false;
Respawns = 0;
UIURespawns = 0;
UIUSpawns = false;

if (calcuationCoroutine.IsRunning)
Timing.KillCoroutines(calcuationCoroutine);

calcuationCoroutine = Timing.RunCoroutine(spawnCalculation());
}

private IEnumerator<float> spawnCalculation()
{
while (true)
{
yield return Timing.WaitForSeconds(1f);

if (Round.IsEnded)
break;

if (Math.Round(Respawn.TimeUntilSpawnWave.TotalSeconds, 0) != plugin.Config.SpawnWaveCalculation)
continue;

if (Respawn.NextKnownTeam == SpawnableTeamType.NineTailedFox)
plugin.IsSpawnable = Loader.Random.Next(100) <= plugin.Config.SpawnManager.Probability &&
Respawns >= plugin.Config.SpawnManager.Respawns &&
UIURespawns < plugin.Config.SpawnManager.MaxSpawns;
}
}

public void OnRespawningTeam(RespawningTeamEventArgs ev)
{
if(Loader.Random.Next(100) <= plugin.Config.SpawnManager.Probability &&
Respawns >= plugin.Config.SpawnManager.Respawns &&
UIURespawns < plugin.Config.SpawnManager.MaxSpawns &&
ev.NextKnownTeam == SpawnableTeamType.NineTailedFox)
if(plugin.IsSpawnable)
{
UIUSpawns = true;
List<Player> players = new List<Player>();
if (ev.Players.Count > plugin.Config.SpawnManager.MaxSquad)
players = ev.Players.GetRange(0, plugin.Config.SpawnManager.MaxSquad);
Expand Down Expand Up @@ -61,7 +82,6 @@ public void OnRespawningTeam(RespawningTeamEventArgs ev)
}
}
UIURespawns++;

ev.NextKnownTeam = SpawnableTeamType.None;
}
Respawns++;
Expand All @@ -70,7 +90,7 @@ public void OnRespawningTeam(RespawningTeamEventArgs ev)
public void OnAnnouncingNtfEntrance(AnnouncingNtfEntranceEventArgs ev)
{
string cassieMessage = string.Empty;
if (!UIUSpawns)
if (!plugin.IsSpawnable)
{
if (ev.ScpsLeft == 0 && !string.IsNullOrEmpty(plugin.Config.SpawnManager.NtfAnnouncmentCassieNoScp))
{
Expand All @@ -95,7 +115,7 @@ public void OnAnnouncingNtfEntrance(AnnouncingNtfEntranceEventArgs ev)
ev.IsAllowed = false;
cassieMessage = plugin.Config.SpawnManager.UiuAnnouncementCassie;
}
UIUSpawns = false;
plugin.IsSpawnable = false;
}

cassieMessage = cassieMessage.Replace("{scpnum}", $"{ev.ScpsLeft} scpsubject");
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// Puede especificar todos los valores o usar los valores predeterminados de número de compilación y de revisión
// utilizando el carácter "*", como se muestra a continuación:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("5.2.0")]
[assembly: AssemblyFileVersion("5.2.0")]
[assembly: AssemblyVersion("5.3.0")]
[assembly: AssemblyFileVersion("5.3.0")]
4 changes: 3 additions & 1 deletion UIURescueSquad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ public class UIURescueSquad : Plugin<Configs.Config>
public override string Name { get; } = "UIURescueSquad";
public override string Author { get; } = "JesusQC, Michal78900, maintained by Marco15453";
public override string Prefix { get; } = "UIURescueSquad";
public override Version Version { get; } = new Version(5, 2, 0);
public override Version Version { get; } = new Version(5, 3, 0);
public override Version RequiredExiledVersion => new Version(7, 1, 0);

public bool IsSpawnable = false;

private EventHandlers eventHandlers;

public override void OnEnabled()
Expand Down

0 comments on commit 9519aad

Please sign in to comment.