diff --git a/Content.Client/_CP14/MagicSpell/CP14ClientMagicVisionSystem.cs b/Content.Client/_CP14/MagicSpell/CP14ClientMagicVisionSystem.cs index 40ef72e5c8..fd5c61f930 100644 --- a/Content.Client/_CP14/MagicSpell/CP14ClientMagicVisionSystem.cs +++ b/Content.Client/_CP14/MagicSpell/CP14ClientMagicVisionSystem.cs @@ -9,7 +9,19 @@ namespace Content.Client._CP14.MagicSpell; public sealed class CP14ClientMagicVisionSystem : CP14SharedMagicVisionSystem { [Dependency] private readonly IClientGameTiming _timing = default!; - public bool MagicVisible { get; set; } + + + private bool _markersVisible; + + public bool MarkersVisible + { + get => _markersVisible; + set + { + _markersVisible = value; + UpdateVisibilityAll(); + } + } private TimeSpan _nextUpdate = TimeSpan.Zero; @@ -17,7 +29,15 @@ public sealed class CP14ClientMagicVisionSystem : CP14SharedMagicVisionSystem { base.Initialize(); - SubscribeLocalEvent(OnStartup); + SubscribeLocalEvent(OnStartupMarker); + } + + private void OnStartupMarker(Entity ent, ref ComponentStartup args) + { + if (!TryComp(ent, out var sprite)) + return; + + UpdateVisibility(ent, sprite); } public override void Update(float frameTime) @@ -27,8 +47,22 @@ public sealed class CP14ClientMagicVisionSystem : CP14SharedMagicVisionSystem if (_timing.CurTime < _nextUpdate) return; - _nextUpdate = _timing.CurTime + TimeSpan.FromSeconds(1f); + _nextUpdate = _timing.CurTime + TimeSpan.FromSeconds(0.5f); + var queryFade = EntityQueryEnumerator(); + while (queryFade.MoveNext(out var uid, out var fade, out var sprite)) + { + UpdateOpaque((uid, fade), sprite); + } + } + + private void UpdateVisibility(Entity ent, SpriteComponent sprite) + { + sprite.Visible = _markersVisible; + } + + private void UpdateVisibilityAll() + { var query = EntityQueryEnumerator(); while (query.MoveNext(out var uid, out var marker, out var sprite)) { @@ -36,27 +70,10 @@ public sealed class CP14ClientMagicVisionSystem : CP14SharedMagicVisionSystem } } - private void OnStartup(Entity ent, ref ComponentStartup args) + private void UpdateOpaque(Entity ent, SpriteComponent sprite) { - if (!TryComp(ent, out var sprite)) - return; - - ent.Comp.SpawnTime = _timing.CurTime; - ent.Comp.EndTime = _timing.CurTime + ent.Comp.VisibilityTime; - - UpdateVisibility(ent, sprite); - } - - private void UpdateVisibility(Entity ent, SpriteComponent sprite) - { - sprite.Visible = MagicVisible; - - if (MagicVisible == false) - return; - 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; - Log.Info($"{ent.Owner.Id} - {alpha.ToString()}"); sprite.Color = Color.White.WithAlpha((float)alpha); } } @@ -71,6 +88,6 @@ internal sealed class ShowMagicCommand : LocalizedCommands public override void Execute(IConsoleShell shell, string argStr, string[] args) { - _entitySystemManager.GetEntitySystem().MagicVisible ^= true; + _entitySystemManager.GetEntitySystem().MarkersVisible ^= true; } } diff --git a/Content.Server/_CP14/MagicSpell/CP14MagicVisionSystem.cs b/Content.Server/_CP14/MagicSpell/CP14MagicVisionSystem.cs index 8ff429df95..e2831ab91f 100644 --- a/Content.Server/_CP14/MagicSpell/CP14MagicVisionSystem.cs +++ b/Content.Server/_CP14/MagicSpell/CP14MagicVisionSystem.cs @@ -12,7 +12,7 @@ public sealed class CP14MagicVisionSystem : CP14SharedMagicVisionSystem { base.Update(frameTime); - var query = EntityQueryEnumerator(); + var query = EntityQueryEnumerator(); while (query.MoveNext(out var uid, out var marker)) { if (_timing.CurTime < marker.EndTime) diff --git a/Content.Shared/_CP14/MagicSpell/CP14SharedMagicVisionSystem.cs b/Content.Shared/_CP14/MagicSpell/CP14SharedMagicVisionSystem.cs index d57db5df4d..5660fffcb4 100644 --- a/Content.Shared/_CP14/MagicSpell/CP14SharedMagicVisionSystem.cs +++ b/Content.Shared/_CP14/MagicSpell/CP14SharedMagicVisionSystem.cs @@ -10,10 +10,10 @@ public abstract class CP14SharedMagicVisionSystem : EntitySystem { base.Initialize(); - SubscribeLocalEvent(OnMapInit); + SubscribeLocalEvent(OnStartupFade); } - private void OnMapInit(Entity ent, ref MapInitEvent args) + private void OnStartupFade(Entity ent, ref ComponentStartup args) { ent.Comp.SpawnTime = _timing.CurTime; ent.Comp.EndTime = _timing.CurTime + ent.Comp.VisibilityTime; diff --git a/Content.Shared/_CP14/MagicSpell/Components/CP14MagicVisionFadeComponent.cs b/Content.Shared/_CP14/MagicSpell/Components/CP14MagicVisionFadeComponent.cs new file mode 100644 index 0000000000..7ef126b9ac --- /dev/null +++ b/Content.Shared/_CP14/MagicSpell/Components/CP14MagicVisionFadeComponent.cs @@ -0,0 +1,17 @@ +namespace Content.Shared._CP14.MagicSpell.Components; + +/// +/// Controls the visibility of this entity to the client, based on the length of time it has existed and the client's ability to see the magic +/// +[RegisterComponent, AutoGenerateComponentPause] +public sealed partial class CP14MagicVisionFadeComponent : Component +{ + [DataField, AutoPausedField] + public TimeSpan SpawnTime = TimeSpan.Zero; + + [DataField, AutoPausedField] + public TimeSpan EndTime = TimeSpan.Zero; + + [DataField] + public TimeSpan VisibilityTime = TimeSpan.FromMinutes(2f); +} diff --git a/Content.Shared/_CP14/MagicSpell/Components/CP14MagicVisionMarkerComponent.cs b/Content.Shared/_CP14/MagicSpell/Components/CP14MagicVisionMarkerComponent.cs index 38655e69a4..32f4871301 100644 --- a/Content.Shared/_CP14/MagicSpell/Components/CP14MagicVisionMarkerComponent.cs +++ b/Content.Shared/_CP14/MagicSpell/Components/CP14MagicVisionMarkerComponent.cs @@ -6,12 +6,4 @@ namespace Content.Shared._CP14.MagicSpell.Components; [RegisterComponent, AutoGenerateComponentPause] public sealed partial class CP14MagicVisionMarkerComponent : Component { - [DataField, AutoPausedField] - public TimeSpan SpawnTime = TimeSpan.Zero; - - [DataField, AutoPausedField] - public TimeSpan EndTime = TimeSpan.Zero; - - [DataField] - public TimeSpan VisibilityTime = TimeSpan.FromMinutes(2f); } diff --git a/Resources/Prototypes/_CP14/Entities/Actions/Spells/Healing/T1_cure_wounds.yml b/Resources/Prototypes/_CP14/Entities/Actions/Spells/Healing/T1_cure_wounds.yml index 7eecaef6f9..f64b1f97ae 100644 --- a/Resources/Prototypes/_CP14/Entities/Actions/Spells/Healing/T1_cure_wounds.yml +++ b/Resources/Prototypes/_CP14/Entities/Actions/Spells/Healing/T1_cure_wounds.yml @@ -66,6 +66,7 @@ - state: cure_wounds shader: unshaded - type: CP14MagicVisionMarker + - type: CP14MagicVisionFade visibilityTime: 20 - type: entity