From 039b8dd1fc044e23096109f9ba2feee7c44ae525 Mon Sep 17 00:00:00 2001 From: CaYpeN1 Date: Fri, 22 Mar 2024 13:39:56 +0500 Subject: [PATCH] change list to enum --- .../_White/Chemistry/NarcoticEffect.cs | 24 +++++++++---------- .../Chemistry/NarcoticEffectComponent.cs | 16 +++++++++---- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/Content.Server/_White/Chemistry/NarcoticEffect.cs b/Content.Server/_White/Chemistry/NarcoticEffect.cs index bb2a2d7254..597992a46f 100644 --- a/Content.Server/_White/Chemistry/NarcoticEffect.cs +++ b/Content.Server/_White/Chemistry/NarcoticEffect.cs @@ -31,60 +31,60 @@ public sealed class NarcoticEffect : EntitySystem private void OnInit(EntityUid uid, NarcoticEffectComponent component, ComponentInit args) { - int index = _robustRandom.Next(0, component.Effects.Count); + int index = _robustRandom.Next(0, Enum.GetNames(typeof(NarcoticEffects)).Length); Effects(uid, component, index); } private void OnRemove(EntityUid uid, NarcoticEffectComponent component, ComponentRemove args) { - component.cancelTokenSource.Cancel(); + component.CancelTokenSource.Cancel(); } private void Effects(EntityUid uid, NarcoticEffectComponent component, int index) { RaiseLocalEvent(uid, new MoodEffectEvent("Stimulator")); - CancellationToken token = component.cancelTokenSource.Token; + CancellationToken token = component.CancelTokenSource.Token; TryComp(uid, out var statusEffectsComp); int timer = component.TimerInterval[_robustRandom.Next(0, component.TimerInterval.Count)]; int slur = component.SlurTime[_robustRandom.Next(0, component.SlurTime.Count)]; - switch (component.Effects[index]) + switch (Enum.GetValues(typeof(NarcoticEffects)).GetValue(index)) { - case "TremorAndShake" when _statusEffectsSystem.HasStatusEffect(uid, "Drunk", statusEffectsComp): + case NarcoticEffects.TremorAndShake when _statusEffectsSystem.HasStatusEffect(uid, "Drunk", statusEffectsComp): Timer.SpawnRepeating(timer, () => _stamina.TakeStaminaDamage(uid, 15F), token); _statusEffectsSystem.TryAddTime(uid, "Drunk", TimeSpan.FromSeconds(slur), statusEffectsComp); break; - case "Shake" when _statusEffectsSystem.HasStatusEffect(uid, "Drunk", statusEffectsComp): + case NarcoticEffects.Shake when _statusEffectsSystem.HasStatusEffect(uid, "Drunk", statusEffectsComp): _statusEffectsSystem.TryAddTime(uid, "Drunk", TimeSpan.FromSeconds(slur), statusEffectsComp); break; - case "StunAndShake" when _statusEffectsSystem.HasStatusEffect(uid, "Drunk", statusEffectsComp): + case NarcoticEffects.StunAndShake when _statusEffectsSystem.HasStatusEffect(uid, "Drunk", statusEffectsComp): Timer.SpawnRepeating(timer, () => _stun.TryParalyze(uid, TimeSpan.FromSeconds(component.StunTime), true), token); _statusEffectsSystem.TryAddTime(uid, "Drunk", TimeSpan.FromSeconds(slur), statusEffectsComp); break; - case "Stun": + case NarcoticEffects.Stun: Timer.SpawnRepeating(timer, () => _stun.TryParalyze(uid, TimeSpan.FromSeconds(component.StunTime), true), token); break; - case "TremorAndShake": + case NarcoticEffects.TremorAndShake: Timer.SpawnRepeating(timer, () => _stamina.TakeStaminaDamage(uid, 15F), token); _statusEffectsSystem.TryAddStatusEffect(uid, "Drunk", TimeSpan.FromSeconds(slur), true, statusEffectsComp); break; - case "Tremor": + case NarcoticEffects.Tremor: Timer.SpawnRepeating(timer, () => _stamina.TakeStaminaDamage(uid, 15F), token); break; - case "Shake": + case NarcoticEffects.Shake: _statusEffectsSystem.TryAddStatusEffect(uid, "Drunk", TimeSpan.FromSeconds(slur), true, statusEffectsComp); break; - case "StunAndShake": + case NarcoticEffects.StunAndShake: Timer.SpawnRepeating(timer, () => _stun.TryParalyze(uid, TimeSpan.FromSeconds(component.StunTime), true), token); _statusEffectsSystem.TryAddStatusEffect(uid, "Drunk", TimeSpan.FromSeconds(slur), true, statusEffectsComp); break; diff --git a/Content.Server/_White/Chemistry/NarcoticEffectComponent.cs b/Content.Server/_White/Chemistry/NarcoticEffectComponent.cs index 0b02955a33..b992ad33d8 100644 --- a/Content.Server/_White/Chemistry/NarcoticEffectComponent.cs +++ b/Content.Server/_White/Chemistry/NarcoticEffectComponent.cs @@ -1,4 +1,5 @@ using System.Threading; +using Robust.Shared.Serialization; namespace Content.Server._White.Chemistry; @@ -12,10 +13,7 @@ public sealed partial class NarcoticEffectComponent : Component public float StunTime = 0.7f; [ViewVariables(VVAccess.ReadWrite), DataField] - public CancellationTokenSource cancelTokenSource = new(); - - [ViewVariables(VVAccess.ReadOnly), DataField] - public List Effects = new() { "Stun", "TremorAndShake", "Tremor", "Shake", "StunAndShake" }; + public CancellationTokenSource CancelTokenSource = new(); [ViewVariables(VVAccess.ReadOnly), DataField] public List TimerInterval = new() { 3000, 6000, 3800, 7000, 5000 }; @@ -23,3 +21,13 @@ public sealed partial class NarcoticEffectComponent : Component [ViewVariables(VVAccess.ReadOnly), DataField] public List SlurTime = new() { 35, 60, 80, 90, 45 }; } + +[Serializable, NetSerializable] +public enum NarcoticEffects +{ + Stun, + Tremor, + Shake, + TremorAndShake, + StunAndShake +}