ActSystem and Destruction Threshold Behaviors use EntityUid.
This commit is contained in:
@@ -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>();
|
||||
destructibleSystem.ActSystem.HandleDestruction(entity);
|
||||
entityManager.EntitySysManager.GetEntitySystem<ActSystem>().HandleDestruction(uid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace Content.Server.Destructible
|
||||
{
|
||||
RaiseLocalEvent(uid, new DamageThresholdReached(component, threshold));
|
||||
|
||||
threshold.Execute(component.Owner, this);
|
||||
threshold.Execute(uid, this, EntityManager);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<ConstructionSystem>().ChangeNode(owner.Uid, null, Node, true, construction);
|
||||
EntitySystem.Get<ConstructionSystem>().ChangeNode(owner, null, Node, true, construction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
{
|
||||
|
||||
@@ -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<GasCanisterSystem>();
|
||||
var gasCanisterSystem = entityManager.EntitySysManager.GetEntitySystem<GasCanisterSystem>();
|
||||
|
||||
gasCanisterSystem.PurgeContents(owner.Uid);
|
||||
gasCanisterSystem.PurgeContents(owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<ContainerManagerComponent>(out var containerManager))
|
||||
if (!entityManager.TryGetComponent<ContainerManagerComponent>(owner, out var containerManager))
|
||||
return;
|
||||
|
||||
foreach (var container in containerManager.GetAllContainers())
|
||||
{
|
||||
container.EmptyContainer(true, owner.Transform.Coordinates);
|
||||
container.EmptyContainer(true, entityManager.GetComponent<TransformComponent>(owner).Coordinates);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace Content.Server.Destructible.Thresholds.Behaviors
|
||||
/// An instance of <see cref="DestructibleSystem"/> to pull dependencies
|
||||
/// and other systems from.
|
||||
/// </param>
|
||||
void Execute(IEntity owner, DestructibleSystem system);
|
||||
/// <param name="entityManager"></param>
|
||||
void Execute(EntityUid owner, DestructibleSystem system, IEntityManager entityManager);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,9 @@ namespace Content.Server.Destructible.Thresholds.Behaviors
|
||||
/// </summary>
|
||||
[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<TransformComponent>(owner).Coordinates;
|
||||
SoundSystem.Play(Filter.Pvs(pos), Sound.GetSound(), pos, AudioHelpers.WithVariation(0.125f));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,10 @@ namespace Content.Server.Destructible.Thresholds.Behaviors
|
||||
[DataField("spawn")]
|
||||
public Dictionary<string, MinMax> Spawn { get; set; } = new();
|
||||
|
||||
public void Execute(IEntity owner, DestructibleSystem system)
|
||||
public void Execute(EntityUid owner, DestructibleSystem system, IEntityManager entityManager)
|
||||
{
|
||||
var position = entityManager.GetComponent<TransformComponent>(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<StackComponent>(entityId))
|
||||
{
|
||||
var spawned = owner.EntityManager.SpawnEntity(entityId, owner.Transform.MapPosition);
|
||||
var spawned = entityManager.SpawnEntity(entityId, position);
|
||||
var stack = spawned.GetComponent<StackComponent>();
|
||||
EntitySystem.Get<StackSystem>().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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,21 +20,23 @@ namespace Content.Server.Destructible.Thresholds.Behaviors
|
||||
/// </summary>
|
||||
/// <param name="owner">Entity on which behavior is executed</param>
|
||||
/// <param name="system">system calling the behavior</param>
|
||||
public void Execute(IEntity owner, DestructibleSystem system)
|
||||
/// <param name="entityManager"></param>
|
||||
public void Execute(EntityUid owner, DestructibleSystem system, IEntityManager entityManager)
|
||||
{
|
||||
var solutionContainerSystem = EntitySystem.Get<SolutionContainerSystem>();
|
||||
|
||||
var coordinates = entityManager.GetComponent<TransformComponent>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,17 +84,17 @@ namespace Content.Server.Destructible.Thresholds
|
||||
/// An instance of <see cref="DestructibleSystem"/> to get dependency and
|
||||
/// system references from, if relevant.
|
||||
/// </param>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<IDestroyAct>().ToList();
|
||||
var destroyActs = EntityManager.GetComponents<IDestroyAct>(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<IBreakAct>().ToList();
|
||||
var breakActs = EntityManager.GetComponents<IBreakAct>(owner).ToList();
|
||||
foreach (var breakAct in breakActs)
|
||||
{
|
||||
breakAct.OnBreak(eventArgs);
|
||||
|
||||
Reference in New Issue
Block a user