Magical vision skill (#1467)

* fix firewave error spamming

* basic magic traces entities

* Add magical vision system and mana trace entities

Introduces the magical vision mechanic, including the CP14MagicVisionComponent, marker entities, and related systems for tracking and displaying magical traces. Adds new actions, skill integration, localization strings, and icons for magical vision and trace markers. Magic traces are now spawned on spell use and mob state changes, with directional pointers and localized descriptions.

* Show time passed for magic vision markers

Adds a display of the time elapsed since a magic vision marker was spawned, using a localized string. Updates English and Russian locale files with the new 'cp14-magic-vision-timed-past' entry.

* aura imprints

* Update critical and death messages for inclusivity

Revised the 'critical' and 'dead' messages in both English and Russian locale files to use more inclusive language, replacing references to 'magical creature' with 'someone'.

* Move magic vision spawn on mob state change to server

Transferred the logic for spawning magic vision markers on mob state changes (Critical/Dead) from CP14SharedMagicVisionSystem to CP14AuraImprintSystem. This centralizes the event handling on the server side. Also increased the duration of magic vision markers for spell usage from 20 to 50 seconds.

* Integrate magic vision with visibility mask system

Added a CP14MagicVision flag to VisibilityFlags and updated the magic vision and religion systems to use the visibility mask system. Magic vision markers now use the Visibility component, and visibility is refreshed when relevant components are added or removed. Removed client-side toggling logic in favor of server-driven visibility.

* drowsiness overlay

* noir shader

* sfx design
This commit is contained in:
Red
2025-06-26 13:49:53 +03:00
committed by GitHub
parent ee036e8372
commit 81e044758f
36 changed files with 746 additions and 4 deletions

View File

@@ -0,0 +1,159 @@
using System.Numerics;
using Content.Shared._CP14.MagicVision;
using Content.Shared.Examine;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Client.Timing;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Map;
using Robust.Shared.Player;
using Robust.Shared.Utility;
namespace Content.Client._CP14.MagicVision;
public sealed class CP14ClientMagicVisionSystem : CP14SharedMagicVisionSystem
{
[Dependency] private readonly IClientGameTiming _timing = default!;
[Dependency] private readonly SpriteSystem _sprite = default!;
[Dependency] private readonly IPlayerManager _player = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly IOverlayManager _overlayMan = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
private CP14MagicVisionOverlay? _overlay;
private CP14MagicVisionNoirOverlay? _overlay2;
private TimeSpan _nextUpdate = TimeSpan.Zero;
private SoundSpecifier _startSound = new SoundPathSpecifier(new ResPath("/Audio/Effects/eye_open.ogg"));
private SoundSpecifier _endSound = new SoundPathSpecifier(new ResPath("/Audio/Effects/eye_close.ogg"));
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<CP14MagicVisionMarkerComponent, AfterAutoHandleStateEvent>(OnHandleStateMarker);
SubscribeLocalEvent<CP14MagicVisionComponent, LocalPlayerAttachedEvent>(OnPlayerAttached);
SubscribeLocalEvent<CP14MagicVisionComponent, LocalPlayerDetachedEvent>(OnPlayerDetached);
SubscribeLocalEvent<CP14MagicVisionComponent, ComponentInit>(OnComponentInit);
SubscribeLocalEvent<CP14MagicVisionComponent, ComponentShutdown>(OnComponentShutdown);
}
private void OnComponentShutdown(Entity<CP14MagicVisionComponent> ent, ref ComponentShutdown args)
{
if (_player.LocalEntity != ent)
return;
if (_overlay != null)
{
_overlayMan.RemoveOverlay(_overlay);
_overlay = null;
}
if (_overlay2 != null)
{
_overlayMan.RemoveOverlay(_overlay2);
_overlay2 = null;
}
_audio.PlayGlobal(_endSound, ent);
}
private void OnComponentInit(Entity<CP14MagicVisionComponent> ent, ref ComponentInit args)
{
if (_player.LocalEntity != ent)
return;
_overlay = new CP14MagicVisionOverlay();
_overlayMan.AddOverlay(_overlay);
_overlay.StartOverlay = _timing.CurTime;
_overlay2 = new CP14MagicVisionNoirOverlay();
_overlayMan.AddOverlay(_overlay2);
_audio.PlayGlobal(_startSound, ent);
}
private void OnPlayerAttached(Entity<CP14MagicVisionComponent> ent, ref LocalPlayerAttachedEvent args)
{
_overlay = new CP14MagicVisionOverlay();
_overlayMan.AddOverlay(_overlay);
_overlay.StartOverlay = _timing.CurTime;
_overlay2 = new CP14MagicVisionNoirOverlay();
_overlayMan.AddOverlay(_overlay2);
_audio.PlayGlobal(_startSound, ent);
}
private void OnPlayerDetached(Entity<CP14MagicVisionComponent> ent, ref LocalPlayerDetachedEvent args)
{
if (_overlay != null)
{
_overlayMan.RemoveOverlay(_overlay);
_overlay = null;
}
if (_overlay2 != null)
{
_overlayMan.RemoveOverlay(_overlay2);
_overlay2 = null;
}
_audio.PlayGlobal(_endSound, ent);
}
protected override void OnExamined(Entity<CP14MagicVisionMarkerComponent> ent, ref ExaminedEvent args)
{
base.OnExamined(ent, ref args);
if (ent.Comp.TargetCoordinates is null)
return;
var originPosition = _transform.GetWorldPosition(ent);
var targetPosition = _transform.ToWorldPosition(ent.Comp.TargetCoordinates.Value);
if ((targetPosition - originPosition).Length() < 0.5f)
return;
Angle angle = new(targetPosition - originPosition);
var pointer = Spawn(ent.Comp.PointerProto, new MapCoordinates(originPosition, _transform.GetMapId(Transform(ent).Coordinates)));
_transform.SetWorldRotation(pointer, angle + Angle.FromDegrees(90));
}
private void OnHandleStateMarker(Entity<CP14MagicVisionMarkerComponent> ent, ref AfterAutoHandleStateEvent args)
{
if (!TryComp<SpriteComponent>(ent, out var sprite))
return;
if (ent.Comp.Icon is null)
return;
var layer = _sprite.AddLayer(ent.Owner, ent.Comp.Icon);
sprite.LayerSetShader(layer, "unshaded");
_sprite.LayerSetScale(ent.Owner, layer, new Vector2(0.5f, 0.5f));
}
public override void Update(float frameTime)
{
base.Update(frameTime);
if (_timing.CurTime < _nextUpdate)
return;
_nextUpdate = _timing.CurTime + TimeSpan.FromSeconds(0.5f);
var queryFade = EntityQueryEnumerator<CP14MagicVisionMarkerComponent, SpriteComponent>();
while (queryFade.MoveNext(out var uid, out var fade, out var sprite))
{
UpdateOpaque((uid, fade), sprite);
}
}
private void UpdateOpaque(Entity<CP14MagicVisionMarkerComponent> ent, SpriteComponent sprite)
{
var progress = Math.Clamp((_timing.CurTime.TotalSeconds - ent.Comp.SpawnTime.TotalSeconds) / (ent.Comp.EndTime.TotalSeconds - ent.Comp.SpawnTime.TotalSeconds), 0, 1);
var alpha = 1 - progress;
_sprite.SetColor(ent.Owner, Color.White.WithAlpha((float)alpha));
}
}

