Files

81 lines
3.4 KiB
C#
Raw Permalink Normal View History

using System.Threading;
using Content.Shared._White.Mood;
2024-03-24 13:21:11 +05:00
using Content.Shared.Chemistry.Components;
using Content.Shared.Damage.Systems;
using Content.Shared.Drugs;
2024-03-21 14:01:32 +05:00
using Content.Shared.Drunk;
2024-03-23 16:25:36 +05:00
using Content.Shared.Standing;
using Content.Shared.Standing.Systems;
2024-03-21 14:01:32 +05:00
using Content.Shared.StatusEffect;
using Robust.Shared.Random;
using Timer = Robust.Shared.Timing.Timer;
2024-03-23 16:25:36 +05:00
namespace Content.Shared._White.Chemistry;
public sealed class NarcoticEffect : EntitySystem
{
[Dependency] private readonly IRobustRandom _robustRandom = default!;
2024-03-21 14:01:32 +05:00
[Dependency] private readonly StatusEffectsSystem _statusEffectsSystem = default!;
[Dependency] private readonly StaminaSystem _stamina = default!;
[Dependency] private readonly SharedStandingStateSystem _standingStateSystem = default!;
/// <inheritdoc/>
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<NarcoticEffectComponent, ComponentInit>(OnInit);
2024-03-24 18:03:56 +05:00
SubscribeLocalEvent<MovespeedModifierMetabolismComponent, ComponentRemove>(OnRemove);
}
private void OnInit(EntityUid uid, NarcoticEffectComponent component, ComponentInit args)
{
2024-03-22 13:39:56 +05:00
int index = _robustRandom.Next(0, Enum.GetNames(typeof(NarcoticEffects)).Length);
Effects(uid, component, index);
}
2024-03-24 18:03:56 +05:00
private void OnRemove(EntityUid uid, MovespeedModifierMetabolismComponent component, ComponentRemove args)
{
2024-03-22 13:39:56 +05:00
component.CancelTokenSource.Cancel();
}
private void Effects(EntityUid uid, NarcoticEffectComponent component, int index)
{
2024-03-24 18:03:56 +05:00
if(!TryComp<StandingStateComponent>(uid, out var standingComp) || !TryComp<MovespeedModifierMetabolismComponent>(uid, out var movespeedModifierComponent))
2024-03-23 16:25:36 +05:00
return;
2024-03-24 18:03:56 +05:00
TryComp<StatusEffectsComponent>(uid, out var statusEffectsComp);
CancellationToken token = movespeedModifierComponent.CancelTokenSource.Token;
2024-03-21 14:01:32 +05:00
int timer = component.TimerInterval[_robustRandom.Next(0, component.TimerInterval.Count)];
int slur = component.SlurTime[_robustRandom.Next(0, component.SlurTime.Count)];
2024-03-22 13:39:56 +05:00
switch (Enum.GetValues(typeof(NarcoticEffects)).GetValue(index))
{
2024-03-22 13:39:56 +05:00
case NarcoticEffects.Shake when _statusEffectsSystem.HasStatusEffect(uid, "Drunk", statusEffectsComp):
2024-03-21 14:07:43 +05:00
_statusEffectsSystem.TryAddTime(uid, "Drunk", TimeSpan.FromSeconds(slur), statusEffectsComp);
break;
case NarcoticEffects.LieDownAndShake when _statusEffectsSystem.HasStatusEffect(uid, "Drunk", statusEffectsComp):
2024-03-24 13:21:11 +05:00
Timer.SpawnRepeating(timer, () => _standingStateSystem.TryLieDown(uid, standingComp), token);
2024-03-21 14:07:43 +05:00
_statusEffectsSystem.TryAddTime(uid, "Drunk", TimeSpan.FromSeconds(slur), statusEffectsComp);
break;
case NarcoticEffects.LieDown:
2024-03-24 13:21:11 +05:00
Timer.SpawnRepeating(timer, () => _standingStateSystem.TryLieDown(uid, standingComp), token);
break;
2024-03-22 13:39:56 +05:00
case NarcoticEffects.Shake:
2024-03-21 14:01:32 +05:00
_statusEffectsSystem.TryAddStatusEffect<DrunkComponent>(uid, "Drunk", TimeSpan.FromSeconds(slur), true, statusEffectsComp);
break;
case NarcoticEffects.LieDownAndShake:
2024-03-24 13:21:11 +05:00
Timer.SpawnRepeating(timer, () => _standingStateSystem.TryLieDown(uid, standingComp), token);
2024-03-21 14:01:32 +05:00
_statusEffectsSystem.TryAddStatusEffect<DrunkComponent>(uid, "Drunk", TimeSpan.FromSeconds(slur), true, statusEffectsComp);
break;
}
}
}