Skip to content

Commit

Permalink
Mochromacy & SeeingStatic
Browse files Browse the repository at this point in the history
  • Loading branch information
nixsilvam404 committed Aug 5, 2024
1 parent 5a576bb commit f62493a
Show file tree
Hide file tree
Showing 14 changed files with 357 additions and 7 deletions.
46 changes: 46 additions & 0 deletions Content.Client/ADT/Overlays/Shaders/MonochromacyOverlay.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Simple Station

using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Shared.Enums;
using Robust.Shared.Prototypes;
using Content.Shared.ADT.Traits;
using Matrix3x2 = System.Numerics.Matrix3x2;

namespace Content.Client.ADT.Overlays
{
public sealed partial class MonochromacyOverlay : Overlay
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] IEntityManager _entityManager = default!;


public override bool RequestScreenTexture => true;
public override OverlaySpace Space => OverlaySpace.WorldSpace;
private readonly ShaderInstance _greyscaleShader;

public MonochromacyOverlay()
{
IoCManager.InjectDependencies(this);
_greyscaleShader = _prototypeManager.Index<ShaderPrototype>("GreyscaleFullscreen").InstanceUnique();
}

protected override void Draw(in OverlayDrawArgs args)
{
if (ScreenTexture == null) return;
if (_playerManager.LocalPlayer?.ControlledEntity is not { Valid: true } player) return;
if (!_entityManager.HasComponent<MonochromacyComponent>(player)) return;

_greyscaleShader?.SetParameter("SCREEN_TEXTURE", ScreenTexture);


var worldHandle = args.WorldHandle;
var viewport = args.WorldBounds;
worldHandle.SetTransform(Matrix3x2.Identity);
worldHandle.UseShader(_greyscaleShader);
worldHandle.DrawRect(viewport, Color.White);
worldHandle.UseShader(null);
}
}
}
93 changes: 93 additions & 0 deletions Content.Client/ADT/Overlays/Shaders/StaticOverlay.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using Content.Shared.ADT.Silicon.Components;
using Content.Shared.ADT.Silicon.Systems;
using Content.Shared.StatusEffect;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Shared.Enums;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;


namespace Content.Client.ADT.Overlays.Shaders;

public sealed class StaticOverlay : Overlay
{
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;

public override OverlaySpace Space => OverlaySpace.WorldSpace;
public override bool RequestScreenTexture => true;
private readonly ShaderInstance _staticShader;

private (TimeSpan, TimeSpan)? _time;
private float? _fullTimeLeft;
private float? _curTimeLeft;

public float MixAmount = 0;

public StaticOverlay()
{
IoCManager.InjectDependencies(this);
_staticShader = _prototypeManager.Index<ShaderPrototype>("SeeingStatic").InstanceUnique();
}

protected override void FrameUpdate(FrameEventArgs args)
{
var playerEntity = _playerManager.LocalPlayer?.ControlledEntity;

if (playerEntity == null)
return;

if (!_entityManager.TryGetComponent<SeeingStaticComponent>(playerEntity, out var staticComp)
|| !_entityManager.TryGetComponent<StatusEffectsComponent>(playerEntity, out var statusComp))
return;

var status = _entityManager.EntitySysManager.GetEntitySystem<StatusEffectsSystem>();

if (playerEntity == null || statusComp == null)
return;

if (!status.TryGetTime(playerEntity.Value, SharedSeeingStaticSystem.StaticKey, out var timeTemp, statusComp))
return;

if (_time != timeTemp) // Resets the shader if the times change. This should factor in wheather it's a reset, or a increase, but I have a lot of cough syrup in me, so TODO.
{
_time = timeTemp;
_fullTimeLeft = null;
_curTimeLeft = null;
}

_fullTimeLeft ??= (float) (timeTemp.Value.Item2 - timeTemp.Value.Item1).TotalSeconds;
_curTimeLeft ??= _fullTimeLeft;

_curTimeLeft -= args.DeltaSeconds;

MixAmount = Math.Clamp(_curTimeLeft.Value / _fullTimeLeft.Value * staticComp.Multiplier, 0, 1);
}

protected override bool BeforeDraw(in OverlayDrawArgs args)
{
if (!_entityManager.TryGetComponent(_playerManager.LocalPlayer?.ControlledEntity, out EyeComponent? eyeComp))
return false;

if (args.Viewport.Eye != eyeComp.Eye)
return false;

return MixAmount > 0;
}

protected override void Draw(in OverlayDrawArgs args)
{
if (ScreenTexture == null)
return;

var handle = args.WorldHandle;
_staticShader.SetParameter("SCREEN_TEXTURE", ScreenTexture);
_staticShader.SetParameter("mixAmount", MixAmount);
handle.UseShader(_staticShader);
handle.DrawRect(args.WorldBounds, Color.White);
handle.UseShader(null);
}
}
56 changes: 56 additions & 0 deletions Content.Client/ADT/Overlays/Systems/MonochromacySystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Simple Station

