Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions Content.Client/_Starlight/Overlay/Overlays/BaseVisionOverlay.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Shared.Enums;

namespace Content.Client._Starlight.Overlay;

/*
Time to mini rant here. this NEEDs to be a abstract because if its not, then
the overlay system will think its trying to apply multiple of the same overlay
Hence, itll remove all of them until theres only one, even if all the instances
youve added are different based on their fields. So to get around this,
we define all the actual BEHAVIOUR here, but then just make it appear as a new
type by inheriting from this and implementing nothing. Thanks Robust Toolbox team.
*/
public abstract class BaseVisionOverlay : Robust.Client.Graphics.Overlay
{
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;

public override bool RequestScreenTexture => true;
public override OverlaySpace Space => OverlaySpace.WorldSpace;
private protected readonly ShaderInstance _shader;
public BaseVisionOverlay(ShaderPrototype shader)
{
IoCManager.InjectDependencies(this);
_shader = shader.InstanceUnique();
}

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

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

var playerEntity = _playerManager.LocalSession?.AttachedEntity;

if (playerEntity == null)
return false;

return true;
}

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

var worldHandle = args.WorldHandle;
var viewport = args.WorldBounds;

_shader.SetParameter("SCREEN_TEXTURE", ScreenTexture);

worldHandle.UseShader(_shader);
worldHandle.DrawRect(viewport, Color.White);
worldHandle.UseShader(null);
}
}
9 changes: 9 additions & 0 deletions Content.Client/_Starlight/Overlay/Overlays/OverlayZIndexes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Content.Client._Starlight.Overlay;

