Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tracer ammunition #2298

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Content.Client/DeltaV/Weapons/Ranged/Overlays/TracerOverlay.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Content.Client.DeltaV.Weapons.Ranged.Systems;
using Robust.Client.Graphics;
using Robust.Shared.Enums;

namespace Content.Client.DeltaV.Weapons.Ranged.Overlays;

public sealed class TracerOverlay : Overlay
{
private readonly TracerSystem _tracer;

public override OverlaySpace Space => OverlaySpace.WorldSpace;

public TracerOverlay(TracerSystem tracer)
{
_tracer = tracer;
IoCManager.InjectDependencies(this);
}

protected override void Draw(in OverlayDrawArgs args)
{
_tracer.Draw(args.WorldHandle, args.MapId);
}
}
89 changes: 89 additions & 0 deletions Content.Client/DeltaV/Weapons/Ranged/Systems/TracerSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
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;

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);
}
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.Numerics;
using Robust.Shared.GameStates;

namespace Content.Shared.DeltaV.Weapons.Ranged.Components;

/// <summary>
/// Added to projectiles to give them tracer effects
/// </summary>
[RegisterComponent, NetworkedComponent]
public sealed partial class TracerComponent : Component
{
/// <summary>
/// How long the tracer effect should remain visible for after firing
/// </summary>
[DataField]
public float Lifetime = 10f;

/// <summary>
/// The maximum length of the tracer trail
/// </summary>
[DataField]
public float Length = 2f;

/// <summary>
/// Color of the tracer line effect
/// </summary>
[DataField]
public Color Color = Color.Red;

public TracerData Data = default!;
}

public sealed class TracerData
{
public List<Vector2> PositionHistory = new();
public TimeSpan EndTime;
}
1 change: 1 addition & 0 deletions Resources/Locale/en-US/deltav/research/technologies.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ research-technology-energy-gun-advance = Advanced Energy Manipulation
research-technology-advance-laser = Advanced Laser Manipulation
research-technology-robust-melee = Robust Melee
research-technology-syringe-gun = Syringe Gun
research-technology-tracer-ammunition = Tracer Ammunition
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,17 @@
- state: mag-1
map: ["enum.GunVisualLayers.Mag"]
- state: rubber

- type: entity
parent: BaseMagazineBoxLightRifle
id: MagazineBoxLightRifleTracer
name: ammunition box (.30 rifle tracer)
components:
- type: BallisticAmmoProvider
proto: CartridgeLightRifleTracer
- type: Sprite
layers:
- state: base
map: [ "enum.GunVisualLayers.Base" ]
- state: mag-1
map: [ "enum.GunVisualLayers.Mag" ]
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,17 @@
- state: mag-1
map: ["enum.GunVisualLayers.Mag"]
- state: rubber

- type: entity
parent: BaseMagazineBoxPistol
id: MagazineBoxPistolTracer
name: ammunition box (.35 auto tracer)
components:
- type: BallisticAmmoProvider
proto: CartridgePistolTracer
- type: Sprite
layers:
- state: base
map: [ "enum.GunVisualLayers.Base" ]
- state: mag-1
map: [ "enum.GunVisualLayers.Mag" ]
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,17 @@
- state: mag-1
map: ["enum.GunVisualLayers.Mag"]
- state: rubber

- type: entity
parent: BaseMagazineBoxRifle
id: MagazineBoxRifleTracer
name: ammunition box (.20 rifle tracer)
components:
- type: BallisticAmmoProvider
proto: CartridgeRifleTracer
- type: Sprite
layers:
- state: base
map: [ "enum.GunVisualLayers.Base" ]
- state: mag-1
map: [ "enum.GunVisualLayers.Mag" ]
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@
- state: tip
map: [ "enum.AmmoVisualLayers.Tip" ]
color: "#43c4f7"

- type: entity
parent: BaseCartridgeLightRifle
id: CartridgeLightRifleTracer
name: cartridge (.30 rifle tracer)
components:
- type: CartridgeAmmo
proto: BulletLightRifleTracer
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@
- state: tip
map: [ "enum.AmmoVisualLayers.Tip" ]
color: "#43c4f7"

