Remove IDestroyAct, IBreakAct (#7876)

This commit is contained in:
Alex Evgrashin
2022-05-03 01:43:25 +03:00
committed by GitHub
parent 5d23100af3
commit 50ae467c76
21 changed files with 135 additions and 151 deletions

View File

@@ -1,5 +1,4 @@
using System.Linq;
using Content.Shared.Acts;
using Content.Shared.Alert;
using Content.Shared.Buckle.Components;
using Content.Shared.DragDrop;
@@ -11,7 +10,7 @@ namespace Content.Server.Buckle.Components
{
[RegisterComponent]
[ComponentReference(typeof(SharedStrapComponent))]
public sealed class StrapComponent : SharedStrapComponent, ISerializationHooks, IDestroyAct
public sealed class StrapComponent : SharedStrapComponent, ISerializationHooks
{
[Dependency] private readonly IEntityManager _entityManager = default!;
@@ -183,12 +182,7 @@ namespace Content.Server.Buckle.Components
RemoveAll();
}
void IDestroyAct.OnDestroy(DestructionEventArgs eventArgs)
{
RemoveAll();
}
private void RemoveAll()
public void RemoveAll()
{
var entManager = IoCManager.Resolve<IEntityManager>();

View File

@@ -1,5 +1,6 @@
using Content.Server.Buckle.Components;
using Content.Server.Interaction;
using Content.Shared.Destructible;
using Content.Shared.Interaction;
using Content.Shared.Storage;
using Content.Shared.Verbs;
@@ -22,6 +23,7 @@ namespace Content.Server.Buckle.Systems
SubscribeLocalEvent<StrapComponent, GetVerbsEvent<InteractionVerb>>(AddStrapVerbs);
SubscribeLocalEvent<StrapComponent, ContainerGettingInsertedAttemptEvent>(OnInsertAttempt);
SubscribeLocalEvent<StrapComponent, InteractHandEvent>(OnInteractHand);
SubscribeLocalEvent<StrapComponent, DestructionEventArgs>(OnDestroy);
}
private void OnInsertAttempt(EntityUid uid, StrapComponent component, ContainerGettingInsertedAttemptEvent args)
@@ -118,5 +120,10 @@ namespace Content.Server.Buckle.Systems
args.Verbs.Add(verb);
}
}
private void OnDestroy(EntityUid uid, StrapComponent component, DestructionEventArgs args)
{
component.RemoveAll();
}
}
}

View File

@@ -4,7 +4,6 @@ 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
{
@@ -14,7 +13,7 @@ namespace Content.Server.Construction.Completions
{
public void PerformAction(EntityUid uid, EntityUid? userUid, IEntityManager entityManager)
{
entityManager.EntitySysManager.GetEntitySystem<ActSystem>().HandleDestruction(uid);
entityManager.EntitySysManager.GetEntitySystem<DestructibleSystem>().DestroyEntity(uid);
}
}
}

View File