View File

@@ -0,0 +1,33 @@
using Robust.Client.Graphics;
using Robust.Shared.Enums;
using Robust.Shared.Prototypes;
namespace Content.Client._CP14.MagicVision;
public sealed class CP14MagicVisionNoirOverlay : Overlay
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
public override OverlaySpace Space => OverlaySpace.WorldSpace;
public override bool RequestScreenTexture => true;
private readonly ShaderInstance _noirShader;
public CP14MagicVisionNoirOverlay()
{
IoCManager.InjectDependencies(this);
_noirShader = _prototypeManager.Index<ShaderPrototype>("CP14BlueNoir").InstanceUnique();
ZIndex = 9; // draw this over the DamageOverlay, RainbowOverlay etc, but before the black and white shader
}
protected override void Draw(in OverlayDrawArgs args)
{
if (ScreenTexture == null)
return;
var handle = args.WorldHandle;
_noirShader.SetParameter("SCREEN_TEXTURE", ScreenTexture);
handle.UseShader(_noirShader);
handle.DrawRect(args.WorldBounds, Color.White);
handle.UseShader(null);
}
}

View File

@@ -0,0 +1,75 @@
using Content.Shared._CP14.MagicVision;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Shared.Enums;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
namespace Content.Client._CP14.MagicVision;
public sealed class CP14MagicVisionOverlay : Overlay
{
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IGameTiming _timing = default!;
public override OverlaySpace Space => OverlaySpace.WorldSpace;
public override bool RequestScreenTexture => true;
private readonly ShaderInstance _drowsinessShader;
public float CurrentPower = 10.0f;
public TimeSpan StartOverlay = TimeSpan.Zero; // when the overlay started
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 CP14MagicVisionOverlay()
{
IoCManager.InjectDependencies(this);
_drowsinessShader = _prototypeManager.Index<ShaderPrototype>("Drowsiness").InstanceUnique();
}
protected override void FrameUpdate(FrameEventArgs args)
{
var playerEntity = _playerManager.LocalEntity;
if (playerEntity == null)
return;
if (!_entityManager.HasComponent<CP14MagicVisionComponent>(playerEntity))
return;
var curTime = _timing.CurTime;
var timeLeft = (float)(curTime - StartOverlay).TotalSeconds;
CurrentPower = Math.Max(50f, 200f - (150f * Math.Min((float)(timeLeft / 3.0), 1.0f)));
}
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);
}
}