2023-10-19 12:34:31 -07:00
|
|
|
using Content.Server.Polymorph.Systems;
|
2023-10-10 00:49:42 +01:00
|
|
|
using Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Components;
|
|
|
|
|
using Content.Server.Xenoarchaeology.XenoArtifacts.Events;
|
|
|
|
|
using Content.Shared.Humanoid;
|
|
|
|
|
using Content.Shared.Mobs.Systems;
|
2023-11-27 22:12:34 +11:00
|
|
|
using Robust.Shared.Audio.Systems;
|
2023-10-10 00:49:42 +01:00
|
|
|
|
|
|
|
|
namespace Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Systems;
|
|
|
|
|
|
2024-02-01 08:17:02 -04:00
|
|
|
public sealed class PolyOthersArtifactSystem : EntitySystem
|
2023-10-10 00:49:42 +01:00
|
|
|
{
|
|
|
|
|
[Dependency] private readonly EntityLookupSystem _lookup = default!;
|
|
|
|
|
[Dependency] private readonly MobStateSystem _mob = default!;
|
|
|
|
|
[Dependency] private readonly PolymorphSystem _poly = default!;
|
|
|
|
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// On effect trigger polymorphs targets in range.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
2024-02-01 08:17:02 -04:00
|
|
|
SubscribeLocalEvent<PolyOthersArtifactComponent, ArtifactActivatedEvent>(OnActivate);
|
2023-10-10 00:49:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Provided target is alive and is not a zombie, polymorphs the target.
|
|
|
|
|
/// </summary>
|
2024-02-01 08:17:02 -04:00
|
|
|
private void OnActivate(Entity<PolyOthersArtifactComponent> ent, ref ArtifactActivatedEvent args)
|
2023-10-10 00:49:42 +01:00
|
|
|
{
|
2024-02-01 08:17:02 -04:00
|
|
|
var xform = Transform(ent);
|
2023-10-19 12:34:31 -07:00
|
|
|
var humanoids = new HashSet<Entity<HumanoidAppearanceComponent>>();
|
2024-02-01 08:17:02 -04:00
|
|
|
_lookup.GetEntitiesInRange(xform.Coordinates, ent.Comp.Range, humanoids);
|
2023-10-19 12:34:31 -07:00
|
|
|
|
|
|
|
|
foreach (var comp in humanoids)
|
2023-10-10 00:49:42 +01:00
|
|
|
{
|
|
|
|
|
var target = comp.Owner;
|
|
|
|
|
if (_mob.IsAlive(target))
|
|
|
|
|
{
|
2024-02-01 08:17:02 -04:00
|
|
|
_poly.PolymorphEntity(target, ent.Comp.PolymorphPrototypeName);
|
|
|
|
|
_audio.PlayPvs(ent.Comp.PolySound, ent);
|
2023-10-10 00:49:42 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|