@@ -4,7 +4,6 @@ using Content.Server.Destructible.Thresholds.Behaviors;
using Content.Server.Destructible.Thresholds.Triggers;
using Content.Server.Explosion.EntitySystems;
using Content.Server.Stack;
using Content.Shared.Acts;
using Content.Shared.Damage;
using Content.Shared.FixedPoint;
using JetBrains.Annotations;
@@ -12,16 +11,16 @@ using Robust.Server.GameObjects;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using System;
using Content.Shared.Destructible;
namespace Content.Server.Destructible
{
[UsedImplicitly]
public sealed class DestructibleSystem : EntitySystem
public sealed class DestructibleSystem : SharedDestructibleSystem
{
[Dependency] public readonly IRobustRandom Random = default!;
public new IEntityManager EntityManager => base.EntityManager;
[Dependency] public readonly ActSystem ActSystem = default!;
[Dependency] public readonly AudioSystem AudioSystem = default!;
[Dependency] public readonly ConstructionSystem ConstructionSystem = default!;
[Dependency] public readonly ExplosionSystem ExplosionSystem = default!;

View File

@@ -1,9 +1,4 @@
using System;
using Content.Shared.Acts;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Server.Destructible.Thresholds.Behaviors
namespace Content.Server.Destructible.Thresholds.Behaviors
{
[Serializable]
[DataDefinition]
@@ -11,7 +6,6 @@ namespace Content.Server.Destructible.Thresholds.Behaviors
{
/// <summary>
/// What acts should be triggered upon activation.
/// See <see cref="ActSystem"/>.
/// </summary>
[DataField("acts")]
public ThresholdActs Acts { get; set; }
@@ -25,12 +19,12 @@ namespace Content.Server.Destructible.Thresholds.Behaviors
{
if (HasAct(ThresholdActs.Breakage))
{
system.ActSystem.HandleBreakage(owner);
system.BreakEntity(owner);
}
if (HasAct(ThresholdActs.Destruction))
{
system.ActSystem.HandleDestruction(owner);
system.DestroyEntity(owner);
}
}
}

View File

@@ -2,7 +2,6 @@ using System;
using System.Linq;
using Content.Server.Disposal.Unit.Components;
using Content.Server.Disposal.Unit.EntitySystems;
using Content.Shared.Acts;
using Content.Shared.Construction.Components;
using Content.Shared.Disposal.Components;
using Content.Shared.Popups;
@@ -18,7 +17,7 @@ using Robust.Shared.ViewVariables;
namespace Content.Server.Disposal.Tube.Components
{
public abstract class DisposalTubeComponent : Component, IDisposalTubeComponent, IBreakAct
public abstract class DisposalTubeComponent : Component, IDisposalTubeComponent
{
[Dependency] private readonly IEntityManager _entMan = default!;
@@ -73,7 +72,7 @@ namespace Content.Server.Disposal.Tube.Components
return true;
}
private void Disconnect()
public void Disconnect()
{
if (!_connected)
{
@@ -171,10 +170,5 @@ namespace Content.Server.Disposal.Tube.Components
Disconnect();
}
void IBreakAct.OnBreak(BreakageEventArgs eventArgs)
{
Disconnect();
}
}
}

View File

@@ -1,6 +1,7 @@
using Content.Server.Disposal.Tube.Components;
using Content.Server.UserInterface;
using Content.Server.Hands.Components;
using Content.Shared.Destructible;
using Content.Shared.Movement;
using Content.Shared.Verbs;
using Content.Shared.Popups;
@@ -23,6 +24,7 @@ namespace Content.Server.Disposal.Tube
SubscribeLocalEvent<DisposalTubeComponent, PhysicsBodyTypeChangedEvent>(BodyTypeChanged);
SubscribeLocalEvent<DisposalTubeComponent, RelayMovementEntityEvent>(OnRelayMovement);
SubscribeLocalEvent<DisposalTubeComponent, BreakageEventArgs>(OnBreak);
SubscribeLocalEvent<DisposalTaggerComponent, GetVerbsEvent<InteractionVerb>>(AddOpenUIVerbs);
SubscribeLocalEvent<DisposalRouterComponent, GetVerbsEvent<InteractionVerb>>(AddOpenUIVerbs);
SubscribeLocalEvent<DisposalRouterComponent, ActivatableUIOpenAttemptEvent>(OnOpenRouterUIAttempt);
@@ -73,6 +75,11 @@ namespace Content.Server.Disposal.Tube
SoundSystem.Play(Filter.Pvs(uid), component.ClangSound.GetSound(), uid);
}
private void OnBreak(EntityUid uid, DisposalTubeComponent component, BreakageEventArgs args)
{
component.Disconnect();
}
private void OnOpenRouterUIAttempt(EntityUid uid, DisposalRouterComponent router, ActivatableUIOpenAttemptEvent args)
{
if (!TryComp<HandsComponent>(args.User, out var hands))

View File

@@ -10,9 +10,9 @@ using Content.Server.Hands.Components;
using Content.Server.Power.Components;
using Content.Server.UserInterface;
using Content.Shared.ActionBlocker;
using Content.Shared.Acts;
using Content.Shared.Atmos;
using Content.Shared.Construction.Components;
using Content.Shared.Destructible;
using Content.Shared.Disposal;
using Content.Shared.Disposal.Components;
using Content.Shared.DragDrop;

View File

@@ -8,7 +8,6 @@ using Content.Server.Power.Components;
using Content.Server.Temperature.Components;
using Content.Server.Temperature.Systems;
using Content.Server.UserInterface;
using Content.Shared.Acts;
using Content.Shared.Body.Components;
using Content.Shared.Body.Part;
using Content.Shared.FixedPoint;
@@ -26,7 +25,7 @@ using Robust.Shared.Player;
namespace Content.Server.Kitchen.Components
{
[RegisterComponent]
public sealed class MicrowaveComponent : SharedMicrowaveComponent, ISuicideAct, IBreakAct
public sealed class MicrowaveComponent : SharedMicrowaveComponent, ISuicideAct
{
[Dependency] private readonly IEntityManager _entities = default!;
@@ -178,7 +177,7 @@ namespace Content.Server.Kitchen.Components
}
}
private void SetAppearance(MicrowaveVisualState state)
public void SetAppearance(MicrowaveVisualState state)
{
var finalState = state;
if (Broken)
@@ -192,11 +191,6 @@ namespace Content.Server.Kitchen.Components
}
}
public void OnBreak(BreakageEventArgs eventArgs)
{
Broken = true;
SetAppearance(MicrowaveVisualState.Broken);
}
// ReSharper disable once InconsistentNaming
// ReSharper disable once IdentifierTypo
private void Wzhzhzh()

View File

@@ -1,8 +1,10 @@
using Content.Server.Chemistry.EntitySystems;
using Content.Server.Kitchen.Components;
using Content.Server.Popups;
using Content.Shared.Destructible;
using Content.Shared.Interaction;
using Content.Shared.Item;
using Content.Shared.Kitchen.Components;
using Robust.Shared.Player;
using JetBrains.Annotations;
@@ -18,6 +20,7 @@ namespace Content.Server.Kitchen.EntitySystems
SubscribeLocalEvent<MicrowaveComponent, SolutionChangedEvent>(OnSolutionChange);
SubscribeLocalEvent<MicrowaveComponent, InteractUsingEvent>(OnInteractUsing);
SubscribeLocalEvent<MicrowaveComponent, BreakageEventArgs>(OnBreak);
}
private void OnSolutionChange(EntityUid uid, MicrowaveComponent component, SolutionChangedEvent args)
@@ -57,5 +60,11 @@ namespace Content.Server.Kitchen.EntitySystems
component.Storage.Insert(args.Used);
component.DirtyUi();
}
private void OnBreak(EntityUid uid, MicrowaveComponent component, BreakageEventArgs args)
{
component.Broken = true;
component.SetAppearance(MicrowaveVisualState.Broken);
}
}
}

