using Content.Shared.Examine; using Content.Shared.Coordinates.Helpers; using Content.Shared.PowerCell; using Content.Shared.Interaction; using Content.Shared.Storage; namespace Content.Server.Holosign; public sealed class HolosignSystem : EntitySystem { [Dependency] private readonly PowerCellSystem _powerCell = default!; [Dependency] private readonly SharedTransformSystem _transform = default!; private const float TileSearchRadius = 0.1f; // sunrise - add public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnBeforeInteract); SubscribeLocalEvent(OnExamine); } private void OnExamine(EntityUid uid, HolosignProjectorComponent component, ExaminedEvent args) { // TODO: This should probably be using an itemstatus // TODO: I'm too lazy to do this rn but it's literally copy-paste from emag. var charges = _powerCell.GetRemainingUses(uid, component.ChargeUse); var maxCharges = _powerCell.GetMaxUses(uid, component.ChargeUse); using (args.PushGroup(nameof(HolosignProjectorComponent))) { args.PushMarkup(Loc.GetString("limited-charges-charges-remaining", ("charges", charges))); if (charges > 0 && charges == maxCharges) { args.PushMarkup(Loc.GetString("limited-charges-max-charges")); } } } private void OnBeforeInteract(EntityUid uid, HolosignProjectorComponent component, BeforeRangedInteractEvent args) { // Sunrise - Start if (args.Handled || !args.CanReach // prevent placing out of range || HasComp(args.Target) // if it's a storage component like a bag, we ignore usage so it can be stored ) return; var tileCoords = args.ClickLocation.SnapToGrid(EntityManager); var mapCoords = _transform.ToMapCoordinates(tileCoords); var lookup = EntityManager.System(); int count = 0; foreach (var ent in lookup.GetEntitiesInRange(mapCoords, TileSearchRadius)) { if (MetaData(ent).EntityPrototype?.ID == component.SignProto) { count++; if (count >= component.CountPerTileLimit) return; } } if (!_powerCell.TryUseCharge(uid, component.ChargeUse, user: args.User)) return; // Sunrise - End // 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 = Spawn(component.SignProto, args.ClickLocation.SnapToGrid(EntityManager)); var xform = Transform(holoUid); // TODO: Just make the prototype anchored 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; } }