using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Shared.Network;
using Content.Shared.ADT.Traits;
using Robust.Shared.Player;

namespace Content.Client.ADT.Overlays;
public sealed class MonochromacySystem : EntitySystem
{
[Dependency] private readonly IPlayerManager _player = default!;
[Dependency] private readonly IOverlayManager _overlayMan = default!;
[Dependency] private readonly INetManager _net = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;

private MonochromacyOverlay _overlay = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<MonochromacyComponent, ComponentStartup>(OnMonochromacyStartup);
SubscribeLocalEvent<MonochromacyComponent, ComponentShutdown>(OnMonochromacyShutdown);

SubscribeLocalEvent<MonochromacyComponent, PlayerAttachedEvent>(OnPlayerAttached);
SubscribeLocalEvent<MonochromacyComponent, PlayerDetachedEvent>(OnPlayerDetached);

_overlay = new();
}

private void OnMonochromacyStartup(EntityUid uid, MonochromacyComponent component, ComponentStartup args)
{
if (_player.LocalPlayer?.ControlledEntity == uid)
_overlayMan.AddOverlay(_overlay);
}

private void OnMonochromacyShutdown(EntityUid uid, MonochromacyComponent component, ComponentShutdown args)
{
if (_player.LocalPlayer?.ControlledEntity == uid)
{
_overlayMan.RemoveOverlay(_overlay);
}
}

private void OnPlayerAttached(EntityUid uid, MonochromacyComponent component, PlayerAttachedEvent args)
{
_overlayMan.AddOverlay(_overlay);
}

private void OnPlayerDetached(EntityUid uid, MonochromacyComponent component, PlayerDetachedEvent args)
{
_overlayMan.RemoveOverlay(_overlay);
}
}
57 changes: 57 additions & 0 deletions Content.Client/ADT/Overlays/Systems/SeeingStaticSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using Content.Client.ADT.Overlays.Shaders;
using Content.Shared.ADT.Silicon.Components;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Shared.Player;

namespace Content.Client.ADT.Overlays;

/// <summary>
/// System to handle the SeeingStatic overlay.
/// </summary>
public sealed class SeeingStaticSystem : EntitySystem
{
[Dependency] private readonly IPlayerManager _player = default!;
[Dependency] private readonly IOverlayManager _overlayMan = default!;

private StaticOverlay _overlay = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<SeeingStaticComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<SeeingStaticComponent, ComponentShutdown>(OnShutdown);

SubscribeLocalEvent<SeeingStaticComponent, LocalPlayerAttachedEvent>(OnPlayerAttached);
SubscribeLocalEvent<SeeingStaticComponent, LocalPlayerDetachedEvent>(OnPlayerDetached);

_overlay = new();
}

private void OnPlayerAttached(EntityUid uid, SeeingStaticComponent component, LocalPlayerAttachedEvent args)
{
_overlayMan.AddOverlay(_overlay);
}

private void OnPlayerDetached(EntityUid uid, SeeingStaticComponent component, LocalPlayerDetachedEvent args)
{
_overlay.MixAmount = 0;
_overlayMan.RemoveOverlay(_overlay);
}

private void OnInit(EntityUid uid, SeeingStaticComponent component, ComponentInit args)
{
if (_player.LocalPlayer?.ControlledEntity == uid)
_overlayMan.AddOverlay(_overlay);
}