View File

@@ -1,5 +1,4 @@
using Content.Server.Light.EntitySystems;
using Content.Shared.Acts;
using Content.Shared.Light;
using Content.Shared.Sound;
using Robust.Shared.Analyzers;
@@ -13,7 +12,7 @@ namespace Content.Server.Light.Components
/// Component that represents a light bulb. Can be broken, or burned, which turns them mostly useless.
/// </summary>
[RegisterComponent, Friend(typeof(LightBulbSystem))]
public sealed class LightBulbComponent : Component, IBreakAct
public sealed class LightBulbComponent : Component
{
[DataField("color")]
public Color Color = Color.White;
@@ -41,12 +40,5 @@ namespace Content.Server.Light.Components
[DataField("breakSound")]
public SoundSpecifier BreakSound = new SoundCollectionSpecifier("GlassBreak");
// TODO: move me to ECS
public void OnBreak(BreakageEventArgs eventArgs)
{
EntitySystem.Get<LightBulbSystem>()
.SetState(Owner, LightBulbState.Broken, this);
}
}
}

View File

@@ -1,10 +1,8 @@
using Content.Server.Light.Components;
using Content.Server.Light.Events;
using Content.Shared.Destructible;
using Content.Shared.Light;
using Content.Shared.Throwing;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.Maths;
using Robust.Shared.Player;
namespace Content.Server.Light.EntitySystems
@@ -17,6 +15,7 @@ namespace Content.Server.Light.EntitySystems
SubscribeLocalEvent<LightBulbComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<LightBulbComponent, LandEvent>(HandleLand);
SubscribeLocalEvent<LightBulbComponent, BreakageEventArgs>(OnBreak);
}
private void OnInit(EntityUid uid, LightBulbComponent bulb, ComponentInit args)
@@ -32,6 +31,11 @@ namespace Content.Server.Light.EntitySystems
SetState(uid, LightBulbState.Broken, bulb);
}
private void OnBreak(EntityUid uid, LightBulbComponent component, BreakageEventArgs args)
{
SetState(uid, LightBulbState.Broken, component);
}
/// <summary>
/// Set a new color for a light bulb and raise event about change
/// </summary>

