* spectra * documentation * added into liquid anomaly * Update TemporaryStealthComponent.cs * Update TemporaryStealthComponent.cs * integrated * new system * mark old status effect system as obsolete * ForcedSleeping new status effect * work with reagents * networking??? * Revert "integrated" This reverts commit bca02b82bae18ae131af593d7eb86e6de2745157. * Revert "Update TemporaryStealthComponent.cs" This reverts commit 4a5be8c4b704a0d1ff9544b2e245d8b2701ec580. * Revert "Update TemporaryStealthComponent.cs" This reverts commit a4875bcb41347638854bd723d96a51c3e6d38034. * Revert "added into liquid anomaly" This reverts commit df5086b14bb35f1467158a36807c0f2163a16d99. * Revert "documentation" This reverts commit 3629b9466758cbdfa4dd5e67ece122fa2f181138. * Revert "spectra" This reverts commit 2d03d88c16d16ad6831c19a7921b84600daeb284. * drowsiness status effect remove * reagents work * polish, remove test changes * first Fildrance review part * Update misc.yml * more fildrance review * final part * fix trailing spaces * sleeping status effect * drowsiness status effect * Create ModifyStatusEffect.cs * some tweak * Yay!!! Manual networking * minor nitpick * oopsie * refactor: xml-docs, notnullwhen attributes, whitespaces * fildrance and emo review * refactor: simplify check in SharedStatusEffectsSystem by using pattern matching, TryEffectsWithComp now returns set of Entity<T, StatusEffectComponent> --------- Co-authored-by: pa.pecherskij <pa.pecherskij@interfax.ru>
94 lines
3.3 KiB
C#
94 lines
3.3 KiB
C#
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;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Content.Client.Drowsiness;
|
|
|
|
public sealed class DrowsinessOverlay : Overlay
|
|
{
|
|
[Dependency] private readonly IEntityManager _entityManager = default!;
|
|
[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;
|
|
private readonly ShaderInstance _drowsinessShader;
|
|
|
|
private EntityQuery<StatusEffectComponent> _statusQuery;
|
|
|
|
public float CurrentPower = 0.0f;
|
|
|
|
private const float PowerDivisor = 250.0f;
|
|
private const float Intensity = 0.2f; // for adjusting the visual scale
|
|
private float _visualScale = 0; // between 0 and 1
|
|
|
|
public DrowsinessOverlay()
|
|
{
|
|
IoCManager.InjectDependencies(this);
|
|
_statusEffects = _sysMan.GetEntitySystem<SharedStatusEffectsSystem>();
|
|
|
|
_statusQuery = _entityManager.GetEntityQuery<StatusEffectComponent>();
|
|
_drowsinessShader = _prototypeManager.Index<ShaderPrototype>("Drowsiness").InstanceUnique();
|
|
}
|
|
|
|
protected override void FrameUpdate(FrameEventArgs args)
|
|
{
|
|
var playerEntity = _playerManager.LocalEntity;
|
|
|
|
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)
|
|
return;
|
|
|
|
var curTime = _timing.CurTime;
|
|
var timeLeft = (float)(remainingTime - curTime).Value.TotalSeconds;
|
|
|
|
CurrentPower += 8f * (0.5f * timeLeft - CurrentPower) * args.DeltaSeconds / (timeLeft + 1);
|
|
}
|
|
|
|
protected override bool BeforeDraw(in OverlayDrawArgs args)
|
|
{
|
|
if (!_entityManager.TryGetComponent(_playerManager.LocalEntity, out EyeComponent? eyeComp))
|
|
return false;
|
|
|
|
if (args.Viewport.Eye != eyeComp.Eye)
|
|
return false;
|
|
|
|
_visualScale = Math.Clamp(CurrentPower / PowerDivisor, 0.0f, 1.0f);
|
|
return _visualScale > 0;
|
|
}
|
|
|
|
protected override void Draw(in OverlayDrawArgs args)
|
|
{
|
|
if (ScreenTexture == null)
|
|
return;
|
|
|
|
var handle = args.WorldHandle;
|
|
_drowsinessShader.SetParameter("SCREEN_TEXTURE", ScreenTexture);
|
|
_drowsinessShader.SetParameter("Strength", _visualScale * Intensity);
|
|
handle.UseShader(_drowsinessShader);
|
|
handle.DrawRect(args.WorldBounds, Color.White);
|
|
handle.UseShader(null);
|
|
}
|
|
}
|