Хотфикс (#242)

* hotfix

* fix
This commit is contained in:
CaypenNow
2024-03-24 18:03:56 +05:00
committed by GitHub
parent 5f01622a07
commit d177127b99
3 changed files with 16 additions and 20 deletions

View File

@@ -1,3 +1,4 @@
using System.Threading;
using Robust.Shared.GameStates; using Robust.Shared.GameStates;
namespace Content.Shared.Chemistry.Components namespace Content.Shared.Chemistry.Components
@@ -6,6 +7,9 @@ namespace Content.Shared.Chemistry.Components
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] [RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
public sealed partial class MovespeedModifierMetabolismComponent : Component public sealed partial class MovespeedModifierMetabolismComponent : Component
{ {
[ViewVariables, DataField]
public CancellationTokenSource CancelTokenSource = new();
[AutoNetworkedField, ViewVariables] [AutoNetworkedField, ViewVariables]
public float WalkSpeedModifier { get; set; } public float WalkSpeedModifier { get; set; }
@@ -15,7 +19,7 @@ namespace Content.Shared.Chemistry.Components
/// <summary> /// <summary>
/// When the current modifier is expected to end. /// When the current modifier is expected to end.
/// </summary> /// </summary>
[AutoNetworkedField, ViewVariables] [AutoNetworkedField, ViewVariables] // WD EDIT
public TimeSpan ModifierTimer { get; set; } = TimeSpan.Zero; public TimeSpan ModifierTimer { get; set; } = TimeSpan.Zero;
} }
} }

View File

@@ -23,7 +23,7 @@ public sealed class NarcoticEffect : EntitySystem
base.Initialize(); base.Initialize();
SubscribeLocalEvent<NarcoticEffectComponent, ComponentInit>(OnInit); SubscribeLocalEvent<NarcoticEffectComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<NarcoticEffectComponent, ComponentRemove>(OnRemove); SubscribeLocalEvent<MovespeedModifierMetabolismComponent, ComponentRemove>(OnRemove);
} }
private void OnInit(EntityUid uid, NarcoticEffectComponent component, ComponentInit args) private void OnInit(EntityUid uid, NarcoticEffectComponent component, ComponentInit args)
@@ -33,34 +33,29 @@ public sealed class NarcoticEffect : EntitySystem
Effects(uid, component, index); Effects(uid, component, index);
} }
private void OnRemove(EntityUid uid, NarcoticEffectComponent component, ComponentRemove args) private void OnRemove(EntityUid uid, MovespeedModifierMetabolismComponent component, ComponentRemove args)
{ {
if (TryComp<MovespeedModifierMetabolismComponent>(uid, out var movespeedModifierComponent))
{
if (movespeedModifierComponent.ModifierTimer != TimeSpan.Zero)
Timer.Spawn(movespeedModifierComponent.ModifierTimer, () => component.CancelTokenSource.Cancel());
return;
}
component.CancelTokenSource.Cancel(); component.CancelTokenSource.Cancel();
} }
private void Effects(EntityUid uid, NarcoticEffectComponent component, int index) private void Effects(EntityUid uid, NarcoticEffectComponent component, int index)
{ {
if(!TryComp<StandingStateComponent>(uid, out var standingComp)) if(!TryComp<StandingStateComponent>(uid, out var standingComp) || !TryComp<MovespeedModifierMetabolismComponent>(uid, out var movespeedModifierComponent))
return; return;
RaiseLocalEvent(uid, new MoodEffectEvent("Stimulator"));
CancellationToken token = component.CancelTokenSource.Token;
TryComp<StatusEffectsComponent>(uid, out var statusEffectsComp); TryComp<StatusEffectsComponent>(uid, out var statusEffectsComp);
RaiseLocalEvent(uid, new MoodEffectEvent("Stimulator"));
CancellationToken token = movespeedModifierComponent.CancelTokenSource.Token;
int timer = component.TimerInterval[_robustRandom.Next(0, component.TimerInterval.Count)]; int timer = component.TimerInterval[_robustRandom.Next(0, component.TimerInterval.Count)];
int slur = component.SlurTime[_robustRandom.Next(0, component.SlurTime.Count)]; int slur = component.SlurTime[_robustRandom.Next(0, component.SlurTime.Count)];
switch (Enum.GetValues(typeof(NarcoticEffects)).GetValue(index)) switch (Enum.GetValues(typeof(NarcoticEffects)).GetValue(index))
{ {
case NarcoticEffects.TremorAndShake when _statusEffectsSystem.HasStatusEffect(uid, "Drunk", statusEffectsComp): case NarcoticEffects.TremorAndShake when _statusEffectsSystem.HasStatusEffect(uid, "Drunk", statusEffectsComp):
Timer.SpawnRepeating(timer, () => _stamina.TakeStaminaDamage(uid, 15F), token); Timer.SpawnRepeating(timer, () => _stamina.TakeStaminaDamage(uid, 25F), token);
_statusEffectsSystem.TryAddTime(uid, "Drunk", TimeSpan.FromSeconds(slur), statusEffectsComp); _statusEffectsSystem.TryAddTime(uid, "Drunk", TimeSpan.FromSeconds(slur), statusEffectsComp);
break; break;
@@ -78,12 +73,12 @@ public sealed class NarcoticEffect : EntitySystem
break; break;
case NarcoticEffects.TremorAndShake: case NarcoticEffects.TremorAndShake:
Timer.SpawnRepeating(timer, () => _stamina.TakeStaminaDamage(uid, 15F), token); Timer.SpawnRepeating(timer, () => _stamina.TakeStaminaDamage(uid, 25F), token);
_statusEffectsSystem.TryAddStatusEffect<DrunkComponent>(uid, "Drunk", TimeSpan.FromSeconds(slur), true, statusEffectsComp); _statusEffectsSystem.TryAddStatusEffect<DrunkComponent>(uid, "Drunk", TimeSpan.FromSeconds(slur), true, statusEffectsComp);
break; break;
case NarcoticEffects.Tremor: case NarcoticEffects.Tremor:
Timer.SpawnRepeating(timer, () => _stamina.TakeStaminaDamage(uid, 15F), token); Timer.SpawnRepeating(timer, () => _stamina.TakeStaminaDamage(uid, 25F), token);
break; break;
case NarcoticEffects.Shake: case NarcoticEffects.Shake:

View File

@@ -9,11 +9,8 @@ namespace Content.Shared._White.Chemistry;
[RegisterComponent] [RegisterComponent]
public sealed partial class NarcoticEffectComponent : Component public sealed partial class NarcoticEffectComponent : Component
{ {
[ViewVariables(VVAccess.ReadWrite), DataField]
public CancellationTokenSource CancelTokenSource = new();
[ViewVariables(VVAccess.ReadOnly), DataField] [ViewVariables(VVAccess.ReadOnly), DataField]
public List<int> TimerInterval = new() { 3000, 6000, 3800, 7000, 5000 }; public List<int> TimerInterval = new() { 8000, 12000, 10000, 12500, 10500 };
[ViewVariables(VVAccess.ReadOnly), DataField] [ViewVariables(VVAccess.ReadOnly), DataField]
public List<int> SlurTime = new() { 35, 60, 80, 90, 45 }; public List<int> SlurTime = new() { 35, 60, 80, 90, 45 };