* Cleanups PolymorphSystem * forgot this * Nah * Fix test --------- Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
63 lines
1.9 KiB
C#
63 lines
1.9 KiB
C#
using Content.Server.Polymorph.Components;
|
|
using Content.Shared.Polymorph;
|
|
using Content.Shared.Projectiles;
|
|
using Robust.Shared.Audio;
|
|
using Robust.Shared.Physics.Events;
|
|
using Robust.Shared.Prototypes;
|
|
|
|
namespace Content.Server.Polymorph.Systems;
|
|
|
|
public partial class PolymorphSystem
|
|
{
|
|
/// <summary>
|
|
/// Need to do this so we don't get a collection enumeration error in physics by polymorphing
|
|
/// an entity we're colliding with
|
|
/// </summary>
|
|
private Queue<PolymorphQueuedData> _queuedPolymorphUpdates = new();
|
|
|
|
private void InitializeCollide()
|
|
{
|
|
SubscribeLocalEvent<PolymorphOnCollideComponent, StartCollideEvent>(OnPolymorphCollide);
|
|
}
|
|
|
|
public void UpdateCollide()
|
|
{
|
|
while (_queuedPolymorphUpdates.TryDequeue(out var data))
|
|
{
|
|
if (Deleted(data.Ent))
|
|
continue;
|
|
|
|
var ent = PolymorphEntity(data.Ent, data.Polymorph);
|
|
if (ent != null)
|
|
_audio.PlayPvs(data.Sound, ent.Value);
|
|
}
|
|
}
|
|
|
|
private void OnPolymorphCollide(EntityUid uid, PolymorphOnCollideComponent component, ref StartCollideEvent args)
|
|
{
|
|
if (args.OurFixtureId != SharedProjectileSystem.ProjectileFixture)
|
|
return;
|
|
|
|
var other = args.OtherEntity;
|
|
if (!component.Whitelist.IsValid(other, EntityManager)
|
|
|| component.Blacklist != null && component.Blacklist.IsValid(other, EntityManager))
|
|
return;
|
|
|
|
_queuedPolymorphUpdates.Enqueue(new (other, component.Sound, component.Polymorph));
|
|
}
|
|
}
|
|
|
|
public struct PolymorphQueuedData
|
|
{
|
|
public EntityUid Ent;
|
|
public SoundSpecifier Sound;
|
|
public ProtoId<PolymorphPrototype> Polymorph;
|
|
|
|
public PolymorphQueuedData(EntityUid ent, SoundSpecifier sound, ProtoId<PolymorphPrototype> polymorph)
|
|
{
|
|
Ent = ent;
|
|
Sound = sound;
|
|
Polymorph = polymorph;
|
|
}
|
|
}
|