Skip to content

Commit b8f0ed3

Browse files
Cleanups PolymorphSystem/Components/Prototypes (space-wizards#23721)
* Cleanups PolymorphSystem * forgot this * Nah * Fix test --------- Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
1 parent c0227bc commit b8f0ed3

File tree

17 files changed

+656
-666
lines changed

17 files changed

+656
-666
lines changed

‎Content.Server/Administration/Commands/AddPolymorphActionCommand.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public void Execute(IConsoleShell shell, string argStr, string[] args)
3232

3333
var polySystem = _entityManager.EntitySysManager.GetEntitySystem<PolymorphSystem>();
3434

35-
_entityManager.EnsureComponent<PolymorphableComponent>(entityUid.Value);
36-
polySystem.CreatePolymorphAction(args[1], entityUid.Value);
35+
var polymorphable = _entityManager.EnsureComponent<PolymorphableComponent>(entityUid.Value);
36+
polySystem.CreatePolymorphAction(args[1], (entityUid.Value, polymorphable));
3737
}
3838
}

‎Content.Server/Chemistry/ReagentEffects/Polymorph.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public sealed partial class Polymorph : ReagentEffect
1818
protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys)
1919
=> Loc.GetString("reagent-effect-guidebook-make-polymorph",
2020
("chance", Probability), ("entityname",
21-
prototype.Index<EntityPrototype>(prototype.Index<PolymorphPrototype>(PolymorphPrototype).Entity).Name));
21+
prototype.Index<EntityPrototype>(prototype.Index<PolymorphPrototype>(PolymorphPrototype).Configuration.Entity).Name));
2222

