2022-11-06 18:05:44 -05:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using Content.Server.Instruments;
|
|
|
|
|
|
using Content.Server.Xenoarchaeology.XenoArtifacts.Triggers.Components;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.Xenoarchaeology.XenoArtifacts.Triggers.Systems;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// This handles activating an artifact when music is playing nearby
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public sealed class ArtifactMusicTriggerSystem : EntitySystem
|
|
|
|
|
|
{
|
|
|
|
|
|
[Dependency] private readonly ArtifactSystem _artifact = default!;
|
|
|
|
|
|
|
2023-10-19 12:34:31 -07:00
|
|
|
|
private readonly List<Entity<ArtifactMusicTriggerComponent, TransformComponent>> _artifacts = new();
|
|
|
|
|
|
|
2022-11-06 18:05:44 -05:00
|
|
|
|
public override void Update(float frameTime)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Update(frameTime);
|
|
|
|
|
|
|
2023-10-19 12:34:31 -07:00
|
|
|
|
_artifacts.Clear();
|
|
|
|
|
|
var artifactQuery = EntityQueryEnumerator<ArtifactMusicTriggerComponent, TransformComponent>();
|
|
|
|
|
|
while (artifactQuery.MoveNext(out var uid, out var trigger, out var xform))
|
|
|
|
|
|
{
|
|
|
|
|
|
_artifacts.Add((uid, trigger, xform));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!_artifacts.Any())
|
2022-11-06 18:05:44 -05:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
List<EntityUid> toActivate = new();
|
2023-10-19 12:34:31 -07:00
|
|
|
|
var query = EntityQueryEnumerator<ActiveInstrumentComponent, TransformComponent>();
|
2022-11-06 18:05:44 -05:00
|
|
|
|
|
|
|
|
|
|
//assume that there's more instruments than artifacts
|
2023-10-19 12:34:31 -07:00
|
|
|
|
while (query.MoveNext(out _, out var instXform))
|
2022-11-06 18:05:44 -05:00
|
|
|
|
{
|
2023-10-19 12:34:31 -07:00
|
|
|
|
foreach (var (uid, trigger, xform) in _artifacts)
|
2022-11-06 18:05:44 -05:00
|
|
|
|
{
|
|
|
|
|
|
if (!instXform.Coordinates.TryDistance(EntityManager, xform.Coordinates, out var distance))
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
if (distance > trigger.Range)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
2023-10-19 12:34:31 -07:00
|
|
|
|
toActivate.Add(uid);
|
2022-11-06 18:05:44 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var a in toActivate)
|
|
|
|
|
|
{
|
|
|
|
|
|
_artifact.TryActivateArtifact(a);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|