Files
wwdpublic/Content.Server/_White/Anomaly/Effects/WormholeAnomalySystem.cs
PuroSlavKing 7ec558348c [Feature] Wormhole Anomaly (#156)
* [Feature] Wormhole Anomaly

* duration edit

* timed teleportation

* IRobustRandom

* Update Content.Server/_White/Anomaly/Effects/WormholeAnomalySystem.cs

Co-authored-by: Remuchi <72476615+Remuchi@users.noreply.github.com>

* remove on shutdown

* counts

---------

Co-authored-by: Remuchi <72476615+Remuchi@users.noreply.github.com>
2024-12-22 12:19:01 +07:00

52 lines
1.7 KiB
C#

using System.Linq;
using System.Numerics;
using Content.Server.Anomaly.Components;
using Robust.Server.Audio;
using Content.Shared.Teleportation.Components;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Random;
using Robust.Shared.GameObjects;
using Robust.Shared.Timing;
namespace Content.Server.Anomaly.Effects
{
public sealed class WormholeAnomalySystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedTransformSystem _xform = default!;
/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<WormholeAnomalyComponent, ComponentInit>(OnInit);
}
private void OnInit(EntityUid uid, WormholeAnomalyComponent component, ComponentInit args)
{
StartPulseTimer(uid, component);
}
private void StartPulseTimer(EntityUid uid, WormholeAnomalyComponent component)
{
Timer.Spawn((int)(component.PulseInterval * 1000), () => OnPulse(uid, component));
}
private void OnPulse(EntityUid uid, WormholeAnomalyComponent component)
{
var xformQuery = GetEntityQuery<TransformComponent>();
if (!xformQuery.TryGetComponent(uid, out var xform))
return;
var range = component.MaxShuffleRadius;
var newPosition = _random.NextVector2(range);
_xform.SetWorldPosition(uid, newPosition);
_audio.PlayPvs(component.TeleportSound, uid);
StartPulseTimer(uid, component);
}
}
}