Files
ss14-wl/Content.Server/Trigger/Systems/RattleOnTriggerSystem.cs
Pieter-Jan BriersandGitHub 5168b5f3d4 IoC source gen compatibility (#43863)
* IoC source gen compatibility

Can be merged before or after https://github.com/space-wizards/RobustToolbox/pull/6549 doesn't really matter.

* Missed a spot
2026-05-09 03:29:58 +00:00

50 lines
1.6 KiB
C#

using Content.Server.Radio.EntitySystems;
using Content.Server.Pinpointer;
using Content.Shared.Mobs.Components;
using Content.Shared.Trigger;
using Content.Shared.Trigger.Components.Effects;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
namespace Content.Server.Trigger.Systems;
public sealed partial class RattleOnTriggerSystem : EntitySystem
{
[Dependency] private IPrototypeManager _prototypeManager = default!;
[Dependency] private RadioSystem _radio = default!;
[Dependency] private NavMapSystem _navMap = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<RattleOnTriggerComponent, TriggerEvent>(OnTrigger);
}
private void OnTrigger(Entity<RattleOnTriggerComponent> ent, ref TriggerEvent args)
{
if (args.Key != null && !ent.Comp.KeysIn.Contains(args.Key))
return;
var target = ent.Comp.TargetUser ? args.User : ent.Owner;
if (target == null)
return;
if (!TryComp<MobStateComponent>(target.Value, out var mobstate))
return;
args.Handled = true;
if (!ent.Comp.Messages.TryGetValue(mobstate.CurrentState, out var messageId))
return;
// Gets the location of the user
var posText = FormattedMessage.RemoveMarkupOrThrow(_navMap.GetNearestBeaconString(target.Value));
var message = Loc.GetString(messageId, ("user", target.Value), ("position", posText));
// Sends a message to the radio channel specified by the implant
_radio.SendRadioMessage(ent.Owner, message, _prototypeManager.Index(ent.Comp.RadioChannel), ent.Owner);
}
}