Skip to content

Commit

Permalink
Change location and improve 049 recall compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
rayzerbrain committed Jul 18, 2022
1 parent 3323091 commit d9a95d6
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 29 deletions.
14 changes: 7 additions & 7 deletions ShootingRange/API/SpectatorRange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Exiled.API.Enums;
using Exiled.API.Features;
using Exiled.API.Features.Toys;
using Exiled.API.Extensions;
using Exiled.CustomItems.API.Features;

using Object = UnityEngine.Object;
Expand All @@ -18,9 +17,9 @@ namespace ShootingRange.API
{
public class SpectatorRange
{
private Vector3 _smallBound = new(205, 997.25f, -52);
private Vector3 _bigBound = new(237, 1015, -37);
public Vector3 Spawn { get; } = new(218.5f, 999.1f, -43.0f);
private Vector3 _smallBound = new(-173.7f, 1003.4f, -45);
private Vector3 _bigBound = new(-143.7f, 1006.8f, -37.9f);
public Vector3 Spawn { get; } = new(-161.1f, 1004.9f, -42.1f);
public bool IsOpen => Round.IsStarted && Respawn.TimeUntilRespawn > 20;

public SpectatorRange() { }
Expand All @@ -45,7 +44,7 @@ public bool HasPlayer(Player plyr)
}
public bool TryAdmit(Player player)
{
if (!(IsOpen && player.IsDead && !PluginMain.Singleton.EventHandler.FreshlyDead.Contains(player)))
if (!(IsOpen && player.IsDead))
return false;

player.SetRole(RoleType.Tutorial);
Expand All @@ -70,7 +69,6 @@ public bool TryAdmit(Player player)
player.Position = Spawn;
player.Health = 100000;
player.ChangeAppearance(RoleType.ChaosConscript);
player.Broadcast(PluginMain.Singleton.Config.RangeGreeting);
});
return true;
Expand Down Expand Up @@ -122,14 +120,16 @@ public void SpawnPrimitives()
prims[i].Type = PrimitiveType.Cube;
}
}

public void SpawnBench()
{
Quaternion rot = Quaternion.Euler(0, 180, 0);
Vector3 pos = new((_bigBound.x + _smallBound.x) / 2, _smallBound.y + 0.25f, _bigBound.z - 1);

GameObject benchPrefab = NetworkClient.prefabs[System.Guid.Parse("307eb9b0-d080-9dc4-78e6-673847876412")];
GameObject benchPrefab = NetworkClient.prefabs[Guid.Parse("307eb9b0-d080-9dc4-78e6-673847876412")];
NetworkServer.Spawn(Object.Instantiate(benchPrefab, pos, rot));
}

public void RemovePlayer(Player plyr)
{
plyr.ClearInventory();
Expand Down
8 changes: 7 additions & 1 deletion ShootingRange/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ public class Config : IConfig
[Description("Determines whether the \".range\" permission is required to use the .range command (this will not affect automatically teleported players)")]
public bool RequirePermission { get; set; } = false;
[Description("Alternative range location. The \"w\" will determine the radius of the sphere (cube) that forms the boundaries.")]
public Vector4 RangeLocation { get; set; } = default;
public Vector4 RangeLocation { get; set; } = new Vector4()
{
w = 10,
x = -156.2f,
y = 1024.3f,
z = -58.5f,
};
[Description("Determines if the above location will be used or not")]
public bool UseRangeLocation { get; set; } = false;
[Description("The items one will spawn with on the range (may be ItemType or the name of a CustomItem")]
Expand Down
43 changes: 22 additions & 21 deletions ShootingRange/EventHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,8 @@ public void OnVerified(VerifiedEventArgs ev)
ev.Player.Broadcast(PluginMain.Singleton.Config.DeathBroadcast);
});
}
public void OnDied(DiedEventArgs ev) => Timing.RunCoroutine(OnDiedCoroutine(ev.Target, ev.Killer != null && ev.Killer.Role == RoleType.Scp049));
private IEnumerator<float> OnDiedCoroutine(Player plyr, bool byDoctor)
{
if (byDoctor)
{
FreshlyDead.Add(plyr);
yield return Timing.WaitForSeconds(10f);
FreshlyDead.Remove(plyr);
}

if (_plugin.Config.ForceSpectators)
{
yield return Timing.WaitForSeconds(0.5f);
_plugin.ActiveRange.TryAdmit(plyr);
}
else
{
yield return Timing.WaitForSeconds(5f);
plyr.Broadcast(_plugin.Config.DeathBroadcast);
}
}
public void OnDied(DiedEventArgs ev) => Timing.RunCoroutine(OnDiedCoroutine(ev.Target));

public void OnShooting(ShootingEventArgs ev)
{
if (_plugin.ActiveRange.HasPlayer(ev.Shooter))
Expand Down Expand Up @@ -91,5 +72,25 @@ public IEnumerator<float> WaitForRespawnCoroutine()
break;
}
}
private IEnumerator<float> OnDiedCoroutine(Player plyr)
{
FreshlyDead.Add(plyr);

if (_plugin.Config.ForceSpectators)
{
yield return Timing.WaitForSeconds(0.5f);
_plugin.ActiveRange.TryAdmit(plyr);
}

yield return Timing.WaitForSeconds(30f);
FreshlyDead.Remove(plyr);

if (plyr.IsDead)
plyr.Broadcast(_plugin.Config.DeathBroadcast);
}
public void OnFinishingRecall(FinishingRecallEventArgs ev)
{
ev.IsAllowed |= FreshlyDead.Contains(ev.Target) && _plugin.ActiveRange.HasPlayer(ev.Target);
}
}
}
3 changes: 3 additions & 0 deletions ShootingRange/PluginMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

using Player = Exiled.Events.Handlers.Player;
using Server = Exiled.Events.Handlers.Server;
using Scp049 = Exiled.Events.Handlers.Scp049;

namespace ShootingRange
{
Expand Down Expand Up @@ -43,6 +44,7 @@ public void RegisterEvents()
Player.Shooting += EventHandler.OnShooting;
Player.DroppingItem += EventHandler.OnDroppingItem;
Server.RoundStarted += EventHandler.OnRoundStarted;
Scp049.FinishingRecall += EventHandler.OnFinishingRecall;
}
public void UnregisterEvents()
{
Expand All @@ -51,6 +53,7 @@ public void UnregisterEvents()
Player.Died -= EventHandler.OnDied;
Player.Shooting -= EventHandler.OnShooting;
Player.DroppingItem -= EventHandler.OnDroppingItem;
Scp049.FinishingRecall -= EventHandler.OnFinishingRecall;
}
}
}

0 comments on commit d9a95d6

Please sign in to comment.