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 Robust.Shared.Serialization.Manager.Attributes;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Content.Server.Destructible;
|
using Content.Server.Destructible;
|
||||||
|
using Content.Shared.Acts;
|
||||||
|
|
||||||
namespace Content.Server.Construction.Completions
|
namespace Content.Server.Construction.Completions
|
||||||
{
|
{
|
||||||
@@ -13,11 +14,7 @@ namespace Content.Server.Construction.Completions
|
|||||||
{
|
{
|
||||||
public void PerformAction(EntityUid uid, EntityUid? userUid, IEntityManager entityManager)
|
public void PerformAction(EntityUid uid, EntityUid? userUid, IEntityManager entityManager)
|
||||||
{
|
{
|
||||||
if (!entityManager.TryGetEntity(uid, out var entity))
|
entityManager.EntitySysManager.GetEntitySystem<ActSystem>().HandleDestruction(uid);
|
||||||
return; // This should never happen, but.
|
|
||||||
|
|
||||||
var destructibleSystem = EntitySystem.Get<DestructibleSystem>();
|
|
||||||
destructibleSystem.ActSystem.HandleDestruction(entity);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ namespace Content.Server.Destructible
|
|||||||
{
|
{
|
||||||
RaiseLocalEvent(uid, new DamageThresholdReached(component, threshold));
|
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")]
|
[DataField("node")]
|
||||||
public string Node { get; private set; } = string.Empty;
|
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;
|
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;
|
return (Acts & act) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Execute(IEntity owner, DestructibleSystem system)
|
public void Execute(EntityUid owner, DestructibleSystem system, IEntityManager entityManager)
|
||||||
{
|
{
|
||||||
if (HasAct(ThresholdActs.Breakage))
|
if (HasAct(ThresholdActs.Breakage))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,11 +10,11 @@ namespace Content.Server.Destructible.Thresholds.Behaviors
|
|||||||
[DataDefinition]
|
[DataDefinition]
|
||||||
public class DumpCanisterBehavior: IThresholdBehavior
|
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]
|
[DataDefinition]
|
||||||
public class EmptyAllContainersBehaviour : IThresholdBehavior
|
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;
|
return;
|
||||||
|
|
||||||
foreach (var container in containerManager.GetAllContainers())
|
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]
|
[DataDefinition]
|
||||||
public class ExplodeBehavior : IThresholdBehavior
|
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;
|
[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);
|
body.Gib(_recursive);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ namespace Content.Server.Destructible.Thresholds.Behaviors
|
|||||||
/// An instance of <see cref="DestructibleSystem"/> to pull dependencies
|
/// An instance of <see cref="DestructibleSystem"/> to pull dependencies
|
||||||
/// and other systems from.
|
/// and other systems from.
|
||||||
/// </param>
|
/// </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>
|
/// </summary>
|
||||||
[DataField("sound", required: true)] public SoundSpecifier Sound { get; set; } = default!;
|
[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));
|
SoundSystem.Play(Filter.Pvs(pos), Sound.GetSound(), pos, AudioHelpers.WithVariation(0.125f));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,8 +19,10 @@ namespace Content.Server.Destructible.Thresholds.Behaviors
|
|||||||
[DataField("spawn")]
|
[DataField("spawn")]
|
||||||
public Dictionary<string, MinMax> Spawn { get; set; } = new();
|
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)
|
foreach (var (entityId, minMax) in Spawn)
|
||||||
{
|
{
|
||||||
var count = minMax.Min >= minMax.Max
|
var count = minMax.Min >= minMax.Max
|
||||||
@@ -31,7 +33,7 @@ namespace Content.Server.Destructible.Thresholds.Behaviors
|
|||||||
|
|
||||||
if (EntityPrototypeHelpers.HasComponent<StackComponent>(entityId))
|
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>();
|
var stack = spawned.GetComponent<StackComponent>();
|
||||||
EntitySystem.Get<StackSystem>().SetCount(spawned.Uid, count, stack);
|
EntitySystem.Get<StackSystem>().SetCount(spawned.Uid, count, stack);
|
||||||
spawned.RandomOffset(0.5f);
|
spawned.RandomOffset(0.5f);
|
||||||
@@ -40,7 +42,7 @@ namespace Content.Server.Destructible.Thresholds.Behaviors
|
|||||||
{
|
{
|
||||||
for (var i = 0; i < count; i++)
|
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);
|
spawned.RandomOffset(0.5f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,21 +20,23 @@ namespace Content.Server.Destructible.Thresholds.Behaviors
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="owner">Entity on which behavior is executed</param>
|
/// <param name="owner">Entity on which behavior is executed</param>
|
||||||
/// <param name="system">system calling the behavior</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 solutionContainerSystem = EntitySystem.Get<SolutionContainerSystem>();
|
||||||
|
|
||||||
|
var coordinates = entityManager.GetComponent<TransformComponent>(owner).Coordinates;
|
||||||
|
|
||||||
if (owner.TryGetComponent(out SpillableComponent? spillableComponent) &&
|
if (entityManager.TryGetComponent(owner, out SpillableComponent? spillableComponent) &&
|
||||||
solutionContainerSystem.TryGetSolution(owner.Uid, spillableComponent.SolutionName,
|
solutionContainerSystem.TryGetSolution(owner, spillableComponent.SolutionName,
|
||||||
out var compSolution))
|
out var compSolution))
|
||||||
{
|
{
|
||||||
compSolution.SpillAt(owner.Transform.Coordinates, "PuddleSmear", false);
|
compSolution.SpillAt(coordinates, "PuddleSmear", false);
|
||||||
}
|
}
|
||||||
else if (Solution != null &&
|
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
|
/// An instance of <see cref="DestructibleSystem"/> to get dependency and
|
||||||
/// system references from, if relevant.
|
/// system references from, if relevant.
|
||||||
/// </param>
|
/// </param>
|
||||||
public void Execute(IEntity owner, DestructibleSystem system)
|
public void Execute(EntityUid owner, DestructibleSystem system, IEntityManager entityManager)
|
||||||
{
|
{
|
||||||
Triggered = true;
|
Triggered = true;
|
||||||
|
|
||||||
foreach (var behavior in Behaviors)
|
foreach (var behavior in Behaviors)
|
||||||
{
|
{
|
||||||
// The owner has been deleted. We stop execution of behaviors here.
|
// The owner has been deleted. We stop execution of behaviors here.
|
||||||
if (owner.Deleted)
|
if (!entityManager.EntityExists(owner))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
behavior.Execute(owner, system);
|
behavior.Execute(owner, system, entityManager);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,12 +19,12 @@ namespace Content.Shared.Acts
|
|||||||
|
|
||||||
public class DestructionEventArgs : EntityEventArgs
|
public class DestructionEventArgs : EntityEventArgs
|
||||||
{
|
{
|
||||||
public IEntity Owner { get; set; } = default!;
|
public EntityUid Owner { get; init; } = default!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class BreakageEventArgs : EventArgs
|
public class BreakageEventArgs : EventArgs
|
||||||
{
|
{
|
||||||
public IEntity Owner { get; set; } = default!;
|
public EntityUid Owner { get; init; } = default!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IBreakAct
|
public interface IBreakAct
|
||||||
@@ -53,21 +53,21 @@ namespace Content.Shared.Acts
|
|||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public sealed class ActSystem : EntitySystem
|
public sealed class ActSystem : EntitySystem
|
||||||
{
|
{
|
||||||
public void HandleDestruction(IEntity owner)
|
public void HandleDestruction(EntityUid owner)
|
||||||
{
|
{
|
||||||
var eventArgs = new DestructionEventArgs
|
var eventArgs = new DestructionEventArgs
|
||||||
{
|
{
|
||||||
Owner = owner
|
Owner = owner
|
||||||
};
|
};
|
||||||
|
|
||||||
var destroyActs = owner.GetAllComponents<IDestroyAct>().ToList();
|
var destroyActs = EntityManager.GetComponents<IDestroyAct>(owner).ToList();
|
||||||
|
|
||||||
foreach (var destroyAct in destroyActs)
|
foreach (var destroyAct in destroyActs)
|
||||||
{
|
{
|
||||||
destroyAct.OnDestroy(eventArgs);
|
destroyAct.OnDestroy(eventArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
owner.QueueDelete();
|
EntityManager.QueueDeleteEntity(owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void HandleExplosion(EntityCoordinates source, IEntity target, ExplosionSeverity severity)
|
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
|
var eventArgs = new BreakageEventArgs
|
||||||
{
|
{
|
||||||
Owner = owner,
|
Owner = owner,
|
||||||
};
|
};
|
||||||
var breakActs = owner.GetAllComponents<IBreakAct>().ToList();
|
var breakActs = EntityManager.GetComponents<IBreakAct>(owner).ToList();
|
||||||
foreach (var breakAct in breakActs)
|
foreach (var breakAct in breakActs)
|
||||||
{
|
{
|
||||||
breakAct.OnBreak(eventArgs);
|
breakAct.OnBreak(eventArgs);
|
||||||
|
|||||||
Reference in New Issue
Block a user