mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 10:21:18 +03:00
* Axes the easy IMapManager references * Axes the references to unported (obsolete) IMapManager methods * Converts salvageruler command to a LocalizedEntityCommand so it can use SharedMapSystem * Removes IMapManager from GameTicker This required axing the map nuke during restart, but that should be fine? Maps are entities so EntityManager.FlushEntities should delete them all and that's the preceding line * submodule update(?) --------- Co-authored-by: ArtisticRoomba <145879011+ArtisticRoomba@users.noreply.github.com>
123 lines
3.9 KiB
C#
123 lines
3.9 KiB
C#
using Content.Shared.Weapons.Misc;
|
|
using Robust.Client.GameObjects;
|
|
using Robust.Client.Graphics;
|
|
using Robust.Client.Input;
|
|
using Robust.Client.Player;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Content.Client.Weapons.Misc;
|
|
|
|
public sealed partial class TetherGunSystem : SharedTetherGunSystem
|
|
{
|
|
[Dependency] private IEyeManager _eyeManager = default!;
|
|
[Dependency] private IGameTiming _timing = default!;
|
|
[Dependency] private IInputManager _input = default!;
|
|
[Dependency] private IOverlayManager _overlay = default!;
|
|
[Dependency] private IPlayerManager _player = default!;
|
|
[Dependency] private MapSystem _mapSystem = default!;
|
|
[Dependency] private SpriteSystem _sprite = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
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.SetColor((component.Tethered.Value, sprite), component.LineColor);
|
|
}
|
|
|
|
public override void Shutdown()
|
|
{
|
|
base.Shutdown();
|
|
_overlay.RemoveOverlay<TetherGunOverlay>();
|
|
}
|
|
|
|
protected override bool CanTether(EntityUid uid, BaseForceGunComponent component, EntityUid target, EntityUid? user)
|
|
{
|
|
// Need powercells predicted sadly :<
|
|
return false;
|
|
}
|
|
|
|
public override void Update(float frameTime)
|
|
{
|
|
base.Update(frameTime);
|
|
|
|
if (!_timing.IsFirstTimePredicted)
|
|
return;
|
|
|
|
var player = _player.LocalEntity;
|
|
|
|
if (player == null ||
|
|
!TryGetTetherGun(player.Value, out _, out var gun) ||
|
|
gun.TetherEntity == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var mousePos = _input.MouseScreenPosition;
|
|
var mouseWorldPos = _eyeManager.PixelToMap(mousePos);
|
|
|
|
if (mouseWorldPos.MapId == MapId.Nullspace)
|
|
return;
|
|
|
|
EntityCoordinates coords;
|
|
|
|
if (_mapSystem.TryFindGridAt(mouseWorldPos, out var gridUid, out _))
|
|
{
|
|
coords = TransformSystem.ToCoordinates(gridUid, mouseWorldPos);
|
|
}
|
|
else
|
|
{
|
|
coords = TransformSystem.ToCoordinates(_mapSystem.GetMap(mouseWorldPos.MapId), mouseWorldPos);
|
|
}
|
|
|
|
const float bufferDistance = 0.1f;
|
|
|
|
if (TryComp(gun.TetherEntity, out TransformComponent? tetherXform) &&
|
|
tetherXform.Coordinates.TryDistance(EntityManager, TransformSystem, coords, out var distance) &&
|
|
distance < bufferDistance)
|
|
{
|
|
return;
|
|
}
|
|
|
|
RaisePredictiveEvent(new RequestTetherMoveEvent()
|
|
{
|
|
Coordinates = GetNetCoordinates(coords)
|
|
});
|
|
}
|
|
|
|
private void OnTetheredStartup(EntityUid uid, TetheredComponent component, ComponentStartup args)
|
|
{
|
|
if (!TryComp<SpriteComponent>(uid, out var sprite))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (TryComp<ForceGunComponent>(component.Tetherer, out var force))
|
|
{
|
|
_sprite.SetColor((uid, sprite), force.LineColor);
|
|
}
|
|
else if (TryComp<TetherGunComponent>(component.Tetherer, out var tether))
|
|
{
|
|
_sprite.SetColor((uid, sprite), tether.LineColor);
|
|
}
|
|
}
|
|
|
|
private void OnTetheredShutdown(EntityUid uid, TetheredComponent component, ComponentShutdown args)
|
|
{
|
|
if (!TryComp<SpriteComponent>(uid, out var sprite))
|
|
return;
|
|
|
|
_sprite.SetColor((uid, sprite), Color.White);
|
|
}
|
|
}
|