diff --git a/EventHandlers.cs b/EventHandlers.cs index 391387c..7b32c26 100644 --- a/EventHandlers.cs +++ b/EventHandlers.cs @@ -30,7 +30,7 @@ public void OnVerified(VerifiedEventArgs ev) public void OnHurt(HurtingEventArgs ev) { - if (ev.Attacker == null || ev.Target == null) return; + if(ev.Attacker.Role==RoleType.Scp0492) ev.Amount=Scp008X.Instance.Config.ZombieDamage; if (ev.Target.ArtificialHealth >= 0) { ev.IsAllowed = false; @@ -69,29 +69,12 @@ public void OnHealed(UsedItemEventArgs ev) } } - public void OnRoleChange(ChangingRoleEventArgs ev) - { - Timing.CallDelayed(1f, () => - { - if(ev.NewRole == RoleType.Scp0492) - { - if(ev.Player.GetEffect(EffectType.Scp207).IsEnabled) ev.Player.DisableEffect(EffectType.Scp207); - CustomRole.Get(typeof(Scp008))?.AddRole(ev.Player); - ev.Player.AddAhp(Scp008X.Instance.Config.StartingAhp,Scp008X.Instance.Config.MaxAhp,0); - } - else if (ev.NewRole.GetTeam() != Team.SCP) - { - ev.Player.ArtificialHealth = 0; - } - }); - } - public void OnReviving(StartingRecallEventArgs ev) { if (!Scp008X.Instance.Config.BuffDoctor) return; ev.IsAllowed = false; - CustomRole.Get(typeof(Scp008))?.AddRole(ev.Target); + CustomRole.Get(typeof(Scp008)).AddRole(ev.Target); ev.Scp049.ShowHint($"Revived {ev.Target.Nickname}"); } diff --git a/Roles/Scp008.cs b/Roles/Scp008.cs index a05c65d..313c0a3 100644 --- a/Roles/Scp008.cs +++ b/Roles/Scp008.cs @@ -6,12 +6,14 @@ namespace SCP008X { - using CustomPlayerEffects; using Exiled.API.Enums; + using Exiled.API.Extensions; using Exiled.API.Features; + using Exiled.API.Features.Attributes; using Exiled.CustomRoles.API.Features; using Exiled.Events.EventArgs; + [CustomRole(RoleType.Scp0492)] public class Scp008 : CustomRole { public override uint Id { get; set; } = 008; @@ -19,52 +21,50 @@ public class Scp008 : CustomRole public override int MaxHealth { get; set; } = Scp008X.Instance.Config.ZombieHealth; public override string Name { get; set; } = "SCP-008"; public override string Description { get; set; } = - "An instance of SCP-008 that spreads the 008 infection with each hit."; + "An instance of SCP-008 that spreads the infection with each hit."; public override string CustomInfo { get; set; } = "SCP-008"; protected override void SubscribeEvents() { - Log.Debug($"{nameof(SubscribeEvents)}: Loading 008 events..", Scp008X.Instance.Config.DebugMode); + Log.Debug($"{nameof(SubscribeEvents)}: Loading 008 custom role events..", Scp008X.Instance.Config.DebugMode); Exiled.Events.Handlers.Player.Hurting += OnHurting; + Exiled.Events.Handlers.Player.ChangingRole += OnSpawning; base.SubscribeEvents(); } protected override void UnsubscribeEvents() { - Log.Debug($"{nameof(UnsubscribeEvents)}: Unloading 008 events..", Scp008X.Instance.Config.DebugMode); + Log.Debug($"{nameof(UnsubscribeEvents)}: Unloading 008 custom role events..", Scp008X.Instance.Config.DebugMode); Exiled.Events.Handlers.Player.Hurting -= OnHurting; + Exiled.Events.Handlers.Player.ChangingRole -= OnSpawning; base.UnsubscribeEvents(); } - private void OnHurting(HurtingEventArgs ev) + private void OnSpawning(ChangingRoleEventArgs ev) { - ev.Amount = Scp008X.Instance.Config.ZombieDamage; - - var buff = Scp008X.Instance.Config.Scp008Buff; - var max = Scp008X.Instance.Config.MaxAhp; - ev.Attacker.AddAhp(buff > 0 && ev.Attacker.ArtificialHealth + buff < max ? buff : (ushort)0,Scp008X.Instance.Config.MaxAhp,0); - - if (ev.Target.IsHuman && ev.Target.Health - ev.Amount <= 0 && - ev.Target.TryGetEffect(EffectType.Poisoned, out PlayerEffect poisoned) && poisoned.Intensity > 0) + if(ev.NewRole == RoleType.Scp0492) { - ev.IsAllowed = false; - ev.Amount = 0; - ev.Target.DropItems(); - ev.Target.SetRole(RoleType.Scp0492, SpawnReason.ForceClass, true); + if(ev.Player.GetEffect(EffectType.Scp207).IsEnabled) ev.Player.DisableEffect(EffectType.Scp207); + ev.Player.AddAhp(Scp008X.Instance.Config.StartingAhp, Scp008X.Instance.Config.MaxAhp, 0); } - - if (!Check(ev.Attacker)) - return; - - if (ev.Target.Role.Team == Team.SCP) + else if (ev.NewRole.GetTeam() != Team.SCP) { - ev.Amount = 0f; - return; + ev.Player.ArtificialHealth = 0; } + } - if (Scp008X.Instance.Rng.Next(100) < Scp008X.Instance.Config.InfectionChance) + private void OnHurting(HurtingEventArgs ev) + { + if (ev.Attacker.Role == RoleType.Scp0492) { - ev.Target.ShowHint($"SCP-008\n{Scp008X.Instance.Config.InfectionAlert}"); - ev.Target.EnableEffect(EffectType.Poisoned); + var buff = Scp008X.Instance.Config.Scp008Buff; + var max = Scp008X.Instance.Config.MaxAhp; + ev.Attacker.AddAhp(buff > 0 && ev.Attacker.ArtificialHealth + buff < max ? buff : (ushort)0,Scp008X.Instance.Config.MaxAhp,0); + + if (Scp008X.Instance.Rng.Next(100) > Scp008X.Instance.Config.InfectionChance) + { + ev.Target.ShowHint($"SCP-008\n{Scp008X.Instance.Config.InfectionAlert}"); + ev.Target.EnableEffect(EffectType.Poisoned); + } } } } diff --git a/Scp008X.cs b/Scp008X.cs index c10393a..37f31ae 100644 --- a/Scp008X.cs +++ b/Scp008X.cs @@ -51,7 +51,6 @@ private void RegisterEvents() PlayerEvents.Shooting += _events.OnShoot; PlayerEvents.Verified += _events.OnVerified; PlayerEvents.UsedItem += _events.OnHealed; - PlayerEvents.ChangingRole += _events.OnRoleChange; Scp049.StartingRecall += _events.OnReviving; @@ -66,7 +65,6 @@ private void UnregisterEvents() PlayerEvents.Shooting -= _events.OnShoot; PlayerEvents.Verified -= _events.OnVerified; PlayerEvents.UsedItem -= _events.OnHealed; - PlayerEvents.ChangingRole -= _events.OnRoleChange; Scp049.StartingRecall -= _events.OnReviving;