using Content.Server.Xenoarchaeology.Artifact.XAE.Components;
using Content.Shared.Popups;
using Content.Shared.Xenoarchaeology.Artifact;
using Content.Shared.Xenoarchaeology.Artifact.XAE;
using Robust.Shared.Player;
using Robust.Shared.Random;
namespace Content.Server.Xenoarchaeology.Artifact.XAE;
///
/// System for xeno artifact activation effect that sends sublime telepathic messages.
///
public sealed class XAETelepathicSystem : BaseXAESystem
{
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
/// Pre-allocated and re-used collection.
private readonly HashSet _entities = new();
///
protected override void OnActivated(Entity ent, ref XenoArtifactNodeActivatedEvent args)
{
var component = ent.Comp;
// try to find victims nearby
_entities.Clear();
_lookup.GetEntitiesInRange(ent, component.Range, _entities);
foreach (var victimUid in _entities)
{
if (!HasComp(victimUid))
continue;
// roll if msg should be usual or drastic
List msgArr;
if (_random.NextFloat() <= component.DrasticMessageProb && component.DrasticMessages != null)
{
msgArr = component.DrasticMessages;
}
else
{
msgArr = component.Messages;
}
// pick a random message
var msgId = _random.Pick(msgArr);
var msg = Loc.GetString(msgId);
// show it as a popup, but only for the victim
_popupSystem.PopupEntity(msg, victimUid, victimUid);
}
}
}