-using Content.Shared.Bed.Sleep;
using Content.Shared.Drowsiness;
using Content.Shared.StatusEffectNew;
-using Content.Shared.StatusEffectNew.Components;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Shared.Enums;
public override bool RequestScreenTexture => true;
private readonly ShaderInstance _drowsinessShader;
- private EntityQuery<StatusEffectComponent> _statusQuery;
-
public float CurrentPower = 0.0f;
private const float PowerDivisor = 250.0f;
public DrowsinessOverlay()
{
IoCManager.InjectDependencies(this);
+
_statusEffects = _sysMan.GetEntitySystem<SharedStatusEffectsSystem>();
- _statusQuery = _entityManager.GetEntityQuery<StatusEffectComponent>();
_drowsinessShader = _prototypeManager.Index<ShaderPrototype>("Drowsiness").InstanceUnique();
}
if (playerEntity == null)
return;
- if (!_statusEffects.TryEffectsWithComp<DrowsinessStatusEffectComponent>(playerEntity, out var drowsinessEffects))
- return;
-
- TimeSpan? remainingTime = TimeSpan.Zero;
- foreach (var (_, _, statusEffectComp) in drowsinessEffects)
- {
- if (statusEffectComp.EndEffectTime > remainingTime)
- remainingTime = statusEffectComp.EndEffectTime;
- }
-
- if (remainingTime is null)
+ if (!_statusEffects.TryGetEffectsEndTimeWithComp<DrowsinessStatusEffectComponent>(playerEntity, out var endTime))
return;
- var curTime = _timing.CurTime;
- var timeLeft = (float)(remainingTime - curTime).Value.TotalSeconds;
-
+ endTime ??= TimeSpan.MaxValue;
+ var timeLeft = (float)(endTime - _timing.CurTime).Value.TotalSeconds;
CurrentPower += 8f * (0.5f * timeLeft - CurrentPower) * args.DeltaSeconds / (timeLeft + 1);
}
using Content.Shared.Drugs;
+using Content.Shared.StatusEffectNew;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Shared.Player;
private RainbowOverlay _overlay = default!;
- public static string RainbowKey = "SeeingRainbows";
-
public override void Initialize()
{
base.Initialize();
- SubscribeLocalEvent<SeeingRainbowsComponent, ComponentInit>(OnInit);
- SubscribeLocalEvent<SeeingRainbowsComponent, ComponentShutdown>(OnShutdown);
+ SubscribeLocalEvent<SeeingRainbowsStatusEffectComponent, StatusEffectAppliedEvent>(OnApplied);
+ SubscribeLocalEvent<SeeingRainbowsStatusEffectComponent, StatusEffectRemovedEvent>(OnRemoved);
- SubscribeLocalEvent<SeeingRainbowsComponent, LocalPlayerAttachedEvent>(OnPlayerAttached);
- SubscribeLocalEvent<SeeingRainbowsComponent, LocalPlayerDetachedEvent>(OnPlayerDetached);
+ SubscribeLocalEvent<SeeingRainbowsStatusEffectComponent, StatusEffectRelayedEvent<LocalPlayerAttachedEvent>>(OnPlayerAttached);
+ SubscribeLocalEvent<SeeingRainbowsStatusEffectComponent, StatusEffectRelayedEvent<LocalPlayerDetachedEvent>>(OnPlayerDetached);
_overlay = new();
}
- private void OnPlayerAttached(EntityUid uid, SeeingRainbowsComponent component, LocalPlayerAttachedEvent args)
+ private void OnRemoved(Entity<SeeingRainbowsStatusEffectComponent> ent, ref StatusEffectRemovedEvent args)
{
- _overlayMan.AddOverlay(_overlay);
- }
+ if (_player.LocalEntity != args.Target)
+ return;
- private void OnPlayerDetached(EntityUid uid, SeeingRainbowsComponent component, LocalPlayerDetachedEvent args)
- {
_overlay.Intoxication = 0;
_overlay.TimeTicker = 0;
_overlayMan.RemoveOverlay(_overlay);
}
- private void OnInit(EntityUid uid, SeeingRainbowsComponent component, ComponentInit args)
+ private void OnApplied(Entity<SeeingRainbowsStatusEffectComponent> ent, ref StatusEffectAppliedEvent args)
{
- if (_player.LocalEntity == uid)
- {
- _overlay.Phase = _random.NextFloat(MathF.Tau); // random starting phase for movement effect
- _overlayMan.AddOverlay(_overlay);
- }
+ if (_player.LocalEntity != args.Target)
+ return;
+
+ _overlay.Phase = _random.NextFloat(MathF.Tau); // random starting phase for movement effect
+ _overlayMan.AddOverlay(_overlay);
}
- private void OnShutdown(EntityUid uid, SeeingRainbowsComponent component, ComponentShutdown args)
+ private void OnPlayerAttached(Entity<SeeingRainbowsStatusEffectComponent> ent, ref StatusEffectRelayedEvent<LocalPlayerAttachedEvent> args)
{
- if (_player.LocalEntity == uid)
- {
- _overlay.Intoxication = 0;
- _overlay.TimeTicker = 0;
- _overlayMan.RemoveOverlay(_overlay);
- }
+ _overlayMan.AddOverlay(_overlay);
+ }
+
+ private void OnPlayerDetached(Entity<SeeingRainbowsStatusEffectComponent> ent, ref StatusEffectRelayedEvent<LocalPlayerDetachedEvent> args)
+ {
+ _overlay.Intoxication = 0;
+ _overlay.TimeTicker = 0;
+ _overlayMan.RemoveOverlay(_overlay);
}
}
using Content.Shared.CCVar;
using Content.Shared.Drugs;
-using Content.Shared.StatusEffect;
+using Content.Shared.StatusEffectNew;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Shared.Configuration;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IEntitySystemManager _sysMan = default!;
+ [Dependency] private readonly IGameTiming _timing = default!;
+ private readonly SharedStatusEffectsSystem _statusEffects = default!;
public override OverlaySpace Space => OverlaySpace.WorldSpace;
public override bool RequestScreenTexture => true;
{
IoCManager.InjectDependencies(this);
+ _statusEffects = _sysMan.GetEntitySystem<SharedStatusEffectsSystem>();
+
_rainbowShader = _prototypeManager.Index<ShaderPrototype>("Rainbow").InstanceUnique();
_config.OnValueChanged(CCVars.ReducedMotion, OnReducedMotionChanged, invokeImmediately: true);
}
if (playerEntity == null)
return;
- if (!_entityManager.HasComponent<SeeingRainbowsComponent>(playerEntity)
- || !_entityManager.TryGetComponent<StatusEffectsComponent>(playerEntity, out var status))
- return;
-
- var statusSys = _sysMan.GetEntitySystem<StatusEffectsSystem>();
- if (!statusSys.TryGetTime(playerEntity.Value, DrugOverlaySystem.RainbowKey, out var time, status))
+ if (!_statusEffects.TryGetEffectsEndTimeWithComp<SeeingRainbowsStatusEffectComponent>(playerEntity, out var endTime))
return;
- var timeLeft = (float)(time.Value.Item2 - time.Value.Item1).TotalSeconds;
+ endTime ??= TimeSpan.MaxValue;
+ var timeLeft = (float)(endTime - _timing.CurTime).Value.TotalSeconds;
TimeTicker += args.DeltaSeconds;
-
if (timeLeft - TimeTicker > timeLeft / 16f)
{
Intoxication += (timeLeft - Intoxication) * args.DeltaSeconds / 16f;
namespace Content.Shared.Drugs;
/// <summary>
-/// Exists for use as a status effect. Adds a shader to the client that scales with the effect duration.
+/// Adds a shader to the client that scales with the effect duration.
+/// Use only in conjunction with <see cref="StatusEffectComponent"/>, on the status effect entity.
/// </summary>
[RegisterComponent, NetworkedComponent]
-public sealed partial class SeeingRainbowsComponent : Component { }
+public sealed partial class SeeingRainbowsStatusEffectComponent : Component;
foreach (var effect in container.ActiveStatusEffects)
{
- if (!TryComp<StatusEffectComponent>(effect, out var statusComp))
+ if (!_effectQuery.TryComp(effect, out var statusComp))
continue;
if (TryComp<T>(effect, out var comp))
}
}
- return effects != null;
+ return effects is not null;
+ }
+
+ /// <summary>
+ /// Helper function for calculating how long it takes for all effects with a particular component to disappear. Useful for overlays.
+ /// </summary>
+ /// <param name="target">An entity from which status effects are checked.</param>
+ /// <param name="endTime">The farthest end time of effects with this component is returned. Can be null if one of the effects is infinite.</param>
+ /// <returns>True if effects with the specified component were found, or False if there are no such effects.</returns>
+ public bool TryGetEffectsEndTimeWithComp<T>(EntityUid? target, out TimeSpan? endTime) where T : IComponent
+ {
+ endTime = _timing.CurTime;
+ if (!_containerQuery.TryComp(target, out var container))
+ return false;
+
+ foreach (var effect in container.ActiveStatusEffects)
+ {
+ if (!HasComp<T>(effect))
+ continue;
+
+ if (!_effectQuery.TryComp(effect, out var statusComp))
+ continue;
+
+ if (statusComp.EndEffectTime is null)
+ {
+ endTime = null;
+ return true; //This effect never ends, so we return null at endTime, but return true that there is time.
+ }
+
+ if (statusComp.EndEffectTime > endTime)
+ endTime = statusComp.EndEffectTime;
+ }
+
+ return endTime is not null;
}
}
- KnockedDown
- SlowedDown
- Stutter
- - SeeingRainbows
- Electrocution
- Drunk
- SlurredSpeech
name: drowsiness
components:
- type: DrowsinessStatusEffect
+
+# Adds drugs overlay
+- type: entity
+ parent: MobStatusEffectBase
+ id: StatusEffectSeeingRainbow
+ name: hallucinations
+ components:
+ - type: SeeingRainbowsStatusEffect
\ No newline at end of file
- !type:AdjustReagent
reagent: Ethanol
amount: 0.05
- - !type:GenericStatusEffect
+ - !type:ModifyStatusEffect
+ effectProto: StatusEffectSeeingRainbow
conditions:
- !type:ReagentThreshold
min: 10
- key: SeeingRainbows
- component: SeeingRainbows
type: Add
time: 5
refresh: false
metabolisms:
Narcotic:
effects:
- - !type:GenericStatusEffect
- key: SeeingRainbows
- component: SeeingRainbows
- type: Add
+ - !type:ModifyStatusEffect
+ effectProto: StatusEffectSeeingRainbow
time: 5
+ type: Add
refresh: false
Drink:
effects:
damage:
types:
Cellular: 1
- - !type:GenericStatusEffect
- key: SeeingRainbows
- component: SeeingRainbows
+ - !type:ModifyStatusEffect
+ effectProto: StatusEffectSeeingRainbow
type: Add
time: 15
refresh: false
damage:
types:
Cellular: 0.5
- - !type:GenericStatusEffect
+ - !type:ModifyStatusEffect
conditions:
- !type:ReagentThreshold
reagent: Frezon
min: 1
- key: SeeingRainbows
- component: SeeingRainbows
+ effectProto: StatusEffectSeeingRainbow
type: Add
time: 500
refresh: false
key: KnockedDown
time: 3.0
type: Remove
- - !type:GenericStatusEffect
- key: SeeingRainbows
+ - !type:ModifyStatusEffect
+ effectProto: StatusEffectSeeingRainbow
time: 15.0
type: Remove
damage:
types:
Poison: 2
- - !type:GenericStatusEffect
+ - !type:ModifyStatusEffect
+ effectProto: StatusEffectSeeingRainbow
conditions:
- !type:ReagentThreshold
min: 30
- key: SeeingRainbows
- component: SeeingRainbows
type: Add
time: 8
refresh: false
key: Jitter
time: 4.0
type: Remove
- - !type:GenericStatusEffect
- key: SeeingRainbows
+ - !type:ModifyStatusEffect
+ effectProto: StatusEffectSeeingRainbow
time: 10.0
type: Remove
- !type:AdjustReagent
metabolisms:
Narcotic:
effects:
- - !type:GenericStatusEffect
- key: SeeingRainbows
- component: SeeingRainbows
- type: Add
+ - !type:ModifyStatusEffect
+ effectProto: StatusEffectSeeingRainbow
time: 16
+ type: Add
refresh: false
- type: reagent
damage:
types:
Poison: 2
- - !type:GenericStatusEffect
- key: SeeingRainbows
- component: SeeingRainbows
- type: Add
+ - !type:ModifyStatusEffect
+ effectProto: StatusEffectSeeingRainbow
time: 10
+ type: Add
refresh: false
- !type:ChemVomit # Vomiting is a symptom of brain damage
probability: 0.05
metabolisms:
Narcotic:
effects:
- - !type:GenericStatusEffect
- key: SeeingRainbows
- component: SeeingRainbows
+ - !type:ModifyStatusEffect
+ effectProto: StatusEffectSeeingRainbow
type: Add
time: 5
refresh: false
metabolisms:
Narcotic:
effects:
- - !type:GenericStatusEffect
- key: SeeingRainbows
- component: SeeingRainbows
+ - !type:ModifyStatusEffect
+ effectProto: StatusEffectSeeingRainbow
type: Add
time: 5
refresh: false
conditions:
- !type:ReagentThreshold
max: 20
- - !type:GenericStatusEffect
- key: SeeingRainbows
- component: SeeingRainbows
+ - !type:ModifyStatusEffect
+ effectProto: StatusEffectSeeingRainbow
type: Add
time: 5
refresh: false
metabolisms:
Poison:
effects:
- - !type:GenericStatusEffect
- key: SeeingRainbows
- component: SeeingRainbows
+ - !type:ModifyStatusEffect
+ effectProto: StatusEffectSeeingRainbow
type: Add
time: 10
refresh: false
- type: statusEffect
id: AllCaps
-- type: statusEffect
- id: SeeingRainbows
-
- type: statusEffect
id: Electrocution