2022-07-29 14:13:12 +12:00
|
|
|
using Content.Server.Polymorph.Components;
|
2024-02-01 08:17:02 -04:00
|
|
|
using Content.Shared.Polymorph;
|
2022-07-14 19:45:27 -07:00
|
|
|
using Content.Shared.Projectiles;
|
|
|
|
|
using Robust.Shared.Audio;
|
2022-09-14 17:26:26 +10:00
|
|
|
using Robust.Shared.Physics.Events;
|
2024-02-01 08:17:02 -04:00
|
|
|
using Robust.Shared.Prototypes;
|
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
|
|
|
{
|
2024-02-01 08:17:02 -04:00
|
|
|
/// <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>
|
2022-07-14 19:45:27 -07:00
|
|
|
private Queue<PolymorphQueuedData> _queuedPolymorphUpdates = new();
|
|
|
|
|
|
2024-02-01 08:17:02 -04:00
|
|
|
private void InitializeCollide()
|
|
|
|
|
{
|
|
|
|
|
SubscribeLocalEvent<PolymorphOnCollideComponent, StartCollideEvent>(OnPolymorphCollide);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-14 17:26:26 +10:00
|
|
|
private void OnPolymorphCollide(EntityUid uid, PolymorphOnCollideComponent component, ref StartCollideEvent args)
|
2022-07-14 19:45:27 -07:00
|
|
|
{
|
2023-08-23 18:55:58 +10:00
|
|
|
if (args.OurFixtureId != SharedProjectileSystem.ProjectileFixture)
|
2022-07-14 19:45:27 -07:00
|
|
|
return;
|
|
|
|
|
|
2023-05-09 19:21:26 +12:00
|
|
|
var other = args.OtherEntity;
|
2024-02-01 08:17:02 -04:00
|
|
|
if (!component.Whitelist.IsValid(other, EntityManager)
|
|
|
|
|
|| component.Blacklist != null && component.Blacklist.IsValid(other, EntityManager))
|
2022-07-14 19:45:27 -07:00
|
|
|
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;
|
2024-02-01 08:17:02 -04:00
|
|
|
public ProtoId<PolymorphPrototype> Polymorph;
|
2022-07-14 19:45:27 -07:00
|
|
|
|
2024-02-01 08:17:02 -04:00
|
|
|
public PolymorphQueuedData(EntityUid ent, SoundSpecifier sound, ProtoId<PolymorphPrototype> polymorph)
|
2022-07-14 19:45:27 -07:00
|
|
|
{
|
|
|
|
|
Ent = ent;
|
|
|
|
|
Sound = sound;
|
|
|
|
|
Polymorph = polymorph;
|
|
|
|
|
}
|
|
|
|
|
}
|