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

@@ -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