View File

@@ -6,9 +6,9 @@ using Content.Server.Popups;
using Content.Server.Power.Components;
using Content.Server.Preferences.Managers;
using Content.Shared.ActionBlocker;
using Content.Shared.Acts;
using Content.Shared.CharacterAppearance.Components;
using Content.Shared.Damage;
using Content.Shared.Destructible;
using Content.Shared.DragDrop;
using Content.Shared.Interaction;
using Content.Shared.MobState.Components;

View File

@@ -5,8 +5,8 @@ using System.Threading.Tasks;
using Content.Server.Construction;
using Content.Server.Construction.Components;
using Content.Server.Ghost.Components;
using Content.Server.Storage.EntitySystems;
using Content.Server.Tools;
using Content.Shared.Acts;
using Content.Shared.Body.Components;
using Content.Shared.Foldable;
using Content.Shared.Interaction;
@@ -29,7 +29,7 @@ namespace Content.Server.Storage.Components
[Virtual]
[ComponentReference(typeof(IActivate))]
[ComponentReference(typeof(IStorageComponent))]
public class EntityStorageComponent : Component, IActivate, IStorageComponent, IInteractUsing, IDestroyAct
public class EntityStorageComponent : Component, IActivate, IStorageComponent, IInteractUsing
{
[Dependency] private readonly IEntityManager _entMan = default!;
@@ -70,7 +70,7 @@ namespace Content.Server.Storage.Components
private bool _occludesLight = true;
[DataField("open")]
private bool _open;
public bool Open;
[DataField("weldingQuality", customTypeSerializer:typeof(PrototypeIdSerializer<ToolQualityPrototype>))]
private string _weldingQuality = "Welding";
@@ -115,13 +115,6 @@ namespace Content.Server.Storage.Components
}
}
[ViewVariables(VVAccess.ReadWrite)]
public bool Open
{
get => _open;
private set => _open = value;
}
[ViewVariables(VVAccess.ReadWrite)]
public bool IsWeldedShut
{
@@ -298,7 +291,7 @@ namespace Content.Server.Storage.Components
protected virtual void OpenStorage()
{
Open = true;
EmptyContents();
EntitySystem.Get<EntityStorageSystem>().EmptyContents(Owner, this);
ModifyComponents();
SoundSystem.Play(Filter.Pvs(Owner), _openSound.GetSound(), Owner);
}
@@ -366,21 +359,6 @@ namespace Content.Server.Storage.Components
return _entMan.GetComponent<TransformComponent>(Owner).WorldPosition;
}
private void EmptyContents()
{
foreach (var contained in Contents.ContainedEntities.ToArray())
{
if (Contents.Remove(contained))
{
_entMan.GetComponent<TransformComponent>(contained).WorldPosition = ContentsDumpPosition();
if (_entMan.TryGetComponent<IPhysBody?>(contained, out var physics))
{
physics.CanCollide = true;
}
}
}
}
public virtual bool TryOpenStorage(EntityUid user)
{
if (!CanOpen(user)) return false;
@@ -473,12 +451,6 @@ namespace Content.Server.Storage.Components
return true;
}
void IDestroyAct.OnDestroy(DestructionEventArgs eventArgs)
{
Open = true;
EmptyContents();
}
protected virtual IEnumerable<EntityUid> DetermineCollidingEntities()
{
var entityLookup = EntitySystem.Get<EntityLookupSystem>();

View File

@@ -0,0 +1,40 @@
using System.Linq;
using Content.Server.Storage.Components;
using Content.Shared.Destructible;
using Robust.Shared.Physics;
namespace Content.Server.Storage.EntitySystems;
public sealed class EntityStorageSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<EntityStorageComponent, DestructionEventArgs>(OnDestroy);
}
private void OnDestroy(EntityUid uid, EntityStorageComponent component, DestructionEventArgs args)
{
component.Open = true;
EmptyContents(uid, component);
}
public void EmptyContents(EntityUid uid, EntityStorageComponent? component = null)
{
if (!Resolve(uid, ref component))
return;
var containedArr = component.Contents.ContainedEntities.ToArray();
foreach (var contained in containedArr)
{
if (component.Contents.Remove(contained))
{
Transform(contained).WorldPosition = component.ContentsDumpPosition();
if (TryComp(contained, out IPhysBody? physics))
{
physics.CanCollide = true;
}
}
}
}
}

