using Content.Server.Popups; using Content.Server.Power.EntitySystems; using Content.Server.Xenoarchaeology.Equipment.Components; using Content.Shared.Examine; using Content.Shared.Interaction; using Content.Shared.Placeable; using Robust.Shared.Timing; namespace Content.Server.Xenoarchaeology.Equipment.Systems; public sealed class TraversalDistorterSystem : EntitySystem { [Dependency] private readonly IGameTiming _timing = default!; [Dependency] private readonly PopupSystem _popup = default!; /// public override void Initialize() { SubscribeLocalEvent(OnInit); SubscribeLocalEvent(OnInteract); SubscribeLocalEvent(OnExamine); SubscribeLocalEvent(OnItemPlaced); SubscribeLocalEvent(OnItemRemoved); } private void OnInit(EntityUid uid, TraversalDistorterComponent component, MapInitEvent args) { component.NextActivation = _timing.CurTime; } private void OnInteract(EntityUid uid, TraversalDistorterComponent component, ActivateInWorldEvent args) { if (args.Handled || !this.IsPowered(uid, EntityManager)) return; if (_timing.CurTime < component.NextActivation) return; args.Handled = true; component.NextActivation = _timing.CurTime + component.ActivationDelay; component.BiasDirection = component.BiasDirection == BiasDirection.In ? BiasDirection.Out : BiasDirection.In; var toPopup = string.Empty; switch (component.BiasDirection) { case BiasDirection.In: toPopup = Loc.GetString("traversal-distorter-set-in"); break; case BiasDirection.Out: toPopup = Loc.GetString("traversal-distorter-set-out"); break; } _popup.PopupEntity(toPopup, uid); } private void OnExamine(EntityUid uid, TraversalDistorterComponent component, ExaminedEvent args) { string examine = string.Empty; switch (component.BiasDirection) { case BiasDirection.In: examine = Loc.GetString("traversal-distorter-desc-in"); break; case BiasDirection.Out: examine = Loc.GetString("traversal-distorter-desc-out"); break; } args.PushMarkup(examine); } private void OnItemPlaced(EntityUid uid, TraversalDistorterComponent component, ref ItemPlacedEvent args) { var bias = EnsureComp(args.OtherEntity); bias.Provider = uid; } private void OnItemRemoved(EntityUid uid, TraversalDistorterComponent component, ref ItemRemovedEvent args) { var otherEnt = args.OtherEntity; if (TryComp(otherEnt, out var bias) && bias.Provider == uid) RemComp(otherEnt, bias); } }