private void OnShutdown(EntityUid uid, SeeingStaticComponent component, ComponentShutdown args)
{
if (_player.LocalPlayer?.ControlledEntity == uid)
{
_overlay.MixAmount = 0;
_overlayMan.RemoveOverlay(_overlay);
}
}
}
2 changes: 1 addition & 1 deletion Content.Server/ADT/Silicon/Systems/SiliconEmpSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private void OnEmpPulse(EntityUid uid, SiliconComponent component, ref EmpPulseE

_stun.TrySlowdown(uid, duration, true, _random.NextFloat(0.50f, 0.70f), _random.NextFloat(0.35f, 0.70f), statusComp);

_status.TryAddStatusEffect<SeeingStaticComponent>(uid, SeeingStaticSystem.StaticKey, duration, true, statusComp);
_status.TryAddStatusEffect<SeeingStaticComponent>(uid, SharedSeeingStaticSystem.StaticKey, duration, true, statusComp);

if (_random.Prob(0.60f))
_stuttering.DoStutter(uid, duration * 2, false, statusComp);
Expand Down
28 changes: 23 additions & 5 deletions Content.Server/Emp/EmpSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,31 @@ public override void Initialize()
/// <param name="duration">The duration of the EMP effects.</param>
public void EmpPulse(MapCoordinates coordinates, float range, float energyConsumption, float duration)
{
/*
foreach (var uid in _lookup.GetEntitiesInRange(coordinates, range))
{
var ev = new EmpPulseEvent(energyConsumption, false, false, TimeSpan.FromSeconds(duration)); // Parkstation-IPCs
TryEmpEffects(uid, energyConsumption, duration);
}
Spawn(EmpPulseEffectPrototype, coordinates);
*/

///ADT-Tweak IPC start
foreach (var uid in _lookup.GetEntitiesInRange(coordinates, range))
{
var ev = new EmpPulseEvent(energyConsumption, false, false, TimeSpan.FromSeconds(duration)); // Parkstation-IPCs
RaiseLocalEvent(uid, ref ev);
if (ev.Affected)
{
Spawn(EmpDisabledEffectPrototype, Transform(uid).Coordinates);
}
if (ev.Disabled)
{
var disabled = EnsureComp<EmpDisabledComponent>(uid);
disabled.DisabledUntil = Timing.CurTime + TimeSpan.FromSeconds(duration);
}
}
Spawn(EmpPulseEffectPrototype, coordinates);
///ADT-Tweak IPC end
}

/// <summary>
Expand Down Expand Up @@ -132,13 +151,12 @@ private void OnCameraSetActive(EntityUid uid, EmpDisabledComponent component, re
args.Cancelled = true;
}


///ADT ion start
///ADT ion start
private void OnProjectileHit(EntityUid uid, EmpOnCollideComponent component, ref ProjectileHitEvent args)
{
TryEmpEffects(args.Target, component.EnergyConsumption, component.DisableDuration);
}
///ADT ion end
///ADT ion end
}

/// <summary>
Expand All @@ -149,7 +167,7 @@ public sealed partial class EmpAttemptEvent : CancellableEntityEventArgs
}

[ByRefEvent]
public record struct EmpPulseEvent(float EnergyConsumption, bool Affected, bool Disabled, TimeSpan Duration);
public record struct EmpPulseEvent(float EnergyConsumption, bool Affected, bool Disabled, TimeSpan Duration); // Parkstation-IPCs

[ByRefEvent]
public record struct EmpDisabledRemoved();
2 changes: 1 addition & 1 deletion Content.Shared/ADT/Silicon/Systems/SeeingStaticSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Content.Shared.ADT.Silicon.Systems;

public sealed class SeeingStaticSystem : EntitySystem
public sealed class SharedSeeingStaticSystem : EntitySystem
{
public const string StaticKey = "SeeingStatic";
}
15 changes: 15 additions & 0 deletions Content.Shared/ADT/Traits/Components/MonochromacyComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Simple Station

using Robust.Shared.GameStates;

namespace Content.Shared.ADT.Traits
{
/// <summary>
/// Entity cannot see color.
/// </summary>
[RegisterComponent, NetworkedComponent]
public sealed partial class MonochromacyComponent : Component
{

}
}
2 changes: 2 additions & 0 deletions Resources/Locale/ru-RU/ADT/traits/disabilities.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
trait-monochromacy-name = Цветовая слепота
trait-monochromacy-description = Ваши глаза получили необратимые повреждения, из-за чего вы видите только в оттенках серого.
6 changes: 6 additions & 0 deletions Resources/Prototypes/ADT/Shaders/shaders.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Simple Station

- type: shader
id: SeeingStatic
kind: source
path: "/Textures/ADT/Shaders/seeing_static.swsl"
4 changes: 4 additions & 0 deletions Resources/Prototypes/ADT/StatusEffects/seeingstatic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Simple Station

- type: statusEffect
id: SeeingStatic
9 changes: 9 additions & 0 deletions Resources/Prototypes/ADT/Traits/disabilities.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Simple Station

- type: trait
id: ColorBlindnessMonochrome
name: trait-monochromacy-name
description: trait-monochromacy-description
category: Disabilities
components:
- type: Monochromacy
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
- KnockedDown
- SlowedDown
- Flashed
- SeeingStatic # ADT IPC (shaders)
- type: TypingIndicator
proto: robot
- type: Speech
Expand Down
Loading

0 comments on commit f62493a

Please sign in to comment.