Adds force-gun (#16561)

This commit is contained in:
metalgearsloth
2023-05-19 17:10:31 +10:00
committed by GitHub
parent eb94a785f9
commit 4efb41aa58
26 changed files with 373 additions and 76 deletions

View File

@@ -19,6 +19,8 @@ public sealed class TetherGunOverlay : Overlay
{
var query = _entManager.EntityQueryEnumerator<TetheredComponent>();
var xformQuery = _entManager.GetEntityQuery<TransformComponent>();
var tetherQuery = _entManager.GetEntityQuery<TetherGunComponent>();
var forceQuery = _entManager.GetEntityQuery<ForceGunComponent>();
var worldHandle = args.WorldHandle;
var xformSystem = _entManager.System<SharedTransformSystem>();
@@ -46,7 +48,18 @@ public sealed class TetherGunOverlay : Overlay
var box = new Box2(-Width, -length, Width, length);
var rotated = new Box2Rotated(box.Translated(midPoint), angle, midPoint);
worldHandle.DrawRect(rotated, Color.Orange.WithAlpha(0.3f));
var color = Color.Red;
if (forceQuery.TryGetComponent(tethered.Tetherer, out var force))
{
color = force.LineColor;
}
else if (tetherQuery.TryGetComponent(tethered.Tetherer, out var tether))
{
color = tether.LineColor;
}
worldHandle.DrawRect(rotated, color.WithAlpha(0.3f));
}
}
}

View File

@@ -22,16 +22,26 @@ public sealed class TetherGunSystem : SharedTetherGunSystem
base.Initialize();
SubscribeLocalEvent<TetheredComponent, ComponentStartup>(OnTetheredStartup);
SubscribeLocalEvent<TetheredComponent, ComponentShutdown>(OnTetheredShutdown);
SubscribeLocalEvent<TetherGunComponent, AfterAutoHandleStateEvent>(OnAfterState);
SubscribeLocalEvent<ForceGunComponent, AfterAutoHandleStateEvent>(OnAfterState);
_overlay.AddOverlay(new TetherGunOverlay(EntityManager));
}
private void OnAfterState(EntityUid uid, BaseForceGunComponent component, ref AfterAutoHandleStateEvent args)
{
if (!TryComp<SpriteComponent>(component.Tethered, out var sprite))
return;
sprite.Color = component.LineColor;
}
public override void Shutdown()
{
base.Shutdown();
_overlay.RemoveOverlay<TetherGunOverlay>();
}
protected override bool CanTether(EntityUid uid, TetherGunComponent component, EntityUid target, EntityUid? user)
protected override bool CanTether(EntityUid uid, BaseForceGunComponent component, EntityUid target, EntityUid? user)
{
// Need powercells predicted sadly :<
return false;
@@ -88,9 +98,18 @@ public sealed class TetherGunSystem : SharedTetherGunSystem
private void OnTetheredStartup(EntityUid uid, TetheredComponent component, ComponentStartup args)
{
if (!TryComp<SpriteComponent>(uid, out var sprite))
{
return;
}
sprite.Color = Color.Orange;
if (TryComp<ForceGunComponent>(component.Tetherer, out var force))
{
sprite.Color = force.LineColor;
}
else if (TryComp<TetherGunComponent>(component.Tetherer, out var tether))
{
sprite.Color = tether.LineColor;
}
}
private void OnTetheredShutdown(EntityUid uid, TetheredComponent component, ComponentShutdown args)