From 2fef5cff333392b1622e1f7ef97016709b299bba Mon Sep 17 00:00:00 2001 From: BuildBoy12 Date: Tue, 10 Nov 2020 14:03:29 -0500 Subject: [PATCH] Inventory Fix, Keep Held Item, Formatting --- Spies/Components/ChaosSpy.cs | 35 +++++++++++--------- Spies/Components/MtfSpy.cs | 33 ++++++++++-------- Spies/Configs/Config.cs | 1 + Spies/Configs/SubConfigs/ChaosSpies.cs | 46 ++++++++++++++++---------- Spies/Configs/SubConfigs/MtfSpies.cs | 17 +++++++--- Spies/Handlers/PlayerHandlers.cs | 30 ++++++++--------- Spies/Handlers/ServerHandlers.cs | 32 +++++++++--------- Spies/Spies.cs | 12 +++---- Spies/Spies.csproj | 4 +-- 9 files changed, 121 insertions(+), 89 deletions(-) diff --git a/Spies/Components/ChaosSpy.cs b/Spies/Components/ChaosSpy.cs index d6533fe..b6605a6 100755 --- a/Spies/Components/ChaosSpy.cs +++ b/Spies/Components/ChaosSpy.cs @@ -8,14 +8,14 @@ namespace Spies.Components using System.Linq; using UnityEngine; using PlayerEvents = Exiled.Events.Handlers.Player; - using static Spies; - + using static Spies; + public class ChaosSpy : MonoBehaviour { private Player _player; public Team disguisedTeam = Team.RIP; private RoleType _disguisedRoleType; - + private void Start() { _player = Player.Get(gameObject); @@ -26,26 +26,27 @@ private void Start() private IEnumerator InitSpy() { yield return Timing.WaitUntilFalse(() => disguisedTeam == Team.RIP); - - _player.Broadcast(Instance.Config.ChaosSpies.SpawningBroadcast.Duration, Instance.Config.ChaosSpies.SpawningBroadcast.Content); + + _player.Broadcast(Instance.Config.ChaosSpies.SpawningBroadcast.Duration, + Instance.Config.ChaosSpies.SpawningBroadcast.Content); _player.SendConsoleMessage(Instance.Config.ChaosSpies.SpawningConsoleInfo, "yellow"); - + _disguisedRoleType = _player.Role; _player.IsFriendlyFireEnabled = true; - - if (!Instance.Config.MtfSpies.Inventory.Any()) + + if (!Instance.Config.ChaosSpies.Inventory.Any()) yield break; - + if (Instance.Config.ChaosSpies.Inventory.TryGetValue(_disguisedRoleType, out List items)) _player.ResetInventory(items); } - + private void Update() { if (_player == null || _player.Role != _disguisedRoleType) Destroy(false); } - + public void OnHurting(HurtingEventArgs ev) { if (ev.Attacker == ev.Target) @@ -55,8 +56,9 @@ public void OnHurting(HurtingEventArgs ev) { if (Instance.Config.PreventSpyFf) ev.Amount = 0; - - ev.Attacker.Broadcast(Instance.Config.ChaosSpies.SameTeamBroadcast.Duration, Instance.Config.ChaosSpies.SameTeamBroadcast.Content); + + ev.Attacker.Broadcast(Instance.Config.ChaosSpies.SameTeamBroadcast.Duration, + Instance.Config.ChaosSpies.SameTeamBroadcast.Content); return; } @@ -65,13 +67,16 @@ public void OnHurting(HurtingEventArgs ev) Destroy(); } - + public void Destroy(bool reveal = true) { if (reveal) { + var curItem = _player.CurrentItem; _player.SetRole(Instance.Config.ChaosSpies.HiddenRole, true); - _player.Broadcast(Instance.Config.ChaosSpies.RevealBroadcast.Duration, Instance.Config.ChaosSpies.RevealBroadcast.Content); + _player.Broadcast(Instance.Config.ChaosSpies.RevealBroadcast.Duration, + Instance.Config.ChaosSpies.RevealBroadcast.Content); + Timing.CallDelayed(0.275f, () => { _player.CurrentItem = curItem; }); } _player.IsFriendlyFireEnabled = false; diff --git a/Spies/Components/MtfSpy.cs b/Spies/Components/MtfSpy.cs index b6f892b..22503c9 100755 --- a/Spies/Components/MtfSpy.cs +++ b/Spies/Components/MtfSpy.cs @@ -8,14 +8,14 @@ namespace Spies.Components using System.Linq; using UnityEngine; using PlayerEvents = Exiled.Events.Handlers.Player; - using static Spies; - + using static Spies; + public class MtfSpy : MonoBehaviour { private Player _player; public Team disguisedTeam = Team.RIP; private RoleType _disguisedRoleType; - + private void Start() { _player = Player.Get(gameObject); @@ -26,23 +26,24 @@ private void Start() private IEnumerator InitSpy() { yield return Timing.WaitUntilFalse(() => disguisedTeam == Team.RIP); - - _player.Broadcast(Instance.Config.MtfSpies.SpawningBroadcast.Duration, Instance.Config.MtfSpies.SpawningBroadcast.Content); + + _player.Broadcast(Instance.Config.MtfSpies.SpawningBroadcast.Duration, + Instance.Config.MtfSpies.SpawningBroadcast.Content); _player.SendConsoleMessage(Instance.Config.MtfSpies.SpawningConsoleInfo, "yellow"); - + _disguisedRoleType = _player.Role; _player.IsFriendlyFireEnabled = true; - - if (Instance.Config.ChaosSpies.Inventory.Any()) + + if (Instance.Config.MtfSpies.Inventory.Any()) _player.ResetInventory(Instance.Config.MtfSpies.Inventory); } - + private void Update() { if (_player == null || _player.Role != _disguisedRoleType) Destroy(false); } - + public void OnHurting(HurtingEventArgs ev) { if (ev.Attacker == ev.Target) @@ -52,8 +53,9 @@ public void OnHurting(HurtingEventArgs ev) { if (Instance.Config.PreventSpyFf) ev.Amount = 0; - - ev.Attacker.Broadcast(Instance.Config.MtfSpies.SameTeamBroadcast.Duration, Instance.Config.MtfSpies.SameTeamBroadcast.Content); + + ev.Attacker.Broadcast(Instance.Config.MtfSpies.SameTeamBroadcast.Duration, + Instance.Config.MtfSpies.SameTeamBroadcast.Content); return; } @@ -62,13 +64,16 @@ public void OnHurting(HurtingEventArgs ev) Destroy(); } - + public void Destroy(bool reveal = true) { if (reveal) { + var curItem = _player.CurrentItem; _player.SetRole(Instance.Config.MtfSpies.HiddenRole, true); - _player.Broadcast(Instance.Config.MtfSpies.RevealBroadcast.Duration, Instance.Config.MtfSpies.RevealBroadcast.Content); + _player.Broadcast(Instance.Config.MtfSpies.RevealBroadcast.Duration, + Instance.Config.MtfSpies.RevealBroadcast.Content); + Timing.CallDelayed(0.275f, () => { _player.CurrentItem = curItem; }); } _player.IsFriendlyFireEnabled = false; diff --git a/Spies/Configs/Config.cs b/Spies/Configs/Config.cs index a66d160..065a0a3 100755 --- a/Spies/Configs/Config.cs +++ b/Spies/Configs/Config.cs @@ -8,6 +8,7 @@ public class Config : IConfig { [Description("Prevents spys from taking damage from the faction they are undercover from.")] public bool PreventSpyFf { get; private set; } = false; + public ChaosSpies ChaosSpies { get; private set; } = new ChaosSpies(); public MtfSpies MtfSpies { get; private set; } = new MtfSpies(); public bool IsEnabled { get; set; } = true; diff --git a/Spies/Configs/SubConfigs/ChaosSpies.cs b/Spies/Configs/SubConfigs/ChaosSpies.cs index ae42d75..9eaf254 100755 --- a/Spies/Configs/SubConfigs/ChaosSpies.cs +++ b/Spies/Configs/SubConfigs/ChaosSpies.cs @@ -3,35 +3,45 @@ namespace Spies.Configs.SubConfigs using Exiled.API.Features; using System.Collections.Generic; using System.ComponentModel; - + public class ChaosSpies { [Description("Percent chance a spy will spawn in a given respawn wave.")] public int SpawnChance { get; private set; } = 40; + [Description("Broadcast played to the spy when they spawn.")] - public Broadcast SpawningBroadcast { get; private set; } = new Broadcast("You are a Chaos Spy!\\nPress [`] for more info.", 10); + public Broadcast SpawningBroadcast { get; private set; } = + new Broadcast("You are a Chaos Spy!\\nPress [`] for more info.", 10); + [Description("Message to send to the spys console when they spawn.")] - public string SpawningConsoleInfo { get; private set; } = "You are a Chaos Spy! You are immune to MTF for now, but as soon as you damage an insurgent, your immunity will turn off. Help Chaos win the round and kill Scientists and MTF as necessary."; + public string SpawningConsoleInfo { get; private set; } = + "You are a Chaos Spy! You are immune to MTF for now, but as soon as you damage an insurgent, your immunity will turn off. Help Chaos win the round and kill Scientists and MTF as necessary."; + [Description("Role the spy will reveal as after shooting a MTF or Scientist.")] public RoleType HiddenRole { get; private set; } = RoleType.ChaosInsurgency; + [Description("Broadcast played to the spy when their role is revealed.")] public Broadcast RevealBroadcast { get; private set; } = new Broadcast("You have been revealed as a spy!", 10); + [Description("Broadcast played when a ClassD or ChaosInsurgency attacks the spy.")] - public Broadcast SameTeamBroadcast { get; private set; } = new Broadcast("You have attacked a spy of your own faction!", 2); + public Broadcast SameTeamBroadcast { get; private set; } = + new Broadcast("You have attacked a spy of your own faction!", 2); + [Description("Inventory the spy will spawn with. Leave empty for the default inventory.")] - public Dictionary> Inventory { get; private set; } = new Dictionary> - { - { - RoleType.NtfCadet, new List - { - ItemType.GunProject90, - ItemType.KeycardNTFLieutenant, - ItemType.GrenadeFrag, - ItemType.GrenadeFlash, - ItemType.Disarmer, - ItemType.WeaponManagerTablet - } - } - }; + public Dictionary> Inventory { get; private set; } = + new Dictionary> + { + { + RoleType.NtfCadet, new List + { + ItemType.GunProject90, + ItemType.KeycardNTFLieutenant, + ItemType.GrenadeFrag, + ItemType.GrenadeFlash, + ItemType.Disarmer, + ItemType.WeaponManagerTablet + } + } + }; } } \ No newline at end of file diff --git a/Spies/Configs/SubConfigs/MtfSpies.cs b/Spies/Configs/SubConfigs/MtfSpies.cs index 2f0f366..3ec3c55 100755 --- a/Spies/Configs/SubConfigs/MtfSpies.cs +++ b/Spies/Configs/SubConfigs/MtfSpies.cs @@ -3,21 +3,30 @@ namespace Spies.Configs.SubConfigs using Exiled.API.Features; using System.Collections.Generic; using System.ComponentModel; - + public class MtfSpies { [Description("Percent chance a spy will spawn in a given respawn wave.")] public int SpawnChance { get; private set; } = 40; + [Description("Broadcast played to the spy when they spawn.")] - public Broadcast SpawningBroadcast { get; private set; } = new Broadcast("You are an MTF Spy!\\nPress [`] for more info.", 10); + public Broadcast SpawningBroadcast { get; private set; } = + new Broadcast("You are an MTF Spy!\\nPress [`] for more info.", 10); + [Description("Message to send to the spys console when they spawn.")] - public string SpawningConsoleInfo { get; private set; } = "You are a MTF Spy! You are immune to chaos for now, but as soon as you damage an insurgent, your immunity will turn off. Help MTF win the round and kill ClassD and Insurgents as necessary."; + public string SpawningConsoleInfo { get; private set; } = + "You are a MTF Spy! You are immune to chaos for now, but as soon as you damage an insurgent, your immunity will turn off. Help MTF win the round and kill ClassD and Insurgents as necessary."; + [Description("Role the spy will reveal as after shooting a ClassD or ChaosInsurgency.")] public RoleType HiddenRole { get; private set; } = RoleType.NtfScientist; + [Description("Broadcast played to the spy when their role is revealed.")] public Broadcast RevealBroadcast { get; private set; } = new Broadcast("You have been revealed as a spy!", 10); + [Description("Broadcast played when a MTF or Scientist attacks the spy.")] - public Broadcast SameTeamBroadcast { get; private set; } = new Broadcast("You have attacked a spy of your own faction!", 2); + public Broadcast SameTeamBroadcast { get; private set; } = + new Broadcast("You have attacked a spy of your own faction!", 2); + [Description("Inventory the spy will spawn with. Leave empty for the default inventory.")] public List Inventory { get; private set; } = new List(); } diff --git a/Spies/Handlers/PlayerHandlers.cs b/Spies/Handlers/PlayerHandlers.cs index 1d7eb77..356004c 100755 --- a/Spies/Handlers/PlayerHandlers.cs +++ b/Spies/Handlers/PlayerHandlers.cs @@ -1,19 +1,19 @@ -namespace Spies.Handlers -{ - using Components; - using Exiled.Events.EventArgs; - using Exiled.API.Features; +namespace Spies.Handlers +{ + using Components; + using Exiled.Events.EventArgs; + using Exiled.API.Features; using System.Linq; using System.Collections.Generic; using MEC; - public class PlayerHandlers - { - public bool MtfExterminated; - public bool ChaosExterminated; - - public void OnDied(DiedEventArgs _) - { + public class PlayerHandlers + { + public bool MtfExterminated; + public bool ChaosExterminated; + + public void OnDied(DiedEventArgs _) + { Timing.CallDelayed(0.1f, () => { MtfExterminated = !Player.Get(Team.MTF).Any() && !Player.Get(Team.RSC).Any(); @@ -34,7 +34,7 @@ public void OnDied(DiedEventArgs _) if (chaosSpy != null) chaosSpy.Destroy(); } - }); - } - } + }); + } + } } \ No newline at end of file diff --git a/Spies/Handlers/ServerHandlers.cs b/Spies/Handlers/ServerHandlers.cs index 209684a..bb2bcff 100755 --- a/Spies/Handlers/ServerHandlers.cs +++ b/Spies/Handlers/ServerHandlers.cs @@ -4,19 +4,19 @@ namespace Spies.Handlers using Exiled.API.Features; using Exiled.Events.EventArgs; using Respawning; - using System; - using System.Linq; + using System; + using System.Linq; using static Spies; - + public class ServerHandlers { private readonly Random _random = new Random(); - + public void OnConsoleCommand(SendingConsoleCommandEventArgs ev) { - if (ev.Name.ToLower() != "reveal") + if (ev.Name.ToLower() != "reveal") return; - + var chaosSpy = ev.Player.GameObject.GetComponent(); var mtfSpy = ev.Player.GameObject.GetComponent(); if (chaosSpy != null) @@ -24,33 +24,35 @@ public void OnConsoleCommand(SendingConsoleCommandEventArgs ev) else if (mtfSpy != null) mtfSpy.Destroy(); else - return; - + return; + ev.IsAllowed = false; ev.ReturnMessage = "Revealing your role.."; ev.Color = "white"; } - + public void OnRespawningTeam(RespawningTeamEventArgs ev) { - Instance._playerHandlers.MtfExterminated = !Player.Get(Team.MTF).Any() && !Player.Get(Team.RSC).Any(); - Instance._playerHandlers.ChaosExterminated = !Player.Get(Team.CHI).Any() && !Player.Get(Team.CDP).Any(); + Instance.PlayerHandlers.MtfExterminated = !Player.Get(Team.MTF).Any() && !Player.Get(Team.RSC).Any(); + Instance.PlayerHandlers.ChaosExterminated = !Player.Get(Team.CHI).Any() && !Player.Get(Team.CDP).Any(); Player ply = ev.Players[_random.Next(ev.Players.Count)]; switch (ev.NextKnownTeam) { case SpawnableTeamType.ChaosInsurgency: - if (_random.Next(101) > Instance.Config.MtfSpies.SpawnChance || Instance._playerHandlers.MtfExterminated) + if (_random.Next(101) > Instance.Config.MtfSpies.SpawnChance || + Instance.PlayerHandlers.MtfExterminated) break; - + var mtfSpy = ply.GameObject.AddComponent(); mtfSpy.disguisedTeam = Team.CHI; break; case SpawnableTeamType.NineTailedFox: - if (_random.Next(101) > Instance.Config.ChaosSpies.SpawnChance || Instance._playerHandlers.ChaosExterminated) + if (_random.Next(101) > Instance.Config.ChaosSpies.SpawnChance || + Instance.PlayerHandlers.ChaosExterminated) break; - + var chaosSpy = ply.GameObject.AddComponent(); chaosSpy.disguisedTeam = Team.MTF; break; diff --git a/Spies/Spies.cs b/Spies/Spies.cs index 136b83f..4d34645 100755 --- a/Spies/Spies.cs +++ b/Spies/Spies.cs @@ -8,15 +8,15 @@ using ServerEvents = Exiled.Events.Handlers.Server; public class Spies : Plugin - { - internal readonly PlayerHandlers _playerHandlers = new PlayerHandlers(); + { + internal readonly PlayerHandlers PlayerHandlers = new PlayerHandlers(); private readonly ServerHandlers _serverHandlers = new ServerHandlers(); internal static Spies Instance; - + public override void OnEnabled() { Instance = this; - PlayerEvents.Died += _playerHandlers.OnDied; + PlayerEvents.Died += PlayerHandlers.OnDied; ServerEvents.SendingConsoleCommand += _serverHandlers.OnConsoleCommand; ServerEvents.RespawningTeam += _serverHandlers.OnRespawningTeam; base.OnEnabled(); @@ -24,7 +24,7 @@ public override void OnEnabled() public override void OnDisabled() { - PlayerEvents.Died -= _playerHandlers.OnDied; + PlayerEvents.Died -= PlayerHandlers.OnDied; ServerEvents.SendingConsoleCommand -= _serverHandlers.OnConsoleCommand; ServerEvents.RespawningTeam -= _serverHandlers.OnRespawningTeam; Instance = null; @@ -32,6 +32,6 @@ public override void OnDisabled() public override string Author => "Build"; public override string Name => "Spies"; - public override Version Version => new Version(1, 0, 1); + public override Version Version => new Version(1, 0, 2); } } \ No newline at end of file diff --git a/Spies/Spies.csproj b/Spies/Spies.csproj index 14d0f53..890ee29 100755 --- a/Spies/Spies.csproj +++ b/Spies/Spies.csproj @@ -17,8 +17,8 @@ - - ..\..\..\Desktop\SCP-Server\SCPSL_Data\Managed\Assembly-CSharp.dll + + ..\..\Assembly-CSharp-Publicized.dll ..\..\EndConditions-ReddKing\EndConditions\bin\Release\net472\Assembly-CSharp-firstpass.dll