Files
OldThink/Content.Server/Polymorph/Systems/PolymorphSystem.Collide.cs

61 lines
1.7 KiB
C#
Raw Normal View History

2022-07-29 14:13:12 +12:00
using Content.Server.Polymorph.Components;
2022-07-14 19:45:27 -07:00
using Content.Shared.Projectiles;
using Robust.Shared.Audio;
using Robust.Shared.Physics.Events;
2022-07-14 19:45:27 -07:00
namespace Content.Server.Polymorph.Systems;
2023-03-06 12:37:18 -05:00
public partial class PolymorphSystem
2022-07-14 19:45:27 -07:00
{
// Need to do this so we don't get a collection enumeration error in physics by polymorphing
// an entity we're colliding with
private Queue<PolymorphQueuedData> _queuedPolymorphUpdates = new();
2023-03-06 12:37:18 -05:00
public void UpdateCollide()
2022-07-14 19:45:27 -07:00
{
while (_queuedPolymorphUpdates.TryDequeue(out var data))
{
if (Deleted(data.Ent))
continue;
var ent = PolymorphEntity(data.Ent, data.Polymorph);
if (ent != null)
{
2023-03-06 12:37:18 -05:00
_audio.PlayPvs(data.Sound, ent.Value);
2022-07-14 19:45:27 -07:00
}
}
}
private void InitializeCollide()
{
SubscribeLocalEvent<PolymorphOnCollideComponent, StartCollideEvent>(OnPolymorphCollide);
}
private void OnPolymorphCollide(EntityUid uid, PolymorphOnCollideComponent component, ref StartCollideEvent args)
2022-07-14 19:45:27 -07:00
{
if (args.OurFixture.ID != SharedProjectileSystem.ProjectileFixture)
return;
var other = args.OtherEntity;
2022-07-14 19:45:27 -07:00
if (!component.Whitelist.IsValid(other)
|| component.Blacklist != null && component.Blacklist.IsValid(other))
return;
_queuedPolymorphUpdates.Enqueue(new (other, component.Sound, component.Polymorph));
}
}
2023-03-06 12:37:18 -05:00
public struct PolymorphQueuedData
2022-07-14 19:45:27 -07:00
{
public EntityUid Ent;
public SoundSpecifier Sound;
public string Polymorph;
public PolymorphQueuedData(EntityUid ent, SoundSpecifier sound, string polymorph)
{
Ent = ent;
Sound = sound;
Polymorph = polymorph;
}
}