magic visibility
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
using Content.Shared._CP14.MagicSpell;
|
||||
using Content.Shared._CP14.MagicSpell.Components;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Timing;
|
||||
using Robust.Shared.Console;
|
||||
|
||||
namespace Content.Client._CP14.MagicSpell;
|
||||
|
||||
public sealed class CP14ClientMagicVisionSystem : CP14SharedMagicVisionSystem
|
||||
{
|
||||
[Dependency] private readonly IClientGameTiming _timing = default!;
|
||||
public bool MagicVisible { get; set; }
|
||||
|
||||
private TimeSpan _nextUpdate = TimeSpan.Zero;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<CP14MagicVisionMarkerComponent, ComponentStartup>(OnStartup);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
|
||||
if (_timing.CurTime < _nextUpdate)
|
||||
return;
|
||||
|
||||
_nextUpdate = _timing.CurTime + TimeSpan.FromSeconds(1f);
|
||||
|
||||
var query = EntityQueryEnumerator<CP14MagicVisionMarkerComponent, SpriteComponent>();
|
||||
while (query.MoveNext(out var uid, out var marker, out var sprite))
|
||||
{
|
||||
UpdateVisibility((uid, marker), sprite);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnStartup(Entity<CP14MagicVisionMarkerComponent> ent, ref ComponentStartup args)
|
||||
{
|
||||
if (!TryComp<SpriteComponent>(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<CP14MagicVisionMarkerComponent> 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);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class ShowMagicCommand : LocalizedCommands
|
||||
{
|
||||
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;
|
||||
|
||||
public override string Command => "cp14_showmagic";
|
||||
|
||||
public override string Help => "Toggle visibility of magic traces";
|
||||
|
||||
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
_entitySystemManager.GetEntitySystem<CP14ClientMagicVisionSystem>().MagicVisible ^= true;
|
||||
}
|
||||
}
|
||||
24
Content.Server/_CP14/MagicSpell/CP14MagicVisionSystem.cs
Normal file
24
Content.Server/_CP14/MagicSpell/CP14MagicVisionSystem.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using Content.Shared._CP14.MagicSpell;
|
||||
using Content.Shared._CP14.MagicSpell.Components;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Server._CP14.MagicSpell;
|
||||
|
||||
public sealed class CP14MagicVisionSystem : CP14SharedMagicVisionSystem
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
|
||||
var query = EntityQueryEnumerator<CP14MagicVisionMarkerComponent>();
|
||||
while (query.MoveNext(out var uid, out var marker))
|
||||
{
|
||||
if (_timing.CurTime < marker.EndTime)
|
||||
continue;
|
||||
|
||||
QueueDel(uid);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using Content.Shared._CP14.MagicSpell.Components;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Shared._CP14.MagicSpell;
|
||||
|
||||
public abstract class CP14SharedMagicVisionSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<CP14MagicVisionMarkerComponent, MapInitEvent>(OnMapInit);
|
||||
}
|
||||
|
||||
private void OnMapInit(Entity<CP14MagicVisionMarkerComponent> ent, ref MapInitEvent args)
|
||||
{
|
||||
ent.Comp.SpawnTime = _timing.CurTime;
|
||||
ent.Comp.EndTime = _timing.CurTime + ent.Comp.VisibilityTime;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace Content.Shared._CP14.MagicSpell.Components;
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// </summary>
|
||||
[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);
|
||||
}
|
||||
14
Resources/Prototypes/_CP14/Entities/TEST.yml
Normal file
14
Resources/Prototypes/_CP14/Entities/TEST.yml
Normal file
@@ -0,0 +1,14 @@
|
||||
- type: entity
|
||||
id: CP14MagicTrace
|
||||
categories: [ ForkFiltered ]
|
||||
components:
|
||||
- type: Sprite
|
||||
drawdepth: Effects
|
||||
snapCardinals: true
|
||||
sprite: _CP14/Effects/fire.rsi
|
||||
layers:
|
||||
- state: full
|
||||
shader: unshaded
|
||||
- type: Clickable
|
||||
- type: CP14MagicVisionMarker
|
||||
visibilityTime: 30
|
||||
Reference in New Issue
Block a user