- type: entity
parent: BaseCartridgePistol
id: CartridgePistolTracer
name: cartridge (.35 auto tracer)
components:
- type: CartridgeAmmo
proto: BulletPistolTracer
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@
- state: tip
map: [ "enum.AmmoVisualLayers.Tip" ]
color: "#43c4f7"

- type: entity
parent: BaseCartridgeRifle
id: CartridgeRifleTracer
name: cartridge (.20 rifle tracer)
components:
- type: CartridgeAmmo
proto: BulletRifleTracer
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,17 @@
map: ["enum.GunVisualLayers.Base"]
- state: mag-1
map: ["enum.GunVisualLayers.Mag"]

- type: entity
parent: BaseMagazineLightRifle
id: MagazineLightRifleTracer
name: magazine (.30 rifle tracer)
components:
- type: BallisticAmmoProvider
proto: CartridgeLightRifleTracer
- type: Sprite
layers:
- state: red
map: [ "enum.GunVisualLayers.Base" ]
- state: mag-1
map: [ "enum.GunVisualLayers.Mag" ]
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@
- state: mag-1
map: ["enum.GunVisualLayers.Mag"]

- type: entity
parent: BaseMagazinePistol
id: MagazinePistolTracer
name: pistol magazine (.35 auto tracer)
components:
- type: BallisticAmmoProvider
proto: CartridgePistolTracer
- type: Sprite
layers:
- state: red
map: [ "enum.GunVisualLayers.Base" ]
- state: mag-1
map: [ "enum.GunVisualLayers.Mag" ]

- type: entity
id: MagazinePistolSubMachineGunRubber
name: SMG magazine (.35 auto rubber)
Expand All @@ -28,6 +42,20 @@
- state: mag-1
map: ["enum.GunVisualLayers.Mag"]

- type: entity
id: MagazinePistolSubMachineGunTracer
name: SMG magazine (.35 auto tracer)
parent: BaseMagazinePistolSubMachineGun
components:
- type: BallisticAmmoProvider
proto: CartridgePistolTracer
- type: Sprite
layers:
- state: red
map: [ "enum.GunVisualLayers.Base" ]
- state: mag-1
map: [ "enum.GunVisualLayers.Mag" ]

# .38 special

- type: entity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,17 @@
map: ["enum.GunVisualLayers.Base"]
- state: mag-1
map: ["enum.GunVisualLayers.Mag"]

- type: entity
parent: BaseMagazineRifle
id: MagazineRifleTracer
name: magazine (.20 rifle tracer)
components:
- type: BallisticAmmoProvider
proto: CartridgeRifleTracer
- type: Sprite
layers:
- state: red
map: [ "enum.GunVisualLayers.Base" ]
- state: mag-1
map: [ "enum.GunVisualLayers.Mag" ]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
- type: entity
id: BulletLightRifleRubber
name: bullet (.20 rifle rubber)
name: bullet (.30 rifle rubber)
deltanedas marked this conversation as resolved.
Show resolved Hide resolved
parent: BaseBulletRubber
categories: [ HideSpawnMenu ]
components:
Expand All @@ -9,3 +9,8 @@
types:
Blunt: 3

- type: entity
parent: [ BaseBulletTracer, BulletLightRifle ]
id: BulletLightRifleTracer
name: bullet (.30 rifle tracer)
categories: [ HideSpawnMenu ]
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@
types:
Blunt: 3

- type: entity
parent: [ BaseBulletTracerYellow, BulletPistol ]
id: BulletPistolTracer
name: bullet (.35 auto tracer)
categories: [ HideSpawnMenu ]
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@
types:
Blunt: 3

- type: entity
parent: [ BaseBulletTracer, BulletRifle ]
id: BulletRifleTracer
name: bullet (0.20 rifle tracer)
categories: [ HideSpawnMenu ]
Loading
Loading