diff --git a/Content.Server/Construction/Completions/DestroyEntity.cs b/Content.Server/Construction/Completions/DestroyEntity.cs index 3a2f1cfd4a..a0a17cdfda 100644 --- a/Content.Server/Construction/Completions/DestroyEntity.cs +++ b/Content.Server/Construction/Completions/DestroyEntity.cs @@ -4,6 +4,7 @@ using Robust.Shared.GameObjects; using Robust.Shared.Serialization.Manager.Attributes; using System.Threading.Tasks; using Content.Server.Destructible; +using Content.Shared.Acts; namespace Content.Server.Construction.Completions { @@ -13,11 +14,7 @@ namespace Content.Server.Construction.Completions { public void PerformAction(EntityUid uid, EntityUid? userUid, IEntityManager entityManager) { - if (!entityManager.TryGetEntity(uid, out var entity)) - return; // This should never happen, but. - - var destructibleSystem = EntitySystem.Get(); - destructibleSystem.ActSystem.HandleDestruction(entity); + entityManager.EntitySysManager.GetEntitySystem().HandleDestruction(uid); } } } diff --git a/Content.Server/Destructible/DestructibleSystem.cs b/Content.Server/Destructible/DestructibleSystem.cs index daa139479c..d36575eb45 100644 --- a/Content.Server/Destructible/DestructibleSystem.cs +++ b/Content.Server/Destructible/DestructibleSystem.cs @@ -33,7 +33,7 @@ namespace Content.Server.Destructible { RaiseLocalEvent(uid, new DamageThresholdReached(component, threshold)); - threshold.Execute(component.Owner, this); + threshold.Execute(uid, this, EntityManager); } } } diff --git a/Content.Server/Destructible/Thresholds/Behaviors/ChangeConstructionNodeBehavior.cs b/Content.Server/Destructible/Thresholds/Behaviors/ChangeConstructionNodeBehavior.cs index 7e911bffef..e89e6db630 100644 --- a/Content.Server/Destructible/Thresholds/Behaviors/ChangeConstructionNodeBehavior.cs +++ b/Content.Server/Destructible/Thresholds/Behaviors/ChangeConstructionNodeBehavior.cs @@ -13,12 +13,12 @@ namespace Content.Server.Destructible.Thresholds.Behaviors [DataField("node")] public string Node { get; private set; } = string.Empty; - public void Execute(IEntity owner, DestructibleSystem system) + public void Execute(EntityUid owner, DestructibleSystem system, IEntityManager entityManager) { - if (string.IsNullOrEmpty(Node) || !owner.TryGetComponent(out ConstructionComponent? construction)) + if (string.IsNullOrEmpty(Node) || !entityManager.TryGetComponent(owner, out ConstructionComponent? construction)) return; - EntitySystem.Get().ChangeNode(owner.Uid, null, Node, true, construction); + EntitySystem.Get().ChangeNode(owner, null, Node, true, construction); } } } diff --git a/Content.Server/Destructible/Thresholds/Behaviors/DoActsBehavior.cs b/Content.Server/Destructible/Thresholds/Behaviors/DoActsBehavior.cs index 76472affd1..865c7f5d61 100644 --- a/Content.Server/Destructible/Thresholds/Behaviors/DoActsBehavior.cs +++ b/Content.Server/Destructible/Thresholds/Behaviors/DoActsBehavior.cs @@ -21,7 +21,7 @@ namespace Content.Server.Destructible.Thresholds.Behaviors return (Acts & act) != 0; } - public void Execute(IEntity owner, DestructibleSystem system) + public void Execute(EntityUid owner, DestructibleSystem system, IEntityManager entityManager) { if (HasAct(ThresholdActs.Breakage)) { diff --git a/Content.Server/Destructible/Thresholds/Behaviors/DumpCanisterBehavior.cs b/Content.Server/Destructible/Thresholds/Behaviors/DumpCanisterBehavior.cs index bddfaee046..0036364aaf 100644 --- a/Content.Server/Destructible/Thresholds/Behaviors/DumpCanisterBehavior.cs +++ b/Content.Server/Destructible/Thresholds/Behaviors/DumpCanisterBehavior.cs @@ -10,11 +10,11 @@ namespace Content.Server.Destructible.Thresholds.Behaviors [DataDefinition] public class DumpCanisterBehavior: IThresholdBehavior { - public void Execute(IEntity owner, DestructibleSystem system) + public void Execute(EntityUid owner, DestructibleSystem system, IEntityManager entityManager) { - var gasCanisterSystem = EntitySystem.Get(); + var gasCanisterSystem = entityManager.EntitySysManager.GetEntitySystem(); - gasCanisterSystem.PurgeContents(owner.Uid); + gasCanisterSystem.PurgeContents(owner); } } } diff --git a/Content.Server/Destructible/Thresholds/Behaviors/EmptyAllContainersBehaviour.cs b/Content.Server/Destructible/Thresholds/Behaviors/EmptyAllContainersBehaviour.cs index f62489b985..4b763d2b1d 100644 --- a/Content.Server/Destructible/Thresholds/Behaviors/EmptyAllContainersBehaviour.cs +++ b/Content.Server/Destructible/Thresholds/Behaviors/EmptyAllContainersBehaviour.cs @@ -10,14 +10,14 @@ namespace Content.Server.Destructible.Thresholds.Behaviors [DataDefinition] public class EmptyAllContainersBehaviour : IThresholdBehavior { - public void Execute(IEntity owner, DestructibleSystem system) + public void Execute(EntityUid owner, DestructibleSystem system, IEntityManager entityManager) { - if (owner.Deleted || !owner.TryGetComponent(out var containerManager)) + if (!entityManager.TryGetComponent(owner, out var containerManager)) return; foreach (var container in containerManager.GetAllContainers()) { - container.EmptyContainer(true, owner.Transform.Coordinates); + container.EmptyContainer(true, entityManager.GetComponent(owner).Coordinates); } } } diff --git a/Content.Server/Destructible/Thresholds/Behaviors/ExplodeBehavior.cs b/Content.Server/Destructible/Thresholds/Behaviors/ExplodeBehavior.cs index c77d780a47..1f5c162ceb 100644 --- a/Content.Server/Destructible/Thresholds/Behaviors/ExplodeBehavior.cs +++ b/Content.Server/Destructible/Thresholds/Behaviors/ExplodeBehavior.cs @@ -13,9 +13,9 @@ namespace Content.Server.Destructible.Thresholds.Behaviors [DataDefinition] public class ExplodeBehavior : IThresholdBehavior { - public void Execute(IEntity owner, DestructibleSystem system) + public void Execute(EntityUid owner, DestructibleSystem system, IEntityManager entityManager) { - owner.SpawnExplosion(); + owner.SpawnExplosion(entityManager:entityManager); } } } diff --git a/Content.Server/Destructible/Thresholds/Behaviors/GibBehavior.cs b/Content.Server/Destructible/Thresholds/Behaviors/GibBehavior.cs index 8994cf839e..e7175c9f18 100644 --- a/Content.Server/Destructible/Thresholds/Behaviors/GibBehavior.cs +++ b/Content.Server/Destructible/Thresholds/Behaviors/GibBehavior.cs @@ -11,9 +11,9 @@ namespace Content.Server.Destructible.Thresholds.Behaviors { [DataField("recursive")] private bool _recursive = true; - public void Execute(IEntity owner, DestructibleSystem system) + public void Execute(EntityUid owner, DestructibleSystem system, IEntityManager entityManager) { - if (owner.TryGetComponent(out SharedBodyComponent? body)) + if (entityManager.TryGetComponent(owner, out SharedBodyComponent? body)) { body.Gib(_recursive); } diff --git a/Content.Server/Destructible/Thresholds/Behaviors/IThresholdBehavior.cs b/Content.Server/Destructible/Thresholds/Behaviors/IThresholdBehavior.cs index 057a64f2c5..bde671277d 100644 --- a/Content.Server/Destructible/Thresholds/Behaviors/IThresholdBehavior.cs +++ b/Content.Server/Destructible/Thresholds/Behaviors/IThresholdBehavior.cs @@ -12,6 +12,7 @@ namespace Content.Server.Destructible.Thresholds.Behaviors /// An instance of to pull dependencies /// and other systems from. /// - void Execute(IEntity owner, DestructibleSystem system); + /// + void Execute(EntityUid owner, DestructibleSystem system, IEntityManager entityManager); } } diff --git a/Content.Server/Destructible/Thresholds/Behaviors/PlaySoundBehavior.cs b/Content.Server/Destructible/Thresholds/Behaviors/PlaySoundBehavior.cs index 7847fb8f37..78fd5f07fc 100644 --- a/Content.Server/Destructible/Thresholds/Behaviors/PlaySoundBehavior.cs +++ b/Content.Server/Destructible/Thresholds/Behaviors/PlaySoundBehavior.cs @@ -17,9 +17,9 @@ namespace Content.Server.Destructible.Thresholds.Behaviors /// [DataField("sound", required: true)] public SoundSpecifier Sound { get; set; } = default!; - public void Execute(IEntity owner, DestructibleSystem system) + public void Execute(EntityUid owner, DestructibleSystem system, IEntityManager entityManager) { - var pos = owner.Transform.Coordinates; + var pos = entityManager.GetComponent(owner).Coordinates; SoundSystem.Play(Filter.Pvs(pos), Sound.GetSound(), pos, AudioHelpers.WithVariation(0.125f)); } } diff --git a/Content.Server/Destructible/Thresholds/Behaviors/SpawnEntitiesBehavior.cs b/Content.Server/Destructible/Thresholds/Behaviors/SpawnEntitiesBehavior.cs index dbbbe7ac17..ef2821c12e 100644 --- a/Content.Server/Destructible/Thresholds/Behaviors/SpawnEntitiesBehavior.cs +++ b/Content.Server/Destructible/Thresholds/Behaviors/SpawnEntitiesBehavior.cs @@ -19,8 +19,10 @@ namespace Content.Server.Destructible.Thresholds.Behaviors [DataField("spawn")] public Dictionary Spawn { get; set; } = new(); - public void Execute(IEntity owner, DestructibleSystem system) + public void Execute(EntityUid owner, DestructibleSystem system, IEntityManager entityManager) { + var position = entityManager.GetComponent(owner).MapPosition; + foreach (var (entityId, minMax) in Spawn) { var count = minMax.Min >= minMax.Max @@ -31,7 +33,7 @@ namespace Content.Server.Destructible.Thresholds.Behaviors if (EntityPrototypeHelpers.HasComponent(entityId)) { - var spawned = owner.EntityManager.SpawnEntity(entityId, owner.Transform.MapPosition); + var spawned = entityManager.SpawnEntity(entityId, position); var stack = spawned.GetComponent(); EntitySystem.Get().SetCount(spawned.Uid, count, stack); spawned.RandomOffset(0.5f); @@ -40,7 +42,7 @@ namespace Content.Server.Destructible.Thresholds.Behaviors { for (var i = 0; i < count; i++) { - var spawned = owner.EntityManager.SpawnEntity(entityId, owner.Transform.MapPosition); + var spawned = entityManager.SpawnEntity(entityId, position); spawned.RandomOffset(0.5f); } } diff --git a/Content.Server/Destructible/Thresholds/Behaviors/SpillBehavior.cs b/Content.Server/Destructible/Thresholds/Behaviors/SpillBehavior.cs index d5c8f768f5..758885cc0f 100644 --- a/Content.Server/Destructible/Thresholds/Behaviors/SpillBehavior.cs +++ b/Content.Server/Destructible/Thresholds/Behaviors/SpillBehavior.cs @@ -20,21 +20,23 @@ namespace Content.Server.Destructible.Thresholds.Behaviors /// /// Entity on which behavior is executed /// system calling the behavior - public void Execute(IEntity owner, DestructibleSystem system) + /// + public void Execute(EntityUid owner, DestructibleSystem system, IEntityManager entityManager) { var solutionContainerSystem = EntitySystem.Get(); + var coordinates = entityManager.GetComponent(owner).Coordinates; - if (owner.TryGetComponent(out SpillableComponent? spillableComponent) && - solutionContainerSystem.TryGetSolution(owner.Uid, spillableComponent.SolutionName, + if (entityManager.TryGetComponent(owner, out SpillableComponent? spillableComponent) && + solutionContainerSystem.TryGetSolution(owner, spillableComponent.SolutionName, out var compSolution)) { - compSolution.SpillAt(owner.Transform.Coordinates, "PuddleSmear", false); + compSolution.SpillAt(coordinates, "PuddleSmear", false); } else if (Solution != null && - solutionContainerSystem.TryGetSolution(owner.Uid, Solution, out var behaviorSolution)) + solutionContainerSystem.TryGetSolution(owner, Solution, out var behaviorSolution)) { - behaviorSolution.SpillAt(owner.Transform.Coordinates, "PuddleSmear", false); + behaviorSolution.SpillAt(coordinates, "PuddleSmear", false); } } } diff --git a/Content.Server/Destructible/Thresholds/DamageThreshold.cs b/Content.Server/Destructible/Thresholds/DamageThreshold.cs index 26ce161ba8..770915ae33 100644 --- a/Content.Server/Destructible/Thresholds/DamageThreshold.cs +++ b/Content.Server/Destructible/Thresholds/DamageThreshold.cs @@ -84,17 +84,17 @@ namespace Content.Server.Destructible.Thresholds /// An instance of to get dependency and /// system references from, if relevant. /// - public void Execute(IEntity owner, DestructibleSystem system) + public void Execute(EntityUid owner, DestructibleSystem system, IEntityManager entityManager) { Triggered = true; foreach (var behavior in Behaviors) { // The owner has been deleted. We stop execution of behaviors here. - if (owner.Deleted) + if (!entityManager.EntityExists(owner)) return; - behavior.Execute(owner, system); + behavior.Execute(owner, system, entityManager); } } } diff --git a/Content.Shared/Acts/ActSystem.cs b/Content.Shared/Acts/ActSystem.cs index b54b40ece5..b994835ba1 100644 --- a/Content.Shared/Acts/ActSystem.cs +++ b/Content.Shared/Acts/ActSystem.cs @@ -19,12 +19,12 @@ namespace Content.Shared.Acts public class DestructionEventArgs : EntityEventArgs { - public IEntity Owner { get; set; } = default!; + public EntityUid Owner { get; init; } = default!; } public class BreakageEventArgs : EventArgs { - public IEntity Owner { get; set; } = default!; + public EntityUid Owner { get; init; } = default!; } public interface IBreakAct @@ -53,21 +53,21 @@ namespace Content.Shared.Acts [UsedImplicitly] public sealed class ActSystem : EntitySystem { - public void HandleDestruction(IEntity owner) + public void HandleDestruction(EntityUid owner) { var eventArgs = new DestructionEventArgs { Owner = owner }; - var destroyActs = owner.GetAllComponents().ToList(); + var destroyActs = EntityManager.GetComponents(owner).ToList(); foreach (var destroyAct in destroyActs) { destroyAct.OnDestroy(eventArgs); } - owner.QueueDelete(); + EntityManager.QueueDeleteEntity(owner); } public void HandleExplosion(EntityCoordinates source, IEntity target, ExplosionSeverity severity) @@ -86,13 +86,13 @@ namespace Content.Shared.Acts } } - public void HandleBreakage(IEntity owner) + public void HandleBreakage(EntityUid owner) { var eventArgs = new BreakageEventArgs { Owner = owner, }; - var breakActs = owner.GetAllComponents().ToList(); + var breakActs = EntityManager.GetComponents(owner).ToList(); foreach (var breakAct in breakActs) { breakAct.OnBreak(eventArgs);