-
Notifications
You must be signed in to change notification settings - Fork 401
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
111 additions
and
137 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
.../Weapons/Ranged/Overlays/TracerOverlay.cs → .../Weapons/Ranged/Overlays/TracerOverlay.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
Content.Client/DeltaV/Weapons/Ranged/Systems/TracerSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using System.Numerics; | ||
using Content.Client.DeltaV.Weapons.Ranged.Overlays; | ||
using Content.Shared.DeltaV.Weapons.Ranged.Components; | ||
using Robust.Client.Graphics; | ||
using Robust.Shared.Map; | ||
using Robust.Shared.Timing; | ||
using TracerComponent = Content.Shared.DeltaV.Weapons.Ranged.Components.TracerComponent; | ||
|
||
namespace Content.Client.DeltaV.Weapons.Ranged.Systems; | ||
|
||
public sealed class TracerSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly IGameTiming _timing = default!; | ||
[Dependency] private readonly IOverlayManager _overlay = default!; | ||
[Dependency] private readonly SharedTransformSystem _transform = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
_overlay.AddOverlay(new TracerOverlay(this)); | ||
|
||
SubscribeLocalEvent<TracerComponent, ComponentStartup>(OnTracerStart); | ||
} | ||
|
||
private void OnTracerStart(Entity<TracerComponent> ent, ref ComponentStartup args) | ||
{ | ||
var xform = Transform(ent); | ||
var pos = _transform.GetWorldPosition(xform); | ||
|
||
ent.Comp.Data = new TracerData | ||
{ | ||
EndTime = _timing.CurTime + TimeSpan.FromSeconds(ent.Comp.Lifetime), | ||
PositionHistory = new List<Vector2> { pos } | ||
}; | ||
} | ||
|
||
public override void Update(float frameTime) | ||
{ | ||
base.Update(frameTime); | ||
|
||
var curTime = _timing.CurTime; | ||
var query = EntityQueryEnumerator<TracerComponent, TransformComponent>(); | ||
|
||
while (query.MoveNext(out var uid, out var tracer, out var xform)) | ||
{ | ||
if (curTime > tracer.Data.EndTime) | ||
{ | ||
RemCompDeferred<TracerComponent>(uid); | ||
continue; | ||
} | ||
|
||
var positions = tracer.Data.PositionHistory; | ||
var currentPos = _transform.GetWorldPosition(xform); | ||
positions.Add(currentPos); | ||
|
||
while (positions.Count > 2 && GetTrailLength(positions) > tracer.Length) | ||
{ | ||
positions.RemoveAt(0); | ||
} | ||
} | ||
} | ||
|
||
private static float GetTrailLength(List<Vector2> positions) | ||
{ | ||
var length = 0f; | ||
for (var i = 1; i < positions.Count; i++) | ||
{ | ||
length += Vector2.Distance(positions[i - 1], positions[i]); | ||
} | ||
return length; | ||
} | ||
|
||
public void Draw(DrawingHandleWorld handle, MapId currentMap) | ||
{ | ||
var query = EntityQueryEnumerator<TracerComponent, TransformComponent>(); | ||
|
||
while (query.MoveNext(out _, out var tracer, out var xform)) | ||
{ | ||
if (xform.MapID != currentMap) | ||
continue; | ||
|
||
var positions = tracer.Data.PositionHistory; | ||
for (var i = 1; i < positions.Count; i++) | ||
{ | ||
handle.DrawLine(positions[i - 1], positions[i], tracer.Color); | ||
} | ||
} | ||
} | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
20 changes: 15 additions & 5 deletions
20
...pons/Ranged/Components/TracerComponent.cs → ...pons/Ranged/Components/TracerComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,38 @@ | ||
using System.Numerics; | ||
using Robust.Shared.GameStates; | ||
using Robust.Shared.Map; | ||
|
||
namespace Content.Shared.Weapons.Ranged.Components; | ||
namespace Content.Shared.DeltaV.Weapons.Ranged.Components; | ||
|
||
/// <summary> | ||
/// Added to projectiles to give them tracer effects | ||
/// </summary> | ||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] | ||
[RegisterComponent, NetworkedComponent] | ||
public sealed partial class TracerComponent : Component | ||
{ | ||
/// <summary> | ||
/// How long the tracer effect should remain visible for after firing | ||
/// </summary> | ||
[DataField, AutoNetworkedField] | ||
[DataField] | ||
public float Lifetime = 10f; | ||
|
||
/// <summary> | ||
/// The maximum length of the tracer trail | ||
/// </summary> | ||
[DataField, AutoNetworkedField] | ||
[DataField] | ||
public float Length = 2f; | ||
|
||
/// <summary> | ||
/// Color of the tracer line effect | ||
/// </summary> | ||
[DataField, AutoNetworkedField] | ||
[DataField] | ||
public Color Color = Color.Red; | ||
|
||
public TracerData Data = default!; | ||
} | ||
|
||
public sealed class TracerData | ||
{ | ||
public List<Vector2> PositionHistory = new(); | ||
public TimeSpan EndTime; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters