Ranged Holosigns (#25120)

* Changed holo signs to be ranged and used on click rather than Z.

* Updated comments

* Failed attempt at ignoring walls

* Getting rid of unused libraries

---------

Co-authored-by: Plykiya <plykiya@protonmail.com>
This commit is contained in:
Plykiya
2024-02-13 21:25:59 -08:00
committed by GitHub
parent 071f19ac08
commit e6c21d66fa

View File

@@ -1,19 +1,21 @@
using Content.Shared.Interaction.Events;
using Content.Shared.Examine;
using Content.Shared.Coordinates.Helpers;
using Content.Server.Power.Components;
using Content.Server.PowerCell;
using Content.Shared.Interaction;
namespace Content.Server.Holosign;
public sealed class HolosignSystem : EntitySystem
{
[Dependency] private readonly PowerCellSystem _powerCell = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<HolosignProjectorComponent, UseInHandEvent>(OnUse);
SubscribeLocalEvent<HolosignProjectorComponent, BeforeRangedInteractEvent>(OnBeforeInteract);
SubscribeLocalEvent<HolosignProjectorComponent, ExaminedEvent>(OnExamine);
}
@@ -36,16 +38,21 @@ public sealed class HolosignSystem : EntitySystem
}
}
private void OnUse(EntityUid uid, HolosignProjectorComponent component, UseInHandEvent args)
private void OnBeforeInteract(EntityUid uid, HolosignProjectorComponent component, BeforeRangedInteractEvent args)
{
if (args.Handled ||
!_powerCell.TryGetBatteryFromSlot(uid, out var battery) ||
!battery.TryUseCharge(component.ChargeUse))
if (args.Handled
|| !args.CanReach // prevent placing out of range
|| !_powerCell.TryUseCharge(uid, component.ChargeUse) // if no battery or no charge, doesn't work
)
return;
// TODO: Too tired to deal
var holo = EntityManager.SpawnEntity(component.SignProto, Transform(args.User).Coordinates.SnapToGrid(EntityManager));
Transform(holo).Anchored = true;
// places the holographic sign at the click location, snapped to grid.
// overlapping of the same holo on one tile remains allowed to allow holofan refreshes
var holoUid = EntityManager.SpawnEntity(component.SignProto, args.ClickLocation.SnapToGrid(EntityManager));
var xform = Transform(holoUid);
if (!xform.Anchored)
_transform.AnchorEntity(holoUid, xform); // anchor to prevent any tempering with (don't know what could even interact with it)
args.Handled = true;
}