2323
public override void Effect(ReagentEffectArgs args)
2424
{
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1+
using Content.Server.Polymorph.Systems;
12
using Content.Shared.Polymorph;
23
using Content.Shared.Whitelist;
34
using Robust.Shared.Audio;
4-
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
5+
using Robust.Shared.Prototypes;
56

67
namespace Content.Server.Polymorph.Components;
78

89
[RegisterComponent]
10+
[Access(typeof(PolymorphSystem))]
911
public sealed partial class PolymorphOnCollideComponent : Component
1012
{
11-
[DataField("polymorph", required: true, customTypeSerializer:typeof(PrototypeIdSerializer<PolymorphPrototype>))]
12-
public string Polymorph = default!;
13+
[DataField(required: true)]
14+
public ProtoId<PolymorphPrototype> Polymorph;
1315

14-
[DataField("whitelist", required: true)]
16+
[DataField(required: true)]
1517
public EntityWhitelist Whitelist = default!;
1618

17-
[DataField("blacklist")]
19+
[DataField]
1820
public EntityWhitelist? Blacklist;
1921

22+
[DataField]
2023
public SoundSpecifier Sound = new SoundPathSpecifier("/Audio/Magic/forcewall.ogg");
2124
}
Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1+
using Content.Server.Polymorph.Systems;
12
using Content.Shared.Polymorph;
2-
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
3+
using Robust.Shared.Prototypes;
34

4-
namespace Content.Server.Polymorph.Components
5+
namespace Content.Server.Polymorph.Components;
6+
7+
[RegisterComponent]
8+
[Access(typeof(PolymorphSystem))]
9+
public sealed partial class PolymorphableComponent : Component
510
{
6-
[RegisterComponent]
7-
public sealed partial class PolymorphableComponent : Component
8-
{
9-
/// <summary>
10-
/// A list of all the polymorphs that the entity has.
11-
/// Used to manage them and remove them if needed.
12-
/// </summary>
13-
public Dictionary<string, EntityUid>? PolymorphActions = null;
11+
/// <summary>
12+
/// A list of all the polymorphs that the entity has.
13+
/// Used to manage them and remove them if needed.
14+
/// </summary>
15+
public Dictionary<ProtoId<PolymorphPrototype>, EntityUid>? PolymorphActions = null;
1416

15-
/// <summary>
16-
/// Timestamp for when the most recent polymorph ended.
17-
/// </summary>
18-
[ViewVariables(VVAccess.ReadOnly)]
19-
public TimeSpan? LastPolymorphEnd = null;
17+
/// <summary>
18+
/// Timestamp for when the most recent polymorph ended.
19+
/// </summary>
20+
[ViewVariables(VVAccess.ReadOnly)]
21+
public TimeSpan? LastPolymorphEnd = null;
2022

2123
/// <summary>
22-
/// The polymorphs that the entity starts out being able to do.
23-
/// </summary>
24-
[DataField("innatePolymorphs", customTypeSerializer : typeof(PrototypeIdListSerializer<PolymorphPrototype>))]
25-
public List<string>? InnatePolymorphs;
26-
}
24+
/// The polymorphs that the entity starts out being able to do.
25+
/// </summary>
26+
[DataField]
27+
public List<ProtoId<PolymorphPrototype>>? InnatePolymorphs;
2728
}
Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
1+
using Content.Server.Polymorph.Systems;
12
using Content.Shared.Polymorph;
2-
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
33

4-
namespace Content.Server.Polymorph.Components
4+
namespace Content.Server.Polymorph.Components;
5+
6+
[RegisterComponent]
7+
[Access(typeof(PolymorphSystem))]
8+
public sealed partial class PolymorphedEntityComponent : Component
59
{
6-
[RegisterComponent]
7-
public sealed partial class PolymorphedEntityComponent : Component
8-
{
9-
/// <summary>
10-
/// The polymorph prototype, used to track various information
11-
/// about the polymorph
12-
/// </summary>
13-
[DataField("prototype", required: true, customTypeSerializer:typeof(PrototypeIdSerializer<PolymorphPrototype>))]
14-
public string Prototype = string.Empty;
10+
/// <summary>
11+
/// The polymorph prototype, used to track various information
12+
/// about the polymorph
13+
/// </summary>
14+
[DataField(required: true)]
15+
public PolymorphConfiguration Configuration = new();
1516

16-
/// <summary>
17-
/// The original entity that the player will revert back into
18-
/// </summary>
19-
[DataField("parent", required: true)]
20-
public EntityUid Parent;
17+
/// <summary>
18+
/// The original entity that the player will revert back into
19+
/// </summary>
20+
[DataField(required: true)]
21+
public EntityUid Parent;
2122

22-
/// <summary>
23-
/// The amount of time that has passed since the entity was created
24-
/// used for tracking the duration
25-
/// </summary>
26-
[DataField("time")]
27-
public float Time;
23+
/// <summary>
24+
/// The amount of time that has passed since the entity was created
25+
/// used for tracking the duration
26+
/// </summary>
27+
[DataField]
28+
public float Time;
2829

29-
[DataField] public EntityUid? Action;
30-
}
30+
[DataField]
31+
public EntityUid? Action;
3132
}

‎Content.Server/Polymorph/Systems/PolymorphSystem.Collide.cs‎

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
using Content.Server.Polymorph.Components;
2+
using Content.Shared.Polymorph;
23
using Content.Shared.Projectiles;
34
using Robust.Shared.Audio;
45
using Robust.Shared.Physics.Events;
6+
using Robust.Shared.Prototypes;
57

68
namespace Content.Server.Polymorph.Systems;
79

810
public partial class PolymorphSystem
911
{
10-
// Need to do this so we don't get a collection enumeration error in physics by polymorphing
11-
// an entity we're colliding with
12+
/// <summary>
13+
/// Need to do this so we don't get a collection enumeration error in physics by polymorphing
14+
/// an entity we're colliding with
15+
/// </summary>
1216
private Queue<PolymorphQueuedData> _queuedPolymorphUpdates = new();
1317

18+
private void InitializeCollide()
19+
{
20+
SubscribeLocalEvent<PolymorphOnCollideComponent, StartCollideEvent>(OnPolymorphCollide);
21+
}
22+
1423
public void UpdateCollide()
1524
{
1625
while (_queuedPolymorphUpdates.TryDequeue(out var data))
@@ -20,25 +29,18 @@ public void UpdateCollide()
2029

2130
var ent = PolymorphEntity(data.Ent, data.Polymorph);
2231
if (ent != null)
23-
{
2432
_audio.PlayPvs(data.Sound, ent.Value);
25-
}
2633
}
2734
}
2835

29-
private void InitializeCollide()
30-
{
31-
SubscribeLocalEvent<PolymorphOnCollideComponent, StartCollideEvent>(OnPolymorphCollide);
32-
}
33-
3436
private void OnPolymorphCollide(EntityUid uid, PolymorphOnCollideComponent component, ref StartCollideEvent args)
3537
{
3638
if (args.OurFixtureId != SharedProjectileSystem.ProjectileFixture)
3739
return;
3840

3941
var other = args.OtherEntity;
40-
if (!component.Whitelist.IsValid(other)
41-
|| component.Blacklist != null && component.Blacklist.IsValid(other))
42+
if (!component.Whitelist.IsValid(other, EntityManager)
43+
|| component.Blacklist != null && component.Blacklist.IsValid(other, EntityManager))
4244
return;
4345

4446
_queuedPolymorphUpdates.Enqueue(new (other, component.Sound, component.Polymorph));
@@ -49,9 +51,9 @@ public struct PolymorphQueuedData
4951
{
5052
public EntityUid Ent;
5153
public SoundSpecifier Sound;
52-
public string Polymorph;
54+
public ProtoId<PolymorphPrototype> Polymorph;
5355

54-
public PolymorphQueuedData(EntityUid ent, SoundSpecifier sound, string polymorph)
56+
public PolymorphQueuedData(EntityUid ent, SoundSpecifier sound, ProtoId<PolymorphPrototype> polymorph)
5557
{
5658
Ent = ent;
5759
Sound = sound;
Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,38 @@
11
using Content.Shared.GameTicking;
22

3-
namespace Content.Server.Polymorph.Systems
3+
namespace Content.Server.Polymorph.Systems;
4+
5+
public sealed partial class PolymorphSystem
46
{
5-
public sealed partial class PolymorphSystem
6-
{
7-
public EntityUid? PausedMap { get; private set; }
7+
public EntityUid? PausedMap { get; private set; }
88

9-
/// <summary>
10-
/// Used to subscribe to the round restart event
11-
/// </summary>
12-
private void InitializeMap()
13-
{
14-
SubscribeLocalEvent<RoundRestartCleanupEvent>(OnRoundRestart);
15-
}
9+
/// <summary>
10+
/// Used to subscribe to the round restart event
11+
/// </summary>
12+
private void InitializeMap()
13+
{
14+
SubscribeLocalEvent<RoundRestartCleanupEvent>(OnRoundRestart);
15+
}
1616

17-
private void OnRoundRestart(RoundRestartCleanupEvent _)
18-
{
19-
if (PausedMap == null || !Exists(PausedMap))
20-
return;
17+
private void OnRoundRestart(RoundRestartCleanupEvent _)
18+
{
19+
if (PausedMap == null || !Exists(PausedMap))
20+
return;
2121

22-
EntityManager.DeleteEntity(PausedMap.Value);
23-
}
22+
Del(PausedMap.Value);
23+
}
2424

25-
/// <summary>
26-
/// Used internally to ensure a paused map that is
27-
/// stores polymorphed entities.
28-
/// </summary>
29-
private void EnsurePausesdMap()
30-
{
31-
if (PausedMap != null && Exists(PausedMap))
32-
return;
25+
/// <summary>
26+
/// Used internally to ensure a paused map that is
27+
/// stores polymorphed entities.
28+
/// </summary>
29+
private void EnsurePausedMap()
30+
{
31+
if (PausedMap != null && Exists(PausedMap))
32+
return;
3333

34-
var newmap = _mapManager.CreateMap();
35-
_mapManager.SetMapPaused(newmap, true);
36-
PausedMap = _mapManager.GetMapEntityId(newmap);
37-
}
34+
var newmap = _mapManager.CreateMap();
35+
_mapManager.SetMapPaused(newmap, true);
36+
PausedMap = _mapManager.GetMapEntityId(newmap);
3837
}
3938
}

0 commit comments

Comments
 (0)