2024-03-21 13:11:08 +05:00
|
|
|
|
using System.Threading;
|
|
|
|
|
|
using Content.Shared._White.Mood;
|
2024-03-24 13:21:11 +05:00
|
|
|
|
using Content.Shared.Chemistry.Components;
|
2024-03-21 13:11:08 +05:00
|
|
|
|
using Content.Shared.Damage.Systems;
|
2024-03-27 09:35:15 +05:00
|
|
|
|
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;
|
2024-04-22 22:14:23 +07:00
|
|
|
|
using Content.Shared.Standing.Systems;
|
2024-03-21 14:01:32 +05:00
|
|
|
|
using Content.Shared.StatusEffect;
|
2024-03-21 13:11:08 +05:00
|
|
|
|
using Robust.Shared.Random;
|
|
|
|
|
|
using Timer = Robust.Shared.Timing.Timer;
|
|
|
|
|
|
|
2024-03-23 16:25:36 +05:00
|
|
|
|
namespace Content.Shared._White.Chemistry;
|
2024-03-21 13:11:08 +05:00
|
|
|
|
|
|
|
|
|
|
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!;
|
2024-03-21 13:11:08 +05:00
|
|
|
|
[Dependency] private readonly StaminaSystem _stamina = default!;
|
2024-04-22 22:14:23 +07:00
|
|
|
|
[Dependency] private readonly SharedStandingStateSystem _standingStateSystem = default!;
|
2024-03-21 13:11:08 +05:00
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<NarcoticEffectComponent, ComponentInit>(OnInit);
|
2024-03-24 18:03:56 +05:00
|
|
|
|
SubscribeLocalEvent<MovespeedModifierMetabolismComponent, ComponentRemove>(OnRemove);
|
2024-03-21 13:11:08 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
2024-03-21 13:11:08 +05:00
|
|
|
|
|
|
|
|
|
|
Effects(uid, component, index);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-24 18:03:56 +05:00
|
|
|
|
private void OnRemove(EntityUid uid, MovespeedModifierMetabolismComponent component, ComponentRemove args)
|
2024-03-21 13:11:08 +05:00
|
|
|
|
{
|
2024-03-22 13:39:56 +05:00
|
|
|
|
component.CancelTokenSource.Cancel();
|
2024-03-21 13:11:08 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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-21 13:11:08 +05:00
|
|
|
|
{
|
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;
|
|
|
|
|
|
|
2024-03-27 09:35:15 +05:00
|
|
|
|
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;
|
|
|
|
|
|
|
2024-03-27 09:35:15 +05:00
|
|
|
|
case NarcoticEffects.LieDown:
|
2024-03-24 13:21:11 +05:00
|
|
|
|
Timer.SpawnRepeating(timer, () => _standingStateSystem.TryLieDown(uid, standingComp), token);
|
2024-03-21 13:11:08 +05:00
|
|
|
|
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);
|
2024-03-21 13:11:08 +05:00
|
|
|
|
break;
|
|
|
|
|
|
|
2024-03-27 09:35:15 +05:00
|
|
|
|
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);
|
2024-03-21 13:11:08 +05:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|