//order doesnt matter here, we just need them to be unique
public enum OverlayZIndexes
{
SLNightVision = 10001,
ThermalVisionEntityHighlight,
ThermalVision,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Robust.Client.Graphics;

namespace Content.Client._Starlight.Overlay;

public sealed class SLNightVisionOverlay : BaseVisionOverlay
{
public SLNightVisionOverlay(ShaderPrototype shader) : base(shader)
=> ZIndex = (int?)OverlayZIndexes.SLNightVision;
}
96 changes: 96 additions & 0 deletions Content.Client/_Starlight/Overlay/Systems/SLNightVisionSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
using Content.Shared.Eye.Blinding.Components;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Content.Shared.Starlight.Overlay;

namespace Content.Client._Starlight.Overlay;

public sealed class SLNightVisionSystem : EntitySystem
{
[Dependency] private readonly IPlayerManager _player = default!;
[Dependency] private readonly IOverlayManager _overlayMan = default!;
[Dependency] private readonly TransformSystem _xformSys = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly FlashImmunitySystem _flashImmunity = default!;

private SLNightVisionOverlay _overlay = default!;
[ViewVariables]
private EntityUid? _effect = null;
private const string ModernSLNightVisionShaderPrototype = "ModernSLNightVisionShader";

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

SubscribeLocalEvent<SLNightVisionComponent, ComponentInit>(OnVisionInit);
SubscribeLocalEvent<SLNightVisionComponent, ComponentShutdown>(OnVisionShutdown);

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

SubscribeLocalEvent<SLNightVisionComponent, FlashImmunityCheckEvent>(OnFlashImmunityChanged);

_overlay = new(_prototypeManager.Index<ShaderPrototype>(ModernSLNightVisionShaderPrototype));
}

private void OnFlashImmunityChanged(Entity<SLNightVisionComponent> ent, ref FlashImmunityCheckEvent args)
{
if (args.IsImmune)
{
AttemptRemoveVision(ent.Owner);
}
else
{
AttemptAddVision(ent.Owner);
}
}

private void OnPlayerAttached(Entity<SLNightVisionComponent> ent, ref LocalPlayerAttachedEvent args)
=> AttemptAddVision(ent.Owner);

private void OnPlayerDetached(Entity<SLNightVisionComponent> ent, ref LocalPlayerDetachedEvent args)
=> AttemptRemoveVision(ent.Owner, true);

private void OnVisionInit(Entity<SLNightVisionComponent> ent, ref ComponentInit args)
=> AttemptAddVision(ent.Owner);

private void OnVisionShutdown(Entity<SLNightVisionComponent> ent, ref ComponentShutdown args)
=> AttemptRemoveVision(ent.Owner);

private void AttemptAddVision(EntityUid uid)
{
if (_player.LocalSession?.AttachedEntity != uid) return;

//if they currently have flash immunity, dont add
if (_flashImmunity.HasFlashImmunityVisionBlockers(uid)) return;

//only add if its active
if (!TryComp<SLNightVisionComponent>(uid, out var nightVision) || !nightVision.Active) return;

//only add if effect isnt already used
if (_effect != null) return;

_overlayMan.AddOverlay(_overlay);

_effect = SpawnAttachedTo(nightVision.EffectPrototype, Transform(uid).Coordinates);
_xformSys.SetParent(_effect.Value, uid);
}

/// <summary>
/// Attempt to remove the overlay from the local player.
/// </summary>
/// <param name="uid"></param>
/// <param name="force">Use if you need to forcefully remove the overlay no matter what. Only should be used with events that ONLY the local player can fire, like attach/detach</param>
private void AttemptRemoveVision(EntityUid uid, bool force = false)
{
//ENSURE this is the local player
if (_player.LocalSession?.AttachedEntity != uid && !force) return;

_overlayMan.RemoveOverlay(_overlay);
Del(_effect);
_effect = null;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using Robust.Shared.GameStates;

namespace Content.Server.Flash.Components;
namespace Content.Shared.Flash.Components;

// Starlight edit - moved this to Shared for BlocksSpecialVision
/// <summary>
/// Makes the entity immune to being flashed.
/// When given to clothes in the "head", "eyes" or "mask" slot it protects the wearer.
/// </summary>
[RegisterComponent] // Goob edit
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] // Goob and Starlight edit
public sealed partial class FlashImmunityComponent : Component
{
[ViewVariables(VVAccess.ReadWrite)]
Expand All @@ -16,4 +17,14 @@ public sealed partial class FlashImmunityComponent : Component
[ViewVariables(VVAccess.ReadWrite)]
[DataField("protectionRange")]
public float ProtectionRange { get; set; } = 0f;

//starlight
/// <summary>
/// If true, will affect night vision, thermal vision, and shadekin vision.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[AutoNetworkedField]
[DataField]
public bool BlocksSpecialVision { get; set; } = true;
//starlight end
}
8 changes: 8 additions & 0 deletions Content.Shared/Flash/Components/FlashModifierComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Content.Shared.Flash.Components;

[RegisterComponent]
public sealed partial class FlashModifierComponent : Component
{
[DataField]
public float Modifier = 1f;
}
15 changes: 15 additions & 0 deletions Content.Shared/Flash/SharedFlashSystem.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Shared._Goobstation.Flashbang;
using Content.Shared.Flash.Components;
using Content.Shared.StatusEffect;
using Robust.Shared.Audio;
Expand All @@ -9,6 +10,20 @@ public abstract class SharedFlashSystem : EntitySystem
{
public ProtoId<StatusEffectPrototype> FlashedKey = "Flashed";

// Starlight edit start - Flash multiplier
public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<FlashModifierComponent, FlashDurationMultiplierEvent>(OnFlashModifier);
}

private void OnFlashModifier(Entity<FlashModifierComponent> ent, ref FlashDurationMultiplierEvent args)
{
args.Multiplier *= ent.Comp.Modifier;
}
// Starlight edit end

public virtual void FlashArea(Entity<FlashComponent?> source, EntityUid? user, float range, float duration, float slowTo = 0.8f, bool displayPopup = false, float probability = 1f, SoundSpecifier? sound = null)
{
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;

namespace Content.Shared.Eye.Blinding.Components;

[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
public sealed partial class SLNightVisionComponent : Component
{
[DataField, AutoNetworkedField]
public bool Active = true;

[DataField]
public EntProtoId EffectPrototype = "EffectSLNightVision";

public bool Clothes;
}

[RegisterComponent]
public sealed partial class ClothesSLNightVisionComponent : Component
{ }
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Content.Shared.Starlight.Overlay;

public sealed class FlashImmunityCheckEvent : EntityEventArgs
{
public readonly EntityUid EntityUid;
public readonly bool IsImmune;

public FlashImmunityCheckEvent(EntityUid entityUid, bool isImmune)
{
EntityUid = entityUid;
IsImmune = isImmune;
}
}
40 changes: 40 additions & 0 deletions Content.Shared/_Starlight/Overlay/Systems/ClothesVisionSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Content.Shared.Inventory.Events;
using Content.Shared.Clothing.Components;
using Robust.Shared.Serialization.Manager;

namespace Content.Shared.Eye.Blinding.Components;

public sealed partial class ClothesVisionSystem : EntitySystem
{
[Dependency] private readonly ISerializationManager _serialization = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ClothesSLNightVisionComponent, GotEquippedEvent>(OnEquipped);
SubscribeLocalEvent<ClothesSLNightVisionComponent, GotUnequippedEvent>(OnUnequipped);
}

private void OnEquipped(EntityUid uid, ClothesSLNightVisionComponent component, GotEquippedEvent args)
{
if (!TryComp<ClothingComponent>(uid, out var clothing)
|| !clothing.Slots.HasFlag(args.SlotFlags))
return;

if (!HasComp<SLNightVisionComponent>(args.Equipee))
{
var nightvision = EnsureComp<SLNightVisionComponent>(args.Equipee);
nightvision.Clothes = true;
}
}

private void OnUnequipped(EntityUid uid, ClothesSLNightVisionComponent component, GotUnequippedEvent args)
{
if (TryComp<SLNightVisionComponent>(args.Equipee, out var nightvision) && !nightvision.Clothes)
{
nightvision.Clothes = false;
return;
}

RemComp<SLNightVisionComponent>(args.Equipee);
}
}
Loading
Loading