Compare commits

...

4 Commits

Author SHA1 Message Date
Ed
066526807f Merge branch 'master' into ed-15-11-2024-magic-signs 2024-11-18 14:58:16 +03:00
Ed
6e7714d86a split components 2024-11-15 23:25:08 +03:00
Ed
cb4b92a5f7 cure trace 2024-11-15 18:45:22 +03:00
Ed
0ca9ac59f9 magic visibility 2024-11-15 18:18:04 +03:00
8 changed files with 192 additions and 4 deletions

View File

@@ -0,0 +1,93 @@
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!;
private bool _markersVisible;
public bool MarkersVisible
{
get => _markersVisible;
set
{
_markersVisible = value;
UpdateVisibilityAll();
}
}
private TimeSpan _nextUpdate = TimeSpan.Zero;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<CP14MagicVisionMarkerComponent, ComponentStartup>(OnStartupMarker);
}
private void OnStartupMarker(Entity<CP14MagicVisionMarkerComponent> ent, ref ComponentStartup args)
{
if (!TryComp<SpriteComponent>(ent, out var sprite))
return;
UpdateVisibility(ent, sprite);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
if (_timing.CurTime < _nextUpdate)
return;
_nextUpdate = _timing.CurTime + TimeSpan.FromSeconds(0.5f);
var queryFade = EntityQueryEnumerator<CP14MagicVisionFadeComponent, SpriteComponent>();
while (queryFade.MoveNext(out var uid, out var fade, out var sprite))
{
UpdateOpaque((uid, fade), sprite);
}
}
private void UpdateVisibility(Entity<CP14MagicVisionMarkerComponent> ent, SpriteComponent sprite)
{
sprite.Visible = _markersVisible;
}
private void UpdateVisibilityAll()
{
var query = EntityQueryEnumerator<CP14MagicVisionMarkerComponent, SpriteComponent>();
while (query.MoveNext(out var uid, out var marker, out var sprite))
{
UpdateVisibility((uid, marker), sprite);
}
}
private void UpdateOpaque(Entity<CP14MagicVisionFadeComponent> 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.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>().MarkersVisible ^= true;
}
}

View 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<CP14MagicVisionFadeComponent>();
while (query.MoveNext(out var uid, out var marker))
{
if (_timing.CurTime < marker.EndTime)
continue;
QueueDel(uid);
}
}
}

View File

@@ -4,7 +4,6 @@ using Content.Shared._CP14.MagicEnergy.Components;
using Content.Shared._CP14.MagicSpell.Components;
using Content.Shared._CP14.MagicSpell.Events;
using Content.Shared._CP14.MagicSpell.Spells;
using Content.Shared._CP14.MagicSpellStorage;
using Content.Shared.Actions;
using Content.Shared.DoAfter;
using Content.Shared.FixedPoint;

View File

@@ -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<CP14MagicVisionFadeComponent, ComponentStartup>(OnStartupFade);
}
private void OnStartupFade(Entity<CP14MagicVisionFadeComponent> ent, ref ComponentStartup args)
{
ent.Comp.SpawnTime = _timing.CurTime;
ent.Comp.EndTime = _timing.CurTime + ent.Comp.VisibilityTime;
}
}

View File

@@ -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 CP14MagicVisionFadeComponent : Component
{
[DataField, AutoPausedField]
public TimeSpan SpawnTime = TimeSpan.Zero;
[DataField, AutoPausedField]
public TimeSpan EndTime = TimeSpan.Zero;
[DataField]
public TimeSpan VisibilityTime = TimeSpan.FromMinutes(2f);
}

View File

@@ -0,0 +1,9 @@
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
{
}

View File

@@ -16,6 +16,7 @@
- !type:CP14SpellSpawnEntityOnTarget
spawns:
- CP14ImpactEffectCureWounds
- CP14MagicTraceCureWounds
- !type:CP14SpellApplyEntityEffect
effects:
- !type:HealthChange
@@ -48,13 +49,26 @@
sound: !type:SoundPathSpecifier
path: /Audio/Magic/rumble.ogg
icon:
sprite: _CP14/Effects/Magic/spells_icons.rsi
sprite: _CP14/Effects/Magic/spells_icons.rsi
state: cure_wounds
event: !type:CP14DelayedEntityTargetActionEvent
cooldown: 10
castDelay: 3
breakOnMove: false
- type: entity
id: CP14MagicTraceCureWounds
parent: CP14BaseMagicTrace
categories: [ HideSpawnMenu ]
components:
- type: Sprite
layers:
- state: cure_wounds
shader: unshaded
- type: CP14MagicVisionMarker
- type: CP14MagicVisionFade
visibilityTime: 20
- type: entity
id: CP14RuneCureWounds
parent: CP14BaseMagicRune

View File

@@ -34,4 +34,15 @@
- type: Sprite
drawdepth: Effects
sprite: _CP14/Effects/Magic/cast_impact.rsi
noRot: true
noRot: true
- type: entity
id: CP14BaseMagicTrace
abstract: true
components:
- type: Sprite
sprite: _CP14/Effects/Magic/spells_icons.rsi
drawdepth: Effects
- type: Clickable
- type: CP14MagicVisionMarker
visibilityTime: 30