View File

@@ -1,6 +1,6 @@
using Content.Server.Popups;
using Content.Server.Storage.Components;
using Content.Shared.Acts;
using Content.Shared.Destructible;
using Content.Shared.Hands.Components;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Item;

View File

@@ -17,7 +17,6 @@ using Robust.Shared.Utility;
using System.Threading;
using Content.Server.DoAfter;
using Content.Server.Interaction;
using Content.Shared.Acts;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Item;
using Content.Shared.Placeable;
@@ -28,6 +27,7 @@ using Robust.Shared.Map;
using Robust.Shared.Player;
using Robust.Server.Containers;
using Content.Server.Popups;
using Content.Shared.Destructible;
using static Content.Shared.Storage.SharedStorageComponent;
namespace Content.Server.Storage.EntitySystems

View File

@@ -9,7 +9,7 @@ using Content.Shared.VendingMachines;
using Robust.Server.GameObjects;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Content.Shared.Acts;
using Content.Shared.Destructible;
using Content.Shared.Emag.Systems;
using static Content.Shared.VendingMachines.SharedVendingMachineComponent;
using Content.Shared.Throwing;

View File

@@ -1,61 +0,0 @@
using System;
using System.Linq;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
namespace Content.Shared.Acts
{
/// <summary>
/// This interface gives components behavior on getting destroyed.
/// </summary>
public interface IDestroyAct
{
/// <summary>
/// Called when object is destroyed
/// </summary>
void OnDestroy(DestructionEventArgs eventArgs);
}
public sealed class DestructionEventArgs : EntityEventArgs { }
public sealed class BreakageEventArgs : EntityEventArgs { }
public interface IBreakAct
{
/// <summary>
/// Called when object is broken
/// </summary>
void OnBreak(BreakageEventArgs eventArgs);
}
[UsedImplicitly]
public sealed class ActSystem : EntitySystem
{
public void HandleDestruction(EntityUid owner)
{
var eventArgs = new DestructionEventArgs();
RaiseLocalEvent(owner, eventArgs, false);
var destroyActs = EntityManager.GetComponents<IDestroyAct>(owner).ToList();
foreach (var destroyAct in destroyActs)
{
destroyAct.OnDestroy(eventArgs);
}
QueueDel(owner);
}
public void HandleBreakage(EntityUid owner)
{
var eventArgs = new BreakageEventArgs();
RaiseLocalEvent(owner, eventArgs, false);
var breakActs = EntityManager.GetComponents<IBreakAct>(owner).ToList();
foreach (var breakAct in breakActs)
{
breakAct.OnBreak(eventArgs);
}
}
}
}

View File

@@ -1,5 +1,4 @@
using Content.Shared.ActionBlocker;
using Content.Shared.Acts;
using Content.Shared.Hands.Components;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Interaction;
@@ -13,6 +12,7 @@ using Robust.Shared.GameStates;
using Robust.Shared.Player;
using Robust.Shared.Timing;
using System.Diagnostics.CodeAnalysis;
using Content.Shared.Destructible;
namespace Content.Shared.Containers.ItemSlots
{

View File

@@ -0,0 +1,40 @@
namespace Content.Shared.Destructible;
public abstract class SharedDestructibleSystem : EntitySystem
{
/// <summary>
/// Force entity to be destroyed and deleted.
/// </summary>
public void DestroyEntity(EntityUid owner)
{
var eventArgs = new DestructionEventArgs();
RaiseLocalEvent(owner, eventArgs, false);
QueueDel(owner);
}
/// <summary>
/// Force entity to broke.
/// </summary>
public void BreakEntity(EntityUid owner)
{
var eventArgs = new BreakageEventArgs();
RaiseLocalEvent(owner, eventArgs, false);
}
}
/// <summary>
/// Raised when entity is destroyed and about to be deleted.
/// </summary>
public sealed class DestructionEventArgs : EntityEventArgs
{
}
/// <summary>
/// Raised when entity was heavy damage and about to break.
/// </summary>
public sealed class BreakageEventArgs : EntityEventArgs
{
}